Python errno.WSAEWOULDBLOCK Examples
The following are 30
code examples of errno.WSAEWOULDBLOCK().
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: udp.py From python-for-android with Apache License 2.0 | 7 votes |
def doRead(self): """ Called when my socket is ready for reading. """ read = 0 while read < self.maxThroughput: try: data, addr = self.socket.recvfrom(self.maxPacketSize) except socket.error, se: no = se.args[0] if no in (EAGAIN, EINTR, EWOULDBLOCK): return if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET): if self._connectedAddr: self.protocol.connectionRefused() else: raise else: read += len(data) try: self.protocol.datagramReceived(data, addr) except: log.err()
Example #2
Source File: tcp.py From learn_python3_spider with MIT License | 6 votes |
def doRead(self): """Calls self.protocol.dataReceived with all available data. This reads up to self.bufferSize bytes of data from its socket, then calls self.dataReceived(data) to process it. If the connection is not lost through an error in the physical recv(), this function will return the result of the dataReceived call. """ try: data = self.socket.recv(self.bufferSize) except socket.error as se: if se.args[0] == EWOULDBLOCK: return else: return main.CONNECTION_LOST return self._dataReceived(data)
Example #3
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 #4
Source File: tcp.py From python-for-android with Apache License 2.0 | 6 votes |
def writeSomeData(self, data): """ Write as much as possible of the given data to this TCP connection. This sends up to C{self.SEND_LIMIT} bytes from C{data}. If the connection is lost, an exception is returned. Otherwise, the number of bytes successfully written is returned. """ try: # Limit length of buffer to try to send, because some OSes are too # stupid to do so themselves (ahem windows) return self.socket.send(buffer(data, 0, self.SEND_LIMIT)) except socket.error, se: if se.args[0] == EINTR: return self.writeSomeData(data) elif se.args[0] in (EWOULDBLOCK, ENOBUFS): return 0 else: return main.CONNECTION_LOST
Example #5
Source File: udp.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def doRead(self): """Called when my socket is ready for reading.""" read = 0 while read < self.maxThroughput: try: data, addr = self.socket.recvfrom(self.maxPacketSize) except socket.error, se: no = se.args[0] if no in (EAGAIN, EINTR, EWOULDBLOCK): return if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET): if self._connectedAddr: self.protocol.connectionRefused() else: raise else: read += len(data) try: self.protocol.datagramReceived(data, addr) except: log.err()
Example #6
Source File: udp.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def doRead(self): """Called when my socket is ready for reading.""" read = 0 while read < self.maxThroughput: try: data, addr = self.socket.recvfrom(self.maxPacketSize) read += len(data) self.protocol.datagramReceived(data) except socket.error, se: no = se.args[0] if no in (EAGAIN, EINTR, EWOULDBLOCK): return if (no == ECONNREFUSED) or (platformType == "win32" and no == WSAECONNRESET): self.protocol.connectionRefused() else: raise except:
Example #7
Source File: tcp.py From learn_python3_spider with MIT License | 6 votes |
def writeSomeData(self, data): """ Write as much as possible of the given data to this TCP connection. This sends up to C{self.SEND_LIMIT} bytes from C{data}. If the connection is lost, an exception is returned. Otherwise, the number of bytes successfully written is returned. """ # Limit length of buffer to try to send, because some OSes are too # stupid to do so themselves (ahem windows) limitedData = lazyByteSlice(data, 0, self.SEND_LIMIT) try: return untilConcludes(self.socket.send, limitedData) except socket.error as se: if se.args[0] in (EWOULDBLOCK, ENOBUFS): return 0 else: return main.CONNECTION_LOST
Example #8
Source File: tcp.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def writeSomeData(self, data): """Connection.writeSomeData(data) -> #of bytes written | CONNECTION_LOST This writes as much data as possible to the socket and returns either the number of bytes read (which is positive) or a connection error code (which is negative) """ try: # Limit length of buffer to try to send, because some OSes are too # stupid to do so themselves (ahem windows) return self.socket.send(buffer(data, 0, self.SEND_LIMIT)) except socket.error, se: if se.args[0] == EINTR: return self.writeSomeData(data) elif se.args[0] in (EWOULDBLOCK, ENOBUFS): return 0 else: return main.CONNECTION_LOST
Example #9
Source File: tcp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def doRead(self): """Calls self.protocol.dataReceived with all available data. This reads up to self.bufferSize bytes of data from its socket, then calls self.dataReceived(data) to process it. If the connection is not lost through an error in the physical recv(), this function will return the result of the dataReceived call. """ try: data = self.socket.recv(self.bufferSize) except socket.error as se: if se.args[0] == EWOULDBLOCK: return else: return main.CONNECTION_LOST return self._dataReceived(data)
Example #10
Source File: tcp.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def writeSomeData(self, data): """ Write as much as possible of the given data to this TCP connection. This sends up to C{self.SEND_LIMIT} bytes from C{data}. If the connection is lost, an exception is returned. Otherwise, the number of bytes successfully written is returned. """ # Limit length of buffer to try to send, because some OSes are too # stupid to do so themselves (ahem windows) limitedData = lazyByteSlice(data, 0, self.SEND_LIMIT) try: return untilConcludes(self.socket.send, limitedData) except socket.error as se: if se.args[0] in (EWOULDBLOCK, ENOBUFS): return 0 else: return main.CONNECTION_LOST
Example #11
Source File: tcp.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def doRead(self): """Calls self.protocol.dataReceived with all available data. This reads up to self.bufferSize bytes of data from its socket, then calls self.dataReceived(data) to process it. If the connection is not lost through an error in the physical recv(), this function will return the result of the dataReceived call. """ try: data = self.socket.recv(self.bufferSize) except socket.error, se: if se.args[0] == EWOULDBLOCK: return else: return main.CONNECTION_LOST
Example #12
Source File: errmgmt.py From Thespian with MIT License | 5 votes |
def err_recv_inprogress(err): return err in [errno.EAGAIN, errno.EWOULDBLOCK, errno.WSAEWOULDBLOCK]
Example #13
Source File: posixbase.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def wakeUp(self): """Send a byte to my connection. """ try: util.untilConcludes(self.w.send, 'x') except socket.error, (err, msg): if err != errno.WSAEWOULDBLOCK: raise
Example #14
Source File: tcp.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _sendCloseAlert(self): # Okay, *THIS* is a bit complicated. # Basically, the issue is, OpenSSL seems to not actually return # errors from SSL_shutdown. Therefore, the only way to # determine if the close notification has been sent is by # SSL_shutdown returning "done". However, it will not claim it's # done until it's both sent *and* received a shutdown notification. # I don't actually want to wait for a received shutdown # notification, though, so, I have to set RECEIVED_SHUTDOWN # before calling shutdown. Then, it'll return True once it's # *SENT* the shutdown. # However, RECEIVED_SHUTDOWN can't be left set, because then # reads will fail, breaking half close. # Also, since shutdown doesn't report errors, an empty write call is # done first, to try to detect if the connection has gone away. # (*NOT* an SSL_write call, because that fails once you've called # shutdown) try: os.write(self.socket.fileno(), '') except OSError, se: if se.args[0] in (EINTR, EWOULDBLOCK, ENOBUFS): return 0 # Write error, socket gone return main.CONNECTION_LOST
Example #15
Source File: asyncore_utils.py From wot-teamspeak-mod with GNU Lesser General Public License v2.1 | 5 votes |
def send(self, data): try: return asynchat.async_chat.send(self, data) except socket.error as err: if err.args[0] == errno.WSAEWOULDBLOCK: return 0 raise
Example #16
Source File: asyncore_utils.py From wot-teamspeak-mod with GNU Lesser General Public License v2.1 | 5 votes |
def connect(self, address): try: self._opened = True return asynchat.async_chat.connect(self, address) except socket.error as err: if err.args[0] == errno.WSAEWOULDBLOCK: self.addr = address return raise
Example #17
Source File: errmgmt.py From Thespian with MIT License | 5 votes |
def err_inprogress(err): return err in [errno.EINPROGRESS, errno.WSAEINVAL, errno.WSAEWOULDBLOCK]
Example #18
Source File: tcp.py From python-for-android with Apache License 2.0 | 5 votes |
def doRead(self): """Calls self.protocol.dataReceived with all available data. This reads up to self.bufferSize bytes of data from its socket, then calls self.dataReceived(data) to process it. If the connection is not lost through an error in the physical recv(), this function will return the result of the dataReceived call. """ try: data = self.socket.recv(self.bufferSize) except socket.error, se: if se.args[0] == EWOULDBLOCK: return else: return main.CONNECTION_LOST
Example #19
Source File: tcp.py From python-for-android with Apache License 2.0 | 5 votes |
def _sendCloseAlert(self): # Okay, *THIS* is a bit complicated. # Basically, the issue is, OpenSSL seems to not actually return # errors from SSL_shutdown. Therefore, the only way to # determine if the close notification has been sent is by # SSL_shutdown returning "done". However, it will not claim it's # done until it's both sent *and* received a shutdown notification. # I don't actually want to wait for a received shutdown # notification, though, so, I have to set RECEIVED_SHUTDOWN # before calling shutdown. Then, it'll return True once it's # *SENT* the shutdown. # However, RECEIVED_SHUTDOWN can't be left set, because then # reads will fail, breaking half close. # Also, since shutdown doesn't report errors, an empty write call is # done first, to try to detect if the connection has gone away. # (*NOT* an SSL_write call, because that fails once you've called # shutdown) try: os.write(self.socket.fileno(), '') except OSError, se: if se.args[0] in (EINTR, EWOULDBLOCK, ENOBUFS): return 0 # Write error, socket gone return main.CONNECTION_LOST
Example #20
Source File: pollbell.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
def read(self, num): try: return self.sr.recv(num) except socket.error as exc: # emulate os.read exception if exc.errno == errno.WSAEWOULDBLOCK: new_exc = OSError() new_exc.errno = errno.EAGAIN raise new_exc else: raise
Example #21
Source File: recipe-578504.py From code with MIT License | 5 votes |
def test_mlistener_nonblocking(self): sock = MultipleSocketsListener([('127.0.0.1', 0), ('::1', 0)]) sock.setblocking(False) try: sock.accept() except socket.error as err: if os.name == 'nt': code = errno.WSAEWOULDBLOCK else: code = errno.EAGAIN self.assertEqual(err.errno, code) else: self.fail('exception not raised')
Example #22
Source File: test_udp_internals.py From learn_python3_spider with MIT License | 5 votes |
def test_connectedReadImmediateError(self): """ If the socket connected, socket reads with an immediate connection refusal are ignored, and reading stops. The protocol's C{connectionRefused} method is called. """ # Add a fake error to the list of those that count as connection # refused: udp._sockErrReadRefuse.append(-6000) self.addCleanup(udp._sockErrReadRefuse.remove, -6000) protocol = KeepReads() refused = [] protocol.connectionRefused = lambda: refused.append(True) port = udp.Port(None, protocol) port.socket = StringUDPSocket([b"a", socket.error(-6000), b"b", socket.error(EWOULDBLOCK)]) port.connect("127.0.0.1", 9999) # Read stops on error: port.doRead() self.assertEqual(protocol.reads, [b"a"]) self.assertEqual(refused, [True]) # Read again: port.doRead() self.assertEqual(protocol.reads, [b"a", b"b"]) self.assertEqual(refused, [True])
Example #23
Source File: test_udp_internals.py From learn_python3_spider with MIT License | 5 votes |
def test_readImmediateError(self): """ If the socket is unconnected, socket reads with an immediate connection refusal are ignored, and reading stops. The protocol's C{connectionRefused} method is not called. """ # Add a fake error to the list of those that count as connection # refused: udp._sockErrReadRefuse.append(-6000) self.addCleanup(udp._sockErrReadRefuse.remove, -6000) protocol = KeepReads() # Fail if connectionRefused is called: protocol.connectionRefused = lambda: 1/0 port = udp.Port(None, protocol) # Try an immediate "connection refused" port.socket = StringUDPSocket([b"a", socket.error(-6000), b"b", socket.error(EWOULDBLOCK)]) port.doRead() # Read stops on error: self.assertEqual(protocol.reads, [b"a"]) # Read again: port.doRead() self.assertEqual(protocol.reads, [b"a", b"b"])
Example #24
Source File: test_socket.py From learn_python3_spider with MIT License | 5 votes |
def test_stopOnlyCloses(self): """ When the L{IListeningPort} returned by L{IReactorSocket.adoptStreamPort} is stopped using C{stopListening}, the underlying socket is closed but not shutdown. This allows another process which still has a reference to it to continue accepting connections over it. """ reactor = self.buildReactor() portSocket = socket.socket() self.addCleanup(portSocket.close) portSocket.bind(("127.0.0.1", 0)) portSocket.listen(1) portSocket.setblocking(False) # The file descriptor is duplicated by adoptStreamPort port = reactor.adoptStreamPort( portSocket.fileno(), portSocket.family, ServerFactory()) d = port.stopListening() def stopped(ignored): # Should still be possible to accept a connection on # portSocket. If it was shutdown, the exception would be # EINVAL instead. exc = self.assertRaises(socket.error, portSocket.accept) if platform.isWindows() and _PY3: self.assertEqual(exc.args[0], errno.WSAEWOULDBLOCK) else: self.assertEqual(exc.args[0], errno.EAGAIN) d.addCallback(stopped) d.addErrback(err, "Failed to accept on original port.") needsRunningReactor( reactor, lambda: d.addCallback(lambda ignored: reactor.stop())) reactor.run()
Example #25
Source File: posixbase.py From learn_python3_spider with MIT License | 5 votes |
def wakeUp(self): """Send a byte to my connection. """ try: util.untilConcludes(self.w.send, b'x') except socket.error as e: if e.args[0] != errno.WSAEWOULDBLOCK: raise
Example #26
Source File: test_udp_internals.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_connectedReadImmediateError(self): """ If the socket connected, socket reads with an immediate connection refusal are ignored, and reading stops. The protocol's C{connectionRefused} method is called. """ # Add a fake error to the list of those that count as connection # refused: udp._sockErrReadRefuse.append(-6000) self.addCleanup(udp._sockErrReadRefuse.remove, -6000) protocol = KeepReads() refused = [] protocol.connectionRefused = lambda: refused.append(True) port = udp.Port(None, protocol) port.socket = StringUDPSocket([b"a", socket.error(-6000), b"b", socket.error(EWOULDBLOCK)]) port.connect("127.0.0.1", 9999) # Read stops on error: port.doRead() self.assertEqual(protocol.reads, [b"a"]) self.assertEqual(refused, [True]) # Read again: port.doRead() self.assertEqual(protocol.reads, [b"a", b"b"]) self.assertEqual(refused, [True])
Example #27
Source File: test_udp_internals.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_readImmediateError(self): """ If the socket is unconnected, socket reads with an immediate connection refusal are ignored, and reading stops. The protocol's C{connectionRefused} method is not called. """ # Add a fake error to the list of those that count as connection # refused: udp._sockErrReadRefuse.append(-6000) self.addCleanup(udp._sockErrReadRefuse.remove, -6000) protocol = KeepReads() # Fail if connectionRefused is called: protocol.connectionRefused = lambda: 1/0 port = udp.Port(None, protocol) # Try an immediate "connection refused" port.socket = StringUDPSocket([b"a", socket.error(-6000), b"b", socket.error(EWOULDBLOCK)]) port.doRead() # Read stops on error: self.assertEqual(protocol.reads, [b"a"]) # Read again: port.doRead() self.assertEqual(protocol.reads, [b"a", b"b"])
Example #28
Source File: test_socket.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def test_stopOnlyCloses(self): """ When the L{IListeningPort} returned by L{IReactorSocket.adoptStreamPort} is stopped using C{stopListening}, the underlying socket is closed but not shutdown. This allows another process which still has a reference to it to continue accepting connections over it. """ reactor = self.buildReactor() portSocket = socket.socket() self.addCleanup(portSocket.close) portSocket.bind(("127.0.0.1", 0)) portSocket.listen(1) portSocket.setblocking(False) # The file descriptor is duplicated by adoptStreamPort port = reactor.adoptStreamPort( portSocket.fileno(), portSocket.family, ServerFactory()) d = port.stopListening() def stopped(ignored): # Should still be possible to accept a connection on # portSocket. If it was shutdown, the exception would be # EINVAL instead. exc = self.assertRaises(socket.error, portSocket.accept) if platform.isWindows() and _PY3: self.assertEqual(exc.args[0], errno.WSAEWOULDBLOCK) else: self.assertEqual(exc.args[0], errno.EAGAIN) d.addCallback(stopped) d.addErrback(err, "Failed to accept on original port.") needsRunningReactor( reactor, lambda: d.addCallback(lambda ignored: reactor.stop())) reactor.run()
Example #29
Source File: posixbase.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def wakeUp(self): """Send a byte to my connection. """ try: util.untilConcludes(self.w.send, b'x') except socket.error as e: if e.args[0] != errno.WSAEWOULDBLOCK: raise
Example #30
Source File: udprelay.py From ssr-ml with Apache License 2.0 | 4 votes |
def _on_remote_read(self): # handle all remote read events self._update_activity() data = None try: data = self._remote_sock.recv(BUF_SIZE) except (OSError, IOError) as e: if eventloop.errno_from_exception(e) in \ (errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK, 10035): #errno.WSAEWOULDBLOCK return if not data: self.destroy() return try: self._server.server_transfer_dl += len(data) recv_data = data beg_pos = 0 max_len = len(recv_data) while beg_pos < max_len: if beg_pos + POST_MTU_MAX >= max_len: split_pos = max_len else: split_pos = beg_pos + self._random_mtu_size[self._random_mtu_index] self._random_mtu_index = (self._random_mtu_index + 1) & 0x3ff #split_pos = beg_pos + random.randint(POST_MTU_MIN, POST_MTU_MAX) data = recv_data[beg_pos:split_pos] beg_pos = split_pos pack_id = self._sendingqueue.append(data) post_data = self._pack_post_data(CMD_POST, pack_id, data) addr = self.get_local_address() self._write_to_sock(post_data, self._local_sock, addr) if pack_id <= DOUBLE_SEND_BEG_IDS: post_data = self._pack_post_data(CMD_POST, pack_id, data) self._write_to_sock(post_data, self._local_sock, addr) except Exception as e: shell.print_exception(e) if self._config['verbose']: traceback.print_exc() # TODO use logging when debug completed self.destroy()