]> git.pld-linux.org Git - packages/python.git/blame - python-poll-instead-of-select-fix.patch
- really use new libdir
[packages/python.git] / python-poll-instead-of-select-fix.patch
CommitLineData
a906a182
MK
1--- Python-2.4.3/Modules/_ssl.c.orig 2006-10-06 00:47:51.000000000 +0200
2+++ Python-2.4.3/Modules/_ssl.c 2006-10-06 00:48:31.000000000 +0200
3@@ -26,6 +26,12 @@
4 /* Include symbols from _socket module */
5 #include "socketmodule.h"
6
7+#if defined(HAVE_POLL_H)
8+#include <poll.h>
9+#elif defined(HAVE_SYS_POLL_H)
10+#include <sys/poll.h>
11+#endif
12+
13 /* Include OpenSSL header files */
14 #include "openssl/rsa.h"
15 #include "openssl/crypto.h"
16@@ -354,7 +360,7 @@
17 PyObject_Del(self);
18 }
19
20-/* If the socket has a timeout, do a select() on the socket.
21+/* If the socket has a timeout, do a select()/poll() on the socket.
22 The argument writing indicates the direction.
23 Returns one of the possibilities in the timeout_state enum (above).
24 */
25@@ -376,6 +382,26 @@
26 if (s->sock_fd < 0)
27 return SOCKET_HAS_BEEN_CLOSED;
28
29+ /* Prefer poll, if available, since you can poll() any fd
30+ * which can't be done with select(). */
31+#ifdef HAVE_POLL
32+ {
33+ struct pollfd pollfd;
34+ int timeout;
35+
36+ pollfd.fd = s->sock_fd;
37+ pollfd.events = writing ? POLLOUT : POLLIN;
38+
39+ /* s->sock_timeout is in seconds, timeout in ms */
40+ timeout = (int)(s->sock_timeout * 1000 + 0.5);
41+ Py_BEGIN_ALLOW_THREADS
42+ rc = poll(&pollfd, 1, timeout);
43+ Py_END_ALLOW_THREADS
44+
45+ goto normal_return;
46+ }
47+#endif
48+
49 /* Guard against socket too large for select*/
50 #ifndef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
51 if (s->sock_fd >= FD_SETSIZE)
52@@ -396,6 +422,7 @@
53 rc = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
54 Py_END_ALLOW_THREADS
55
56+normal_return:
57 /* Return SOCKET_TIMED_OUT on timeout, SOCKET_OPERATION_OK otherwise
58 (when we are able to write or when there's something to read) */
59 return rc == 0 ? SOCKET_HAS_TIMED_OUT : SOCKET_OPERATION_OK;
60--- Python-2.4.3/Modules/socketmodule.c.orig 2006-02-20 10:42:37.000000000 +0100
61+++ Python-2.4.3/Modules/socketmodule.c 2006-10-06 00:48:31.000000000 +0200
62@@ -390,14 +390,24 @@
63 there has to be a circular reference. */
64 static PyTypeObject sock_type;
65
66-/* Can we call select() with this socket without a buffer overrun? */
67+#if defined(HAVE_POLL_H)
68+#include <poll.h>
69+#elif defined(HAVE_SYS_POLL_H)
70+#include <sys/poll.h>
71+#endif
72+
73 #ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
74 /* Platform can select file descriptors beyond FD_SETSIZE */
75 #define IS_SELECTABLE(s) 1
76+#elif defined(HAVE_POLL)
77+/* Instead of select(), we'll use poll() since poll() works on any fd. */
78+#define IS_SELECTABLE(s) 1
79+/* Can we call select() with this socket without a buffer overrun? */
80 #else
81 /* POSIX says selecting file descriptors beyond FD_SETSIZE
82- has undefined behaviour. */
83-#define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE)
84+ has undefined behaviour. If there's no timeout left, we don't have to
85+ call select, so it's a safe, little white lie. */
86+#define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE || s->sock_timeout <= 0.0)
87 #endif
88
89 static PyObject*
90@@ -640,7 +650,7 @@
91 return 1;
92 }
93
94-/* Do a select() on the socket, if necessary (sock_timeout > 0).
95+/* Do a select()/poll() on the socket, if necessary (sock_timeout > 0).
96 The argument writing indicates the direction.
97 This does not raise an exception; we'll let our caller do that
98 after they've reacquired the interpreter lock.
99@@ -648,8 +658,6 @@
100 static int
101 internal_select(PySocketSockObject *s, int writing)
102 {
103- fd_set fds;
104- struct timeval tv;
105 int n;
106
107 /* Nothing to do unless we're in timeout mode (not non-blocking) */
108@@ -660,17 +668,37 @@
109 if (s->sock_fd < 0)
110 return 0;
111
112- /* Construct the arguments to select */
113- tv.tv_sec = (int)s->sock_timeout;
114- tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
115- FD_ZERO(&fds);
116- FD_SET(s->sock_fd, &fds);
117-
118- /* See if the socket is ready */
119- if (writing)
120- n = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
121- else
122- n = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
123+ /* Prefer poll, if available, since you can poll() any fd
124+ * which can't be done with select(). */
125+#ifdef HAVE_POLL
126+ {
127+ struct pollfd pollfd;
128+ int timeout;
129+
130+ pollfd.fd = s->sock_fd;
131+ pollfd.events = writing ? POLLOUT : POLLIN;
132+
133+ /* s->sock_timeout is in seconds, timeout in ms */
134+ timeout = (int)(s->sock_timeout * 1000 + 0.5);
135+ n = poll(&pollfd, 1, timeout);
136+ }
137+#else
138+ {
139+ /* Construct the arguments to select */
140+ fd_set fds;
141+ struct timeval tv;
142+ tv.tv_sec = (int)s->sock_timeout;
143+ tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
144+ FD_ZERO(&fds);
145+ FD_SET(s->sock_fd, &fds);
146+
147+ /* See if the socket is ready */
148+ if (writing)
149+ n = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
150+ else
151+ n = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
152+ }
153+#endif
154 if (n == 0)
155 return 1;
156 return 0;
This page took 0.07786 seconds and 4 git commands to generate.