def send_output(self): """Called when socket is write-ready.""" try: pyngus.write_socket_output(self.connection, self.socket) except socket.error: pass self.connection.process(time.time())
def process_connection(connection, my_socket): """Handle I/O and Timers on a single Connection.""" if connection.closed: return False work = False readfd = [] writefd = [] if connection.needs_input > 0: readfd = [my_socket] work = True if connection.has_output > 0: writefd = [my_socket] work = True timeout = None deadline = connection.next_tick if deadline: work = True now = time.time() timeout = 0 if deadline <= now else deadline - now if not work: return False readable, writable, ignore = select.select(readfd, writefd, [], timeout) if readable: pyngus.read_socket_input(connection, my_socket) connection.process(time.time()) if writable: pyngus.write_socket_output(connection, my_socket) return True
def send_output(self): """Called when socket is write-ready""" try: pyngus.write_socket_output(self.connection, self.socket) except Exception as e: LOG.error("Exception on socket write: %s", str(e)) self.connection.close_output() self.connection.close() self.connection.process(time.time())
def write_socket(self): """Called to write to the socket.""" if self.socket: try: pyngus.write_socket_output(self.pyngus_conn, self.socket) self.pyngus_conn.process(now()) except (socket.timeout, socket.error) as e: # pyngus handles EAGAIN/EWOULDBLOCK and EINTER self.pyngus_conn.close_output() self.pyngus_conn.close_input() self._handler.socket_error(str(e))
def send_output(self): """Called when socket is write-ready""" try: pyngus.write_socket_output(self.connection, self.socket) except Exception as e: LOG.error("Exception on socket write: %s", str(e)) # may be redundant if closed cleanly: self.connection_closed(self.connection) return self.connection.process(time.time())
def process_connection(connection, my_socket): """Handle I/O and Timers on a single Connection.""" if connection.closed: return False work = False readfd = [] writefd = [] if connection.needs_input > 0: readfd = [my_socket] work = True if connection.has_output > 0: writefd = [my_socket] work = True timeout = None deadline = connection.next_tick if deadline: work = True now = time.time() timeout = 0 if deadline <= now else deadline - now if not work: return False readable, writable, ignore = select.select(readfd, writefd, [], timeout) if readable: try: pyngus.read_socket_input(connection, my_socket) except Exception as e: # treat any socket error as LOG.error("Socket error on read: %s", str(e)) connection.close_input() # make an attempt to cleanly close connection.close() connection.process(time.time()) if writable: try: pyngus.write_socket_output(connection, my_socket) except Exception as e: LOG.error("Socket error on write %s", str(e)) connection.close_output() # this may not help, but it won't hurt: connection.close() return True
def process(self): """ Do connection-based processing (I/O and timers) """ readfd = [] writefd = [] if self.connection.needs_input > 0: readfd = [self.socket] if self.connection.has_output > 0: writefd = [self.socket] timeout = None deadline = self.connection.next_tick if deadline: now = time.time() timeout = 0 if deadline <= now else deadline - now LOG.debug("select() start (t=%s)", str(timeout)) readable, writable, ignore = select.select(readfd, writefd, [], timeout) LOG.debug("select() returned") if readable: try: pyngus.read_socket_input(self.connection, self.socket) except Exception as e: LOG.error("Exception on socket read: %s", str(e)) self.connection.close_input() self.connection.close() self.connection.process(time.time()) if writable: try: pyngus.write_socket_output(self.connection, self.socket) except Exception as e: LOG.error("Exception on socket write: %s", str(e)) self.connection.close_output() self.connection.close()
def write(self): """Called when socket is write-ready.""" while True: try: rc = pyngus.write_socket_output(self.connection, self.socket) self.connection.process(time.time()) return rc except (socket.timeout, socket.error) as e: # pyngus handles EAGAIN/EWOULDBLOCK and EINTER self.connection.close_output() self.connection.close() self._handler.socket_error(str(e)) return pyngus.Connection.EOS
def write(self): """Called when socket is write-ready.""" while True: try: rc = pyngus.write_socket_output(self.connection, self.socket) self.connection.process(time.time()) return rc except (socket.timeout, socket.error) as e: # pyngus handles EAGAIN/EWOULDBLOCK and EINTER self.connection.close_output() self.connection.close_input() self._handler.socket_error(str(e)) return pyngus.Connection.EOS
def write(self): """Called when socket is write-ready.""" while True: try: rc = pyngus.write_socket_output(self.connection, self.socket) if rc > 0: self.connection.process(time.time()) return rc except socket.error as e: if e.errno == errno.EAGAIN or e.errno == errno.EINTR: continue elif e.errno == errno.EWOULDBLOCK: return 0 else: self._handler.socket_error(str(e)) return pyngus.Connection.EOS