From: Amos Jeffries Date: Tue, 3 Feb 2015 11:21:26 +0000 (-0800) Subject: Cleanup: migrate netdbExchangeState to CBDATA_CLASS API X-Git-Tag: merge-candidate-3-v1~296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fa91d03082926c2f422578b9affa4277adca297b;p=thirdparty%2Fsquid.git Cleanup: migrate netdbExchangeState to CBDATA_CLASS API Also fixes a compile error for pinger when --disable-inline is used. --- diff --git a/src/icmp/Makefile.am b/src/icmp/Makefile.am index 5295be180a..18b9a7a475 100644 --- a/src/icmp/Makefile.am +++ b/src/icmp/Makefile.am @@ -80,7 +80,8 @@ nodist_pinger_SOURCES = \ pinger_LDFLAGS = $(LIBADD_DL) pinger_LDADD=\ libicmp-core.la \ - ../ip/libip.la \ + $(top_builddir)/src/ip/libip.la \ + $(top_builddir)/src/base/libbase.la \ $(COMPAT_LIB) \ $(XTRA_LIBS) diff --git a/src/icmp/net_db.cc b/src/icmp/net_db.cc index c39349505e..e5849aeda6 100644 --- a/src/icmp/net_db.cc +++ b/src/icmp/net_db.cc @@ -58,7 +58,37 @@ typedef enum { STATE_BODY } netdb_conn_state_t; -typedef struct { +class netdbExchangeState +{ + CBDATA_CLASS(netdbExchangeState); + +public: + netdbExchangeState(CachePeer *aPeer, HttpRequest *theReq) : + p(cbdataReference(aPeer)), + e(NULL), + sc(NULL), + r(theReq), + used(0), + buf_sz(NETDB_REQBUF_SZ), + buf_ofs(0), + connstate(STATE_HEADER) + { + *buf = 0; + + assert(NULL != r); + HTTPMSGLOCK(r); + // TODO: check if we actually need to do this. should be implicit + r->http_ver = Http::ProtocolVersion(); + } + + ~netdbExchangeState() { + debugs(38, 3, e->url()); + storeUnregister(sc, e, this); + e->unlock("netdbExchangeDone"); + HTTPMSGUNLOCK(r); + cbdataReferenceDone(p); + } + CachePeer *p; StoreEntry *e; store_client *sc; @@ -68,7 +98,9 @@ typedef struct { char buf[NETDB_REQBUF_SZ]; int buf_ofs; netdb_conn_state_t connstate; -} netdbExchangeState; +}; + +CBDATA_CLASS_INIT(netdbExchangeState); static hash_table *addr_table = NULL; static hash_table *host_table = NULL; @@ -92,7 +124,6 @@ static QS netdbLRU; static FREE netdbFreeNameEntry; static FREE netdbFreeNetdbEntry; static STCB netdbExchangeHandleReply; -static void netdbExchangeDone(void *); /* We have to keep a local list of CachePeer names. The Peers structure * gets freed during a reconfigure. We want this database to @@ -689,16 +720,15 @@ netdbExchangeHandleReply(void *data, StoreIOBuffer receivedData) if (!cbdataReferenceValid(ex->p)) { debugs(38, 3, "netdbExchangeHandleReply: Peer became invalid"); - netdbExchangeDone(ex); + delete ex; return; } debugs(38, 3, "netdbExchangeHandleReply: for '" << ex->p->host << ":" << ex->p->http_port << "'"); - if (receivedData.length == 0 && - !receivedData.flags.error) { + if (receivedData.length == 0 && !receivedData.flags.error) { debugs(38, 3, "netdbExchangeHandleReply: Done"); - netdbExchangeDone(ex); + delete ex; return; } @@ -723,7 +753,7 @@ netdbExchangeHandleReply(void *data, StoreIOBuffer receivedData) debugs(38, 3, "netdbExchangeHandleReply: reply status " << rep->sline.status()); if (rep->sline.status() != Http::scOkay) { - netdbExchangeDone(ex); + delete ex; return; } @@ -789,7 +819,7 @@ netdbExchangeHandleReply(void *data, StoreIOBuffer receivedData) default: debugs(38, DBG_IMPORTANT, "netdbExchangeHandleReply: corrupt data, aborting"); - netdbExchangeDone(ex); + delete ex; return; } } @@ -845,7 +875,7 @@ netdbExchangeHandleReply(void *data, StoreIOBuffer receivedData) if (EBIT_TEST(ex->e->flags, ENTRY_ABORTED)) { debugs(38, 3, "netdbExchangeHandleReply: ENTRY_ABORTED"); - netdbExchangeDone(ex); + delete ex; } else if (ex->e->store_status == STORE_PENDING) { StoreIOBuffer tempBuffer; tempBuffer.offset = ex->used; @@ -857,18 +887,6 @@ netdbExchangeHandleReply(void *data, StoreIOBuffer receivedData) } } -static void -netdbExchangeDone(void *data) -{ - netdbExchangeState *ex = (netdbExchangeState *)data; - debugs(38, 3, "netdbExchangeDone: " << ex->e->url() ); - HTTPMSGUNLOCK(ex->r); - storeUnregister(ex->sc, ex->e, ex); - ex->e->unlock("netdbExchangeDone"); - cbdataReferenceDone(ex->p); - cbdataFree(ex); -} - static void netdbRegisterWithCacheManager(void) { @@ -1266,42 +1284,31 @@ netdbBinaryExchange(StoreEntry * s) s->complete(); } -#if USE_ICMP -CBDATA_TYPE(netdbExchangeState); -#endif - void netdbExchangeStart(void *data) { #if USE_ICMP CachePeer *p = (CachePeer *)data; - char *uri; - netdbExchangeState *ex; - StoreIOBuffer tempBuffer; - CBDATA_INIT_TYPE(netdbExchangeState); - ex = cbdataAlloc(netdbExchangeState); - ex->p = cbdataReference(p); - uri = internalRemoteUri(p->host, p->http_port, "/squid-internal-dynamic/", "netdb"); + char *uri = internalRemoteUri(p->host, p->http_port, "/squid-internal-dynamic/", "netdb"); debugs(38, 3, "netdbExchangeStart: Requesting '" << uri << "'"); assert(NULL != uri); - ex->r = HttpRequest::CreateFromUrl(uri); + HttpRequest *req = HttpRequest::CreateFromUrl(uri); - if (NULL == ex->r) { + if (req == NULL) { debugs(38, DBG_IMPORTANT, "netdbExchangeStart: Bad URI " << uri); return; } - HTTPMSGLOCK(ex->r); - assert(NULL != ex->r); - ex->r->http_ver = Http::ProtocolVersion(); - ex->connstate = STATE_HEADER; + netdbExchangeState *ex = new netdbExchangeState(p, req); ex->e = storeCreateEntry(uri, uri, RequestFlags(), Http::METHOD_GET); - ex->buf_sz = NETDB_REQBUF_SZ; assert(NULL != ex->e); - ex->sc = storeClientListAdd(ex->e, ex); - tempBuffer.offset = 0; + + StoreIOBuffer tempBuffer; tempBuffer.length = ex->buf_sz; tempBuffer.data = ex->buf; + + ex->sc = storeClientListAdd(ex->e, ex); + storeClientCopy(ex->sc, ex->e, tempBuffer, netdbExchangeHandleReply, ex); ex->r->flags.loopDetected = true; /* cheat! -- force direct */