From: Amos Jeffries Date: Sun, 18 Jul 2010 11:55:28 +0000 (+1200) Subject: Add ConnOpener to Comm namespace X-Git-Tag: take08~55^2~124^2~108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4accd6d87d220bd2961d7d636b8127164533e259;p=thirdparty%2Fsquid.git Add ConnOpener to Comm namespace --- diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index 6605536037..c16782fe04 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -129,7 +129,7 @@ void Adaptation::Icap::Xaction::openConnection() connector = asyncCall(93,3, "Adaptation::Icap::Xaction::noteCommConnected", ConnectDialer(this, &Adaptation::Icap::Xaction::noteCommConnected)); - ConnOpener *cs = new ConnOpener(connection, connector, TheConfig.connect_timeout(service().cfg().bypass)); + Comm::ConnOpener *cs = new Comm::ConnOpener(connection, connector, TheConfig.connect_timeout(service().cfg().bypass)); cs->setHost(s.cfg().host.termedBuf()); AsyncJob::AsyncStart(cs); } diff --git a/src/comm/ConnOpener.cc b/src/comm/ConnOpener.cc index 2efdbe7d88..4a8f97eaa5 100644 --- a/src/comm/ConnOpener.cc +++ b/src/comm/ConnOpener.cc @@ -11,10 +11,12 @@ #include "icmp/net_db.h" #include "SquidTime.h" -CBDATA_CLASS_INIT(ConnOpener); +namespace Comm { + CBDATA_CLASS_INIT(ConnOpener); +}; -ConnOpener::ConnOpener(Comm::ConnectionPointer &c, AsyncCall::Pointer &handler, time_t ctimeout) : - AsyncJob("ConnOpener"), +Comm::ConnOpener::ConnOpener(Comm::ConnectionPointer &c, AsyncCall::Pointer &handler, time_t ctimeout) : + AsyncJob("Comm::ConnOpener"), connect_timeout(ctimeout), host(NULL), solo(c), @@ -26,7 +28,7 @@ ConnOpener::ConnOpener(Comm::ConnectionPointer &c, AsyncCall::Pointer &handler, memset(&calls, 0, sizeof(calls)); } -ConnOpener::~ConnOpener() +Comm::ConnOpener::~ConnOpener() { safe_free(host); solo = NULL; @@ -35,34 +37,34 @@ ConnOpener::~ConnOpener() } bool -ConnOpener::doneAll() const +Comm::ConnOpener::doneAll() const { // is the conn to be opened still waiting? if (solo != NULL) { - debugs(5, 6, HERE << " ConnOpener::doneAll() ? NO. 'solo' is still set"); + debugs(5, 6, HERE << " Comm::ConnOpener::doneAll() ? NO. 'solo' is still set"); return false; } // is the callback still to be called? if (callback != NULL) { - debugs(5, 6, HERE << " ConnOpener::doneAll() ? NO. callback is still set"); + debugs(5, 6, HERE << " Comm::ConnOpener::doneAll() ? NO. callback is still set"); return false; } - debugs(5, 6, HERE << " ConnOpener::doneAll() ? YES."); + debugs(5, 6, HERE << " Comm::ConnOpener::doneAll() ? YES."); return true; } void -ConnOpener::swanSong() +Comm::ConnOpener::swanSong() { // cancel any event watchers if (calls.earlyabort != NULL) { - calls.earlyabort->cancel("ConnOpener::swanSong"); + calls.earlyabort->cancel("Comm::ConnOpener::swanSong"); calls.earlyabort = NULL; } if (calls.timeout != NULL) { - calls.timeout->cancel("ConnOpener::swanSong"); + calls.timeout->cancel("Comm::ConnOpener::swanSong"); calls.timeout = NULL; } @@ -77,7 +79,7 @@ ConnOpener::swanSong() } void -ConnOpener::setHost(const char * new_host) +Comm::ConnOpener::setHost(const char * new_host) { // unset and erase if already set. if (host != NULL) @@ -89,24 +91,24 @@ ConnOpener::setHost(const char * new_host) } const char * -ConnOpener::getHost() const +Comm::ConnOpener::getHost() const { return host; } void -ConnOpener::callCallback(comm_err_t status, int xerrno) +Comm::ConnOpener::callCallback(comm_err_t status, int xerrno) { /* remove handlers we don't want to happen anymore */ if (solo != NULL && solo->fd > 0) { if (calls.earlyabort != NULL) { comm_remove_close_handler(solo->fd, calls.earlyabort); - calls.earlyabort->cancel("ConnOpener completed."); + calls.earlyabort->cancel("Comm::ConnOpener completed."); calls.earlyabort = NULL; } if (calls.timeout != NULL) { commSetTimeout(solo->fd, -1, NULL, NULL); - calls.timeout->cancel("ConnOpener completed."); + calls.timeout->cancel("Comm::ConnOpener completed."); calls.timeout = NULL; } } @@ -128,7 +130,7 @@ ConnOpener::callCallback(comm_err_t status, int xerrno) } void -ConnOpener::start() +Comm::ConnOpener::start() { Must(solo != NULL); @@ -147,16 +149,16 @@ ConnOpener::start() } if (calls.earlyabort == NULL) { - typedef CommCbMemFunT Dialer; - calls.earlyabort = asyncCall(5, 4, "ConnOpener::earlyAbort", - Dialer(this, &ConnOpener::earlyAbort)); + typedef CommCbMemFunT Dialer; + calls.earlyabort = asyncCall(5, 4, "Comm::ConnOpener::earlyAbort", + Dialer(this, &Comm::ConnOpener::earlyAbort)); } comm_add_close_handler(solo->fd, calls.earlyabort); if (calls.timeout == NULL) { - typedef CommCbMemFunT Dialer; - calls.timeout = asyncCall(5, 4, "ConnOpener::timeout", - Dialer(this, &ConnOpener::timeout)); + typedef CommCbMemFunT Dialer; + calls.timeout = asyncCall(5, 4, "Comm::ConnOpener::timeout", + Dialer(this, &Comm::ConnOpener::timeout)); } debugs(5, 3, HERE << "FD " << solo->fd << " timeout " << connect_timeout); commSetTimeout(solo->fd, connect_timeout, calls.timeout); @@ -178,7 +180,7 @@ ConnOpener::start() return; } else { debugs(5, 5, HERE << "FD " << solo->fd << ": COMM_INPROGRESS"); - commSetSelect(solo->fd, COMM_SELECT_WRITE, ConnOpener::ConnectRetry, this, 0); + commSetSelect(solo->fd, COMM_SELECT_WRITE, Comm::ConnOpener::ConnectRetry, this, 0); } break; @@ -235,32 +237,32 @@ ConnOpener::start() } void -ConnOpener::earlyAbort(const CommConnectCbParams &io) +Comm::ConnOpener::earlyAbort(const CommConnectCbParams &io) { debugs(5, 3, HERE << "FD " << io.conn->fd); callCallback(COMM_ERR_CLOSING, io.xerrno); // NP: is closing or shutdown better? } void -ConnOpener::connect(const CommConnectCbParams &unused) +Comm::ConnOpener::connect(const CommConnectCbParams &unused) { start(); } void -ConnOpener::timeout(const CommTimeoutCbParams &unused) +Comm::ConnOpener::timeout(const CommTimeoutCbParams &unused) { start(); } void -ConnOpener::ConnectRetry(int fd, void *data) +Comm::ConnOpener::ConnectRetry(int fd, void *data) { - ConnOpener *cs = static_cast(data); + ConnOpener *cs = static_cast(data); cs->start(); - // see if its done and delete ConnOpener? comm Writes are not yet a Job call. + // see if its done and delete Comm::ConnOpener? comm Writes are not yet a Job call. // so the automatic cleanup on call completion does not seem to happen if (cs->doneAll()); - cs->deleteThis("Done after ConnOpener::ConnectRetry()"); + cs->deleteThis("Done after Comm::ConnOpener::ConnectRetry()"); } diff --git a/src/comm/ConnOpener.h b/src/comm/ConnOpener.h index e287675414..9060728042 100644 --- a/src/comm/ConnOpener.h +++ b/src/comm/ConnOpener.h @@ -8,6 +8,8 @@ #include "comm/comm_err_t.h" #include "comm/forward.h" +namespace Comm { + /** * Async-opener of a Comm connection. */ @@ -89,4 +91,6 @@ private: CBDATA_CLASS2(ConnOpener); }; +}; // namespace Comm + #endif /* _SQUID_SRC_COMM_CONNOPENER_H */ diff --git a/src/dns_internal.cc b/src/dns_internal.cc index d62716d553..f20d643d85 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -749,7 +749,7 @@ idnsInitVC(int ns) AsyncCall::Pointer call = commCbCall(78,3, "idnsInitVCConnected", CommConnectCbPtrFun(idnsInitVCConnected, vc)); - ConnOpener *cs = new ConnOpener(conn, call, Config.Timeout.connect); + Comm::ConnOpener *cs = new Comm::ConnOpener(conn, call, Config.Timeout.connect); cs->setHost("DNS TCP Socket"); AsyncJob::AsyncStart(cs); } diff --git a/src/forward.cc b/src/forward.cc index 0a727b2f12..344982baa3 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -80,7 +80,7 @@ FwdState::abort(void* d) FwdState* fwd = (FwdState*)d; Pointer tmp = fwd; // Grab a temporary pointer to keep the object alive during our scope. - if (fwd->paths.size() > 0 && fwd->paths[0]->fd > -1) { + if (fwd->paths.size() > 0 && fwd->paths[0]->isOpen()) { comm_remove_close_handler(fwd->paths[0]->fd, fwdServerClosedWrapper, fwd); fwd->paths[0]->close(); } @@ -171,7 +171,7 @@ FwdState::~FwdState() entry = NULL; - if (paths.size() > 0 && paths[0]->fd > -1) { + if (paths.size() > 0 && paths[0]->isOpen()) { comm_remove_close_handler(paths[0]->fd, fwdServerClosedWrapper, this); debugs(17, 3, HERE << "closing FD " << paths[0]->fd); paths[0]->close(); @@ -815,7 +815,7 @@ FwdState::connectStart() #endif AsyncCall::Pointer call = commCbCall(17,3, "fwdConnectDoneWrapper", CommConnectCbPtrFun(fwdConnectDoneWrapper, this)); - ConnOpener *cs = new ConnOpener(paths[0], call, ctimeout); + Comm::ConnOpener *cs = new Comm::ConnOpener(paths[0], call, ctimeout); cs->setHost(host); AsyncJob::AsyncStart(cs); } diff --git a/src/ftp.cc b/src/ftp.cc index bc6d563d99..f949ddeec1 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -2418,7 +2418,7 @@ ftpReadEPSV(FtpStateData* ftpState) conn->fd = fd; AsyncCall::Pointer call = commCbCall(9,3, "FtpStateData::ftpPasvCallback", CommConnectCbPtrFun(FtpStateData::ftpPasvCallback, ftpState)); - ConnOpener *cs = new ConnOpener(conn, call, Config.Timeout.connect); + Comm::ConnOpener *cs = new Comm::ConnOpener(conn, call, Config.Timeout.connect); cs->setHost(ftpState->data.host); AsyncJob::AsyncStart(cs); } @@ -2702,7 +2702,7 @@ ftpReadPasv(FtpStateData * ftpState) conn->fd = ftpState->data.fd; AsyncCall::Pointer call = commCbCall(9,3, "FtpStateData::ftpPasvCallback", CommConnectCbPtrFun(FtpStateData::ftpPasvCallback, ftpState)); - ConnOpener *cs = new ConnOpener(conn, call, Config.Timeout.connect); + Comm::ConnOpener *cs = new Comm::ConnOpener(conn, call, Config.Timeout.connect); cs->setHost(ftpState->data.host); AsyncJob::AsyncStart(cs); } diff --git a/src/ident/Ident.cc b/src/ident/Ident.cc index bb20ef52d6..1955f18241 100644 --- a/src/ident/Ident.cc +++ b/src/ident/Ident.cc @@ -250,7 +250,7 @@ Ident::Start(Comm::ConnectionPointer &conn, IDCB * callback, void *data) hash_join(ident_hash, &state->hash); AsyncCall::Pointer call = commCbCall(30,3, "Ident::ConnectDone", CommConnectCbPtrFun(Ident::ConnectDone, state)); - AsyncJob::AsyncStart(new ConnOpener(state->conn, call, Ident::TheConfig.timeout)); + AsyncJob::AsyncStart(new Comm::ConnOpener(state->conn, call, Ident::TheConfig.timeout)); } void diff --git a/src/neighbors.cc b/src/neighbors.cc index 28f104f8d4..2558d536e8 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1369,7 +1369,7 @@ peerProbeConnect(peer * p) p->testing_now++; AsyncCall::Pointer call = commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone, p)); - ConnOpener *cs = new ConnOpener(conn, call, ctimeout); + Comm::ConnOpener *cs = new Comm::ConnOpener(conn, call, ctimeout); cs->setHost(p->host); AsyncJob::AsyncStart(cs); } diff --git a/src/tunnel.cc b/src/tunnel.cc index 79a8dc3124..e69307e050 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -547,7 +547,7 @@ tunnelConnectDone(Comm::ConnectionPointer &conn, comm_err_t status, int xerrno, if (status != COMM_TIMEOUT && tunnelState->paths.size() > 0) { /* Try another IP of this destination host */ AsyncCall::Pointer call = commCbCall(26,3, "tunnelConnectDone", CommConnectCbPtrFun(tunnelConnectDone, tunnelState)); - ConnOpener *cs = new ConnOpener(tunnelState->paths[0], call, Config.Timeout.connect); + Comm::ConnOpener *cs = new Comm::ConnOpener(tunnelState->paths[0], call, Config.Timeout.connect); cs->setHost(tunnelState->url); AsyncJob::AsyncStart(cs); } else { @@ -700,7 +700,7 @@ tunnelPeerSelectComplete(Comm::Paths *peer_paths, void *data) } AsyncCall::Pointer call = commCbCall(26,3, "tunnelConnectDone", CommConnectCbPtrFun(tunnelConnectDone, tunnelState)); - ConnOpener *cs = new ConnOpener(tunnelState->paths[0], call, Config.Timeout.connect); + Comm::ConnOpener *cs = new Comm::ConnOpener(tunnelState->paths[0], call, Config.Timeout.connect); cs->setHost(tunnelState->url); AsyncJob::AsyncStart(cs); }