Python errno.ENOBUFS Examples
The following are 29
code examples of errno.ENOBUFS().
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: sendfdport.py From ccs-twistedextensions with Apache License 2.0 | 6 votes |
def doWrite(self, sendfd=sendfd): """ Transmit as many queued pending file descriptors as we can. """ while self.outgoingSocketQueue: skt, desc = self.outgoingSocketQueue.pop(0) try: sendfd(self.outSocket.fileno(), skt.fileno(), desc) except SocketError, se: if se.errno in (EAGAIN, ENOBUFS): self.outgoingSocketQueue.insert(0, (skt, desc)) return raise # Ready to close this socket; wait until it is acknowledged. self.pendingCloseSocketQueue.append(skt)
Example #2
Source File: test_socket.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _testCongestion(self): # test the behavior in case of congestion self.data = b'fill' self.cli.setblocking(False) try: # try to lower the receiver's socket buffer size self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 16384) except OSError: pass with self.assertRaises(OSError) as cm: try: # fill the receiver's socket buffer while True: self.cli.sendto(self.data, 0, (HOST, self.port)) finally: # signal the receiver we're done self.evt.set() # sendto() should have failed with ENOBUFS self.assertEqual(cm.exception.errno, errno.ENOBUFS) # and we should have received a congestion notification through poll r, w, x = select.select([self.serv], [], [], 3.0) self.assertIn(self.serv, r)
Example #3
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 #4
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 #5
Source File: test_socket.py From ironpython3 with Apache License 2.0 | 6 votes |
def _testCongestion(self): # test the behavior in case of congestion self.data = b'fill' self.cli.setblocking(False) try: # try to lower the receiver's socket buffer size self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 16384) except OSError: pass with self.assertRaises(OSError) as cm: try: # fill the receiver's socket buffer while True: self.cli.sendto(self.data, 0, (HOST, self.port)) finally: # signal the receiver we're done self.evt.set() # sendto() should have failed with ENOBUFS self.assertEqual(cm.exception.errno, errno.ENOBUFS) # and we should have received a congestion notification through poll r, w, x = select.select([self.serv], [], [], 3.0) self.assertIn(self.serv, r)
Example #6
Source File: test_socket.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def _testCongestion(self): # test the behavior in case of congestion self.data = b'fill' self.cli.setblocking(False) try: # try to lower the receiver's socket buffer size self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 16384) except OSError: pass with self.assertRaises(OSError) as cm: try: # fill the receiver's socket buffer while True: self.cli.sendto(self.data, 0, (HOST, self.port)) finally: # signal the receiver we're done self.evt.set() # sendto() should have failed with ENOBUFS self.assertEqual(cm.exception.errno, errno.ENOBUFS) # and we should have received a congestion notification through poll r, w, x = select.select([self.serv], [], [], 3.0) self.assertIn(self.serv, r)
Example #7
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 #8
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 #9
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 #10
Source File: vxrd.py From vxfld with GNU General Public License v2.0 | 5 votes |
def __initialize_db(self): """ Initializes the RD's database and binds the netlink socket. Also invoked when socket.recv returns ENOBUFS to rebind the netlink socket. """ if self.__nlmonitor.socket is not None: self._logger.info('Rebinding netlink socket') self.__nlmonitor.bind() self._pool.spawn_n(self._serve, self.__nlmonitor.socket, self.__nlmonitor.handle_netlink_msg, bufsize=netlink.Netlink.NLSOCK_BYTES, err_cbs={errno.ENOBUFS: self.__initialize_db}) old, self.__vni_config = self.__vni_config, None while self.__vni_config is None: self.__vni_config = self.__get_vxlan_config() if old and old != self.__vni_config: removed = {vni: vni_config for vni, vni_config in old.iteritems() if vni not in self.__vni_config} self.__remove_vnis(removed) # Send a refresh message to the SND with the current config. # Schedule another refresh in 1 sec just in case the UDP # msg is lost. self.__send_refresh(self.__vni_config, self._conf.holdtime) self.__next_refresh = int(time.time()) + 1
Example #11
Source File: mock_client.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def send_query(sock: socket.socket, query: Union[dns.message.Message, bytes]) -> None: message = query if isinstance(query, bytes) else query.to_wire() while True: try: sendto_msg(sock, message) break except OSError as ex: # ENOBUFS, throttle sending if ex.errno == errno.ENOBUFS: time.sleep(0.1) else: raise
Example #12
Source File: mock_client.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def recvfrom_blob(sock: socket.socket, timeout: int = SOCKET_OPERATION_TIMEOUT) -> Tuple[bytes, str]: """ Receive DNS message from TCP/UDP socket. """ # deadline is always time.monotonic deadline = time.monotonic() + timeout while True: try: if sock.type & socket.SOCK_DGRAM: handle_socket_timeout(sock, deadline) data, addr = sock.recvfrom(RECEIVE_MESSAGE_SIZE) elif sock.type & socket.SOCK_STREAM: # First 2 bytes of TCP packet are the size of the message # See https://tools.ietf.org/html/rfc1035#section-4.2.2 data = recv_n_bytes_from_tcp(sock, 2, deadline) msg_len = struct.unpack_from("!H", data)[0] data = recv_n_bytes_from_tcp(sock, msg_len, deadline) addr = sock.getpeername()[0] else: raise NotImplementedError("[recvfrom_blob]: unknown socket type '%i'" % sock.type) return data, addr except socket.timeout: raise RuntimeError("Server took too long to respond") except OSError as ex: if ex.errno == errno.ENOBUFS: time.sleep(0.1) else: raise
Example #13
Source File: mock_client.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def send_query(sock: socket.socket, query: Union[dns.message.Message, bytes]) -> None: message = query if isinstance(query, bytes) else query.to_wire() while True: try: sendto_msg(sock, message) break except OSError as ex: # ENOBUFS, throttle sending if ex.errno == errno.ENOBUFS: time.sleep(0.1) else: raise
Example #14
Source File: mock_client.py From deckard with BSD 2-Clause "Simplified" License | 5 votes |
def recvfrom_blob(sock: socket.socket, timeout: int = SOCKET_OPERATION_TIMEOUT) -> Tuple[bytes, str]: """ Receive DNS message from TCP/UDP socket. """ # deadline is always time.monotonic deadline = time.monotonic() + timeout while True: try: if sock.type & socket.SOCK_DGRAM: handle_socket_timeout(sock, deadline) data, addr = sock.recvfrom(RECEIVE_MESSAGE_SIZE) elif sock.type & socket.SOCK_STREAM: # First 2 bytes of TCP packet are the size of the message # See https://tools.ietf.org/html/rfc1035#section-4.2.2 data = recv_n_bytes_from_tcp(sock, 2, deadline) msg_len = struct.unpack_from("!H", data)[0] data = recv_n_bytes_from_tcp(sock, msg_len, deadline) addr = sock.getpeername()[0] else: raise NotImplementedError("[recvfrom_blob]: unknown socket type '%i'" % sock.type) return data, addr except socket.timeout: raise RuntimeError("Server took too long to respond") except OSError as ex: if ex.errno == errno.ENOBUFS: time.sleep(0.1) else: raise
Example #15
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 #16
Source File: selector_events.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def _accept_connection(self, protocol_factory, sock, sslcontext=None, server=None, backlog=100): # This method is only called once for each event loop tick where the # listening socket has triggered an EVENT_READ. There may be multiple # connections waiting for an .accept() so it is called in a loop. # See https://bugs.python.org/issue27906 for more details. for _ in range(backlog): try: conn, addr = sock.accept() if self._debug: logger.debug("%r got a new connection from %r: %r", server, addr, conn) conn.setblocking(False) except (BlockingIOError, InterruptedError, ConnectionAbortedError): # Early exit because the socket accept buffer is empty. return None except OSError as exc: # There's nowhere to send the error, so just log it. if exc.errno in (errno.EMFILE, errno.ENFILE, errno.ENOBUFS, errno.ENOMEM): # Some platforms (e.g. Linux keep reporting the FD as # ready, so we remove the read handler temporarily. # We'll try again in a while. self.call_exception_handler({ 'message': 'socket.accept() out of system resource', 'exception': exc, 'socket': sock, }) self._remove_reader(sock.fileno()) self.call_later(constants.ACCEPT_RETRY_DELAY, self._start_serving, protocol_factory, sock, sslcontext, server, backlog) else: raise # The event loop will catch, log and ignore it. else: extra = {'peername': addr} accept = self._accept_connection2(protocol_factory, conn, extra, sslcontext, server) self.create_task(accept)
Example #17
Source File: error.py From libnl with GNU Lesser General Public License v2.1 | 5 votes |
def nl_syserr2nlerr(error_): """https://github.com/thom311/libnl/blob/libnl3_2_25/lib/error.c#L84.""" error_ = abs(error_) legend = { errno.EBADF: libnl.errno_.NLE_BAD_SOCK, errno.EADDRINUSE: libnl.errno_.NLE_EXIST, errno.EEXIST: libnl.errno_.NLE_EXIST, errno.EADDRNOTAVAIL: libnl.errno_.NLE_NOADDR, errno.ESRCH: libnl.errno_.NLE_OBJ_NOTFOUND, errno.ENOENT: libnl.errno_.NLE_OBJ_NOTFOUND, errno.EINTR: libnl.errno_.NLE_INTR, errno.EAGAIN: libnl.errno_.NLE_AGAIN, errno.ENOTSOCK: libnl.errno_.NLE_BAD_SOCK, errno.ENOPROTOOPT: libnl.errno_.NLE_INVAL, errno.EFAULT: libnl.errno_.NLE_INVAL, errno.EACCES: libnl.errno_.NLE_NOACCESS, errno.EINVAL: libnl.errno_.NLE_INVAL, errno.ENOBUFS: libnl.errno_.NLE_NOMEM, errno.ENOMEM: libnl.errno_.NLE_NOMEM, errno.EAFNOSUPPORT: libnl.errno_.NLE_AF_NOSUPPORT, errno.EPROTONOSUPPORT: libnl.errno_.NLE_PROTO_MISMATCH, errno.EOPNOTSUPP: libnl.errno_.NLE_OPNOTSUPP, errno.EPERM: libnl.errno_.NLE_PERM, errno.EBUSY: libnl.errno_.NLE_BUSY, errno.ERANGE: libnl.errno_.NLE_RANGE, errno.ENODEV: libnl.errno_.NLE_NODEV, } return int(legend.get(error_, libnl.errno_.NLE_FAILURE))
Example #18
Source File: selector_events.py From annotated-py-projects with MIT License | 5 votes |
def _accept_connection(self, protocol_factory, sock, sslcontext=None, server=None): try: conn, addr = sock.accept() if self._debug: logger.debug("%r got a new connection from %r: %r", server, addr, conn) conn.setblocking(False) except (BlockingIOError, InterruptedError, ConnectionAbortedError): pass # False alarm. except OSError as exc: # There's nowhere to send the error, so just log it. if exc.errno in (errno.EMFILE, errno.ENFILE, errno.ENOBUFS, errno.ENOMEM): # Some platforms (e.g. Linux keep reporting the FD as # ready, so we remove the read handler temporarily. # We'll try again in a while. self.call_exception_handler({ 'message': 'socket.accept() out of system resource', 'exception': exc, 'socket': sock, }) self.remove_reader(sock.fileno()) self.call_later(constants.ACCEPT_RETRY_DELAY, self._start_serving, protocol_factory, sock, sslcontext, server) else: raise # The event loop will catch, log and ignore it. else: extra = {'peername': addr} accept = self._accept_connection2(protocol_factory, conn, extra, sslcontext, server) self.create_task(accept)
Example #19
Source File: selector_events.py From ironpython3 with Apache License 2.0 | 5 votes |
def _accept_connection(self, protocol_factory, sock, sslcontext=None, server=None): try: conn, addr = sock.accept() if self._debug: logger.debug("%r got a new connection from %r: %r", server, addr, conn) conn.setblocking(False) except (BlockingIOError, InterruptedError, ConnectionAbortedError): pass # False alarm. except OSError as exc: # There's nowhere to send the error, so just log it. if exc.errno in (errno.EMFILE, errno.ENFILE, errno.ENOBUFS, errno.ENOMEM): # Some platforms (e.g. Linux keep reporting the FD as # ready, so we remove the read handler temporarily. # We'll try again in a while. self.call_exception_handler({ 'message': 'socket.accept() out of system resource', 'exception': exc, 'socket': sock, }) self.remove_reader(sock.fileno()) self.call_later(constants.ACCEPT_RETRY_DELAY, self._start_serving, protocol_factory, sock, sslcontext, server) else: raise # The event loop will catch, log and ignore it. else: extra = {'peername': addr} accept = self._accept_connection2(protocol_factory, conn, extra, sslcontext, server) self.create_task(accept)
Example #20
Source File: selector_events.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def _accept_connection(self, protocol_factory, sock, sslcontext=None, server=None): try: conn, addr = sock.accept() if self._debug: logger.debug("%r got a new connection from %r: %r", server, addr, conn) conn.setblocking(False) except (BlockingIOError, InterruptedError, ConnectionAbortedError): pass # False alarm. except OSError as exc: # There's nowhere to send the error, so just log it. if exc.errno in (errno.EMFILE, errno.ENFILE, errno.ENOBUFS, errno.ENOMEM): # Some platforms (e.g. Linux keep reporting the FD as # ready, so we remove the read handler temporarily. # We'll try again in a while. self.call_exception_handler({ 'message': 'socket.accept() out of system resource', 'exception': exc, 'socket': sock, }) self.remove_reader(sock.fileno()) self.call_later(constants.ACCEPT_RETRY_DELAY, self._start_serving, protocol_factory, sock, sslcontext, server) else: raise # The event loop will catch, log and ignore it. else: extra = {'peername': addr} accept = self._accept_connection2(protocol_factory, conn, extra, sslcontext, server) self.create_task(accept)
Example #21
Source File: sendfdport.py From ccs-twistedextensions with Apache License 2.0 | 5 votes |
def doWrite(self): """ Write some data. """ while self.statusQueue: msg = self.statusQueue.pop(0) try: send1msg(self.fd, msg, 0) except SocketError, se: if se.errno in (EAGAIN, ENOBUFS): self.statusQueue.insert(0, msg) return raise
Example #22
Source File: sendfdport.py From ccs-twistedextensions with Apache License 2.0 | 5 votes |
def doRead(self, recvmsg=recv1msg): """ Receive a status / health message and record it. """ try: data, _ignore_flags, _ignore_ancillary = recvmsg( self.outSocket.fileno() ) except SocketError, se: if se.errno not in (EAGAIN, ENOBUFS): raise
Example #23
Source File: tcp.py From python-for-android with Apache License 2.0 | 4 votes |
def doRead(self): """Called when my socket is ready for reading. This accepts a connection and calls self.protocol() to handle the wire-level protocol. """ try: if platformType == "posix": numAccepts = self.numberAccepts else: # win32 event loop breaks if we do more than one accept() # in an iteration of the event loop. numAccepts = 1 for i in range(numAccepts): # we need this so we can deal with a factory's buildProtocol # calling our loseConnection if self.disconnecting: return try: skt, addr = self.socket.accept() except socket.error, e: if e.args[0] in (EWOULDBLOCK, EAGAIN): self.numberAccepts = i break elif e.args[0] == EPERM: # Netfilter on Linux may have rejected the # connection, but we get told to try to accept() # anyway. continue elif e.args[0] in (EMFILE, ENOBUFS, ENFILE, ENOMEM, ECONNABORTED): # Linux gives EMFILE when a process is not allowed # to allocate any more file descriptors. *BSD and # Win32 give (WSA)ENOBUFS. Linux can also give # ENFILE if the system is out of inodes, or ENOMEM # if there is insufficient memory to allocate a new # dentry. ECONNABORTED is documented as possible on # both Linux and Windows, but it is not clear # whether there are actually any circumstances under # which it can happen (one might expect it to be # possible if a client sends a FIN or RST after the # server sends a SYN|ACK but before application code # calls accept(2), however at least on Linux this # _seems_ to be short-circuited by syncookies. log.msg("Could not accept new connection (%s)" % ( errorcode[e.args[0]],)) break raise fdesc._setCloseOnExec(skt.fileno()) protocol = self.factory.buildProtocol(self._buildAddr(addr)) if protocol is None: skt.close() continue s = self.sessionno self.sessionno = s+1 transport = self.transport(skt, protocol, addr, self, s, self.reactor) transport = self._preMakeConnection(transport) protocol.makeConnection(transport) else:
Example #24
Source File: unix.py From learn_python3_spider with MIT License | 4 votes |
def writeSomeData(self, data): """ Send as much of C{data} as possible. Also send any pending file descriptors. """ # Make it a programming error to send more file descriptors than you # send regular bytes. Otherwise, due to the limitation mentioned # below, we could end up with file descriptors left, but no bytes to # send with them, therefore no way to send those file descriptors. if len(self._sendmsgQueue) > len(data): return error.FileDescriptorOverrun() # If there are file descriptors to send, try sending them first, using # a little bit of data from the stream-oriented write buffer too. It # is not possible to send a file descriptor without sending some # regular data. index = 0 try: while index < len(self._sendmsgQueue): fd = self._sendmsgQueue[index] try: untilConcludes( sendmsg.sendmsg, self.socket, data[index:index+1], _ancillaryDescriptor(fd)) except socket.error as se: if se.args[0] in (EWOULDBLOCK, ENOBUFS): return index else: return main.CONNECTION_LOST else: index += 1 finally: del self._sendmsgQueue[:index] # Hand the remaining data to the base implementation. Avoid slicing in # favor of a buffer, in case that happens to be any faster. limitedData = lazyByteSlice(data, index) result = self._writeSomeDataBase.writeSomeData(self, limitedData) try: return index + result except TypeError: return result
Example #25
Source File: selector_events.py From odoo13-x64 with GNU General Public License v3.0 | 4 votes |
def _accept_connection( self, protocol_factory, sock, sslcontext=None, server=None, backlog=100, ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT): # This method is only called once for each event loop tick where the # listening socket has triggered an EVENT_READ. There may be multiple # connections waiting for an .accept() so it is called in a loop. # See https://bugs.python.org/issue27906 for more details. for _ in range(backlog): try: conn, addr = sock.accept() if self._debug: logger.debug("%r got a new connection from %r: %r", server, addr, conn) conn.setblocking(False) except (BlockingIOError, InterruptedError, ConnectionAbortedError): # Early exit because the socket accept buffer is empty. return None except OSError as exc: # There's nowhere to send the error, so just log it. if exc.errno in (errno.EMFILE, errno.ENFILE, errno.ENOBUFS, errno.ENOMEM): # Some platforms (e.g. Linux keep reporting the FD as # ready, so we remove the read handler temporarily. # We'll try again in a while. self.call_exception_handler({ 'message': 'socket.accept() out of system resource', 'exception': exc, 'socket': sock, }) self._remove_reader(sock.fileno()) self.call_later(constants.ACCEPT_RETRY_DELAY, self._start_serving, protocol_factory, sock, sslcontext, server, backlog, ssl_handshake_timeout) else: raise # The event loop will catch, log and ignore it. else: extra = {'peername': addr} accept = self._accept_connection2( protocol_factory, conn, extra, sslcontext, server, ssl_handshake_timeout) self.create_task(accept)
Example #26
Source File: selector_events.py From Imogen with MIT License | 4 votes |
def _accept_connection( self, protocol_factory, sock, sslcontext=None, server=None, backlog=100, ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT): # This method is only called once for each event loop tick where the # listening socket has triggered an EVENT_READ. There may be multiple # connections waiting for an .accept() so it is called in a loop. # See https://bugs.python.org/issue27906 for more details. for _ in range(backlog): try: conn, addr = sock.accept() if self._debug: logger.debug("%r got a new connection from %r: %r", server, addr, conn) conn.setblocking(False) except (BlockingIOError, InterruptedError, ConnectionAbortedError): # Early exit because the socket accept buffer is empty. return None except OSError as exc: # There's nowhere to send the error, so just log it. if exc.errno in (errno.EMFILE, errno.ENFILE, errno.ENOBUFS, errno.ENOMEM): # Some platforms (e.g. Linux keep reporting the FD as # ready, so we remove the read handler temporarily. # We'll try again in a while. self.call_exception_handler({ 'message': 'socket.accept() out of system resource', 'exception': exc, 'socket': sock, }) self._remove_reader(sock.fileno()) self.call_later(constants.ACCEPT_RETRY_DELAY, self._start_serving, protocol_factory, sock, sslcontext, server, backlog, ssl_handshake_timeout) else: raise # The event loop will catch, log and ignore it. else: extra = {'peername': addr} accept = self._accept_connection2( protocol_factory, conn, extra, sslcontext, server, ssl_handshake_timeout) self.create_task(accept)
Example #27
Source File: selector_events.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
def _accept_connection( self, protocol_factory, sock, sslcontext=None, server=None, backlog=100, ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT): # This method is only called once for each event loop tick where the # listening socket has triggered an EVENT_READ. There may be multiple # connections waiting for an .accept() so it is called in a loop. # See https://bugs.python.org/issue27906 for more details. for _ in range(backlog): try: conn, addr = sock.accept() if self._debug: logger.debug("%r got a new connection from %r: %r", server, addr, conn) conn.setblocking(False) except (BlockingIOError, InterruptedError, ConnectionAbortedError): # Early exit because the socket accept buffer is empty. return None except OSError as exc: # There's nowhere to send the error, so just log it. if exc.errno in (errno.EMFILE, errno.ENFILE, errno.ENOBUFS, errno.ENOMEM): # Some platforms (e.g. Linux keep reporting the FD as # ready, so we remove the read handler temporarily. # We'll try again in a while. self.call_exception_handler({ 'message': 'socket.accept() out of system resource', 'exception': exc, 'socket': sock, }) self._remove_reader(sock.fileno()) self.call_later(constants.ACCEPT_RETRY_DELAY, self._start_serving, protocol_factory, sock, sslcontext, server, backlog, ssl_handshake_timeout) else: raise # The event loop will catch, log and ignore it. else: extra = {'peername': addr} accept = self._accept_connection2( protocol_factory, conn, extra, sslcontext, server, ssl_handshake_timeout) self.create_task(accept)
Example #28
Source File: selector_events.py From android_universal with MIT License | 4 votes |
def _accept_connection( self, protocol_factory, sock, sslcontext=None, server=None, backlog=100, ssl_handshake_timeout=constants.SSL_HANDSHAKE_TIMEOUT): # This method is only called once for each event loop tick where the # listening socket has triggered an EVENT_READ. There may be multiple # connections waiting for an .accept() so it is called in a loop. # See https://bugs.python.org/issue27906 for more details. for _ in range(backlog): try: conn, addr = sock.accept() if self._debug: logger.debug("%r got a new connection from %r: %r", server, addr, conn) conn.setblocking(False) except (BlockingIOError, InterruptedError, ConnectionAbortedError): # Early exit because the socket accept buffer is empty. return None except OSError as exc: # There's nowhere to send the error, so just log it. if exc.errno in (errno.EMFILE, errno.ENFILE, errno.ENOBUFS, errno.ENOMEM): # Some platforms (e.g. Linux keep reporting the FD as # ready, so we remove the read handler temporarily. # We'll try again in a while. self.call_exception_handler({ 'message': 'socket.accept() out of system resource', 'exception': exc, 'socket': sock, }) self._remove_reader(sock.fileno()) self.call_later(constants.ACCEPT_RETRY_DELAY, self._start_serving, protocol_factory, sock, sslcontext, server, backlog, ssl_handshake_timeout) else: raise # The event loop will catch, log and ignore it. else: extra = {'peername': addr} accept = self._accept_connection2( protocol_factory, conn, extra, sslcontext, server, ssl_handshake_timeout) self.create_task(accept)
Example #29
Source File: unix.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 4 votes |
def writeSomeData(self, data): """ Send as much of C{data} as possible. Also send any pending file descriptors. """ # Make it a programming error to send more file descriptors than you # send regular bytes. Otherwise, due to the limitation mentioned # below, we could end up with file descriptors left, but no bytes to # send with them, therefore no way to send those file descriptors. if len(self._sendmsgQueue) > len(data): return error.FileDescriptorOverrun() # If there are file descriptors to send, try sending them first, using # a little bit of data from the stream-oriented write buffer too. It # is not possible to send a file descriptor without sending some # regular data. index = 0 try: while index < len(self._sendmsgQueue): fd = self._sendmsgQueue[index] try: untilConcludes( sendmsg.sendmsg, self.socket, data[index:index+1], _ancillaryDescriptor(fd)) except socket.error as se: if se.args[0] in (EWOULDBLOCK, ENOBUFS): return index else: return main.CONNECTION_LOST else: index += 1 finally: del self._sendmsgQueue[:index] # Hand the remaining data to the base implementation. Avoid slicing in # favor of a buffer, in case that happens to be any faster. limitedData = lazyByteSlice(data, index) result = self._writeSomeDataBase.writeSomeData(self, limitedData) try: return index + result except TypeError: return result