]> sjero.net Git - wget/commitdiff
[svn] Generalized the third argument to select_fd.
authorhniksic <devnull@localhost>
Sun, 2 Nov 2003 23:17:59 +0000 (15:17 -0800)
committerhniksic <devnull@localhost>
Sun, 2 Nov 2003 23:17:59 +0000 (15:17 -0800)
src/ChangeLog
src/connect.c
src/connect.h
src/gen_sslfunc.c

index 9622f2830641f781d681b6e9dd015a87e2e69706..d4959915ecaf6669b4d04d22ce96abae53cd352a 100644 (file)
@@ -1,3 +1,9 @@
+2003-11-03  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * connect.c (select_fd): Generalize the third argument into WAIT,
+       so that the caller can request waiting for both read and write.
+       Updated callers.
+
 2003-11-02  Hrvoje Niksic  <hniksic@xemacs.org>
 
        * html-url.c (cleanup_html_url): Destroy the hash tables, don't
index 4136cc6e6206d2839e267bbd6c72a4a4d9783270..52dc0b01f2e0f27301da5678d5dacb57b7d63e5c 100644 (file)
@@ -464,29 +464,34 @@ bindport (const ip_address *bind_address, int *port, int *local_sock)
 }
 
 #ifdef HAVE_SELECT
-/* Wait for file descriptor FD to be available, timing out after
-   MAXTIME seconds.  "Available" means readable if writep is 0,
-   writeable otherwise.
+/* Wait for file descriptor FD to be readable or writable or both,
+   timing out after MAXTIME seconds.  Returns 1 if FD is available, 0
+   for timeout and -1 for error.  The argument WHAT can be a
+   combination of WAIT_READ and WAIT_WRITE.
 
-   Returns 1 if FD is available, 0 for timeout and -1 for error.  */
+   This is a mere convenience wrapper around the select call, and
+   should be taken as such.  */
 
 int
-select_fd (int fd, double maxtime, int writep)
+select_fd (int fd, double maxtime, int wait)
 {
-  fd_set fds;
-  fd_set *rd = NULL, *wrt = NULL;
+  fd_set fdset;
+  fd_set *rd = NULL, *wr = NULL;
   struct timeval tmout;
   int result;
 
-  FD_ZERO (&fds);
-  FD_SET (fd, &fds);
-  *(writep ? &wrt : &rd) = &fds;
+  FD_ZERO (&fdset);
+  FD_SET (fd, &fdset);
+  if (wait & WAIT_READ)
+    rd = &fdset;
+  if (wait & WAIT_WRITE)
+    wr = &fdset;
 
   tmout.tv_sec = (long)maxtime;
   tmout.tv_usec = 1000000L * (maxtime - (long)maxtime);
 
   do
-    result = select (fd + 1, rd, wrt, NULL, &tmout);
+    result = select (fd + 1, rd, wr, NULL, &tmout);
   while (result < 0 && errno == EINTR);
 
   /* When we've timed out, set errno to ETIMEDOUT for the convenience
@@ -512,7 +517,7 @@ acceptport (int local_sock, int *sock)
 
 #ifdef HAVE_SELECT
   if (opt.connect_timeout)
-    if (select_fd (local_sock, opt.connect_timeout, 0) <= 0)
+    if (select_fd (local_sock, opt.connect_timeout, WAIT_READ) <= 0)
       return ACCEPTERR;
 #endif
   if ((*sock = accept (local_sock, sa, &addrlen)) < 0)
@@ -576,7 +581,7 @@ iread (int fd, char *buf, int len)
 
 #ifdef HAVE_SELECT
   if (opt.read_timeout)
-    if (select_fd (fd, opt.read_timeout, 0) <= 0)
+    if (select_fd (fd, opt.read_timeout, WAIT_READ) <= 0)
       return -1;
 #endif
   do
@@ -604,7 +609,7 @@ iwrite (int fd, char *buf, int len)
     {
 #ifdef HAVE_SELECT
       if (opt.read_timeout)
-       if (select_fd (fd, opt.read_timeout, 1) <= 0)
+       if (select_fd (fd, opt.read_timeout, WAIT_WRITE) <= 0)
          return -1;
 #endif
       do
index ab161c0b7d25061f4df56805f39aed0cf8ce460d..8b0ed4b31d57605e8ac9ed87248fb7bb877a4fb6 100644 (file)
@@ -37,6 +37,12 @@ enum {
   E_HOST = -100
 };
 
+/* Flags for select_fd's WAIT argument. */
+enum {
+  WAIT_READ = 1,
+  WAIT_WRITE = 2
+};
+
 /* bindport flags */
 #define BIND_ON_IPV4_ONLY LH_IPV4_ONLY
 #define BIND_ON_IPV6_ONLY LH_IPV6_ONLY
index d9f1ceccbb1bd4a5f0e35aa9dfabba4ea8f99510..1e3ecffc5056045f88dde4a7bdc4777a5bbbf9a9 100644 (file)
@@ -318,7 +318,7 @@ ssl_iread (SSL *con, char *buf, int len)
   BIO_get_fd (con->rbio, &fd);
 #ifdef HAVE_SELECT
   if (opt.read_timeout && !SSL_pending (con))
-    if (select_fd (fd, opt.read_timeout, 0) <= 0)
+    if (select_fd (fd, opt.read_timeout, WAIT_READ) <= 0)
       return -1;
 #endif
   do
@@ -344,7 +344,7 @@ ssl_iwrite (SSL *con, char *buf, int len)
     {
 #ifdef HAVE_SELECT
       if (opt.read_timeout)
-       if (select_fd (fd, opt.read_timeout, 1) <= 0)
+       if (select_fd (fd, opt.read_timeout, WAIT_WRITE) <= 0)
          return -1;
 #endif
       do