コード例 #1
0
 def fileno(self):
     try:
         return self.sock.fileno()
     except socket.error:
         self.close()
         ex = sys.exc_info()[1]
         if get_exc_errno(ex) == errno.EBADF:
             raise EOFError()
         else:
             raise
コード例 #2
0
 def read(self, count):
     data = []
     while count > 0:
         try:
             buf = self.sock.recv(min(self.MAX_IO_CHUNK, count))
         except socket.timeout:
             continue
         except socket.error:
             ex = sys.exc_info()[1]
             if get_exc_errno(ex) in retry_errnos:
                 # windows just has to be a bitch
                 continue
             self.close()
             raise EOFError(ex)
         if not buf:
             self.close()
             raise EOFError("connection closed by peer")
         data.append(buf)
         count -= len(buf)
     return BYTES_LITERAL("").join(data)
コード例 #3
0
ファイル: server.py プロジェクト: alex-tu-cc/checkbox-ng
    def accept(self):
        """accepts an incoming socket connection (blocking)"""
        while self.active:
            try:
                sock, addrinfo = self.listener.accept()
            except socket.timeout:
                pass
            except socket.error:
                ex = sys.exc_info()[1]
                if get_exc_errno(ex) in (errno.EINTR, errno.EAGAIN):
                    pass
                else:
                    raise EOFError()
            else:
                break

        if not self.active:
            return

        sock.setblocking(True)
        self.logger.info("accepted %s with fd %s", addrinfo, sock.fileno())
        self.clients.add(sock)
        self._accept_method(sock)