diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-24 21:30:20 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-24 21:30:20 (GMT) |
commit | ec146185c4382206ecbbcaa505c81b8c04992f3a (patch) | |
tree | a92f2f92c4ef19ad0adf8f558b0f9c43b027a740 /Modules | |
parent | 44bb1f7eabd850db1e03574debbba8e40d897e1c (diff) | |
download | cpython-ec146185c4382206ecbbcaa505c81b8c04992f3a.zip cpython-ec146185c4382206ecbbcaa505c81b8c04992f3a.tar.gz cpython-ec146185c4382206ecbbcaa505c81b8c04992f3a.tar.bz2 |
Merged revisions 80454 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r80454 | antoine.pitrou | 2010-04-24 23:26:44 +0200 (sam., 24 avril 2010) | 15 lines
Merged revisions 80451-80452 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80451 | antoine.pitrou | 2010-04-24 21:57:01 +0200 (sam., 24 avril 2010) | 4 lines
The do_handshake() method of SSL objects now adjusts the blocking mode of
the SSL structure if necessary (as other methods already do).
........
r80452 | antoine.pitrou | 2010-04-24 22:04:58 +0200 (sam., 24 avril 2010) | 4 lines
Issue #5103: SSL handshake would ignore the socket timeout and block
indefinitely if the other end didn't respond.
........
................
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ssl.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 5e0f473..c21ac5d 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -445,20 +445,25 @@ static PyObject *PySSL_SSLdo_handshake(PySSLObject *self) { int ret; int err; - int sockstate; + int sockstate, nonblocking; + PySocketSockObject *sock + = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); + + if (((PyObject*)sock) == Py_None) { + _setSSLError("Underlying socket connection gone", + PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); + return NULL; + } + + /* just in case the blocking state of the socket has been changed */ + nonblocking = (sock->sock_timeout >= 0.0); + BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); + BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); /* Actually negotiate SSL connection */ /* XXX If SSL_do_handshake() returns 0, it's also a failure. */ sockstate = 0; do { - PySocketSockObject *sock - = (PySocketSockObject *) PyWeakref_GetObject(self->Socket); - if (((PyObject*)sock) == Py_None) { - _setSSLError("Underlying socket connection gone", - PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); - return NULL; - } - PySSL_BEGIN_ALLOW_THREADS ret = SSL_do_handshake(self->ssl); err = SSL_get_error(self->ssl, ret); |