]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
reinstall read handlers when we get EAGAIN or EWOULDBLOCK
authorwessels <>
Fri, 29 Mar 1996 03:42:46 +0000 (03:42 +0000)
committerwessels <>
Fri, 29 Mar 1996 03:42:46 +0000 (03:42 +0000)
src/ftp.cc
src/gopher.cc
src/http.cc
src/wais.cc

index e575b1f7c71708d956d156c243e5964c2d6f05e3..f1bf72c9106c6b39bc89b135bf505a671dbcff20 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: ftp.cc,v 1.13 1996/03/27 18:15:45 wessels Exp $ */
+/* $Id: ftp.cc,v 1.14 1996/03/28 20:42:46 wessels Exp $ */
 
 #include "squid.h"
 
@@ -169,9 +169,28 @@ int ftpReadReply(fd, data)
     if (len < 0 || ((len == 0) && (entry->mem_obj->e_current_len == 0))) {
        if (len < 0)
            debug(0, 1, "ftpReadReply: read error: %s\n", xstrerror());
-       cached_error_entry(entry, ERR_READ_ERROR, NULL);
-       comm_close(fd);
-       safe_free(data);
+       if (errno == ECONNRESET) {
+           /* Connection reset by peer */
+           /* consider it as a EOF */
+           if (!(entry->flag & DELETE_BEHIND))
+               entry->expires = cached_curtime + ttlSet(entry);
+           sprintf(tmp_error_buf, "\nWarning: The Remote Server sent RESET at the end of transmission.\n");
+           storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
+           storeComplete(entry);
+           comm_close(fd);
+           safe_free(data);
+       } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+           /* reinstall handlers */
+           /* XXX This may loop forever */
+           comm_set_select_handler(fd, COMM_SELECT_READ,
+               (PF) ftpReadReply, (caddr_t) data);
+           /* note there is no ftpReadReplyTimeout.  Timeouts are handled
+            * by `ftpget'. */
+       } else {
+           cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
+           comm_close(fd);
+           safe_free(data);
+       }
     } else if (len == 0) {
        /* Connection closed; retrieval done. */
        if (!data->got_marker) {
index b731f010f32bcb7aa5e14fddb9a6f2c2c63d441c..48f9a1c50ed0775ea08e3d19ce5b98cf7245b83f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gopher.cc,v 1.9 1996/03/27 18:15:45 wessels Exp $ */
+/* $Id: gopher.cc,v 1.10 1996/03/28 20:42:47 wessels Exp $ */
 
 #include "squid.h"
 
@@ -651,15 +651,35 @@ int gopherReadReply(fd, data)
        }
     }
     buf = get_free_4k_page();
+    errno = 0;
     len = read(fd, buf, TEMP_BUF_SIZE - 1);    /* leave one space for \0 in gopherToHTML */
-    debug(0, 5, "gopherReadReply - fd: %d read len:%d\n", fd, len);
+    debug(0, 5, "gopherReadReply: FD %d read len=%d\n", fd, len);
 
     if (len < 0 || ((len == 0) && (entry->mem_obj->e_current_len == 0))) {
-       debug(0, 1, "gopherReadReply - error reading: %s\n",
+       debug(0, 1, "gopherReadReply: error reading: %s\n",
            xstrerror());
-       cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
-       comm_close(fd);
-       freeGopherData(data);
+       if (errno == ECONNRESET) {
+           /* Connection reset by peer */
+           /* consider it as a EOF */
+           if (!(entry->flag & DELETE_BEHIND))
+               entry->expires = cached_curtime + ttlSet(entry);
+           sprintf(tmp_error_buf, "\nWarning: The Remote Server sent RESET at the end of transmission.\n");
+           storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
+           storeComplete(entry);
+           comm_close(fd);
+           freeGopherData(data);
+       } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+           /* reinstall handlers */
+           /* XXX This may loop forever */
+           comm_set_select_handler(fd, COMM_SELECT_READ,
+               (PF) gopherReadReply, (caddr_t) data);
+           comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT,
+               (PF) gopherReadReplyTimeout, (caddr_t) data, getReadTimeout());
+       } else {
+           cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
+           comm_close(fd);
+           freeGopherData(data);
+       }
     } else if (len == 0) {
        /* Connection closed; retrieval done. */
        /* flush the rest of data in temp buf if there is one. */
@@ -671,7 +691,6 @@ int gopherReadReply(fd, data)
        storeComplete(entry);
        comm_close(fd);
        freeGopherData(data);
-
     } else if (((entry->mem_obj->e_current_len + len) > getGopherMax()) &&
        !(entry->flag & DELETE_BEHIND)) {
        /*  accept data, but start to delete behind it */
@@ -724,7 +743,7 @@ void gopherSendComplete(fd, buf, size, errflag, data)
 {
     StoreEntry *entry = NULL;
     entry = data->entry;
-    debug(0, 5, "gopherSendComplete - fd: %d size: %d errflag: %d\n",
+    debug(0, 5, "gopherSendComplete: FD %d size: %d errflag: %d\n",
        fd, size, errflag);
     if (errflag) {
        cached_error_entry(entry, ERR_CONNECT_FAIL, xstrerror());
@@ -818,7 +837,7 @@ int gopherSendRequest(fd, data)
        sprintf(buf, "%s%c%c", data->request, CR, LF);
     }
 
-    debug(0, 5, "gopherSendRequest - fd: %d\n", fd);
+    debug(0, 5, "gopherSendRequest: FD %d\n", fd);
     data->icp_rwd_ptr = icpWrite(fd,
        buf,
        len,
@@ -839,7 +858,7 @@ int gopherStart(unusedfd, url, entry)
 
     data->entry = entry;
 
-    debug(0, 3, "gopherStart - url: %s\n", url);
+    debug(0, 3, "gopherStart: url: %s\n", url);
 
     /* Parse url. */
     if (gopher_url_parser(url, data->host, &data->port,
@@ -896,7 +915,7 @@ int gopherStart(unusedfd, url, entry)
            freeGopherData(data);
            return COMM_ERROR;
        } else {
-           debug(0, 5, "startGopher - conn %d EINPROGRESS\n", sock);
+           debug(0, 5, "startGopher: conn %d EINPROGRESS\n", sock);
        }
     }
     /* Install connection complete handler. */
index 292183aeef4dd34491dab6eee4414b940c9647bb..15160b89d2930abeb39360ee7d2f2f54677a91d8 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: http.cc,v 1.11 1996/03/27 18:15:46 wessels Exp $ */
+/* $Id: http.cc,v 1.12 1996/03/28 20:42:48 wessels Exp $ */
 
 #include "squid.h"
 
@@ -194,19 +194,20 @@ void httpReadReply(fd, data)
            sprintf(tmp_error_buf, "\n<p>Warning: The Remote Server sent RESET at the end of transmission.\n");
            storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
            storeComplete(entry);
-#ifdef POSSIBLE_FIX
+           comm_close(fd);
+           safe_free(data);
        } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
            /* reinstall handlers */
+           /* XXX This may loop forever */
            comm_set_select_handler(fd, COMM_SELECT_READ,
                (PF) httpReadReply, (caddr_t) data);
            comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT,
                (PF) httpReadReplyTimeout, (caddr_t) data, getReadTimeout());
-#endif
        } else {
            cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
+           comm_close(fd);
+           safe_free(data);
        }
-       comm_close(fd);
-       safe_free(data);
     } else if (len == 0) {
        /* Connection closed; retrieval done. */
        if (!(entry->flag & DELETE_BEHIND))
index 0d9da16b94b2687668fa22ece3ffeaa3e040ee75..0969c2ad204b228becbb9ae47109246406a49bad 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: wais.cc,v 1.12 1996/03/28 05:39:21 wessels Exp $ */
+/* $Id: wais.cc,v 1.13 1996/03/28 20:42:48 wessels Exp $ */
 
 #include "squid.h"
 
@@ -121,16 +121,25 @@ void waisReadReply(fd, data)
        if (errno == ECONNRESET) {
            /* Connection reset by peer */
            /* consider it as a EOF */
-           entry->expires = cached_curtime;
-
-           sprintf(tmp_error_buf, "\n<p>Warning: The Remote Server sent RESET at the end of transmission.\n");
+           if (!(entry->flag & DELETE_BEHIND))
+               entry->expires = cached_curtime + ttlSet(entry);
+           sprintf(tmp_error_buf, "\nWarning: The Remote Server sent RESET at the end of transmission.\n");
            storeAppend(entry, tmp_error_buf, strlen(tmp_error_buf));
            storeComplete(entry);
+           comm_close(fd);
+           safe_free(data);
+       } else if (errno == EAGAIN || errno == EWOULDBLOCK) {
+           /* reinstall handlers */
+           /* XXX This may loop forever */
+           comm_set_select_handler(fd, COMM_SELECT_READ,
+               (PF) waisReadReply, (caddr_t) data);
+           comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT,
+               (PF) waisReadReplyTimeout, (caddr_t) data, getReadTimeout());
        } else {
            cached_error_entry(entry, ERR_READ_ERROR, xstrerror());
+           comm_close(fd);
+           safe_free(data);
        }
-       comm_close(fd);
-       safe_free(data);
     } else if (len == 0) {
        /* Connection closed; retrieval done. */
        entry->expires = cached_curtime;
@@ -143,15 +152,26 @@ void waisReadReply(fd, data)
        storeStartDeleteBehind(entry);
 
        storeAppend(entry, buf, len);
-       comm_set_select_handler(fd, COMM_SELECT_READ, (PF) waisReadReply, (caddr_t) data);
-       comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT, (PF) waisReadReplyTimeout,
-           (caddr_t) data, getReadTimeout());
-
+       comm_set_select_handler(fd,
+           COMM_SELECT_READ,
+           (PF) waisReadReply,
+           (caddr_t) data);
+       comm_set_select_handler_plus_timeout(fd,
+           COMM_SELECT_TIMEOUT,
+           (PF) waisReadReplyTimeout,
+           (caddr_t) data,
+           getReadTimeout());
     } else {
        storeAppend(entry, buf, len);
-       comm_set_select_handler(fd, COMM_SELECT_READ, (PF) waisReadReply, (caddr_t) data);
-       comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT, (PF) waisReadReplyTimeout,
-           (caddr_t) data, getReadTimeout());
+       comm_set_select_handler(fd,
+           COMM_SELECT_READ,
+           (PF) waisReadReply,
+           (caddr_t) data);
+       comm_set_select_handler_plus_timeout(fd,
+           COMM_SELECT_TIMEOUT,
+           (PF) waisReadReplyTimeout,
+           (caddr_t) data,
+           getReadTimeout());
     }
 }
 
@@ -174,9 +194,15 @@ void waisSendComplete(fd, buf, size, errflag, data)
        safe_free(data);
     } else {
        /* Schedule read reply. */
-       comm_set_select_handler(fd, COMM_SELECT_READ, (PF) waisReadReply, (caddr_t) data);
-       comm_set_select_handler_plus_timeout(fd, COMM_SELECT_TIMEOUT, (PF) waisReadReplyTimeout,
-           (caddr_t) data, getReadTimeout());
+       comm_set_select_handler(fd,
+           COMM_SELECT_READ,
+           (PF) waisReadReply,
+           (caddr_t) data);
+       comm_set_select_handler_plus_timeout(fd,
+           COMM_SELECT_TIMEOUT,
+           (PF) waisReadReplyTimeout,
+           (caddr_t) data,
+           getReadTimeout());
     }
     safe_free(buf);            /* Allocated by waisSendRequest. */
 }