SOURCES: python-ssl-nonblocking.patch - less intrusive, cleaner ve...

arekm arekm at pld-linux.org
Thu Dec 15 18:22:31 CET 2005


Author: arekm                        Date: Thu Dec 15 17:22:31 2005 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- less intrusive, cleaner version

---- Files affected:
SOURCES:
   python-ssl-nonblocking.patch (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: SOURCES/python-ssl-nonblocking.patch
diff -u SOURCES/python-ssl-nonblocking.patch:1.1 SOURCES/python-ssl-nonblocking.patch:1.2
--- SOURCES/python-ssl-nonblocking.patch:1.1	Wed Dec 14 23:40:01 2005
+++ SOURCES/python-ssl-nonblocking.patch	Thu Dec 15 18:22:25 2005
@@ -28,97 +28,37 @@
  
  if __name__ == "__main__":
      test_main()
---- Python.org/Modules/_ssl.c	2004-08-04 16:59:00.000000000 +0200
-+++ Python/Modules/_ssl.c	2005-12-14 23:36:18.000000000 +0100
-@@ -65,6 +65,7 @@
- static PyObject *PySSL_SSLwrite(PySSLObject *self, PyObject *args);
- static PyObject *PySSL_SSLread(PySSLObject *self, PyObject *args);
- static int check_socket_and_wait_for_timeout(PySocketSockObject *s, 
-+					     SSL *ssl,
- 					     int writing);
+--- Modules/_ssl.c.org	2005-12-15 18:17:03.000000000 +0100
++++ Modules/_ssl.c	2005-12-15 18:18:42.000000000 +0100
+@@ -455,6 +455,7 @@
+ 	int len = 1024;
+ 	int sockstate;
+ 	int err;
++	int pending;
  
- #define PySSLObject_Check(v)	((v)->ob_type == &PySSL_Type)
-@@ -260,9 +261,9 @@
-                         goto fail;
- 		}
- 		if (err == SSL_ERROR_WANT_READ) {
--			sockstate = check_socket_and_wait_for_timeout(Sock, 0);
-+			sockstate = check_socket_and_wait_for_timeout(Sock, NULL, 0);
- 		} else if (err == SSL_ERROR_WANT_WRITE) {
--			sockstate = check_socket_and_wait_for_timeout(Sock, 1);
-+			sockstate = check_socket_and_wait_for_timeout(Sock, NULL, 1);
- 		} else {
- 			sockstate = SOCKET_OPERATION_OK;
- 		}
-@@ -356,11 +357,11 @@
-  */
- 
- static int
--check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
-+check_socket_and_wait_for_timeout(PySocketSockObject *s, SSL *ssl, int writing)
- {
- 	fd_set fds;
- 	struct timeval tv;
--	int rc;
-+	int pending, rc;
- 
- 	/* Nothing to do unless we're in timeout mode (not non-blocking) */
- 	if (s->sock_timeout < 0.0)
-@@ -372,6 +373,15 @@
- 	if (s->sock_fd < 0)
- 		return SOCKET_HAS_BEEN_CLOSED;
- 
-+	/* There is data to be read from SSL layer (even if there is no data on socket!) */
-+	if (!writing && ssl) {
-+		Py_BEGIN_ALLOW_THREADS
-+		pending = SSL_pending(ssl);
-+		Py_END_ALLOW_THREADS
-+		if (pending)
-+			return SOCKET_OPERATION_OK;
-+	}
-+
- 	/* Construct the arguments to select */
- 	tv.tv_sec = (int)s->sock_timeout;
- 	tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
-@@ -402,7 +412,7 @@
- 	if (!PyArg_ParseTuple(args, "s#:write", &data, &count))
- 		return NULL;
- 
--	sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
-+	sockstate = check_socket_and_wait_for_timeout(self->Socket, NULL, 1);
- 	if (sockstate == SOCKET_HAS_TIMED_OUT) {
- 		PyErr_SetString(PySSLErrorObject, "The write operation timed out");
+ 	if (!PyArg_ParseTuple(args, "|i:read", &len))
  		return NULL;
-@@ -420,9 +430,9 @@
- 			return NULL;
- 		}
- 		if (err == SSL_ERROR_WANT_READ) {
--			sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
-+			sockstate = check_socket_and_wait_for_timeout(self->Socket, NULL, 0);
- 		} else if (err == SSL_ERROR_WANT_WRITE) {
--			sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
-+			sockstate = check_socket_and_wait_for_timeout(self->Socket, NULL, 1);
- 		} else {
- 			sockstate = SOCKET_OPERATION_OK;
- 		}
-@@ -462,7 +472,7 @@
+@@ -462,11 +463,17 @@
  	if (!(buf = PyString_FromStringAndSize((char *) 0, len)))
  		return NULL;
  
 -	sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
-+	sockstate = check_socket_and_wait_for_timeout(self->Socket, self->ssl, 0);
- 	if (sockstate == SOCKET_HAS_TIMED_OUT) {
- 		PyErr_SetString(PySSLErrorObject, "The read operation timed out");
- 		Py_DECREF(buf);
-@@ -479,9 +489,9 @@
- 			return NULL;
- 		}
- 		if (err == SSL_ERROR_WANT_READ) {
--			sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
-+			sockstate = check_socket_and_wait_for_timeout(self->Socket, NULL, 0);
- 		} else if (err == SSL_ERROR_WANT_WRITE) {
--			sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
-+			sockstate = check_socket_and_wait_for_timeout(self->Socket, NULL, 1);
- 		} else {
- 			sockstate = SOCKET_OPERATION_OK;
- 		}
+-	if (sockstate == SOCKET_HAS_TIMED_OUT) {
+-		PyErr_SetString(PySSLErrorObject, "The read operation timed out");
+-		Py_DECREF(buf);
+-		return NULL;
++	Py_BEGIN_ALLOW_THREADS
++	pending = SSL_pending(self->ssl);
++	Py_END_ALLOW_THREADS
++	
++	if (!pending) {
++		sockstate = check_socket_and_wait_for_timeout(self->Socket, 0);
++		if (sockstate == SOCKET_HAS_TIMED_OUT) {
++			PyErr_SetString(PySSLErrorObject, "The read operation timed out");
++			Py_DECREF(buf);
++			return NULL;
++		}
+ 	}
+ 	do {
+ 		err = 0;
+
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/SOURCES/python-ssl-nonblocking.patch?r1=1.1&r2=1.2&f=u




More information about the pld-cvs-commit mailing list