Python errno.EISCONN Examples
The following are 30
code examples of errno.EISCONN().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
errno
, or try the search function
.
Example #1
Source File: asyncadapter.py From plex-for-kodi with GNU General Public License v2.0 | 6 votes |
def _connect(self, sock, sa): while not self._canceled and not ABORT_FLAG_FUNCTION(): time.sleep(0.01) self._check_timeout() # this should be done at the beginning of each loop status = sock.connect_ex(sa) if not status or status in (errno.EISCONN, WIN_EISCONN): break elif status in (errno.EINPROGRESS, WIN_EWOULDBLOCK): self.deadline = time.time() + self._timeout.getConnectTimeout() # elif status in (errno.EWOULDBLOCK, errno.EALREADY) or (os.name == 'nt' and status == errno.WSAEINVAL): # pass yield if self._canceled or ABORT_FLAG_FUNCTION(): raise CanceledException('Request canceled') error = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) if error: # TODO: determine when this case can actually happen raise socket.error((error,))
Example #2
Source File: asyncredis.py From collection with MIT License | 6 votes |
def __init__ (self): self.sock = None # socket object self.send_buf = [] # send buffer self.recv_buf = [] # recv buffer self.pend_buf = '' # send pending self.state = NET_STATE_CLOSED self.errd = [ errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK ] self.conn = ( errno.EISCONN, 10057, 10053 ) self.errc = 0 self.ipv6 = False self.eintr = () if 'EINTR' in errno.__dict__: self.eintr = (errno.__dict__['EINTR'],) if 'WSAEWOULDBLOCK' in errno.__dict__: self.errd.append(errno.WSAEWOULDBLOCK) self.errd = tuple(self.errd) self.timeout = 0 self.timecon = 0
Example #3
Source File: link.py From luscan-devel with GNU General Public License v2.0 | 6 votes |
def connect(self, address): """ Try to make an actual connection. :return: True if connected """ sock = self._connectors[address] err = sock.connect() self.poller.register(sock) self._sock_by_fd[sock.fileno()] = sock self._socks_waiting_to_connect.add(sock) if err in (0, errno.EISCONN): self.handle_connect(sock) return True elif err in (errno.ECONNREFUSED, errno.ENETUNREACH): self.handle_conn_refused(sock) elif err not in (errno.EINPROGRESS, errno.EWOULDBLOCK): raise socket.error(err, errno.errorcode[err]) return False ##########################################################
Example #4
Source File: test_ssl.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_timeout_connect_ex(self): # Issue #12065: on a timeout, connect_ex() should return the original # errno (mimicking the behaviour of non-SSL sockets). with support.transient_internet(REMOTE_HOST): s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_REQUIRED, ca_certs=REMOTE_ROOT_CERT, do_handshake_on_connect=False) try: s.settimeout(0.0000001) rc = s.connect_ex((REMOTE_HOST, 443)) if rc == errno.EISCONN: self.skipTest("REMOTE_HOST responded too quickly") self.assertIn(rc, (errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK)) finally: s.close()
Example #5
Source File: ssl.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def connect_ex(self, addr): """Connects to remote ADDR, and then wraps the connection in an SSL channel.""" if self.server_side: raise ValueError("can't connect in server-side mode") if self._connected: raise ValueError("attempt to connect already-connected SSLSocket!") log.debug("Connect SSL with handshaking %s", self.do_handshake_on_connect, extra={"sock": self._sock}) rc = self._sock.connect_ex(addr) if rc == errno.EISCONN: self._connected = True if self.do_handshake_on_connect: self.do_handshake() return rc
Example #6
Source File: test_ssl.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_timeout_connect_ex(self): # Issue #12065: on a timeout, connect_ex() should return the original # errno (mimicking the behaviour of non-SSL sockets). with support.transient_internet(REMOTE_HOST): s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_REQUIRED, ca_certs=REMOTE_ROOT_CERT, do_handshake_on_connect=False) try: s.settimeout(0.0000001) rc = s.connect_ex((REMOTE_HOST, 443)) if rc == errno.EISCONN: self.skipTest("REMOTE_HOST responded too quickly") self.assertIn(rc, (errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK)) finally: s.close()
Example #7
Source File: ssl.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def connect_ex(self, addr): """Connects to remote ADDR, and then wraps the connection in an SSL channel.""" if self.server_side: raise ValueError("can't connect in server-side mode") if self._connected: raise ValueError("attempt to connect already-connected SSLSocket!") log.debug("Connect SSL with handshaking %s", self.do_handshake_on_connect, extra={"sock": self._sock}) rc = self._sock.connect_ex(addr) if rc == errno.EISCONN: self._connected = True if self.do_handshake_on_connect: self.do_handshake() return rc
Example #8
Source File: ssl.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def connect_ex(self, addr): """Connects to remote ADDR, and then wraps the connection in an SSL channel.""" if self.server_side: raise ValueError("can't connect in server-side mode") if self._connected: raise ValueError("attempt to connect already-connected SSLSocket!") log.debug("Connect SSL with handshaking %s", self.do_handshake_on_connect, extra={"sock": self._sock}) rc = self._sock.connect_ex(addr) if rc == errno.EISCONN: self._connected = True if self.do_handshake_on_connect: self.do_handshake() return rc
Example #9
Source File: ssl.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def connect_ex(self, addr): """Connects to remote ADDR, and then wraps the connection in an SSL channel.""" if self.server_side: raise ValueError("can't connect in server-side mode") if self._connected: raise ValueError("attempt to connect already-connected SSLSocket!") log.debug("Connect SSL with handshaking %s", self.do_handshake_on_connect, extra={"sock": self._sock}) rc = self._sock.connect_ex(addr) if rc == errno.EISCONN: self._connected = True if self.do_handshake_on_connect: self.do_handshake() return rc
Example #10
Source File: test_select_new.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def start_connect(self): result = self.socket.connect_ex(self.server_addr) if result == errno.EISCONN: self.connected = True else: assert result in [errno.EINPROGRESS, errno.ENOTCONN], \ "connect_ex returned %s (%s)" % (result, errno.errorcode.get(result, "Unknown errno"))
Example #11
Source File: test_socket_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def do_nonblocking_connection(self, results, index): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(0) connect_errno = 0 connect_attempt = 0 sock = ssl.wrap_socket(sock, certfile=CERTFILE, do_handshake_on_connect=True) while connect_errno != errno.EISCONN and connect_attempt < 10000: connect_attempt += 1 connect_errno = sock.connect_ex(self.address) results[index].append(connect_errno) time.sleep(0.01) sock.close()
Example #12
Source File: test_socket_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_connect_ex_workout(self): """Verify connect_ex states go through EINPROGRESS?, EALREADY*, EISCONN""" # Tests fix for http://bugs.jython.org/issue2428; based in part on the # code showing failure that was submitted with that bug for result in self.do_workout(): self.assertIn(result[0], {errno.EINPROGRESS, errno.EISCONN}) self.assertEqual(result[-1], errno.EISCONN) for code in result[1:-1]: self.assertEqual(code, errno.EALREADY)
Example #13
Source File: _socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def connect_ex(self, addr): was_connecting = self.connected # actually means self.connecting if # not blocking if not self.connected: try: self.connect(addr) except error as e: return e.errno if not self.connect_future.isDone(): if was_connecting: try: # Timing is based on CPython and was empirically # guesstimated. Of course this means user code is # polling, so the the best we can do is wait like # this in supposedly nonblocking mode without # completely busy waiting! self.connect_future.get(1500, TimeUnit.MICROSECONDS) except ExecutionException: # generally raised if closed; pick up the state # when testing for success pass except TimeoutException: # more than 1.5ms, will report EALREADY below pass if not self.connect_future.isDone(): if was_connecting: return errno.EALREADY else: return errno.EINPROGRESS elif self.connect_future.isSuccess(): # from socketmodule.c # if (res == EISCONN) # res = 0; # but http://bugs.jython.org/issue2428 return errno.EISCONN else: return errno.ENOTCONN # SERVER METHODS # Calling listen means this is a server socket
Example #14
Source File: _socket.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def connect_ex(self, addr): was_connecting = self.connected # actually means self.connecting if # not blocking if not self.connected: try: self.connect(addr) except error as e: return e.errno if not self.connect_future.isDone(): if was_connecting: try: # Timing is based on CPython and was empirically # guesstimated. Of course this means user code is # polling, so the the best we can do is wait like # this in supposedly nonblocking mode without # completely busy waiting! self.connect_future.get(1500, TimeUnit.MICROSECONDS) except ExecutionException: # generally raised if closed; pick up the state # when testing for success pass except TimeoutException: # more than 1.5ms, will report EALREADY below pass if not self.connect_future.isDone(): if was_connecting: return errno.EALREADY else: return errno.EINPROGRESS elif self.connect_future.isSuccess(): # from socketmodule.c # if (res == EISCONN) # res = 0; # but http://bugs.jython.org/issue2428 return errno.EISCONN else: return errno.ENOTCONN # SERVER METHODS # Calling listen means this is a server socket
Example #15
Source File: test_select_new.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def start_connect(self): result = self.socket.connect_ex(self.server_addr) if result == errno.EISCONN: self.connected = True else: assert result in [errno.EINPROGRESS, errno.ENOTCONN], \ "connect_ex returned %s (%s)" % (result, errno.errorcode.get(result, "Unknown errno"))
Example #16
Source File: test_socket_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def do_nonblocking_connection(self, results, index): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(0) connect_errno = 0 connect_attempt = 0 while connect_errno != errno.EISCONN and connect_attempt < 10000: connect_attempt += 1 connect_errno = sock.connect_ex(self.address) results[index].append(connect_errno) time.sleep(0.01) sock.close()
Example #17
Source File: test_socket_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_connect_ex_workout(self): """Verify connect_ex states go through EINPROGRESS?, EALREADY*, EISCONN""" # Tests fix for http://bugs.jython.org/issue2428; based in part on the # code showing failure that was submitted with that bug for result in self.do_workout(): self.assertIn(result[0], {errno.EINPROGRESS, errno.EISCONN}) self.assertEqual(result[-1], errno.EISCONN) for code in result[1:-1]: self.assertEqual(code, errno.EALREADY)
Example #18
Source File: test_socket_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def do_nonblocking_connection(self, results, index): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(0) connect_errno = 0 connect_attempt = 0 sock = ssl.wrap_socket(sock, certfile=CERTFILE, do_handshake_on_connect=True) while connect_errno != errno.EISCONN and connect_attempt < 10000: connect_attempt += 1 connect_errno = sock.connect_ex(self.address) results[index].append(connect_errno) time.sleep(0.01) sock.close()
Example #19
Source File: test_socket_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_connect_ex_workout(self): """Verify connect_ex states go through EINPROGRESS?, EALREADY*, EISCONN""" # Tests fix for http://bugs.jython.org/issue2428; based in part on the # code showing failure that was submitted with that bug for result in self.do_workout(): self.assertIn(result[0], {errno.EINPROGRESS, errno.EISCONN}) self.assertEqual(result[-1], errno.EISCONN) for code in result[1:-1]: self.assertEqual(code, errno.EALREADY)
Example #20
Source File: test_socket_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_connect_ex_workout(self): """Verify connect_ex states go through EINPROGRESS?, EALREADY*, EISCONN""" # Tests fix for http://bugs.jython.org/issue2428; based in part on the # code showing failure that was submitted with that bug for result in self.do_workout(): self.assertIn(result[0], {errno.EINPROGRESS, errno.EISCONN}) self.assertEqual(result[-1], errno.EISCONN) for code in result[1:-1]: self.assertEqual(code, errno.EALREADY)
Example #21
Source File: test_socket_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def do_nonblocking_connection(self, results, index): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setblocking(0) connect_errno = 0 connect_attempt = 0 while connect_errno != errno.EISCONN and connect_attempt < 10000: connect_attempt += 1 connect_errno = sock.connect_ex(self.address) results[index].append(connect_errno) time.sleep(0.01) sock.close()
Example #22
Source File: _socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def connect_ex(self, addr): was_connecting = self.connected # actually means self.connecting if # not blocking if not self.connected: try: self.connect(addr) except error as e: return e.errno if not self.connect_future.isDone(): if was_connecting: try: # Timing is based on CPython and was empirically # guesstimated. Of course this means user code is # polling, so the the best we can do is wait like # this in supposedly nonblocking mode without # completely busy waiting! self.connect_future.get(1500, TimeUnit.MICROSECONDS) except ExecutionException: # generally raised if closed; pick up the state # when testing for success pass except TimeoutException: # more than 1.5ms, will report EALREADY below pass if not self.connect_future.isDone(): if was_connecting: return errno.EALREADY else: return errno.EINPROGRESS elif self.connect_future.isSuccess(): # from socketmodule.c # if (res == EISCONN) # res = 0; # but http://bugs.jython.org/issue2428 return errno.EISCONN else: return errno.ENOTCONN # SERVER METHODS # Calling listen means this is a server socket
Example #23
Source File: _socket.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def connect_ex(self, addr): was_connecting = self.connected # actually means self.connecting if # not blocking if not self.connected: try: self.connect(addr) except error as e: return e.errno if not self.connect_future.isDone(): if was_connecting: try: # Timing is based on CPython and was empirically # guesstimated. Of course this means user code is # polling, so the the best we can do is wait like # this in supposedly nonblocking mode without # completely busy waiting! self.connect_future.get(1500, TimeUnit.MICROSECONDS) except ExecutionException: # generally raised if closed; pick up the state # when testing for success pass except TimeoutException: # more than 1.5ms, will report EALREADY below pass if not self.connect_future.isDone(): if was_connecting: return errno.EALREADY else: return errno.EINPROGRESS elif self.connect_future.isSuccess(): # from socketmodule.c # if (res == EISCONN) # res = 0; # but http://bugs.jython.org/issue2428 return errno.EISCONN else: return errno.ENOTCONN # SERVER METHODS # Calling listen means this is a server socket
Example #24
Source File: test_select_new.py From medicare-demo with Apache License 2.0 | 5 votes |
def start_connect(self): result = self.socket.connect_ex(SERVER_ADDRESS) if result == errno.EISCONN: self.connected = 1 else: assert result == errno.EINPROGRESS
Example #25
Source File: socket.py From medicare-demo with Apache License 2.0 | 5 votes |
def connect_ex(self, addr): "This signifies a client socket" if not self.sock_impl: self._do_connect(addr) if self.sock_impl.finish_connect(): self._setup() if self.mode == MODE_NONBLOCKING: return errno.EISCONN return 0 return errno.EINPROGRESS
Example #26
Source File: TimeoutSocket.py From p2pool-n with GNU General Public License v3.0 | 5 votes |
def connect(self, *addr): timeout = self.timeout sock = self.sock try: # Non-blocking mode sock.setblocking(0) apply(sock.connect, addr) sock.setblocking(timeout != 0) return 1 except socket.error,why: if not timeout: raise sock.setblocking(1) if len(why.args) == 1: code = 0 else: code, why = why if code not in ( errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK ): raise r,w,e = select.select([],[sock],[],timeout) if w: try: apply(sock.connect, addr) return 1 except socket.error,why: if len(why.args) == 1: code = 0 else: code, why = why if code in (errno.EISCONN, WSAEINVAL): return 1 raise
Example #27
Source File: _remote_socket.py From python-compat-runtime with Apache License 2.0 | 5 votes |
def connect(self, address, _hostname_hint=None): """connect(address) Connect the socket to a remote address. For IP sockets, the address is a pair (host, port). """ if not self._created: if self.gettimeout() is None: self._CreateSocket(address=address, address_hostname_hint=_hostname_hint) return else: self._CreateSocket() if not self._socket_descriptor: raise error(errno.EBADF, os.strerror(errno.EBADF)) if self._connected: raise error(errno.EISCONN, os.strerror(errno.EISCONN)) request = remote_socket_service_pb.ConnectRequest() request.set_socket_descriptor(self._socket_descriptor) self._SetProtoFromAddr(request.mutable_remote_ip(), address, _hostname_hint) if self.gettimeout() is not None: request.set_timeout_seconds(self.gettimeout()) reply = remote_socket_service_pb.ConnectReply() try: apiproxy_stub_map.MakeSyncCall('remote_socket', 'Connect', request, reply) except apiproxy_errors.ApplicationError, e: translated_e = _SystemExceptionFromAppError(e) if translated_e.errno == errno.EISCONN: self._bound = True self._connected = True elif translated_e.errno == errno.EINPROGRESS: self._connect_in_progress = True raise translated_e
Example #28
Source File: tco.py From nfcpy with European Union Public License 1.1 | 4 votes |
def connect(self, dest): with self.lock: if not self.state.CLOSED: self.err("connect() in socket state {0}".format(self.state)) if self.state.ESTABLISHED: raise err.Error(errno.EISCONN) if self.state.CONNECT: raise err.Error(errno.EALREADY) raise err.Error(errno.EPIPE) if isinstance(dest, (bytes, bytearray)): send_pdu = pdu.Connect(1, self.addr, self.recv_miu, self.recv_win, bytes(dest)) elif isinstance(dest, str): send_pdu = pdu.Connect(1, self.addr, self.recv_miu, self.recv_win, dest.encode('latin')) elif isinstance(dest, int): send_pdu = pdu.Connect(dest, self.addr, self.recv_miu, self.recv_win) else: raise TypeError("connect destination must be int or bytes") self.state.CONNECT = True self.send_queue.append(send_pdu) try: rcvd_pdu = super(DataLinkConnection, self).recv() except IndexError: raise err.Error(errno.EPIPE) if rcvd_pdu.name == "DM": logstr = "connect rejected with reason {}" self.log(logstr.format(rcvd_pdu.reason)) self.state.CLOSED = True raise err.ConnectRefused(rcvd_pdu.reason) elif rcvd_pdu.name == "CC": self.peer = rcvd_pdu.ssap self.recv_buf = self.recv_win self.send_miu = rcvd_pdu.miu self.send_win = rcvd_pdu.rw self.state.ESTABLISHED = True return else: # pragma: no cover raise RuntimeError("CC or DM expected, not " + rcvd_pdu.name)
Example #29
Source File: _remote_socket.py From python-compat-runtime with Apache License 2.0 | 4 votes |
def sendto(self, data, *args): """sendto(data[, flags], address) -> count Like send(data, flags) but allows specifying the destination address. For IP sockets, the address is a pair (hostaddr, port). """ if len(args) == 1: flags, address = 0, args[0] elif len(args) == 2: flags, address = args if not self._created: self._CreateSocket() if not self._socket_descriptor: raise error(errno.EBADF, os.strerror(errno.EBADF)) if self._shutdown_write: raise error(errno.EPIPE, os.strerror(errno.EPIPE)) request = remote_socket_service_pb.SendRequest() request.set_socket_descriptor(self._socket_descriptor) if len(data) > 512*1024: request.set_data(data[:512*1024]) else: request.set_data(data) request.set_flags(flags) request.set_stream_offset(self._stream_offset) if address: if self._connected: raise error(errno.EISCONN, os.strerror(errno.EISCONN)) if self.type != SOCK_DGRAM: raise error(errno.ENOTCONN, os.strerror(errno.ENOTCONN)) self._SetProtoFromAddr(request.mutable_send_to(), address) else: if not (self._connected or self._connect_in_progress): raise error(errno.ENOTCONN, os.strerror(errno.ENOTCONN)) if self.gettimeout() is not None: request.set_timeout_seconds(self.gettimeout()) reply = remote_socket_service_pb.SendReply() try: apiproxy_stub_map.MakeSyncCall('remote_socket', 'Send', request, reply) except apiproxy_errors.ApplicationError, e: raise _SystemExceptionFromAppError(e)
Example #30
Source File: tcp.py From learn_python3_spider with MIT License | 4 votes |
def doConnect(self): """ Initiate the outgoing connection attempt. @note: Applications do not need to call this method; it will be invoked internally as part of L{IReactorTCP.connectTCP}. """ self.doWrite = self.doConnect self.doRead = self.doConnect if not hasattr(self, "connector"): # this happens when connection failed but doConnect # was scheduled via a callLater in self._finishInit return err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) if err: self.failIfNotConnected(error.getConnectError((err, strerror(err)))) return # doConnect gets called twice. The first time we actually need to # start the connection attempt. The second time we don't really # want to (SO_ERROR above will have taken care of any errors, and if # it reported none, the mere fact that doConnect was called again is # sufficient to indicate that the connection has succeeded), but it # is not /particularly/ detrimental to do so. This should get # cleaned up some day, though. try: connectResult = self.socket.connect_ex(self.realAddress) except socket.error as se: connectResult = se.args[0] if connectResult: if connectResult == EISCONN: pass # on Windows EINVAL means sometimes that we should keep trying: # http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/connect_2.asp elif ((connectResult in (EWOULDBLOCK, EINPROGRESS, EALREADY)) or (connectResult == EINVAL and platformType == "win32")): self.startReading() self.startWriting() return else: self.failIfNotConnected(error.getConnectError((connectResult, strerror(connectResult)))) return # If I have reached this point without raising or returning, that means # that the socket is connected. del self.doWrite del self.doRead # we first stop and then start, to reset any references to the old doRead self.stopReading() self.stopWriting() self._connectDone()