def _ssl_seterror(space, ss, ret): assert ret <= 0 if ss is None: errval = libssl_ERR_peek_last_error() errstr = rffi.charp2str(libssl_ERR_error_string(errval, None)) return ssl_error(space, errstr, errval) elif ss.ssl: err = libssl_SSL_get_error(ss.ssl, ret) else: err = SSL_ERROR_SSL errstr = "" errval = 0 if err == SSL_ERROR_ZERO_RETURN: errstr = "TLS/SSL connection has been closed" errval = PY_SSL_ERROR_ZERO_RETURN elif err == SSL_ERROR_WANT_READ: errstr = "The operation did not complete (read)" errval = PY_SSL_ERROR_WANT_READ elif err == SSL_ERROR_WANT_WRITE: errstr = "The operation did not complete (write)" errval = PY_SSL_ERROR_WANT_WRITE elif err == SSL_ERROR_WANT_X509_LOOKUP: errstr = "The operation did not complete (X509 lookup)" errval = PY_SSL_ERROR_WANT_X509_LOOKUP elif err == SSL_ERROR_WANT_CONNECT: errstr = "The operation did not complete (connect)" errval = PY_SSL_ERROR_WANT_CONNECT elif err == SSL_ERROR_SYSCALL: e = libssl_ERR_get_error() if e == 0: if ret == 0 or space.is_w(ss.w_socket, space.w_None): errstr = "EOF occurred in violation of protocol" errval = PY_SSL_ERROR_EOF elif ret == -1: # the underlying BIO reported an I/0 error error = rsocket.last_error() return interp_socket.converted_error(space, error) else: errstr = "Some I/O error occurred" errval = PY_SSL_ERROR_SYSCALL else: errstr = rffi.charp2str(libssl_ERR_error_string(e, None)) errval = PY_SSL_ERROR_SYSCALL elif err == SSL_ERROR_SSL: e = libssl_ERR_get_error() errval = PY_SSL_ERROR_SSL if e != 0: errstr = rffi.charp2str(libssl_ERR_error_string(e, None)) else: errstr = "A failure in the SSL library occurred" else: errstr = "Invalid error code" errval = PY_SSL_ERROR_INVALID_ERROR_CODE return ssl_error(space, errstr, errval)
def _ssl_seterror(space, ss, ret): assert ret <= 0 if ss and ss.ssl: err = libssl_SSL_get_error(ss.ssl, ret) else: err = SSL_ERROR_SSL errstr = "" errval = 0 if err == SSL_ERROR_ZERO_RETURN: errstr = "TLS/SSL connection has been closed" errval = PY_SSL_ERROR_ZERO_RETURN elif err == SSL_ERROR_WANT_READ: errstr = "The operation did not complete (read)" errval = PY_SSL_ERROR_WANT_READ elif err == SSL_ERROR_WANT_WRITE: errstr = "The operation did not complete (write)" errval = PY_SSL_ERROR_WANT_WRITE elif err == SSL_ERROR_WANT_X509_LOOKUP: errstr = "The operation did not complete (X509 lookup)" errval = PY_SSL_ERROR_WANT_X509_LOOKUP elif err == SSL_ERROR_WANT_CONNECT: errstr = "The operation did not complete (connect)" errval = PY_SSL_ERROR_WANT_CONNECT elif err == SSL_ERROR_SYSCALL: e = libssl_ERR_get_error() if e == 0: if ret == 0 or space.is_w(ss.w_socket, space.w_None): errstr = "EOF occurred in violation of protocol" errval = PY_SSL_ERROR_EOF elif ret == -1: # the underlying BIO reported an I/0 error error = rsocket.last_error() return interp_socket.converted_error(space, error) else: errstr = "Some I/O error occurred" errval = PY_SSL_ERROR_SYSCALL else: errstr = rffi.charp2str(libssl_ERR_error_string(e, None)) errval = PY_SSL_ERROR_SYSCALL elif err == SSL_ERROR_SSL: e = libssl_ERR_get_error() errval = PY_SSL_ERROR_SSL if e != 0: errstr = rffi.charp2str(libssl_ERR_error_string(e, None)) else: errstr = "A failure in the SSL library occurred" else: errstr = "Invalid error code" errval = PY_SSL_ERROR_INVALID_ERROR_CODE return ssl_error(space, errstr, errval)
def ioctl_w(self, space, cmd, w_option): from pypy.rpython.lltypesystem import rffi, lltype from pypy.rlib import rwin32 from pypy.rlib.rsocket import _c recv_ptr = lltype.malloc(rwin32.LPDWORD.TO, 1, flavor='raw') try: if cmd == _c.SIO_RCVALL: value_size = rffi.sizeof(rffi.INTP) elif cmd == _c.SIO_KEEPALIVE_VALS: value_size = rffi.sizeof(_c.tcp_keepalive) else: raise operationerrfmt(space.w_ValueError, "invalid ioctl command %d", cmd) value_ptr = lltype.malloc(rffi.VOIDP.TO, value_size, flavor='raw') try: if cmd == _c.SIO_RCVALL: option_ptr = rffi.cast(rffi.INTP, value_ptr) option_ptr[0] = space.int_w(w_option) elif cmd == _c.SIO_KEEPALIVE_VALS: w_onoff, w_time, w_interval = space.unpackiterable(w_option) option_ptr = rffi.cast(lltype.Ptr(_c.tcp_keepalive), value_ptr) option_ptr.c_onoff = space.uint_w(w_onoff) option_ptr.c_keepalivetime = space.uint_w(w_time) option_ptr.c_keepaliveinterval = space.uint_w(w_interval) res = _c.WSAIoctl( self.fd, cmd, value_ptr, value_size, rffi.NULL, 0, recv_ptr, rffi.NULL, rffi.NULL) if res < 0: raise converted_error(space, rsocket.last_error()) finally: if value_ptr: lltype.free(value_ptr, flavor='raw') return space.wrap(recv_ptr[0]) finally: lltype.free(recv_ptr, flavor='raw')