]> sjero.net Git - wget/blobdiff - src/connect.c
[svn] Only allocate an error string on actual error.
[wget] / src / connect.c
index 35f50cc50803c19e7f8a1e096a50d65aa6222d8d..dc7145f20a94686d72b55c0fb228ce445dcf7b95 100644 (file)
@@ -638,6 +638,17 @@ select_fd (int fd, double maxtime, int wait_for)
   return result;
 }
 
+/* Return true iff the connection to the remote site established
+   through SOCK is still open.
+
+   Specifically, this function returns true if SOCK is not ready for
+   reading.  This is because, when the connection closes, the socket
+   is ready for reading because EOF is about to be delivered.  A side
+   effect of this method is that sockets that have pending data are
+   considered non-open.  This is actually a good thing for callers of
+   this function, where such pending data can only be unwanted
+   leftover from a previous request.  */
+
 bool
 test_socket_open (int sock)
 {
@@ -654,13 +665,12 @@ test_socket_open (int sock)
   to.tv_sec = 0;
   to.tv_usec = 1;
 
-  /* If we get a timeout, then that means still connected */
   if (select (sock + 1, &check_set, NULL, NULL, &to) == 0)
-    {
-      /* Connection is valid (not EOF), so continue */
-      return true;
-    }
+    /* We got a timeout, it means we're still connected. */
+    return true;
   else
+    /* Read now would not wait, it means we have either pending data
+       or EOF/error. */
     return false;
 }
 \f
@@ -787,7 +797,8 @@ fd_transport_context (int fd)
 
 #define LAZY_RETRIEVE_INFO(info) do {                                  \
   static struct transport_info *last_info;                             \
-  static int last_fd = -1, last_tick;                                  \
+  static int last_fd = -1;                                             \
+  static unsigned int last_tick;                                       \
   if (!transport_map)                                                  \
     info = NULL;                                                       \
   else if (last_fd == fd && last_tick == transport_map_modified_tick)  \
@@ -902,7 +913,8 @@ fd_write (int fd, char *buf, int bufsize, double timeout)
    used.
 
    If the transport doesn't support error messages or doesn't supply
-   one, strerror(errno) is returned.  */
+   one, strerror(errno) is returned.  The returned error message
+   should not be used after fd_close has been called.  */
 
 const char *
 fd_errstr (int fd)