From: wessels <> Date: Thu, 18 Apr 1996 00:06:24 +0000 (+0000) Subject: use COMM_SELECT_CLOSE handlers for freeing data X-Git-Tag: SQUID_3_0_PRE1~6121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=51fa90db0aa32c47e98d4ec5fb227f8c358bb3c1;p=thirdparty%2Fsquid.git use COMM_SELECT_CLOSE handlers for freeing data --- diff --git a/src/ftp.cc b/src/ftp.cc index 4fab7f8a78..da62692fc5 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,4 +1,4 @@ -/* $Id: ftp.cc,v 1.36 1996/04/16 05:05:22 wessels Exp $ */ +/* $Id: ftp.cc,v 1.37 1996/04/17 18:06:24 wessels Exp $ */ /* * DEBUG: Section 9 ftp: FTP @@ -33,25 +33,24 @@ typedef struct _Ftpdata { int reply_hdr_state; } FtpData; -static void ftpCloseAndFree(fd, data) +static int ftpStateFree(fd, ftpState) int fd; - FtpData *data; + FtpData *ftpState; { - if (fd >= 0) - comm_close(fd); - if (data) { - if (data->reply_hdr) { - put_free_8k_page(data->reply_hdr); - data->reply_hdr = NULL; - } - if (data->icp_page_ptr) { - put_free_8k_page(data->icp_page_ptr); - data->icp_page_ptr = NULL; - } - if (data->icp_rwd_ptr) - safe_free(data->icp_rwd_ptr); + if (ftpState == NULL) + return 1; + if (ftpState->reply_hdr) { + put_free_8k_page(ftpState->reply_hdr); + ftpState->reply_hdr = NULL; } - xfree(data); + if (ftpState->icp_page_ptr) { + put_free_8k_page(ftpState->icp_page_ptr); + ftpState->icp_page_ptr = NULL; + } + if (ftpState->icp_rwd_ptr) + safe_free(ftpState->icp_rwd_ptr); + xfree(ftpState); + return 0; } int ftp_url_parser(url, data) @@ -143,7 +142,7 @@ void ftpLifetimeExpire(fd, data) entry = data->entry; debug(9, 4, "ftpLifeTimeExpire: FD %d: \n", fd, entry->url); squid_error_entry(entry, ERR_LIFETIME_EXP, NULL); - ftpCloseAndFree(fd, data); + comm_close(fd); } @@ -311,7 +310,7 @@ int ftpReadReply(fd, data) } else { /* we can terminate connection right now */ squid_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL); - ftpCloseAndFree(fd, data); + comm_close(fd); return 0; } } @@ -332,13 +331,13 @@ int ftpReadReply(fd, data) BIT_RESET(entry->flag, CACHABLE); storeReleaseRequest(entry); squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); - ftpCloseAndFree(fd, data); + comm_close(fd); } } else if (len == 0 && entry->mem_obj->e_current_len == 0) { squid_error_entry(entry, ERR_ZERO_SIZE_OBJECT, errno ? xstrerror() : NULL); - ftpCloseAndFree(fd, data); + comm_close(fd); } else if (len == 0) { /* Connection closed; retrieval done. */ if (!data->got_marker) { @@ -354,7 +353,7 @@ int ftpReadReply(fd, data) } /* update fdstat and fdtable */ storeComplete(entry); - ftpCloseAndFree(fd, data); + comm_close(fd); } else if (((entry->mem_obj->e_current_len + len) > getFtpMax()) && !(entry->flag & DELETE_BEHIND)) { /* accept data, but start to delete behind it */ @@ -368,7 +367,7 @@ int ftpReadReply(fd, data) /* append the last bit of info we get */ storeAppend(entry, buf, len); squid_error_entry(entry, ERR_CLIENT_ABORT, NULL); - ftpCloseAndFree(fd, data); + comm_close(fd); } else { /* check for a magic marker at the end of the read */ data->got_marker = 0; @@ -416,7 +415,7 @@ void ftpSendComplete(fd, buf, size, errflag, data) if (errflag) { squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); - ftpCloseAndFree(fd, data); + comm_close(fd); return; } else { comm_set_select_handler(data->ftp_fd, @@ -549,7 +548,7 @@ void ftpConnInProgress(fd, data) break; /* cool, we're connected */ default: squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); - ftpCloseAndFree(fd, data); + comm_close(fd); return; } /* Call the real write handler, now that we're fully connected */ @@ -590,11 +589,17 @@ int ftpStart(unusedfd, url, entry) } /* Pipe/socket created ok */ + /* register close handler */ + comm_set_select_handler(data->ftp_fd, + COMM_SELECT_CLOSE, + ftpStateFree, + (void *) data); + /* Now connect ... */ if ((status = comm_connect(data->ftp_fd, "localhost", CACHE_FTP_PORT))) { if (status != EINPROGRESS) { squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); - ftpCloseAndFree(data->ftp_fd, data); + comm_close(data->ftp_fd); return COMM_ERROR; } else { debug(9, 5, "ftpStart: FD %d: EINPROGRESS.\n", data->ftp_fd); diff --git a/src/gopher.cc b/src/gopher.cc index f1a1b530a0..a0368e5290 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,4 +1,4 @@ -/* $Id: gopher.cc,v 1.27 1996/04/16 16:35:27 wessels Exp $ */ +/* $Id: gopher.cc,v 1.28 1996/04/17 18:06:25 wessels Exp $ */ /* * DEBUG: Section 10 gopher: GOPHER @@ -66,14 +66,15 @@ GopherData *CreateGopherData(); char def_gopher_bin[] = "www/unknown"; char def_gopher_text[] = "text/plain"; -static void gopherCloseAndFree(fd, data) +static int gopherStateFree(fd, gopherState) int fd; - GopherData *data; + GopherData *gopherState; { - if (fd > +0) - comm_close(fd); - put_free_4k_page(data->buf); - xfree(data); + if (gopherState == NULL) + return 1; + put_free_4k_page(gopherState->buf); + xfree(gopherState); + return 0; } @@ -246,7 +247,7 @@ int gopherCachable(url) default: cachable = 1; } - gopherCloseAndFree(-1, data); + gopherStateFree(-1, data); return cachable; } @@ -572,7 +573,7 @@ int gopherReadReplyTimeout(fd, data) put_free_4k_page(data->icp_page_ptr); if (data->icp_rwd_ptr) safe_free(data->icp_rwd_ptr); - gopherCloseAndFree(fd, data); + comm_close(fd); return 0; } @@ -593,7 +594,7 @@ void gopherLifetimeExpire(fd, data) COMM_SELECT_READ | COMM_SELECT_WRITE, 0, 0); - gopherCloseAndFree(fd, data); + comm_close(fd); } @@ -640,7 +641,7 @@ int gopherReadReply(fd, data) } else { /* we can terminate connection right now */ squid_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL); - gopherCloseAndFree(fd, data); + comm_close(fd); return 0; } } @@ -662,13 +663,13 @@ int gopherReadReply(fd, data) BIT_RESET(entry->flag, CACHABLE); storeReleaseRequest(entry); squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); - gopherCloseAndFree(fd, data); + comm_close(fd); } } else if (len == 0 && entry->mem_obj->e_current_len == 0) { squid_error_entry(entry, ERR_ZERO_SIZE_OBJECT, errno ? xstrerror() : NULL); - gopherCloseAndFree(fd, data); + comm_close(fd); } else if (len == 0) { /* Connection closed; retrieval done. */ /* flush the rest of data in temp buf if there is one. */ @@ -678,7 +679,7 @@ int gopherReadReply(fd, data) entry->expires = squid_curtime + ttlSet(entry); BIT_RESET(entry->flag, DELAY_SENDING); storeComplete(entry); - gopherCloseAndFree(fd, data); + comm_close(fd); } else if (((entry->mem_obj->e_current_len + len) > getGopherMax()) && !(entry->flag & DELETE_BEHIND)) { /* accept data, but start to delete behind it */ @@ -709,7 +710,7 @@ int gopherReadReply(fd, data) if (data->conversion != NORMAL) gopherEndHTML(data); BIT_RESET(entry->flag, DELAY_SENDING); - gopherCloseAndFree(fd, data); + comm_close(fd); } else { if (data->conversion != NORMAL) { gopherToHTML(data, buf, len); @@ -745,7 +746,7 @@ void gopherSendComplete(fd, buf, size, errflag, data) fd, size, errflag); if (errflag) { squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); - gopherCloseAndFree(fd, data); + comm_close(fd); if (buf) put_free_4k_page(buf); /* Allocated by gopherSendRequest. */ return; @@ -860,7 +861,7 @@ int gopherStart(unusedfd, url, entry) if (gopher_url_parser(url, data->host, &data->port, &data->type_id, data->request)) { squid_error_entry(entry, ERR_INVALID_URL, NULL); - gopherCloseAndFree(-1, data); + gopherStateFree(-1, data); return COMM_ERROR; } /* Create socket. */ @@ -868,16 +869,21 @@ int gopherStart(unusedfd, url, entry) if (sock == COMM_ERROR) { debug(10, 4, "gopherStart: Failed because we're out of sockets.\n"); squid_error_entry(entry, ERR_NO_FDS, xstrerror()); - gopherCloseAndFree(-1, data); + gopherStateFree(-1, data); return COMM_ERROR; } + comm_set_select_handler(sock, + COMM_SELECT_CLOSE, + gopherStateFree, + (void *) data); + /* 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. */ if (!ipcache_gethostbyname(data->host)) { debug(10, 4, "gopherStart: Called without IP entry in ipcache. OR lookup failed.\n"); squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message); - gopherCloseAndFree(sock, data); + comm_close(sock); return COMM_ERROR; } if (((data->type_id == GOPHER_INDEX) || (data->type_id == GOPHER_CSO)) @@ -898,14 +904,14 @@ int gopherStart(unusedfd, url, entry) } gopherToHTML(data, (char *) NULL, 0); storeComplete(entry); - gopherCloseAndFree(sock, data); + comm_close(sock); return COMM_OK; } /* Open connection. */ if ((status = comm_connect(sock, data->host, data->port)) != 0) { if (status != EINPROGRESS) { squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); - gopherCloseAndFree(sock, data); + comm_close(sock); return COMM_ERROR; } else { debug(10, 5, "startGopher: conn %d EINPROGRESS\n", sock); diff --git a/src/wais.cc b/src/wais.cc index f8dcf91fef..0df8334378 100644 --- a/src/wais.cc +++ b/src/wais.cc @@ -1,4 +1,4 @@ -/* $Id: wais.cc,v 1.27 1996/04/16 05:13:39 wessels Exp $ */ +/* $Id: wais.cc,v 1.28 1996/04/17 18:06:25 wessels Exp $ */ /* * DEBUG: Section 24 wais @@ -17,13 +17,14 @@ typedef struct _waisdata { char request[MAX_URL]; } WAISData; -static void waisCloseAndFree(fd, data) +static int waisStateFree(fd, waisState) int fd; - WAISData *data; + WAISData *waisState; { - if (fd >= 0) - comm_close(fd); - xfree(data); + if (waisState == NULL) + return 1; + xfree(waisState); + return 0; } /* This will be called when timeout on read. */ @@ -37,7 +38,7 @@ static void waisReadReplyTimeout(fd, data) debug(24, 4, "waisReadReplyTimeout: Timeout on %d\n url: %s\n", fd, entry->url); squid_error_entry(entry, ERR_READ_TIMEOUT, NULL); comm_set_select_handler(fd, COMM_SELECT_READ, 0, 0); - waisCloseAndFree(fd, data); + comm_close(fd); } /* This will be called when socket lifetime is expired. */ @@ -51,7 +52,7 @@ void waisLifetimeExpire(fd, data) debug(24, 4, "waisLifeTimeExpire: FD %d: \n", fd, entry->url); squid_error_entry(entry, ERR_LIFETIME_EXP, NULL); comm_set_select_handler(fd, COMM_SELECT_READ | COMM_SELECT_WRITE, 0, 0); - waisCloseAndFree(fd, data); + comm_close(fd); } @@ -97,7 +98,7 @@ void waisReadReply(fd, data) } else { /* we can terminate connection right now */ squid_error_entry(entry, ERR_NO_CLIENTS_BIG_OBJ, NULL); - waisCloseAndFree(fd, data); + comm_close(fd); return; } } @@ -117,18 +118,18 @@ void waisReadReply(fd, data) BIT_RESET(entry->flag, CACHABLE); storeReleaseRequest(entry); squid_error_entry(entry, ERR_READ_ERROR, xstrerror()); - waisCloseAndFree(fd, data); + comm_close(fd); } } else if (len == 0 && entry->mem_obj->e_current_len == 0) { squid_error_entry(entry, ERR_ZERO_SIZE_OBJECT, errno ? xstrerror() : NULL); - waisCloseAndFree(fd, data); + comm_close(fd); } else if (len == 0) { /* Connection closed; retrieval done. */ entry->expires = squid_curtime; storeComplete(entry); - waisCloseAndFree(fd, data); + comm_close(fd); } else if (((entry->mem_obj->e_current_len + len) > getWAISMax()) && !(entry->flag & DELETE_BEHIND)) { /* accept data, but start to delete behind it */ @@ -172,7 +173,7 @@ void waisSendComplete(fd, buf, size, errflag, data) fd, size, errflag); if (errflag) { squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); - waisCloseAndFree(fd, data); + comm_close(fd); } else { /* Schedule read reply. */ comm_set_select_handler(fd, @@ -237,41 +238,45 @@ int waisStart(unusedfd, url, method, mime_hdr, entry) RequestMethodStr[method], url); debug(24, 4, " header: %s\n", mime_hdr); - data = (WAISData *) xcalloc(1, sizeof(WAISData)); - data->entry = entry; - data->method = method; - data->relayhost = getWaisRelayHost(); - data->relayport = getWaisRelayPort(); - data->mime_hdr = mime_hdr; - if (!getWaisRelayHost()) { debug(24, 0, "waisStart: Failed because no relay host defined!\n"); squid_error_entry(entry, ERR_NO_RELAY, NULL); - safe_free(data); return COMM_ERROR; } + /* Create socket. */ sock = comm_open(COMM_NONBLOCKING, 0, 0, url); if (sock == COMM_ERROR) { debug(24, 4, "waisStart: Failed because we're out of sockets.\n"); squid_error_entry(entry, ERR_NO_FDS, xstrerror()); - safe_free(data); return COMM_ERROR; } + + data = (WAISData *) xcalloc(1, sizeof(WAISData)); + data->entry = entry; + data->method = method; + data->relayhost = getWaisRelayHost(); + data->relayport = getWaisRelayPort(); + data->mime_hdr = mime_hdr; + comm_set_select_handler(sock, + COMM_SELECT_CLOSE, + waisStateFree, + (void *) data); + /* 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. */ if (!ipcache_gethostbyname(data->relayhost)) { debug(24, 4, "waisstart: Called without IP entry in ipcache. OR lookup failed.\n"); squid_error_entry(entry, ERR_DNS_FAIL, dns_error_message); - waisCloseAndFree(sock, data); + comm_close(sock); return COMM_ERROR; } /* Open connection. */ if ((status = comm_connect(sock, data->relayhost, data->relayport))) { if (status != EINPROGRESS) { squid_error_entry(entry, ERR_CONNECT_FAIL, xstrerror()); - waisCloseAndFree(sock, data); + comm_close(sock); return COMM_ERROR; } else { debug(24, 5, "waisStart: FD %d EINPROGRESS\n", sock);