From: Amos Jeffries Date: Sat, 4 Sep 2010 15:03:12 +0000 (+1200) Subject: Make conn a shared field for CommCalls X-Git-Tag: take08~55^2~124^2~72 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7957e7044bffae7ce0c7f54add701deb2abc1a02;p=thirdparty%2Fsquid.git Make conn a shared field for CommCalls Create a commSetConnTimeout() function to hide FD field from code needing to set timeouts. Also, some extra build fixes after FwdStart and server Start() changes. --- diff --git a/src/CommCalls.cc b/src/CommCalls.cc index 63d51750fb..fd5a14a599 100644 --- a/src/CommCalls.cc +++ b/src/CommCalls.cc @@ -23,7 +23,11 @@ CommCommonCbParams::~CommCommonCbParams() void CommCommonCbParams::print(std::ostream &os) const { - os << "FD " << fd; + if (conn != NULL) + os << conn; + else + os << "FD " << fd; + if (xerrno) os << ", errno=" << xerrno; if (flag != COMM_OK) @@ -70,14 +74,6 @@ CommConnectCbParams::syncWithComm() return true; // now we are in sync and can handle the call } -void -CommConnectCbParams::print(std::ostream &os) const -{ - CommCommonCbParams::print(os); - if (conn != NULL) - os << ", " << conn; -} - /* CommIoCbParams */ CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData), @@ -124,7 +120,6 @@ CommTimeoutCbParams::CommTimeoutCbParams(void *aData): { } - /* CommAcceptCbPtrFun */ CommAcceptCbPtrFun::CommAcceptCbPtrFun(IOACB *aHandler, @@ -231,6 +226,16 @@ CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF *aHandler, void CommTimeoutCbPtrFun::dial() { + // AYJ NP: since the old code is still used by pipes and IPC + // we cant discard the params.fd functions entirely for old callbacks. + // new callers supposed to only set conn. + // sync FD and conn fields at this single failure point before dialing. + if (params.conn != NULL) { + if (params.fd < 0 && params.conn->fd > 0) + params.fd = params.conn->fd; + assert(params.fd == params.conn->fd); // Must() ? + } + handler(params.fd, params.data); } diff --git a/src/CommCalls.h b/src/CommCalls.h index b67b59b2cb..cff7d5a5ad 100644 --- a/src/CommCalls.h +++ b/src/CommCalls.h @@ -54,7 +54,8 @@ public: public: void *data; // cbdata-protected - int fd; + Comm::ConnectionPointer conn; + int fd; // raw FD from legacy calls. use conn instead. int xerrno; comm_err_t flag; @@ -83,11 +84,6 @@ public: CommConnectCbParams(void *aData); bool syncWithComm(); // see CommCommonCbParams::syncWithComm - - void print(std::ostream &os) const; - -public: - Comm::ConnectionPointer conn; }; // read/write (I/O) parameters diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 67626523f3..75bad3daff 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1683,7 +1683,7 @@ clientReplyContext::doGetMoreData() #if USE_ZPH_QOS if (Ip::Qos::TheConfig.tos_local_hit) { debugs(33, 2, "ZPH Local hit, TOS=" << Ip::Qos::TheConfig.tos_local_hit); - comm_set_tos(http->getConn()->fd, Ip::Qos::TheConfig.tos_local_hit); + comm_set_tos(http->getConn()->clientConn->fd, Ip::Qos::TheConfig.tos_local_hit); } #endif /* USE_ZPH_QOS */ localTempBuffer.offset = reqofs; diff --git a/src/comm.cc b/src/comm.cc index 6ba1ab62b6..d3f17c5825 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -876,6 +876,7 @@ commSetTimeout_old(int fd, int timeout, PF * handler, void *data) } #endif +// Legacy pre-AsyncCalls API for FD timeouts. int commSetTimeout(int fd, int timeout, PF * handler, void *data) { @@ -888,7 +889,8 @@ commSetTimeout(int fd, int timeout, PF * handler, void *data) return commSetTimeout(fd, timeout, call); } - +// Legacy pre-Comm::Connection API for FD timeouts +// still used by non-socket FD code dealing with pipes and IPC sockets. int commSetTimeout(int fd, int timeout, AsyncCall::Pointer &callback) { @@ -913,7 +915,32 @@ commSetTimeout(int fd, int timeout, AsyncCall::Pointer &callback) } return F->timeout; +} + +int +commSetConnTimeout(const Comm::ConnectionPointer &conn, int timeout, AsyncCall::Pointer &callback) +{ + debugs(5, 3, HERE << conn << " timeout " << timeout); + assert(Comm::IsConnOpen(conn)); + assert(conn->fd < Squid_MaxFD); + fde *F = &fd_table[conn->fd]; + assert(F->flags.open); + + if (timeout < 0) { + F->timeoutHandler = NULL; + F->timeout = 0; + } else { + if (callback != NULL) { + typedef CommTimeoutCbParams Params; + Params ¶ms = GetCommParams(callback); + params.conn = conn; + F->timeoutHandler = callback; + } + F->timeout = squid_curtime + (time_t) timeout; + } + + return F->timeout; } int diff --git a/src/comm.h b/src/comm.h index fdcd4df841..6caf48aa6b 100644 --- a/src/comm.h +++ b/src/comm.h @@ -70,6 +70,13 @@ extern void comm_write_mbuf(int fd, MemBuf *mb, AsyncCall::Pointer &callback); SQUIDCEXTERN void commCallCloseHandlers(int fd); SQUIDCEXTERN int commSetTimeout(int fd, int, PF *, void *); extern int commSetTimeout(int fd, int, AsyncCall::Pointer &calback); + +/** + * Set or clear the timeout for some action on an active connection. + * API to replace commSetTimeout() when a Comm::ConnectionPointer is available. + */ +extern int commSetConnTimeout(const Comm::ConnectionPointer &conn, int seconds, AsyncCall::Pointer &calback); + SQUIDCEXTERN int ignoreErrno(int); SQUIDCEXTERN void commCloseAllSockets(void); SQUIDCEXTERN void checkTimeouts(void); diff --git a/src/icmp/net_db.cc b/src/icmp/net_db.cc index 58532b5c01..359e584ac0 100644 --- a/src/icmp/net_db.cc +++ b/src/icmp/net_db.cc @@ -1336,7 +1336,8 @@ netdbExchangeStart(void *data) urlCanonical(ex->r); - FwdState::fwdStart(-1, ex->e, ex->r); + Comm::ConnectionPointer nul; + FwdState::fwdStart(nul, ex->e, ex->r); #endif } diff --git a/src/peer_digest.cc b/src/peer_digest.cc index 4f009ec93e..e8cb71d891 100644 --- a/src/peer_digest.cc +++ b/src/peer_digest.cc @@ -393,7 +393,8 @@ peerDigestRequest(PeerDigest * pd) /* push towards peer cache */ debugs(72, 3, "peerDigestRequest: forwarding to fwdStart..."); - FwdState::fwdStart(-1, e, req); + Comm::ConnectionPointer nul; + FwdState::fwdStart(nul, e, req); tempBuffer.offset = 0; diff --git a/src/tests/stub_cache_manager.cc b/src/tests/stub_cache_manager.cc index b67584e549..bb2bb8085d 100644 --- a/src/tests/stub_cache_manager.cc +++ b/src/tests/stub_cache_manager.cc @@ -57,7 +57,7 @@ CacheManager::findAction(char const * action) } void -CacheManager::Start(int fd, HttpRequest * request, StoreEntry * entry) +CacheManager::Start(const Comm::ConnectionPointer &conn, HttpRequest * request, StoreEntry * entry) { return; }