From: wessels <> Date: Mon, 2 Jun 1997 11:39:43 +0000 (+0000) Subject: change CLIENT_ABORT_REQUEST into mem_obj->abort.callback() X-Git-Tag: SQUID_3_0_PRE1~4959 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bfcaf585362143aa0255692766642768d029d9c4;p=thirdparty%2Fsquid.git change CLIENT_ABORT_REQUEST into mem_obj->abort.callback() --- diff --git a/src/ftp.cc b/src/ftp.cc index b731758ca3..a52ae21022 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.115 1997/06/02 01:06:11 wessels Exp $ + * $Id: ftp.cc,v 1.116 1997/06/02 05:39:43 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -141,6 +141,7 @@ static void ftpRestOrList _PARAMS((FtpStateData * ftpState)); static void ftpReadQuit _PARAMS((FtpStateData * ftpState)); static void ftpDataTransferDone _PARAMS((FtpStateData * ftpState)); static void ftpAppendSuccessHeader _PARAMS((FtpStateData * ftpState)); +static STABH ftpAbort; static FTPSM ftpReadWelcome; static FTPSM ftpReadUser; @@ -182,6 +183,7 @@ ftpStateFree(int fd, void *data) if (ftpState == NULL) return; storeUnlockObject(ftpState->entry); + storeUnregisterAbort(ftpState->entry); if (ftpState->reply_hdr) { put_free_8k_page(ftpState->reply_hdr); ftpState->reply_hdr = NULL; @@ -598,22 +600,17 @@ ftpReadData(int fd, void *data) int clen; int off; int bin; - StoreEntry *entry = NULL; + StoreEntry *entry = ftpState->entry; assert(fd == ftpState->data.fd); - entry = ftpState->entry; if (protoAbortFetch(entry)) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - ftpDataTransferDone(ftpState); - return; + squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); + ftpDataTransferDone(ftpState); + return; } /* check if we want to defer reading */ clen = entry->mem_obj->e_current_len; off = storeGetLowestReaderOffset(entry); if ((clen - off) > FTP_DELETE_GAP) { - if (entry->flag & CLIENT_ABORT_REQUEST) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - ftpDataTransferDone(ftpState); - } IOStats.Ftp.reads_deferred++; debug(9, 3, "ftpReadData: Read deferred for Object: %s\n", entry->url); @@ -669,9 +666,6 @@ ftpReadData(int fd, void *data) storeTimestampsSet(entry); storeComplete(entry); ftpDataTransferDone(ftpState); - } else if (entry->flag & CLIENT_ABORT_REQUEST) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - ftpDataTransferDone(ftpState); } else { if (EBIT_TEST(ftpState->flags, FTP_ISDIR)) { ftpParseListing(ftpState, len); @@ -866,6 +860,7 @@ ftpStart(request_t * request, StoreEntry * entry) ftpState->ctrl.fd = fd; comm_add_close_handler(fd, ftpStateFree, ftpState); commSetTimeout(fd, Config.Timeout.connect, ftpTimeout, ftpState); + storeRegisterAbort(entry, ftpAbort, ftpState); ipcache_nbgethostbyname(request->host, fd, ftpConnect, ftpState); } @@ -1004,11 +999,6 @@ ftpReadControlReply(int fd, void *data) debug(9, 5, "ftpReadControlReply: FD %d, Read %d bytes\n", fd, len); if (len > 0) commSetTimeout(fd, Config.Timeout.read, NULL, NULL); - if (entry->flag & CLIENT_ABORT_REQUEST) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - comm_close(fd); - return; - } if (len < 0) { debug(50, 1, "ftpReadControlReply: read error: %s\n", xstrerror()); if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { @@ -1499,3 +1489,11 @@ ftpAppendSuccessHeader(FtpStateData * ftpState) assert(e->flag & KEY_PRIVATE); storeSetPublicKey(e); } + +static void +ftpAbort(void *data) +{ + FtpStateData *ftpState = data; + debug(9, 1, "ftpAbort: %s\n", ftpState->entry->url); + ftpDataTransferDone(ftpState); +} diff --git a/src/gopher.cc b/src/gopher.cc index 86078b0f22..f24d35b971 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,5 +1,5 @@ /* - * $Id: gopher.cc,v 1.81 1997/05/22 15:51:54 wessels Exp $ + * $Id: gopher.cc,v 1.82 1997/06/02 05:39:44 wessels Exp $ * * DEBUG: section 10 Gopher * AUTHOR: Harvest Derived @@ -156,6 +156,7 @@ typedef struct gopher_ds { int cso_recno; int len; char *buf; /* pts to a 4k page */ + int fd; } GopherStateData; static PF gopherStateFree; @@ -178,6 +179,7 @@ static void gopherSendComplete(int fd, static PF gopherSendRequest; static GopherStateData *CreateGopherStateData _PARAMS((void)); static CNCB gopherConnectDone; +static STABH gopherAbort; static char def_gopher_bin[] = "www/unknown"; static char def_gopher_text[] = "text/plain"; @@ -188,8 +190,10 @@ gopherStateFree(int fd, void *data) GopherStateData *gopherState = data; if (gopherState == NULL) return; - if (gopherState->entry) + if (gopherState->entry) { storeUnlockObject(gopherState->entry); + storeUnregisterAbort(gopherState->entry); + } put_free_4k_page(gopherState->buf); xfree(gopherState); } @@ -652,28 +656,21 @@ static void gopherReadReply(int fd, void *data) { GopherStateData *gopherState = data; + StoreEntry *entry = gopherState->entry; char *buf = NULL; int len; int clen; int off; - StoreEntry *entry = NULL; int bin; - - entry = gopherState->entry; if (protoAbortFetch(entry)) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - comm_close(fd); - return; + squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); + comm_close(fd); + return; } /* check if we want to defer reading */ clen = entry->mem_obj->e_current_len; off = storeGetLowestReaderOffset(entry); if ((clen - off) > GOPHER_DELETE_GAP) { - if (entry->flag & CLIENT_ABORT_REQUEST) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - comm_close(fd); - return; - } IOStats.Gopher.reads_deferred++; debug(10, 3, "gopherReadReply: Read deferred for Object: %s\n", entry->url); @@ -737,12 +734,6 @@ gopherReadReply(int fd, void *data) BIT_RESET(entry->flag, DELAY_SENDING); storeComplete(entry); comm_close(fd); - } else if (entry->flag & CLIENT_ABORT_REQUEST) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - if (gopherState->conversion != NORMAL) - gopherEndHTML(data); - BIT_RESET(entry->flag, DELAY_SENDING); - comm_close(fd); } else { if (gopherState->conversion != NORMAL) { gopherToHTML(data, buf, len); @@ -879,9 +870,8 @@ gopherStart(StoreEntry * entry) gopherStateFree(-1, gopherState); return; } - comm_add_close_handler(fd, - gopherStateFree, - gopherState); + comm_add_close_handler(fd, gopherStateFree, gopherState); + storeRegisterAbort(entry, gopherAbort, gopherState); /* check if IP is already in cache. It must be. * It should be done before this route is called. * Otherwise, we cannot check return code for connect. */ @@ -917,6 +907,7 @@ gopherStart(StoreEntry * entry) gopherState->port, gopherConnectDone, gopherState); + gopherState->fd = fd; } static void @@ -945,3 +936,11 @@ CreateGopherStateData(void) gd->buf = get_free_4k_page(); return (gd); } + +static void +gopherAbort(void *data) +{ + GopherStateData *gopherState = data; + debug(10,1,"gopherAbort: %s\n", gopherState->entry->url); + comm_close(gopherState->fd); +} diff --git a/src/http.cc b/src/http.cc index 601b7b144e..26092efc62 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.166 1997/06/01 23:22:20 wessels Exp $ + * $Id: http.cc,v 1.167 1997/06/02 05:39:45 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -208,6 +208,7 @@ static void httpAppendRequestHeader _PARAMS((char *hdr, const char *line, size_t static void httpCacheNegatively _PARAMS((StoreEntry *)); static void httpMakePrivate _PARAMS((StoreEntry *)); static void httpMakePublic _PARAMS((StoreEntry *)); +static STABH httpAbort; static void httpStateFree(int fd, void *data) @@ -216,6 +217,7 @@ httpStateFree(int fd, void *data) if (httpState == NULL) return; storeUnlockObject(httpState->entry); + storeUnregisterAbort(httpState->entry); if (httpState->reply_hdr) { put_free_8k_page(httpState->reply_hdr); httpState->reply_hdr = NULL; @@ -521,27 +523,20 @@ httpReadReply(int fd, void *data) { HttpStateData *httpState = data; LOCAL_ARRAY(char, buf, SQUID_TCP_SO_RCVBUF); + StoreEntry *entry = httpState->entry; int len; int bin; int clen; int off; - StoreEntry *entry = NULL; - - entry = httpState->entry; if (protoAbortFetch(entry)) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - comm_close(fd); - return; + squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); + comm_close(fd); + return; } /* check if we want to defer reading */ clen = entry->mem_obj->e_current_len; off = storeGetLowestReaderOffset(entry); if ((clen - off) > HTTP_DELETE_GAP) { - if (entry->flag & CLIENT_ABORT_REQUEST) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - comm_close(fd); - return; - } IOStats.Http.reads_deferred++; debug(11, 3, "httpReadReply: Read deferred for Object: %s\n", entry->url); @@ -602,9 +597,6 @@ httpReadReply(int fd, void *data) storeAppend(entry, buf, len); /* invoke handlers! */ storeComplete(entry); /* deallocates mem_obj->request */ comm_close(fd); - } else if (entry->flag & CLIENT_ABORT_REQUEST) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - comm_close(fd); } else { if (httpState->reply_hdr_state < 2) httpProcessReplyHeader(httpState, buf, len); @@ -897,12 +889,11 @@ httpConnectDone(int fd, int status, void *data) peerCheckConnectStart(httpState->neighbor); comm_close(fd); } else { - /* Install connection complete handler. */ if (opt_no_ipcache) ipcacheInvalidate(request->host); fd_note(fd, entry->url); - commSetSelect(fd, COMM_SELECT_WRITE, - httpSendRequest, httpState, 0); + storeRegisterAbort(entry, httpAbort, httpState); + commSetSelect(fd, COMM_SELECT_WRITE, httpSendRequest, httpState, 0); } } @@ -960,3 +951,11 @@ httpReplyHeaderStats(StoreEntry * entry) ReplyHeaderStats.cc[i]); storeAppendPrintf(entry, close_bracket); } + +static void +httpAbort(void *data) +{ + HttpStateData *httpState = data; + debug(11, 1, "httpAbort: %s\n", httpState->entry->url); + comm_close(httpState->fd); +} diff --git a/src/stat.cc b/src/stat.cc index 2495d3af3b..f7a3aa4a68 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.139 1997/05/02 21:34:13 wessels Exp $ + * $Id: stat.cc,v 1.140 1997/06/02 05:39:48 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -333,8 +333,10 @@ describeFlags(const StoreEntry * entry) #endif if (BIT_TEST(flags, DELETE_BEHIND)) strcat(buf, "DB,"); +#ifdef OLD_CODE if (BIT_TEST(flags, CLIENT_ABORT_REQUEST)) strcat(buf, "CA,"); +#endif if (BIT_TEST(flags, DELAY_SENDING)) strcat(buf, "DS,"); if (BIT_TEST(flags, ABORT_MSG_PENDING)) diff --git a/src/store.cc b/src/store.cc index e8ccf239ea..9ccd583f71 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.248 1997/06/02 01:06:17 wessels Exp $ + * $Id: store.cc,v 1.249 1997/06/02 05:39:50 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -804,7 +804,6 @@ storeAddDiskRestore(const char *url, int file_number, int size, time_t expires, e->swap_file_number = file_number; e->object_len = size; e->lock_count = 0; - BIT_RESET(e->flag, CLIENT_ABORT_REQUEST); e->refcount = 0; e->lastref = timestamp; e->timestamp = timestamp; @@ -1714,6 +1713,10 @@ storeAbort(StoreEntry * e, const char *msg) /* We assign an object length here--The only other place we assign the * object length is in storeComplete() */ e->object_len = mem->e_current_len; + if (mem->abort.callback) { + mem->abort.callback(mem->abort.data); + mem->abort.callback = NULL; + } InvokeHandlers(e); storeUnlockObject(e); return; @@ -2779,3 +2782,22 @@ storePutUnusedFileno(int fileno) else unlinkdUnlink(storeSwapFullPath(fileno, NULL)); } + +void +storeRegisterAbort(StoreEntry * e, STABH * cb, void *data) +{ + MemObject *mem = e->mem_obj; + assert(mem); + assert(mem->abort.callback == NULL); + mem->abort.callback = cb; + mem->abort.data = data; +} + +void +storeUnregisterAbort(StoreEntry * e) +{ + MemObject *mem = e->mem_obj; + assert(mem); + mem->abort.callback = NULL; +} + diff --git a/src/wais.cc b/src/wais.cc index 5210128235..5c6b839d98 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,6 +1,6 @@ /* - * $Id: wais.cc,v 1.73 1997/06/02 01:06:19 wessels Exp $ + * $Id: wais.cc,v 1.74 1997/06/02 05:39:51 wessels Exp $ * * DEBUG: section 24 WAIS Relay * AUTHOR: Harvest Derived @@ -124,6 +124,7 @@ static PF waisReadReply; static CWCB waisSendComplete; static PF waisSendRequest; static CNCB waisConnectDone; +static STABH waisAbort; static void waisStateFree(int fd, void *data) @@ -132,6 +133,7 @@ waisStateFree(int fd, void *data) if (waisState == NULL) return; storeUnlockObject(waisState->entry); + storeUnregisterAbort(waisState->entry); xfree(waisState); } @@ -155,12 +157,16 @@ waisReadReply(int fd, void *data) { WaisStateData *waisState = data; LOCAL_ARRAY(char, buf, 4096); - int len; StoreEntry *entry = waisState->entry; + int len; int clen; int off; int bin; - + if (protoAbortFetch(entry)) { + squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); + comm_close(fd); + return; + } if (entry->flag & DELETE_BEHIND && !storeClientWaiting(entry)) { /* we can terminate connection right now */ squid_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL); @@ -171,11 +177,6 @@ waisReadReply(int fd, void *data) clen = entry->mem_obj->e_current_len; off = storeGetLowestReaderOffset(entry); if ((clen - off) > WAIS_DELETE_GAP) { - if (entry->flag & CLIENT_ABORT_REQUEST) { - squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - comm_close(fd); - return; - } IOStats.Wais.reads_deferred++; debug(24, 3, "waisReadReply: Read deferred for Object: %s\n", entry->url); @@ -326,9 +327,8 @@ waisStart(request_t *request, StoreEntry * entry) waisState->fd = fd; waisState->entry = entry; xstrncpy(waisState->request, url, MAX_URL); - comm_add_close_handler(waisState->fd, - waisStateFree, - waisState); + comm_add_close_handler(waisState->fd, waisStateFree, waisState); + storeRegisterAbort(entry, waisAbort, waisState); commSetTimeout(fd, Config.Timeout.read, waisTimeout, waisState); storeLockObject(entry); commConnectStart(waisState->fd, @@ -358,3 +358,11 @@ waisConnectDone(int fd, int status, void *data) waisSendRequest, waisState, 0); } + +static void +waisAbort(void *data) +{ + HttpStateData *waisState = data; + debug(24, 1, "waisAbort: %s\n", waisState->entry->url); + comm_close(waisState->fd); +}