Exemple #1
0
    def close(self):
        # FIXME Abort ssl_events of the handshake.
        # FIXME This repeats BaseTCPSocket.close(). The socket might be closed
        # before the handshake has completed. In this case there might be
        # deferred _reader or _writer events, which did not add the socket to
        # read or write queues.
        try:
            fileno = self.fileno()

            del self.env.fds[fileno]
            # TODO Remove events.
            if self._reader is not None:
                self._reader.fail(socket_error(errno.EBADF))
                self._reader = None
                try:
                    self.env._rd.remove(fileno)
                except ValueError:
                    pass
            if self._writer is not None:
                self._writer.fail(socket_error(errno.EBADF))
                self._writer = None
                try:
                    self.env._wd.remove(fileno)
                except ValueError:
                    pass
            self.sock.close()
        except socket.error as e:
            if e.errno == errno.EBADF:
                return
            raise e
    def close(self):
        try:
            fileno = self.fileno()
            del self.env.fds[fileno]
            self.env._poll.unregister(fileno)

            # Fail events.
            if self._reader is not None:
                self._reader.fail(socket_error(errno.EBADF))
                self._reader = None
            if self._writer is not None:
                self._writer.fail(socket_error(errno.EBADF))
                self._writer = None
            self.sock.close()
        except socket.error as e:
            if e.errno == errno.EBADF:
                return
            raise e
Exemple #3
0
    def close(self):
        try:
            fileno = self.fileno()

            del self.env.fds[fileno]
            # FIXME Abort ssl_events of the handshake.

            # Fail events.
            if self._reader is not None:
                self._reader.fail(socket_error(errno.EBADF))
                self._reader = None
            if self._writer is not None:
                self._writer.fail(socket_error(errno.EBADF))
                self._writer = None
            self.sock.close()
        except socket.error as e:
            if e.errno == errno.EBADF:
                return
            raise e
 def _do_read(self):
     try:
         self._reader._value = self.sock.recv(self._reader.amount)
         if not self._reader._value:
             self._reader._ok = False
             self._reader._value = socket_error(errno.ECONNRESET)
         else:
             self._reader._ok = True
         self.env.schedule(self._reader)
     except socket.error as e:
         if e.errno in blocking_io_errors:
             self._flags |= self._read_flag
             self.env._poll.modify(self.fileno(), self._flags)
             return
         self._reader.fail(e)
     self._reader = None
Exemple #5
0
    def _do_accept(self):
        try:
            self._reader._value = type(self)(self.env, self.sock.accept()[0])
            if not self._reader._value:
                self._reader._ok = False
                self._reader._value = socket_error(errno.ECONNRESET)
            else:
                self._reader._ok = True
            self.env.schedule(self._reader)
        except SocketError as e:
            if e.errno in blocking_io_errors:
                self.env._rd.append(self.fileno())
                return

            self._reader.fail(e)
        self._reader = None
Exemple #6
0
 def _do_read(self):
     try:
         self._reader._value = self.sock.recv(self._reader.amount)
         if not self._reader._value:
             self._reader._ok = False
             self._reader._value = socket_error(errno.ECONNRESET)
         else:
             self._reader._ok = True
         self.env.schedule(self._reader)
     except BlockingIOError:
         return
     except socket.error as e:
         if e.errno in blocking_io_errors:
             # Python 2 branch.
             return
         self._reader.fail(e)
     self._reader = None
Exemple #7
0
    def _do_read(self):
        try:
            self._reader._value = self.sock.recv(self._reader.amount)
            if not self._reader._value:
                self._reader._ok = False
                self._reader._value = socket_error(errno.ECONNRESET)
            else:
                self._reader._ok = True
            self.env.schedule(self._reader)
        except ssl.SSLError as e:
            if e.errno == ssl.SSL_ERROR_WANT_READ:
                self.env._rd.append(self.fileno())
                return

            self._reader.fail(e)
        except SocketError as e:
            if e.errno in blocking_io_errors:
                self.env._rd.append(self.sock.fileno())
                return

            self._reader.fail(e)
        self._reader = None