From: wessels <> Date: Wed, 18 Jun 1997 06:19:50 +0000 (+0000) Subject: Junk the 'callback_meta' idea X-Git-Tag: SQUID_3_0_PRE1~4934 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8407afee05f8a6bc518315bb2c772fae4f06d339;p=thirdparty%2Fsquid.git Junk the 'callback_meta' idea Now use a hash table of callback datas. A callback pointer is added when the data is created, then callback functions lock and unlock it while waiting for the operation to complete. --- diff --git a/src/Makefile.in b/src/Makefile.in index 24e121f566..a2379f4e92 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.76 1997/06/17 03:03:19 wessels Exp $ +# $Id: Makefile.in,v 1.77 1997/06/18 00:19:50 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -78,7 +78,7 @@ OBJS = \ aiops.o \ async_io.o \ cache_cf.o \ - callback.o \ + cbdata.o \ client_db.o \ client_side.o \ comm.o \ diff --git a/src/acl.cc b/src/acl.cc index 39506a3f43..8c35c634ab 100644 --- a/src/acl.cc +++ b/src/acl.cc @@ -1,5 +1,5 @@ /* - * $Id: acl.cc,v 1.98 1997/06/17 03:03:20 wessels Exp $ + * $Id: acl.cc,v 1.99 1997/06/18 00:19:51 wessels Exp $ * * DEBUG: section 28 Access Control * AUTHOR: Duane Wessels @@ -1176,8 +1176,7 @@ aclCheck(aclCheck_t * checklist) checklist->state[ACL_DST_IP] = ACL_LOOKUP_PENDING; ipcache_nbgethostbyname(checklist->request->host, aclLookupDstIPDone, - checklist, - &checklist->cbm_list); + checklist); return; } else if (checklist->state[ACL_SRC_DOMAIN] == ACL_LOOKUP_NEEDED) { checklist->state[ACL_SRC_DOMAIN] = ACL_LOOKUP_PENDING; @@ -1216,16 +1215,20 @@ aclChecklistFree(aclCheck_t * checklist) fqdncacheUnregister(checklist->src_addr, checklist); if (checklist->state[ACL_DST_DOMAIN] == ACL_LOOKUP_PENDING) fqdncacheUnregister(checklist->dst_addr, checklist); + if (checklist->state[ACL_DST_IP] == ACL_LOOKUP_PENDING) + ipcacheUnregister(checklist->request->host, checklist); requestUnlink(checklist->request); - callbackUnlinkList(checklist->cbm_list); - xfree(checklist); + checklist->request = NULL; + cbdataFree(checklist); } static void aclCheckCallback(aclCheck_t * checklist, int answer) { debug(28, 3) ("aclCheckCallback: answer=%d\n", answer); - checklist->callback(answer, checklist->callback_data); + if (cbdataValid(checklist->callback_data)) + checklist->callback(answer, checklist->callback_data); + cbdataUnlock(checklist->callback_data); checklist->callback = NULL; checklist->callback_data = NULL; aclChecklistFree(checklist); @@ -1263,6 +1266,7 @@ aclChecklistCreate(const struct _acl_access *A, char *ident) { aclCheck_t *checklist = xcalloc(1, sizeof(aclCheck_t));; + cbdataAdd(checklist); checklist->access_list = A; checklist->request = requestLink(request); checklist->src_addr = src_addr; @@ -1278,6 +1282,7 @@ aclNBCheck(aclCheck_t * checklist, PF callback, void *callback_data) { checklist->callback = callback; checklist->callback_data = callback_data; + cbdataLock(callback_data); aclCheck(checklist); } diff --git a/src/comm.cc b/src/comm.cc index 11930bc435..8a7c63659d 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.163 1997/06/17 03:03:21 wessels Exp $ + * $Id: comm.cc,v 1.164 1997/06/18 00:19:52 wessels Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -140,7 +140,6 @@ typedef struct { struct in_addr in_addr; int locks; int fd; - callback_meta *cbm_list; } ConnectStateData; /* GLOBAL */ @@ -331,14 +330,16 @@ void commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *data) { ConnectStateData *cs = xcalloc(1, sizeof(ConnectStateData)); + cbdataAdd(cs); cs->fd = fd; cs->host = xstrdup(host); cs->port = port; cs->callback = callback; cs->data = data; + cbdataLock(data); comm_add_close_handler(fd, commConnectFree, cs); cs->locks++; - ipcache_nbgethostbyname(host, commConnectDnsHandle, cs, &cs->cbm_list); + ipcache_nbgethostbyname(host, commConnectDnsHandle, cs); } static void @@ -364,16 +365,19 @@ commConnectCallback(ConnectStateData * cs, int status) int fd = cs->fd; comm_remove_close_handler(fd, commConnectFree, cs); commConnectFree(fd, cs); - callback(fd, status, data); + if (cbdataValid(data)) + callback(fd, status, data); + cbdataUnlock(data); } static void commConnectFree(int fdunused, void *data) { ConnectStateData *cs = data; - callbackUnlinkList(cs->cbm_list); - xfree(cs->host); - xfree(cs); + if (cs->locks) + ipcacheUnregister(cs->host, cs); + safe_free(cs->host); + cbdataFree(cs); } static int @@ -425,7 +429,7 @@ commConnectHandle(int fd, void *data) cs->S.sin_addr.s_addr = 0; ipcacheCycleAddr(cs->host); cs->locks++; - ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs, &cs->cbm_list); + ipcache_nbgethostbyname(cs->host, commConnectDnsHandle, cs); } else { ipcacheRemoveBadAddr(cs->host, cs->S.sin_addr); commConnectCallback(cs, COMM_ERR_CONNECT); diff --git a/src/http.cc b/src/http.cc index cc44365e61..d6c612629d 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,5 +1,5 @@ /* - * $Id: http.cc,v 1.170 1997/06/04 06:15:57 wessels Exp $ + * $Id: http.cc,v 1.171 1997/06/18 00:19:53 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -750,6 +750,9 @@ httpBuildRequestHeader(request_t * request, url = entry ? entry->url : urlCanonical(orig_request, NULL); sprintf(ybuf, "Cache-control: Max-age=%d", (int) getMaxAge(url)); httpAppendRequestHeader(hdr_out, ybuf, &len, out_sz); +if (request->urlpath) { + assert(strstr(url, request->urlpath)); +} } httpAppendRequestHeader(hdr_out, null_string, &len, out_sz); put_free_4k_page(xbuf); diff --git a/src/ipcache.cc b/src/ipcache.cc index 06693e4d99..d378dd724e 100644 --- a/src/ipcache.cc +++ b/src/ipcache.cc @@ -1,6 +1,6 @@ /* - * $Id: ipcache.cc,v 1.123 1997/06/17 04:54:11 wessels Exp $ + * $Id: ipcache.cc,v 1.124 1997/06/18 00:19:56 wessels Exp $ * * DEBUG: section 14 IP Cache * AUTHOR: Harvest Derived @@ -108,7 +108,7 @@ struct _ip_pending { IPH *handler; - callback_meta *cbm; + void *handlerData; struct _ip_pending *next; }; @@ -147,7 +147,7 @@ static int ipcacheHasPending _PARAMS((ipcache_entry *)); static ipcache_entry *ipcache_get _PARAMS((const char *)); static IPH dummy_handler; static int ipcacheExpiredEntry _PARAMS((ipcache_entry *)); -static void ipcacheAddPending _PARAMS((ipcache_entry *, IPH *, void *, callback_meta **)); +static void ipcacheAddPending _PARAMS((ipcache_entry *, IPH *, void *)); static void ipcacheEnqueue _PARAMS((ipcache_entry *)); static void *ipcacheDequeue _PARAMS((void)); static void ipcache_dnsDispatch _PARAMS((dnsserver_t *, ipcache_entry *)); @@ -156,7 +156,6 @@ static void ipcacheUnlockEntry _PARAMS((ipcache_entry *)); static void ipcacheLockEntry _PARAMS((ipcache_entry *)); static void ipcacheNudgeQueue _PARAMS((void)); static void ipcacheChangeKey _PARAMS((ipcache_entry * i)); -static UNREG ipcacheUnregister; static ipcache_addrs static_addrs; static hash_table * ip_table = NULL; @@ -448,26 +447,28 @@ ipcache_call_pending(ipcache_entry * i) { struct _ip_pending *p = NULL; int nhandler = 0; - void *handlerData; i->lastref = squid_curtime; ipcacheLockEntry(i); while (i->pending_head != NULL) { - p = i->pending_head; - i->pending_head = p->next; - handlerData = callbackCheck(p->cbm); - if (p->handler && handlerData) { - nhandler++; - dns_error_message = i->error_message; - p->handler(i->status == IP_CACHED ? &i->addrs : NULL, handlerData); - } - callbackUnlink(p->cbm); - safe_free(p); + p = i->pending_head; + i->pending_head = p->next; + if (p->handler) { + nhandler++; + dns_error_message = i->error_message; + if (cbdataValid(p->handlerData)) { + p->handler(i->status == IP_CACHED ? &i->addrs : NULL, + p->handlerData); + } + cbdataUnlock(p->handlerData); + } + safe_free(p); } - i->pending_head = NULL; /* nuke list */ + i->pending_head = NULL; /* nuke list */ debug(14, 10) ("ipcache_call_pending: Called %d handlers.\n", nhandler); ipcacheUnlockEntry(i); } + static ipcache_entry * ipcache_parsebuffer(const char *inbuf, dnsserver_t * dnsData) { @@ -627,13 +628,14 @@ ipcache_dnsHandleRead(int fd, void *data) } static void -ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData, callback_meta **head) +ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData) { struct _ip_pending *pending = xcalloc(1, sizeof(struct _ip_pending)); struct _ip_pending **I = NULL; i->lastref = squid_curtime; pending->handler = handler; - pending->cbm = callbackRegister(handlerData, ipcacheUnregister, pending, head); + pending->handlerData = handlerData; + cbdataLock(handlerData); for (I = &(i->pending_head); *I; I = &((*I)->next)); *I = pending; if (i->status == IP_PENDING) @@ -641,7 +643,7 @@ ipcacheAddPending(ipcache_entry * i, IPH * handler, void *handlerData, callback_ } void -ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData, callback_meta **cbmhead) +ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData) { ipcache_entry *i = NULL; dnsserver_t *dnsData = NULL; @@ -673,7 +675,7 @@ ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData, call debug(14, 5) ("ipcache_nbgethostbyname: MISS for '%s'\n", name); IpcacheStats.misses++; i = ipcacheAddNew(name, NULL, IP_PENDING); - ipcacheAddPending(i, handler, handlerData, cbmhead); + ipcacheAddPending(i, handler, handlerData); } else if (i->status == IP_CACHED || i->status == IP_NEGATIVE_CACHED) { /* HIT */ debug(14, 4) ("ipcache_nbgethostbyname: HIT for '%s'\n", name); @@ -681,13 +683,13 @@ ipcache_nbgethostbyname(const char *name, IPH * handler, void *handlerData, call IpcacheStats.negative_hits++; else IpcacheStats.hits++; - ipcacheAddPending(i, handler, handlerData, cbmhead); + ipcacheAddPending(i, handler, handlerData); ipcache_call_pending(i); return; } else if (i->status == IP_PENDING || i->status == IP_DISPATCHED) { debug(14, 4) ("ipcache_nbgethostbyname: PENDING for '%s'\n", name); IpcacheStats.pending_hits++; - ipcacheAddPending(i, handler, handlerData, cbmhead); + ipcacheAddPending(i, handler, handlerData); if (squid_curtime - i->expires > 600) { debug(14, 0) ("ipcache_nbgethostbyname: '%s' PENDING for %d seconds, aborting\n", name, squid_curtime + Config.negativeDnsTtl - i->expires); ipcacheChangeKey(i); @@ -778,12 +780,27 @@ ipcache_init(void) (float) Config.ipcache.low) / (float) 100); } -static void -ipcacheUnregister(void *data) +int +ipcacheUnregister(const char *name, void *data) { - struct _ip_pending *p = data; - p->handler = NULL; - debug(14, 3) ("ipcacheUnregister: unregistered something\n"); + ipcache_entry *i = NULL; + struct _ip_pending *p = NULL; + int n = 0; + debug(14, 3) ("ipcacheUnregister: FD %d, name '%s'\n", name); + if ((i = ipcache_get(name)) == NULL) + return 0; + if (i->status == IP_PENDING || i->status == IP_DISPATCHED) { + for (p = i->pending_head; p; p = p->next) { + if (p->handlerData != data) + continue; + p->handler = NULL; + n++; + } + } + if (n == 0) + debug_trap("ipcacheUnregister: callback data not found"); + debug(14, 3) ("ipcacheUnregister: unregistered %d handlers\n", n); + return n; } const ipcache_addrs * @@ -858,7 +875,7 @@ ipcache_gethostbyname(const char *name, int flags) } } if (flags & IP_LOOKUP_IF_MISS) - ipcache_nbgethostbyname(name, dummy_handler, NULL, NULL); + ipcache_nbgethostbyname(name, dummy_handler, NULL); return NULL; } diff --git a/src/main.cc b/src/main.cc index 430e5fa05b..21c9883e07 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,5 @@ /* - * $Id: main.cc,v 1.154 1997/06/17 03:03:23 wessels Exp $ + * $Id: main.cc,v 1.155 1997/06/18 00:19:57 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -390,7 +390,7 @@ serverConnectionsOpen(void) icpHandleUdp, NULL, 0); for (s = Config.mcast_group_list; s; s = s->next) - ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL, NULL); + ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL); debug(1, 1) ("Accepting ICP connections on port %d, FD %d.\n", (int) port, theInIcpConnection); @@ -513,6 +513,8 @@ mainInitialize(void) squid_signal(SIGPIPE, SIG_IGN, SA_RESTART); squid_signal(SIGCHLD, sig_child, SA_NODEFER | SA_RESTART); + if (!configured_once) + cbdataInit(); if (ConfigFile == NULL) ConfigFile = xstrdup(DefaultConfigFile); parseConfigFile(ConfigFile); diff --git a/src/neighbors.cc b/src/neighbors.cc index c0b584b06c..0185c85937 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,5 +1,5 @@ /* - * $Id: neighbors.cc,v 1.145 1997/06/17 03:03:24 wessels Exp $ + * $Id: neighbors.cc,v 1.146 1997/06/18 00:19:58 wessels Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -757,6 +757,7 @@ neighborAdd(const char *host, } } p = xcalloc(1, sizeof(peer)); + cbdataAdd(p); p->http_port = http_port; p->icp_port = icp_port; p->mcast.ttl = mcast_ttl; @@ -923,9 +924,10 @@ peerDestroy(peer * p) safe_free(l->domain); safe_free(l); } - callbackUnlinkList(p->cbm_list); + if (p->ip_lookup_pending) + ipcacheUnregister(p->host, p); safe_free(p->host); - safe_free(p); + cbdataFree(p); } static void @@ -934,6 +936,7 @@ peerDNSConfigure(const ipcache_addrs * ia, void *data) peer *p = data; struct sockaddr_in *ap; int j; + p->ip_lookup_pending = 0; if (p->n_addresses == 0) { debug(15, 1) ("Configuring %s %s/%d/%d\n", neighborTypeStr(p), p->host, p->http_port, p->icp_port); @@ -970,9 +973,10 @@ peerRefreshDNS(void *junk) peer *next = Peers.peers_head; while ((p = next)) { next = p->next; + p->ip_lookup_pending = 1; /* some random, bogus FD for ipcache */ p->test_fd = Squid_MaxFD + current_time.tv_usec; - ipcache_nbgethostbyname(p->host, peerDNSConfigure, p, &p->cbm_list); + ipcache_nbgethostbyname(p->host, peerDNSConfigure, p); } /* Reconfigure the peers every hour */ eventAdd("peerRefreshDNS", peerRefreshDNS, NULL, 3600); @@ -987,14 +991,16 @@ peerCheckConnect(void *data) 0, COMM_NONBLOCKING, p->host); if (fd < 0) return; + p->ip_lookup_pending = 1; p->test_fd = fd; - ipcache_nbgethostbyname(p->host, peerCheckConnect2, p, &p->cbm_list); + ipcache_nbgethostbyname(p->host, peerCheckConnect2, p); } static void peerCheckConnect2(const ipcache_addrs * ia, void *data) { peer *p = data; + p->ip_lookup_pending = 0; commConnectStart(p->test_fd, p->host, p->http_port, diff --git a/src/peer_select.cc b/src/peer_select.cc index b77d24193d..6ac01aa57d 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -1,6 +1,6 @@ /* - * $Id: peer_select.cc,v 1.13 1997/06/04 06:16:05 wessels Exp $ + * $Id: peer_select.cc,v 1.14 1997/06/18 00:20:01 wessels Exp $ * * DEBUG: section 44 Peer Selection Algorithm * AUTHOR: Duane Wessels @@ -73,7 +73,8 @@ peerSelectStateFree(ps_state * psstate) aclChecklistFree(psstate->acl_checklist); } requestUnlink(psstate->request); - xfree(psstate); + psstate->request = NULL; + cbdataFree(psstate); } int @@ -138,11 +139,13 @@ peerSelect(request_t * request, void *callback_data) { ps_state *psstate = xcalloc(1, sizeof(ps_state)); + cbdataAdd(psstate); psstate->request = requestLink(request); psstate->entry = entry; psstate->callback = callback; psstate->fail_callback = fail_callback; psstate->callback_data = callback_data; + cbdataLock(callback_data); psstate->icp.start = current_time; peerSelectFoo(psstate); } @@ -171,12 +174,15 @@ static void peerSelectCallback(ps_state * psstate, peer * p) { StoreEntry *entry = psstate->entry; + void *data = psstate->callback_data; if (entry) { if (entry->ping_status == PING_WAITING) eventDelete(peerPingTimeout, psstate); entry->ping_status = PING_DONE; } - psstate->callback(p, psstate->callback_data); + if (cbdataValid(data)) + psstate->callback(p, data); + cbdataUnlock(data); peerSelectStateFree(psstate); } @@ -184,12 +190,15 @@ static void peerSelectCallbackFail(ps_state * psstate) { request_t *request = psstate->request; + void *data = psstate->callback_data; char *url = psstate->entry ? psstate->entry->url : urlCanonical(request, NULL); debug(44, 1) ("Failed to select source for '%s'\n", url); debug(44, 1) (" always_direct = %d\n", psstate->always_direct); debug(44, 1) (" never_direct = %d\n", psstate->never_direct); debug(44, 1) (" timeout = %d\n", psstate->icp.timeout); - psstate->fail_callback(NULL, psstate->callback_data); + if (cbdataValid(data)) + psstate->fail_callback(NULL, data); + cbdataUnlock(data); peerSelectStateFree(psstate); } diff --git a/src/send-announce.cc b/src/send-announce.cc index aa543f7417..6a2edbcf22 100644 --- a/src/send-announce.cc +++ b/src/send-announce.cc @@ -1,6 +1,6 @@ /* - * $Id: send-announce.cc,v 1.38 1997/06/17 03:03:26 wessels Exp $ + * $Id: send-announce.cc,v 1.39 1997/06/18 00:20:02 wessels Exp $ * * DEBUG: section 27 Cache Announcer * AUTHOR: Duane Wessels @@ -38,7 +38,7 @@ start_announce(void *unused) { if (!Config.Announce.on) return; - ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL, NULL); + ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL); eventAdd("send_announce", start_announce, NULL, Config.Announce.rate); } diff --git a/src/squid.h b/src/squid.h index d6fec7fe01..ab910e9470 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.121 1997/06/17 03:03:26 wessels Exp $ + * $Id: squid.h,v 1.122 1997/06/18 00:20:03 wessels Exp $ * * AUTHOR: Duane Wessels * @@ -273,7 +273,6 @@ typedef void STCB _PARAMS((void *, char *, size_t)); /* store callback */ #include "cache_cf.h" #include "fd.h" -#include "callback.h" #include "comm.h" #include "disk.h" #include "debug.h" @@ -312,6 +311,7 @@ typedef void STCB _PARAMS((void *, char *, size_t)); /* store callback */ #include "refresh.h" #include "unlinkd.h" #include "multicast.h" +#include "cbdata.h" #if !HAVE_TEMPNAM #include "tempnam.h" diff --git a/src/stat.cc b/src/stat.cc index ab4890b917..72a9a6961a 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.142 1997/06/04 07:00:33 wessels Exp $ + * $Id: stat.cc,v 1.143 1997/06/18 00:20:04 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -441,6 +441,8 @@ stat_get(const cacheinfo * obj, const char *req, StoreEntry * sentry) netdbDump(sentry); } else if (strcmp(req, "storedir") == 0) { storeDirStats(sentry); + } else if (strcmp(req, "cbdata") == 0) { + cbdataDump(sentry); } }