OSSP CVS Repository

ossp - Check-in [4990]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 4990
Date: 2005-Jan-29 09:17:32 (local)
2005-Jan-29 08:17:32 (UTC)
User:rse
Branch:
Comment: Fix timeout handling in various functions by fixing the internal select(2) usage: the timeout structure is (standard compliantly) modified in place on some platforms (like Linux), so its values have to be preserved before calls to select(2)).

Problem found by: Robert Wood <Robert.Wood@smdc.army.mil>

Tickets:
Inspections:
Files:
ossp-pkg/sa/ChangeLog      1.43 -> 1.44     8 inserted, 0 deleted
ossp-pkg/sa/THANKS      1.6 -> 1.7     1 inserted, 0 deleted
ossp-pkg/sa/sa.c      1.88 -> 1.89     20 inserted, 12 deleted

ossp-pkg/sa/ChangeLog 1.43 -> 1.44

--- ChangeLog    2005/01/24 15:10:09     1.43
+++ ChangeLog    2005/01/29 08:17:32     1.44
@@ -11,6 +11,14 @@
   This is a list of all changes to OSSP sa.
   For a more brief summary please have a look at the NEWS file.
 
+  Changes between 1.2.3 and 1.2.4 (24-Jan-2005 to 29-Jan-2005)
+
+   o Fix timeout handling in various functions by fixing the internal
+     select(2) usage: the timeout structure is (standard compliantly)
+     modified in place on some platforms (like Linux), so its values
+     have to be preserved before calls to select(2)).
+     [Robert Wood <Robert.Wood@smdc.army.mil>]
+
   Changes between 1.2.2 and 1.2.3 (26-Jun-2004 to 24-Jan-2005)
 
    o Adjusted all copyright messages for new year 2005.


ossp-pkg/sa/THANKS 1.6 -> 1.7

--- THANKS       2004/06/26 11:16:02     1.6
+++ THANKS       2005/01/29 08:17:32     1.7
@@ -24,4 +24,5 @@
     o  Amos Gouaux                 <amos@utdallas.edu>
     o  Thomas Lotterer             <thomas@lotterer.net>
     o  Alvaro Lopez Ortega         <alvaro@alobbs.com>
+    o  Robert Wood                 <Robert.Wood@smdc.army.mil>
 


ossp-pkg/sa/sa.c 1.88 -> 1.89

--- sa.c 2005/01/24 15:10:09     1.88
+++ sa.c 2005/01/29 08:17:32     1.89
@@ -1456,6 +1456,7 @@
     socklen_t len;
     sa_rc_t rv;
     struct timeval *tv;
+    struct timeval tv_buf;
 
     /* argument sanity check(s) */
     if (sa == NULL || raddr == NULL)
@@ -1512,8 +1513,10 @@
     FD_ZERO(&wset);
     FD_SET(sa->fdSocket, &rset);
     FD_SET(sa->fdSocket, &wset);
-    if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_CONNECT]))
-        tv = &sa->tvTimeout[SA_TIMEOUT_CONNECT];
+    if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_CONNECT])) {
+        memcpy(&tv_buf, &sa->tvTimeout[SA_TIMEOUT_CONNECT], sizeof(struct timeval));
+        tv = &tv_buf;
+    }
     else
         tv = NULL;
     do {
@@ -1591,6 +1594,7 @@
 #endif
     } sa_buf;
     socklen_t sa_size;
+    struct timeval tv;
     int s;
     int i;
 
@@ -1610,9 +1614,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_ACCEPT])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_ACCEPT], sizeof(struct timeval));
         do {
-            n = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL,
-                             &sa->tvTimeout[SA_TIMEOUT_ACCEPT]);
+            n = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL, &tv);
         } while (n == -1 && errno == EINTR);
         if (n == 0)
             return SA_RC(SA_ERR_TMT);
@@ -1763,6 +1767,7 @@
     int rv;
 #if !(defined(SO_RCVTIMEO) && defined(USE_SO_RCVTIMEO) && defined(SO_SNDTIMEO) && defined(USE_SO_SNDTIMEO))
     fd_set fds;
+    struct timeval tv;
 #endif
 
     /* if timeout is enabled, perform explicit/smart blocking instead
@@ -1771,9 +1776,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_READ])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_READ], sizeof(struct timeval));
         do {
-            rv = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL,
-                              &sa->tvTimeout[SA_TIMEOUT_READ]);
+            rv = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL, &tv);
         } while (rv == -1 && errno == EINTR);
         if (rv == 0) {
             errno = ETIMEDOUT;
@@ -1942,6 +1947,7 @@
     int rv;
 #if !(defined(SO_RCVTIMEO) && defined(USE_SO_RCVTIMEO) && defined(SO_SNDTIMEO) && defined(USE_SO_SNDTIMEO))
     fd_set fds;
+    struct timeval tv;
 #endif
 
     /* if timeout is enabled, perform explicit/smart blocking instead
@@ -1950,9 +1956,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_WRITE])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_WRITE], sizeof(struct timeval));
         do {
-            rv = SA_SC_CALL_5(sa, select, sa->fdSocket+1, (fd_set *)NULL, &fds, (fd_set *)NULL,
-                              &sa->tvTimeout[SA_TIMEOUT_WRITE]);
+            rv = SA_SC_CALL_5(sa, select, sa->fdSocket+1, (fd_set *)NULL, &fds, (fd_set *)NULL, &tv);
         } while (rv == -1 && errno == EINTR);
         if (rv == 0) {
             errno = ETIMEDOUT;
@@ -2177,6 +2183,7 @@
     ssize_t n;
     int k;
     fd_set fds;
+    struct timeval tv;
 
     /* argument sanity check(s) */
     if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
@@ -2195,9 +2202,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_READ])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_READ], sizeof(struct timeval));
         do {
-            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL,
-                             &sa->tvTimeout[SA_TIMEOUT_READ]);
+            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, &fds, (fd_set *)NULL, (fd_set *)NULL, &tv);
         } while (k == -1 && errno == EINTR);
         if (k == 0)
             errno = ETIMEDOUT;
@@ -2233,6 +2240,7 @@
     int k;
     fd_set fds;
     sa_rc_t rv;
+    struct timeval tv;
 
     /* argument sanity check(s) */
     if (sa == NULL || buf == NULL || buflen == 0 || raddr == NULL)
@@ -2252,9 +2260,9 @@
     if (!SA_TVISZERO(sa->tvTimeout[SA_TIMEOUT_WRITE])) {
         FD_ZERO(&fds);
         FD_SET(sa->fdSocket, &fds);
+        memcpy(&tv, &sa->tvTimeout[SA_TIMEOUT_WRITE], sizeof(struct timeval));
         do {
-            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, (fd_set *)NULL, &fds, (fd_set *)NULL,
-                             &sa->tvTimeout[SA_TIMEOUT_WRITE]);
+            k = SA_SC_CALL_5(sa, select, sa->fdSocket+1, (fd_set *)NULL, &fds, (fd_set *)NULL, &tv);
         } while (k == -1 && errno == EINTR);
         if (k == 0)
             errno = ETIMEDOUT;

CVSTrac 2.0.1