def _copy_loop(self, log_name, from_conn, to_conn): while True: log("%s: waiting for data", log_name) buf = untilConcludes(from_conn.read, 4096) if not buf: log("%s: connection lost", log_name) self._quit() return while buf: log("%s: writing %s bytes", log_name, len(buf)) written = untilConcludes(to_conn.write, buf) buf = buf[written:]
def _write_thread_loop(self): try: while True: item = self._write_queue.get() # Used to signal that we should exit: if item is None: log("write thread: empty marker, exiting") break buf, start_cb, end_cb = item try: if start_cb: start_cb(self.output_bytecount) while buf and not self._closed: written = untilConcludes(self._conn.write, buf) if written: buf = buf[written:] self.output_raw_packetcount += 1 self.output_bytecount += written if end_cb: end_cb(self.output_bytecount) except (OSError, IOError, socket.error), e: self._call_connection_lost("Error writing to connection: %s" % e) break except TypeError: #can happen during close(), in which case we just ignore: if self._closed: break raise if self._write_queue.empty(): gobject.idle_add(self._maybe_queue_more_writes)
def _write_thread_loop(self): try: while not self._closed: items = self._write_queue.get() # Used to signal that we should exit: if items is None: log("write thread: empty marker, exiting") break for buf, start_cb, end_cb in items: if start_cb: try: start_cb(self._conn.output_bytecount) except: log.error("error on %s", start_cb, exc_info=True) while buf and not self._closed: written = untilConcludes(self._conn.write, buf) if written: buf = buf[written:] self.output_raw_packetcount += 1 if end_cb: try: end_cb(self._conn.output_bytecount) except: if not self._closed: log.error("error on %s", end_cb, exc_info=True) log("write thread: ended") except (OSError, IOError, socket_error), e: if not self._closed: self._call_connection_lost("Error writing to connection: %s" % e)
def _write_thread_loop(self): try: while not self._closed: item = self._write_queue.get() # Used to signal that we should exit: if item is None: log("write thread: empty marker, exiting") break buf, start_cb, end_cb = item try: if start_cb and not self._closed: try: start_cb(self._conn.output_bytecount) except: log.error("error on %s", start_cb, exc_info=True) while buf and not self._closed: written = untilConcludes(self._conn.write, buf) if written: buf = buf[written:] self.output_raw_packetcount += 1 if end_cb and not self._closed: try: end_cb(self._conn.output_bytecount) except: log.error("error on %s", end_cb, exc_info=True) except (OSError, IOError, socket.error), e: self._call_connection_lost( "Error writing to connection: %s" % e) break except Exception, e: #can happen during close(), in which case we just ignore: if self._closed: break raise e
def _write_thread_loop(self): try: while not self._closed: item = self._write_queue.get() # Used to signal that we should exit: if item is None: log("write thread: empty marker, exiting") break buf, start_cb, end_cb = item try: if start_cb and not self._closed: try: start_cb(self._conn.output_bytecount) except: log.error("error on %s", start_cb, exc_info=True) while buf and not self._closed: written = untilConcludes(self._conn.write, buf) if written: buf = buf[written:] self.output_raw_packetcount += 1 if end_cb and not self._closed: try: end_cb(self._conn.output_bytecount) except: log.error("error on %s", end_cb, exc_info=True) except (OSError, IOError, socket.error), e: self._call_connection_lost("Error writing to connection: %s" % e) break except Exception, e: #can happen during close(), in which case we just ignore: if self._closed: break raise e
def _write_thread_loop(self): try: while True: item = self._write_queue.get() # Used to signal that we should exit: if item is None: log("write thread: empty marker, exiting") break buf, start_cb, end_cb = item try: if start_cb: start_cb(self.output_bytecount) while buf and not self._closed: written = untilConcludes(self._conn.write, buf) if written: buf = buf[written:] self.output_raw_packetcount += 1 self.output_bytecount += written if end_cb: end_cb(self.output_bytecount) except (OSError, IOError, socket.error), e: self._call_connection_lost( "Error writing to connection: %s" % e) break except TypeError: #can happen during close(), in which case we just ignore: if self._closed: break raise if self._write_queue.empty(): gobject.idle_add(self._maybe_queue_more_writes)
def _read_thread_loop(self): try: while not self._closed: try: buf = untilConcludes(self._conn.read, 8192) except (ValueError, OSError, IOError, socket.error), e: self._call_connection_lost("Error reading from connection: %s" % e) return except Exception, e: if self._closed: return raise e
def _read_thread_loop(self): try: while not self._closed: buf = untilConcludes(self._conn.read, 8192) #log("read thread: got data of size %s: %s", len(buf), repr_ellipsized(buf)) self._read_queue.put(buf) if not buf: log("read thread: eof") break self.input_raw_packetcount += 1 except (ValueError, OSError, IOError, socket_error), e: if not self._closed: self._call_connection_lost("Error reading from connection: %s" % e)
def _read_thread_loop(self): try: while not self._closed: try: buf = untilConcludes(self._conn.read, 8192) except (ValueError, OSError, IOError, socket.error), e: self._call_connection_lost( "Error reading from connection: %s" % e) return except Exception, e: if self._closed: return raise e
def _read_thread_loop(self): try: while not self._closed: buf = untilConcludes(self._conn.read, 8192) #log("read thread: got data of size %s: %s", len(buf), repr_ellipsized(buf)) self._read_queue.put(buf) if not buf: log("read thread: eof") break self.input_raw_packetcount += 1 except (ValueError, OSError, IOError, socket_error), e: if not self._closed: self._call_connection_lost( "Error reading from connection: %s" % e)