summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-11-25 18:55:32 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-11-25 18:55:32 (GMT)
commit7d7aede558bc93196a40bd00fd857f57d00dd5bc (patch)
treeb5f8b100bac2a4beee4f45403ba74ddf9da3b264 /Modules
parentb742a96c523339d640ca9dc3d077ef9b6ec13d8e (diff)
downloadcpython-7d7aede558bc93196a40bd00fd857f57d00dd5bc.zip
cpython-7d7aede558bc93196a40bd00fd857f57d00dd5bc.tar.gz
cpython-7d7aede558bc93196a40bd00fd857f57d00dd5bc.tar.bz2
Merged revisions 75529 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r75529 | antoine.pitrou | 2009-10-19 19:59:07 +0200 (lun., 19 oct. 2009) | 5 lines Issue #7133: SSL objects now support the new buffer API. This fixes the test_ssl failure. ........
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ssl.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
index 906138d..dfe2fb0 100644
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -1146,9 +1146,8 @@ normal_return:
static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
{
- char *data;
+ Py_buffer buf;
int len;
- int count;
int sockstate;
int err;
int nonblocking;
@@ -1161,7 +1160,7 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
return NULL;
}
- if (!PyArg_ParseTuple(args, "y#:write", &data, &count))
+ if (!PyArg_ParseTuple(args, "y*:write", &buf))
return NULL;
/* just in case the blocking state of the socket has been changed */
@@ -1173,24 +1172,24 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
if (sockstate == SOCKET_HAS_TIMED_OUT) {
PyErr_SetString(PySSLErrorObject,
"The write operation timed out");
- return NULL;
+ goto error;
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
PyErr_SetString(PySSLErrorObject,
"Underlying socket has been closed.");
- return NULL;
+ goto error;
} else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) {
PyErr_SetString(PySSLErrorObject,
"Underlying socket too large for select().");
- return NULL;
+ goto error;
}
do {
err = 0;
PySSL_BEGIN_ALLOW_THREADS
- len = SSL_write(self->ssl, data, count);
+ len = SSL_write(self->ssl, buf.buf, buf.len);
err = SSL_get_error(self->ssl, len);
PySSL_END_ALLOW_THREADS
- if(PyErr_CheckSignals()) {
- return NULL;
+ if (PyErr_CheckSignals()) {
+ goto error;
}
if (err == SSL_ERROR_WANT_READ) {
sockstate =
@@ -1204,19 +1203,25 @@ static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args)
if (sockstate == SOCKET_HAS_TIMED_OUT) {
PyErr_SetString(PySSLErrorObject,
"The write operation timed out");
- return NULL;
+ goto error;
} else if (sockstate == SOCKET_HAS_BEEN_CLOSED) {
PyErr_SetString(PySSLErrorObject,
"Underlying socket has been closed.");
- return NULL;
+ goto error;
} else if (sockstate == SOCKET_IS_NONBLOCKING) {
break;
}
} while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
+
+ PyBuffer_Release(&buf);
if (len > 0)
return PyLong_FromLong(len);
else
return PySSL_SetError(self, len, __FILE__, __LINE__);
+
+error:
+ PyBuffer_Release(&buf);
+ return NULL;
}
PyDoc_STRVAR(PySSL_SSLwrite_doc,