[Python-checkins] python/dist/src/Modules socketmodule.c,1.219,1.220
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Thu, 06 Jun 2002 18:42:49 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv17706
Modified Files:
socketmodule.c
Log Message:
Correct several blunders in the timeout code, mostly my own fault (for
not testing it -- apparently test_timeout.py doesn't test anything
useful):
In internal_select():
- The tv_usec part of the timeout for select() was calculated wrong.
- The first argument to select() was one too low.
- The sense of the direction argument to internal_select() was
inverted.
In PySocketSock_settimeout():
- The calls to internal_setblocking() were swapped.
Also, repaired some comments and fixed the test for the return value
of internal_select() in sendall -- this was in the original patch.
Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.219
retrieving revision 1.220
diff -C2 -d -r1.219 -r1.220
*** socketmodule.c 6 Jun 2002 21:08:16 -0000 1.219
--- socketmodule.c 7 Jun 2002 01:42:47 -0000 1.220
***************
*** 488,496 ****
/* For access to the select module to poll the socket for timeout
! * functionality. If reading is: 1 poll as read, 0, poll as write.
* Return value: -1 if error, 0 if not ready, >= 1 if ready.
*/
static int
! internal_select(PySocketSockObject *s, int reading)
{
fd_set fds;
--- 488,497 ----
/* For access to the select module to poll the socket for timeout
! * functionality. writing is 1 for writing, 0 for reading.
* Return value: -1 if error, 0 if not ready, >= 1 if ready.
+ * An exception is set when the return value is <= 0 (!).
*/
static int
! internal_select(PySocketSockObject *s, int writing)
{
fd_set fds;
***************
*** 500,512 ****
/* Construct the arguments to select */
tv.tv_sec = (int)s->sock_timeout;
! tv.tv_usec = (int)(s->sock_timeout/1e6);
FD_ZERO(&fds);
FD_SET(s->sock_fd, &fds);
/* See if the socket is ready */
! if (reading)
! count = select(s->sock_fd, &fds, NULL, NULL, &tv);
else
! count = select(s->sock_fd, NULL, &fds, NULL, &tv);
/* Check for errors */
--- 501,513 ----
/* Construct the arguments to select */
tv.tv_sec = (int)s->sock_timeout;
! tv.tv_usec = (int)((s->sock_timeout - tv.tv_sec) * 1e6);
FD_ZERO(&fds);
FD_SET(s->sock_fd, &fds);
/* See if the socket is ready */
! if (writing)
! count = select(s->sock_fd+1, NULL, &fds, NULL, &tv);
else
! count = select(s->sock_fd+1, &fds, NULL, NULL, &tv);
/* Check for errors */
***************
*** 1076,1082 ****
This uses the FIONBIO ioctl with the O_NDELAY flag.";
! /* s.settimeout (float | int | long) method.
! * Causes an exception to be raised when the integer number of seconds
! * has elapsed when performing a blocking socket operation.
*/
static PyObject *
--- 1077,1083 ----
This uses the FIONBIO ioctl with the O_NDELAY flag.";
! /* s.settimeout(float | None) method.
! * Causes an exception to be raised when the given time has
! * elapsed when performing a blocking socket operation.
*/
static PyObject *
***************
*** 1111,1118 ****
* blocking by nature.
*/
! if (value < 0.0)
! internal_setblocking(s, 0);
! else
! internal_setblocking(s, 1);
s->sock_blocking = 1; /* Always negate setblocking() */
--- 1112,1116 ----
* blocking by nature.
*/
! internal_setblocking(s, value < 0.0);
s->sock_blocking = 1; /* Always negate setblocking() */
***************
*** 1820,1824 ****
if (s->sock_timeout >= 0.0) {
if (s->sock_blocking) {
! if (internal_select(s, 1) < 0)
return NULL;
}
--- 1818,1822 ----
if (s->sock_timeout >= 0.0) {
if (s->sock_blocking) {
! if (internal_select(s, 1) <= 0)
return NULL;
}