我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用gevent.socket.EBADF。
def fileno(self): result = self._fileno if result is None: raise IOError(EBADF, 'Bad file descriptor (%s object is closed)' % self.__class__.__name) return result
def read(self, len=1024): """Read up to LEN bytes and return them. Return zero-length string on EOF.""" while True: try: return self._sslobj.read(len) except SSLError, ex: if ex.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs: return '' elif ex.args[0] == SSL_ERROR_WANT_READ: if self.timeout == 0.0: raise sys.exc_clear() try: wait_read(self.fileno(), timeout=self.timeout, timeout_exc=_SSLErrorReadTimeout, event=self._read_event) except socket_error, ex: if ex[0] == EBADF: return '' raise elif ex.args[0] == SSL_ERROR_WANT_WRITE: if self.timeout == 0.0: raise sys.exc_clear() try: # note: using _SSLErrorReadTimeout rather than _SSLErrorWriteTimeout below is intentional wait_write(self.fileno(), timeout=self.timeout, timeout_exc=_SSLErrorReadTimeout, event=self._write_event) except socket_error, ex: if ex[0] == EBADF: return '' raise else: raise
def write(self, data): """Write DATA to the underlying SSL channel. Returns number of bytes of DATA actually transmitted.""" while True: try: return self._sslobj.write(data) except SSLError, ex: if ex.args[0] == SSL_ERROR_WANT_READ: if self.timeout == 0.0: raise sys.exc_clear() try: wait_read(self.fileno(), timeout=self.timeout, timeout_exc=_SSLErrorWriteTimeout, event=self._read_event) except socket_error, ex: if ex[0] == EBADF: return 0 raise elif ex.args[0] == SSL_ERROR_WANT_WRITE: if self.timeout == 0.0: raise sys.exc_clear() try: wait_write(self.fileno(), timeout=self.timeout, timeout_exc=_SSLErrorWriteTimeout, event=self._write_event) except socket_error, ex: if ex[0] == EBADF: return 0 raise else: raise
def send(self, data, flags=0, timeout=timeout_default): if timeout is timeout_default: timeout = self.timeout if self._sslobj: if flags != 0: raise ValueError( "non-zero flags not allowed in calls to send() on %s" % self.__class__) while True: try: v = self._sslobj.write(data) except SSLError, x: if x.args[0] == SSL_ERROR_WANT_READ: if self.timeout == 0.0: return 0 sys.exc_clear() try: wait_read(self.fileno(), timeout=timeout, event=self._read_event) except socket_error, ex: if ex[0] == EBADF: return 0 raise elif x.args[0] == SSL_ERROR_WANT_WRITE: if self.timeout == 0.0: return 0 sys.exc_clear() try: wait_write(self.fileno(), timeout=timeout, event=self._write_event) except socket_error, ex: if ex[0] == EBADF: return 0 raise else: raise else: return v else: return socket.send(self, data, flags, timeout) # is it possible for sendall() to send some data without encryption if another end shut down SSL?
def _sslobj_shutdown(self): while True: try: return self._sslobj.shutdown() except SSLError, ex: if ex.args[0] == SSL_ERROR_EOF and self.suppress_ragged_eofs: return '' elif ex.args[0] == SSL_ERROR_WANT_READ: if self.timeout == 0.0: raise sys.exc_clear() try: wait_read(self.fileno(), timeout=self.timeout, timeout_exc=_SSLErrorReadTimeout, event=self._read_event) except socket_error, ex: if ex[0] == EBADF: return '' raise elif ex.args[0] == SSL_ERROR_WANT_WRITE: if self.timeout == 0.0: raise sys.exc_clear() try: wait_write(self.fileno(), timeout=self.timeout, timeout_exc=_SSLErrorWriteTimeout, event=self._write_event) except socket_error, ex: if ex[0] == EBADF: return '' raise else: raise