------------------------------------------------------------ revno: 13065 revision-id: squid3@treenet.co.nz-20131025190730-rsko6h9zotp9raqx parent: squid3@treenet.co.nz-20131026060956-02v3coatdstukeuw committer: Amos Jeffries branch nick: trunk timestamp: Fri 2013-10-25 12:07:30 -0700 message: Cleanup ASState * convert from struct to class - moving initialization of members from transaction setup to ctor. * implement with CBDATA_CLASS2 macro - removing uses of cbdataAlloc/cbdataFree and CBDATA_TYPE/CBDATA_INIT_TYPE * set bool member dataRead using true/false instead of 0/1 * upgrade HttpRequest pointer member to Pointer type ------------------------------------------------------------ # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: squid3@treenet.co.nz-20131025190730-rsko6h9zotp9raqx # target_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # testament_sha1: 9ff6c80685a1117d5d71e5571a6eef00f156aad9 # timestamp: 2013-10-26 20:56:24 +0000 # source_branch: http://bzr.squid-cache.org/bzr/squid3/trunk/ # base_revision_id: squid3@treenet.co.nz-20131026060956-\ # 02v3coatdstukeuw # # Begin patch === modified file 'src/acl/Asn.cc' --- src/acl/Asn.cc 2013-06-07 04:35:25 +0000 +++ src/acl/Asn.cc 2013-10-25 19:07:30 +0000 @@ -89,17 +89,45 @@ time_t expires; /* NOTUSED */ }; -struct ASState { +class ASState +{ +public: + ASState(); + ~ASState(); + StoreEntry *entry; store_client *sc; - HttpRequest *request; + HttpRequest::Pointer request; int as_number; int64_t offset; int reqofs; char reqbuf[AS_REQBUF_SZ]; bool dataRead; +private: + CBDATA_CLASS2(ASState); }; +CBDATA_CLASS_INIT(ASState); + +ASState::ASState() : + entry(NULL), + sc(NULL), + request(NULL), + as_number(0), + offset(0), + reqofs(0), + dataRead(false) +{ + memset(reqbuf, 0, AS_REQBUF_SZ); +} + +ASState::~ASState() +{ + debugs(53, 3, entry->url()); + storeUnregister(sc, entry, this); + entry->unlock(); +} + /** entry into the radix tree */ struct rtentry_t { struct squid_radix_node e_nodes[2]; @@ -127,8 +155,6 @@ void asnAclInitialize(ACL * acls); -static void asStateFree(void *data); - static void destroyRadixNodeInfo(as_info *); static OBJH asnStats; @@ -197,13 +223,11 @@ SQUIDCEXTERN int squid_max_keylen; /* yuck.. this is in lib/radix.c */ -CBDATA_TYPE(ASState); void asnInit(void) { static bool inited = false; squid_max_keylen = 40; - CBDATA_INIT_TYPE(ASState); if (!inited) { inited = true; @@ -237,35 +261,25 @@ { LOCAL_ARRAY(char, asres, 4096); StoreEntry *e; - ASState *asState; - asState = cbdataAlloc(ASState); - asState->dataRead = 0; - debugs(53, 3, "asnCacheStart: AS " << as); + ASState *asState = new ASState; + debugs(53, 3, "AS " << as); snprintf(asres, 4096, "whois://%s/!gAS%d", Config.as_whois_server, as); asState->as_number = as; asState->request = HttpRequest::CreateFromUrl(asres); - assert(NULL != asState->request); - HTTPMSGLOCK(asState->request); + assert(asState->request != NULL); if ((e = storeGetPublic(asres, Http::METHOD_GET)) == NULL) { e = storeCreateEntry(asres, asres, RequestFlags(), Http::METHOD_GET); asState->sc = storeClientListAdd(e, asState); - FwdState::fwdStart(Comm::ConnectionPointer(), e, asState->request); + FwdState::fwdStart(Comm::ConnectionPointer(), e, asState->request.getRaw()); } else { - e->lock(); asState->sc = storeClientListAdd(e, asState); } asState->entry = e; - asState->offset = 0; - asState->reqofs = 0; StoreIOBuffer readBuffer (AS_REQBUF_SZ, asState->offset, asState->reqbuf); - storeClientCopy(asState->sc, - e, - readBuffer, - asHandleReply, - asState); + storeClientCopy(asState->sc, e, readBuffer, asHandleReply, asState); } static void @@ -284,21 +298,21 @@ /* First figure out whether we should abort the request */ if (EBIT_TEST(e->flags, ENTRY_ABORTED)) { - asStateFree(asState); + delete asState; return; } if (result.length == 0 && asState->dataRead) { - debugs(53, 3, "asHandleReply: Done: " << e->url() ); - asStateFree(asState); + debugs(53, 3, "asHandleReply: Done: " << e->url()); + delete asState; return; } else if (result.flags.error) { debugs(53, DBG_IMPORTANT, "asHandleReply: Called with Error set and size=" << (unsigned int) result.length); - asStateFree(asState); + delete asState; return; } else if (e->getReply()->sline.status() != Http::scOkay) { debugs(53, DBG_IMPORTANT, "WARNING: AS " << asState->as_number << " whois request failed"); - asStateFree(asState); + delete asState; return; } @@ -326,7 +340,7 @@ debugs(53, 3, "asHandleReply: AS# " << s << " (" << asState->as_number << ")"); asnAddNet(s, asState->as_number); s = t + 1; - asState->dataRead = 1; + asState->dataRead = true; } /* @@ -377,17 +391,6 @@ } } -static void -asStateFree(void *data) -{ - ASState *asState = (ASState *)data; - debugs(53, 3, "asnStateFree: " << asState->entry->url() ); - storeUnregister(asState->sc, asState->entry, asState); - asState->entry->unlock(); - HTTPMSGUNLOCK(asState->request); - cbdataFree(asState); -} - /** * add a network (addr, mask) to the radix tree, with matching AS number */