[3.11] gh-87020: Revert "Use SSL_write/read_ex() GH-27271, GH-25468" by tiran · Pull Request #95594 · python/cpython
if (b->len > INT_MAX) { PyErr_Format(PyExc_OverflowError, "string longer than %d bytes", INT_MAX); goto error; }
if (sock != NULL) { /* just in case the blocking state of the socket has been changed */ nonblocking = (sock->sock_timeout >= 0);
do { PySSL_BEGIN_ALLOW_THREADS retval = SSL_write_ex(self->ssl, b->buf, (size_t)b->len, &count); err = _PySSL_errno(retval == 0, self->ssl, retval); len = SSL_write(self->ssl, b->buf, (int)b->len); err = _PySSL_errno(len <= 0, self->ssl, len); PySSL_END_ALLOW_THREADS self->err = err;
Py_XDECREF(sock); if (retval == 0) return PySSL_SetError(self, retval, __FILE__, __LINE__); if (len <= 0) return PySSL_SetError(self, len, __FILE__, __LINE__); if (PySSL_ChainExceptions(self) < 0) return NULL; return PyLong_FromSize_t(count); return PyLong_FromLong(len); error: Py_XDECREF(sock); PySSL_ChainExceptions(self);
/*[clinic input] _ssl._SSLSocket.read size as len: Py_ssize_t size as len: int [ buffer: Py_buffer(accept={rwbuffer}) ]
static PyObject * _ssl__SSLSocket_read_impl(PySSLSocket *self, Py_ssize_t len, int group_right_1, Py_buffer *buffer) /*[clinic end generated code: output=49b16e6406023734 input=ec48bf622be1c4a1]*/ _ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1, Py_buffer *buffer) /*[clinic end generated code: output=00097776cec2a0af input=ff157eb918d0905b]*/ { PyObject *dest = NULL; char *mem; size_t count = 0; int retval; int count; int sockstate; _PySSLError err; int nonblocking;
do { PySSL_BEGIN_ALLOW_THREADS retval = SSL_read_ex(self->ssl, mem, (size_t)len, &count); err = _PySSL_errno(retval == 0, self->ssl, retval); count = SSL_read(self->ssl, mem, len); err = _PySSL_errno(count <= 0, self->ssl, count); PySSL_END_ALLOW_THREADS self->err = err;
if (retval == 0) { PySSL_SetError(self, retval, __FILE__, __LINE__); if (count <= 0) { PySSL_SetError(self, count, __FILE__, __LINE__); goto error; } if (self->exc_type != NULL)
error: