How to use the eventlet.green.socket.socket function in eventlet

To help you get started, we’ve selected a few eventlet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eventlet / eventlet / tests / test__socket_errors.py View on Github external
def test_connection_refused(self):
        # open and close a dummy server to find an unused port
        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        server.bind(('127.0.0.1', 0))
        server.listen(1)
        port = server.getsockname()[1]
        server.close()
        del server
        s = socket.socket()
        try:
            s.connect(('127.0.0.1', port))
            self.fail("Shouldn't have connected")
        except socket.error as ex:
            code, text = ex.args
            assert code in [111, 61, 10061], (code, text)
            assert 'refused' in text.lower(), (code, text)
github Node-DC / Node-DC-EIS / Node-DC-EIS-client / node_dc_eis_testurls.py View on Github external
query = ''
  if urlo.query != '':
    query = '?{}'.format(urlo.query)

  req_path = '{}{}'.format(urlo.path, query)

  req = '''GET {} HTTP/1.1
Host: {}
User-Agent: runspec/0.9
Accept: {}

'''.format(req_path, urlo.netloc, accept_header)

  try:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.settimeout(30)
    sock.connect((ip, urlo.port))
    sock.sendall(req)
    while len(data) < 15:
      data += sock.recv(15)
    http_status = data[9:12]
    if http_status[0] != '3' or http_status[0] != '2':
      http_err += 1

  except socket.timeout:
    timeout_err += 1 
  except socket.error as e:
    conn_err += 1
  finally:
    sock.close()
    end = time.time()
github rdw / Eventlet / tests / test_timeout.py View on Github external
def setUp(self):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.addr_remote = ('www.python.org.', 80)
        self.addr_local  = ('127.0.0.1', 25339)
github oracle / solaris-userland / components / openstack / cinder / files / solaris / zfs.py View on Github external
try:
            src_rc = self._get_rc_connect()
            dst_rc = self._get_rc_connect(dst_san_info)

            src_pat = self._get_zfs_volume_name(src['name'])
            src_vol_obj = src_rc.get_object(zfsmgr.ZfsDataset(),
                                            radc.ADRGlobPattern({"name":
                                                                src_pat}))
            dst_pat = dst.rsplit('/', 1)[0]
            dst_vol_obj = dst_rc.get_object(zfsmgr.ZfsDataset(),
                                            radc.ADRGlobPattern({"name":
                                                                dst_pat}))

            send_sock_info = src_vol_obj.get_send_socket(
                name=src_snapshot_name, socket_type=zfsmgr.SocketType.AF_INET)
            send_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            send_sock.connect((self.hostname, int(send_sock_info.socket)))

            dst_san_ip = dst_san_info.split(';')[0]
            remote_host, alias, addresslist = socket.gethostbyaddr(dst_san_ip)

            recv_sock_info = dst_vol_obj.get_receive_socket(
                name=dst, socket_type=zfsmgr.SocketType.AF_INET,
                name_options=zfsmgr.ZfsRecvNameOptions.use_provided_name)
            recv_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            recv_sock.connect((remote_host, int(recv_sock_info.socket)))

            # Set 4mb buffer size
            buf_size = 4194304
            while True:
                # Read the data from the send stream
                buf = send_sock.recv(buf_size)
github zerovm / zerocloud / zerocloud / proxyquery.py View on Github external
def _get_local_address(node):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect((node['ip'], node['port']))
    result = s.getsockname()[0]
    s.shutdown(socket.SHUT_RDWR)
    s.close()
    return result
github sorgloomer / websocket_terminal / server-python3 / server.py View on Github external
def create_binary(self):
        if self.kind == 'ssh':
            from wspty.SshTerminal import SshTerminal
            return SshTerminal(
                self.hostname, self.port, self.username, self.password, self.term
            )
        if self.kind == 'raw':
            from wspty.SocketTerminal import SocketTerminal
            sock = eventlet.green.socket.socket()
            ip = eventlet.green.socket.gethostbyname(self.hostname)
            sock.connect((ip, self.port))
            return SocketTerminal(sock)
        if self.kind == 'echo':
            return EchoTerminal()
        if self.kind == 'prompt':
            if not self.allow_unsafe:
                raise Exception("kind {} is disabled".format(self.kind))
            from wspty import PromptTerminal
            return PromptTerminal.os_terminal()
        raise NotImplemented('kind: {}'.format(self.kind))
github openstack / oslo.service / oslo_service / eventlet_backdoor.py View on Github external
def _listen_func(host, port):
    # eventlet is setting SO_REUSEPORT by default from v0.20.
    # But we can configure it by passing reuse_port argument
    # from v0.22
    try:
        return eventlet.listen((host, port), reuse_port=False)
    except TypeError:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.bind((host, port))
        sock.listen(50)
        return sock
github DeadWisdom / Minister / minister / fastcgi.py View on Github external
def _getConnection(self):
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect(self.address)
        return sock
github tamiel / fshttpstream / src / fshttpstream / fsconnector.py View on Github external
def connect(self):
        self.log.info("fsconnector - connecting to %s %s" % (self.password, str(self.addr)))
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.settimeout(20.0)
        timer = eventlet.timeout.Timeout(20.0)
        try:
            self.sock.connect(self.addr)
            data = self.sock.recv(1024)
            if not self.__command('auth %s' % self.password):
                self.sock.close()
                self.log.error("fsconnector - auth failure")
                return False
            self.log.info("fsconnector - auth success")
            res = self.__set_filter()
            if res:
                self.log.info("fsconnector - connected")
                self.running = True
                return res
        except eventlet.timeout.Timeout, te: