]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Update comm timeout handlers to use CommTimeoutCbParams
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 4 Dec 2010 15:48:48 +0000 (04:48 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 4 Dec 2010 15:48:48 +0000 (04:48 +1300)
17 files changed:
src/CommCalls.cc
src/CommCalls.h
src/adaptation/icap/Xaction.cc
src/client_side.cc
src/comm.cc
src/comm.h
src/comm/ConnOpener.cc
src/dns_internal.cc
src/ftp.cc
src/gopher.cc
src/http.cc
src/ident/Ident.cc
src/ipc/UdsOp.cc
src/pconn.cc
src/pconn.h
src/tunnel.cc
src/whois.cc

index b656b810405779c4710bc9fca3d8ed59ef70c443..ef9456894c48056c3656b9676e44f8dc57d3b347 100644 (file)
@@ -74,13 +74,15 @@ CommIoCbParams::CommIoCbParams(void *aData): CommCommonCbParams(aData),
 bool
 CommIoCbParams::syncWithComm()
 {
+#if 0 // transition past??
     // transition only: read/write legacy code does not know about conn, it just sets FD
     if (fd >= 0) {
-        if (conn == NULL)
+        if (conn == NULL) {
             conn = new Comm::Connection;
-        if (conn->fd != fd)
             conn->fd = fd;
+        }
     }
+#endif
 
     // change parameters if the call was scheduled before comm_close but
     // is being fired after comm_close
@@ -221,7 +223,7 @@ CommCloseCbPtrFun::print(std::ostream &os) const
 
 /* CommTimeoutCbPtrFun */
 
-CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF *aHandler,
+CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(CTCB *aHandler,
         const CommTimeoutCbParams &aParams):
         CommDialerParamsT<CommTimeoutCbParams>(aParams),
         handler(aHandler)
@@ -231,17 +233,7 @@ 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);
+    handler(params);
 }
 
 void
index cb8a9fc540a3fadd6a4073a7058b2691ff0dc454..5268dd50f769e35f03a0b9f181be45eb261ffe37 100644 (file)
  * The classes cover two call dialer kinds:
  *     - A C-style call using a function pointer (depricated);
  *     - A C++-style call to an AsyncJob child.
- * and three comm_* callback kinds:
- *     - accept (IOACB),
- *     - connect (CNCB),
- *     - I/O (IOCB).
+ * and several comm_* callback kinds:
+ *     - accept (IOACB)
+ *     - connect (CNCB)
+ *     - I/O (IOCB)
+ *     - timeout (CTCB)
  */
 
 typedef void IOACB(int fd, const Comm::ConnectionPointer &details, comm_err_t flag, int xerrno, void *data);
 typedef void CNCB(const Comm::ConnectionPointer &conn, comm_err_t status, int xerrno, void *data);
 typedef void IOCB(const Comm::ConnectionPointer &conn, char *, size_t size, comm_err_t flag, int xerrno, void *data);
 
+class CommTimeoutCbParams;
+typedef void CTCB(const CommTimeoutCbParams &params);
+
 /*
  * TODO: When there are no function-pointer-based callbacks left, all
  * this complexity can be removed. Jobs that need comm services will just
@@ -62,7 +66,7 @@ public:
      * \itemize On read calls this is the connection just read from.
      * \itemize On close calls this describes the connection which is now closed.
      * \itemize On timeouts this is the connection whose operation timed out.
-     *          NP: timeouts should now return to the connect/read/write handler with COMM_ERR_TIMEOUT.
+     *          NP: timeouts might also return to the connect/read/write handler with COMM_ERR_TIMEOUT.
      */
     Comm::ConnectionPointer conn;
 
@@ -249,13 +253,13 @@ class CommTimeoutCbPtrFun:public CallDialer,
 public:
     typedef CommTimeoutCbParams Params;
 
-    CommTimeoutCbPtrFun(PF *aHandler, const Params &aParams);
+    CommTimeoutCbPtrFun(CTCB *aHandler, const Params &aParams);
     void dial();
 
     virtual void print(std::ostream &os) const;
 
 public:
-    PF *handler;
+    CTCB *handler;
 };
 
 // AsyncCall to comm handlers implemented as global functions.
index 04bda5a1d9d51c3117d04e3d69fa9c55c741d799..da2161622362997659e999cd51883c00c0f13954 100644 (file)
@@ -167,8 +167,8 @@ void Adaptation::Icap::Xaction::closeConnection()
         if (reuseConnection) {
             //status() adds leading spaces.
             debugs(93,3, HERE << "pushing pconn" << status());
-            AsyncCall::Pointer nul;
-            commSetTimeout(connection->fd, -1, nul);
+            AsyncCall::Pointer nil;
+            commUnsetConnTimeout(connection);
             icapPconnPool->push(connection, NULL);
             disableRetries();
         } else {
@@ -308,12 +308,11 @@ void Adaptation::Icap::Xaction::updateTimeout()
         // TODO: service bypass status may differ from that of a transaction
         typedef CommCbMemFunT<Adaptation::Icap::Xaction, CommTimeoutCbParams> TimeoutDialer;
         AsyncCall::Pointer call = JobCallback(93, 5, TimeoutDialer, this, Adaptation::Icap::Xaction::noteCommTimedout);
-        commSetTimeout(connection->fd, TheConfig.io_timeout(service().cfg().bypass), call);
+        commSetConnTimeout(connection, TheConfig.io_timeout(service().cfg().bypass), call);
     } else {
         // clear timeout when there is no I/O
         // Do we need a lifetime timeout?
-        AsyncCall::Pointer call = NULL;
-        commSetTimeout(connection->fd, -1, call);
+        commUnsetConnTimeout(connection);
     }
 }
 
index 33348fb9e66c3b7d492d74e545bda5c09bc01327..765d491154c779bfa90065b25018fafbf548caf6 100644 (file)
@@ -191,7 +191,7 @@ static IOCB clientWriteBodyComplete;
 static IOACB httpAccept;
 static IOACB httpsAccept;
 static bool clientParseRequest(ConnStateData * conn, bool &do_next_read);
-static PF clientLifetimeTimeout;
+static CTCB clientLifetimeTimeout;
 static ClientSocketContext *parseHttpRequestAbort(ConnStateData * conn, const char *uri);
 static ClientSocketContext *parseHttpRequest(ConnStateData *, HttpParser *, HttpRequestMethod *, HttpVersion *);
 #if USE_IDENT
@@ -1489,7 +1489,7 @@ ConnStateData::readNextRequest()
     typedef CommCbMemFunT<ConnStateData, CommTimeoutCbParams> TimeoutDialer;
     AsyncCall::Pointer timeoutCall = JobCallback(33, 5,
                                      TimeoutDialer, this, ConnStateData::requestTimeout);
-    commSetTimeout(clientConn->fd, Config.Timeout.persistent_request, timeoutCall);
+    commSetConnTimeout(clientConn, Config.Timeout.persistent_request, timeoutCall);
 
     readSomeData();
     /** Please don't do anything with the FD past here! */
@@ -2706,8 +2706,9 @@ clientParseRequest(ConnStateData * conn, bool &do_next_read)
         /* status -1 or 1 */
         if (context) {
             debugs(33, 5, HERE << conn->clientConn << ": parsed a request");
-            commSetTimeout(conn->clientConn->fd, Config.Timeout.lifetime, clientLifetimeTimeout,
-                           context->http);
+            AsyncCall::Pointer timeoutCall = commCbCall(5, 4, "clientLifetimeTimeout",
+                                                        CommTimeoutCbPtrFun(clientLifetimeTimeout, context->http));
+            commSetConnTimeout(conn->clientConn, Config.Timeout.lifetime, timeoutCall);
 
             clientProcessRequest(conn, &hp, context, method, http_ver);
 
@@ -3031,7 +3032,7 @@ ConnStateData::requestTimeout(const CommTimeoutCbParams &io)
         typedef CommCbMemFunT<ConnStateData, CommTimeoutCbParams> TimeoutDialer;
         AsyncCall::Pointer timeoutCall =  JobCallback(33, 5,
                                           TimeoutDialer, this, ConnStateData::requestTimeout);
-        commSetTimeout(io.fd, 30, timeoutCall);
+        commSetConnTimeout(io.conn, 30, timeoutCall);
 
         /*
          * Aha, but we don't want a read handler!
@@ -3049,21 +3050,19 @@ ConnStateData::requestTimeout(const CommTimeoutCbParams &io)
     * connection)
     */
     debugs(33, 3, "requestTimeout: FD " << io.fd << ": lifetime is expired.");
-
-    clientConn->close();
-
+    io.conn->close();
 #endif
 }
 
 static void
-clientLifetimeTimeout(int fd, void *data)
+clientLifetimeTimeout(const CommTimeoutCbParams &io)
 {
-    ClientHttpRequest *http = (ClientHttpRequest *)data;
+    ClientHttpRequest *http = static_cast<ClientHttpRequest *>(io.data);
     debugs(33, DBG_IMPORTANT, "WARNING: Closing client connection due to lifetime timeout");
     debugs(33, DBG_IMPORTANT, "\t" << http->uri);
     http->al.http.timedout = true;
-    if (http->getConn() && Comm::IsConnOpen(http->getConn()->clientConn))
-        http->getConn()->clientConn->close();
+    if (Comm::IsConnOpen(io.conn))
+        io.conn->close();
 }
 
 ConnStateData *
@@ -3134,7 +3133,7 @@ httpAccept(int sock, const Comm::ConnectionPointer &details, comm_err_t flag, in
     typedef CommCbMemFunT<ConnStateData, CommTimeoutCbParams> TimeoutDialer;
     AsyncCall::Pointer timeoutCall =  JobCallback(33, 5,
                                       TimeoutDialer, connState, ConnStateData::requestTimeout);
-    commSetTimeout(details->fd, Config.Timeout.read, timeoutCall);
+    commSetConnTimeout(details, Config.Timeout.read, timeoutCall);
 
 #if USE_IDENT
     if (Ident::TheConfig.identLookup) {
@@ -3378,7 +3377,7 @@ httpsAccept(int sock, const Comm::ConnectionPointer& details, comm_err_t flag, i
     typedef CommCbMemFunT<ConnStateData, CommTimeoutCbParams> TimeoutDialer;
     AsyncCall::Pointer timeoutCall =  JobCallback(33, 5,
                                       TimeoutDialer, connState, ConnStateData::requestTimeout);
-    commSetTimeout(details->fd, Config.Timeout.request, timeoutCall);
+    commSetConnTimeout(details, Config.Timeout.request, timeoutCall);
 
 #if USE_IDENT
     if (Ident::TheConfig.identLookup) {
@@ -3503,7 +3502,7 @@ ConnStateData::getSslContextDone(SSL_CTX * sslContext, bool isNew)
     if (!(ssl = httpsCreate(clientConn, sslContext)))
         return false;
 
-    // commSetTimeout() was called for this request before we switched.
+    // commSetConnTimeout() was called for this request before we switched.
 
     // Disable the client read handler until peer selection is complete
     commSetSelect(clientConn->fd, COMM_SELECT_READ, NULL, NULL, 0);
index 52fd50eda2933a7292e72cfa5748cf63c5dce7a7..9c5e32a2e470a80036f9c43d4016fcd87195fa84 100644 (file)
@@ -738,7 +738,7 @@ comm_import_opened(const Comm::ConnectionPointer &conn,
 
 #if 0
 int
-commSetTimeout_old(int fd, int timeout, PF * handler, void *data)
+commSetTimeout_old(int fd, int timeout, CTCB * handler, void *data)
 {
     debugs(5, 3, HERE << "FD " << fd << " timeout " << timeout);
     assert(fd >= 0);
@@ -766,7 +766,7 @@ commSetTimeout_old(int fd, int timeout, PF * handler, void *data)
 
 // Legacy pre-AsyncCalls API for FD timeouts.
 int
-commSetTimeout(int fd, int timeout, PF * handler, void *data)
+commSetTimeout(int fd, int timeout, CTCB * handler, void *data)
 {
     AsyncCall::Pointer call;
     debugs(5, 3, HERE << "FD " << fd << " timeout " << timeout);
@@ -831,6 +831,14 @@ commSetConnTimeout(const Comm::ConnectionPointer &conn, int timeout, AsyncCall::
     return F->timeout;
 }
 
+int
+commUnsetConnTimeout(const Comm::ConnectionPointer &conn)
+{
+    debugs(5, 3, HERE << "Remove timeout for " << conn);
+    AsyncCall::Pointer nil;
+    return commSetConnTimeout(conn, -1, nil);
+}
+
 int
 comm_connect_addr(int sock, const Ip::Address &address)
 {
index 10bd170a7fe12483d91ec40113f8293495fb72e6..d021258d52144d1daaf9010b0e865057b34e2495 100644 (file)
@@ -59,7 +59,7 @@ SQUIDCEXTERN void commResetSelect(int);
 
 SQUIDCEXTERN int comm_udp_sendto(int sock, const Ip::Address &to, const void *buf, int buflen);
 SQUIDCEXTERN void commCallCloseHandlers(int fd);
-SQUIDCEXTERN int commSetTimeout(int fd, int, PF *, void *);
+SQUIDCEXTERN int commSetTimeout(int fd, int, CTCB *, void *);
 extern int commSetTimeout(int fd, int, AsyncCall::Pointer &callback);
 
 /**
@@ -67,6 +67,7 @@ extern int commSetTimeout(int fd, int, AsyncCall::Pointer &callback);
  * API to replace commSetTimeout() when a Comm::ConnectionPointer is available.
  */
 extern int commSetConnTimeout(const Comm::ConnectionPointer &conn, int seconds, AsyncCall::Pointer &callback);
+extern int commUnsetConnTimeout(const Comm::ConnectionPointer &conn);
 
 SQUIDCEXTERN int ignoreErrno(int);
 SQUIDCEXTERN void commCloseAllSockets(void);
index 36fdf70ba2efbcef703f2cdaa6112d7dc729687c..de81be255be10f4078d6bac500e11f4f31cc72b9 100644 (file)
@@ -65,7 +65,7 @@ Comm::ConnOpener::swanSong()
     if (conn_ != NULL && conn_->isOpen()) {
         // drop any handlers now to save a lot of cycles later
         commSetSelect(conn_->fd, COMM_SELECT_WRITE, NULL, NULL, 0);
-        commSetTimeout(conn_->fd, -1, NULL, NULL);
+        commUnsetConnTimeout(conn_);
         // it never reached fully open, so abort the FD
         conn_->close();
     }
@@ -161,7 +161,7 @@ Comm::ConnOpener::start()
     typedef CommCbMemFunT<Comm::ConnOpener, CommTimeoutCbParams> timeoutDialer;
     calls_.timeout_ = JobCallback(5, 4, timeoutDialer, this, Comm::ConnOpener::timeout);
     debugs(5, 3, HERE << conn_ << " timeout " << connectTimeout_);
-    commSetTimeout(conn_->fd, connectTimeout_, calls_.timeout_);
+    commSetConnTimeout(conn_, connectTimeout_, calls_.timeout_);
 
     connectStart_ = squid_curtime;
     connect();
@@ -285,7 +285,7 @@ Comm::ConnOpener::earlyAbort(const CommConnectCbParams &io)
 
 /**
  * Handles the case(s) when a partially setup connection gets timed out.
- * NP: When commSetTimeout accepts generic CommCommonCbParams this can die.
+ * NP: When commSetConnTimeout accepts generic CommCommonCbParams this can die.
  */
 void
 Comm::ConnOpener::timeout(const CommTimeoutCbParams &)
index c18626ef59c979dbbc8aedf58b054cb77d2c9ac6..ae460a5276f50028f5c614e8df8ac798be2642dc 100644 (file)
@@ -771,7 +771,8 @@ idnsDoSendQueryVC(nsvc *vc)
 
     vc->busy = 1;
 
-    commSetTimeout(vc->conn->fd, Config.Timeout.idns_query, NULL, NULL);
+    AsyncCall::Pointer nil;
+    commSetConnTimeout(vc->conn, Config.Timeout.idns_query, nil);
 
     AsyncCall::Pointer call = commCbCall(78, 5, "idnsSentQueryVC",
                                          CommIoCbPtrFun(&idnsSentQueryVC, vc));
index 916ab5aaf389d527e2578a0bec158f1470fc5ce8..9aae0fc162a61945e50860330e30157aecc4ab3f 100644 (file)
@@ -626,12 +626,11 @@ FtpStateData::loginParser(const char *login, int escaped)
 void
 FtpStateData::switchTimeoutToDataChannel()
 {
-    AsyncCall::Pointer nullCall = NULL;
-    commSetTimeout(ctrl.conn->fd, -1, nullCall);
+    commUnsetConnTimeout(ctrl.conn);
 
     typedef CommCbMemFunT<FtpStateData, CommTimeoutCbParams> TimeoutDialer;
     AsyncCall::Pointer timeoutCall = JobCallback(9, 5, TimeoutDialer, this, FtpStateData::ftpTimeout);
-    commSetTimeout(data.conn->fd, Config.Timeout.read, timeoutCall);
+    commSetConnTimeout(data.conn, Config.Timeout.read, timeoutCall);
 }
 
 void
@@ -649,9 +648,9 @@ FtpStateData::listenForDataChannel(const Comm::ConnectionPointer &conn, const ch
 void
 FtpStateData::ftpTimeout(const CommTimeoutCbParams &io)
 {
-    debugs(9, 4, "ftpTimeout: FD " << io.fd << ": '" << entry->url() << "'" );
+    debugs(9, 4, HERE << io.conn << ": '" << entry->url() << "'" );
 
-    if (SENT_PASV == state && io.fd == data.conn->fd) {
+    if (SENT_PASV == state && io.conn->fd == data.conn->fd) {
         /* stupid ftp.netscape.com */
         flags.pasv_supported = false;
         debugs(9, DBG_IMPORTANT, "ftpTimeout: timeout in SENT_PASV state" );
@@ -1202,7 +1201,7 @@ FtpStateData::maybeReadVirginBody()
     typedef CommCbMemFunT<FtpStateData, CommTimeoutCbParams> TimeoutDialer;
     AsyncCall::Pointer timeoutCall =  JobCallback(9, 5,
                                       TimeoutDialer, this, FtpStateData::ftpTimeout);
-    commSetTimeout(data.conn->fd, Config.Timeout.read, timeoutCall);
+    commSetConnTimeout(data.conn, Config.Timeout.read, timeoutCall);
 
     debugs(9,5,HERE << "queueing read on FD " << data.conn->fd);
 
@@ -1259,7 +1258,7 @@ FtpStateData::dataRead(const CommIoCbParams &io)
             typedef CommCbMemFunT<FtpStateData, CommTimeoutCbParams> TimeoutDialer;
             AsyncCall::Pointer timeoutCall = JobCallback(9, 5,
                                              TimeoutDialer, this, FtpStateData::ftpTimeout);
-            commSetTimeout(io.fd, Config.Timeout.read, timeoutCall);
+            commSetConnTimeout(io.conn, Config.Timeout.read, timeoutCall);
 
             maybeReadVirginBody();
         } else {
@@ -1699,13 +1698,12 @@ FtpStateData::scheduleReadControlReply(int buffered_ok)
          * establish one on the control socket.
          */
         if (Comm::IsConnOpen(data.conn)) {
-            AsyncCall::Pointer nullCall = NULL;
-            commSetTimeout(data.conn->fd, -1, nullCall);
+            commUnsetConnTimeout(data.conn);
         }
 
         typedef CommCbMemFunT<FtpStateData, CommTimeoutCbParams> TimeoutDialer;
         AsyncCall::Pointer timeoutCall = JobCallback(9, 5, TimeoutDialer, this, FtpStateData::ftpTimeout);
-        commSetTimeout(ctrl.conn->fd, Config.Timeout.read, timeoutCall);
+        commSetConnTimeout(ctrl.conn, Config.Timeout.read, timeoutCall);
 
         typedef CommCbMemFunT<FtpStateData, CommIoCbParams> Dialer;
         AsyncCall::Pointer reader = JobCallback(9, 5, Dialer, this, FtpStateData::ftpReadControlReply);
@@ -2571,8 +2569,7 @@ ftpSendPassive(FtpStateData * ftpState)
     typedef CommCbMemFunT<FtpStateData, CommTimeoutCbParams> TimeoutDialer;
     AsyncCall::Pointer timeoutCall =  JobCallback(9, 5,
                                       TimeoutDialer, ftpState, FtpStateData::ftpTimeout);
-
-    commSetTimeout(ftpState->ctrl.conn->fd, Config.Timeout.connect, timeoutCall);
+    commSetConnTimeout(ftpState->ctrl.conn, Config.Timeout.connect, timeoutCall);
 }
 
 void
index b87ab1599568e4b9a3c2420b0df891a2831949aa..b5eeccf9f62190274ecfdd388a3f04f55a04d222 100644 (file)
@@ -148,7 +148,7 @@ static void gopher_request_parse(const HttpRequest * req,
                                  char *request);
 static void gopherEndHTML(GopherStateData *);
 static void gopherToHTML(GopherStateData *, char *inbuf, int len);
-static PF gopherTimeout;
+static CTCB gopherTimeout;
 static IOCB gopherReadReply;
 static IOCB gopherSendComplete;
 static PF gopherSendRequest;
@@ -752,15 +752,15 @@ gopherToHTML(GopherStateData * gopherState, char *inbuf, int len)
 
 /// \ingroup ServerProtocolGopherInternal
 static void
-gopherTimeout(int fd, void *data)
+gopherTimeout(const CommTimeoutCbParams &io)
 {
-    GopherStateData *gopherState = (GopherStateData *)data;
-    debugs(10, 4, HERE << gopherState->serverConn << ": '" << gopherState->entry->url() << "'" );
+    GopherStateData *gopherState = static_cast<GopherStateData *>(io.data);
+    debugs(10, 4, HERE << io.conn << ": '" << gopherState->entry->url() << "'" );
 
     gopherState->fwd->fail(errorCon(ERR_READ_TIMEOUT, HTTP_GATEWAY_TIMEOUT, gopherState->fwd->request));
 
-    if (Comm::IsConnOpen(gopherState->serverConn))
-        gopherState->serverConn->close();
+    if (Comm::IsConnOpen(io.conn))
+        io.conn->close();
 }
 
 /**
@@ -811,7 +811,8 @@ gopherReadReply(const Comm::ConnectionPointer &conn, char *buf, size_t len, comm
         kb_incr(&statCounter.server.all.kbytes_in, len);
         kb_incr(&statCounter.server.other.kbytes_in, len);
 
-        commSetTimeout(conn->fd, Config.Timeout.read, NULL, NULL);
+        AsyncCall::Pointer nil;
+        commSetConnTimeout(conn, Config.Timeout.read, nil);
         IOStats.Gopher.reads++;
 
         for (clen = len - 1, bin = 0; clen; bin++)
@@ -940,7 +941,7 @@ gopherSendComplete(const Comm::ConnectionPointer &conn, char *buf, size_t size,
     }
 
     /* Schedule read reply. */
-    AsyncCall::Pointer call =  commCbCall(10,5, "gopherReadReply",
+    AsyncCall::Pointer call =  commCbCall(5,5, "gopherReadReply",
                                           CommIoCbPtrFun(gopherReadReply, gopherState));
     entry->delayAwareRead(conn, gopherState->replybuf, BUFSIZ, call);
 
@@ -1040,5 +1041,7 @@ gopherStart(FwdState * fwd)
 
     gopherState->serverConn = fwd->serverConnection();
     gopherSendRequest(fwd->serverConnection()->fd, gopherState);
-    commSetTimeout(fwd->serverConnection()->fd, Config.Timeout.read, gopherTimeout, gopherState);
+    AsyncCall::Pointer timeoutCall = commCbCall(5, 4, "gopherTimeout",
+                                                CommTimeoutCbPtrFun(gopherTimeout, gopherState));
+    commSetConnTimeout(fwd->serverConnection(), Config.Timeout.read, timeoutCall);
 }
index d153802b2d942b15ee9c4da832625ad241960097..dee62d3b9114cce4a3f8d0b1d35f1a4c4aab2d1b 100644 (file)
@@ -1357,7 +1357,6 @@ HttpStateData::decodeAndWriteReplyBody()
 void
 HttpStateData::processReplyBody()
 {
-    AsyncCall::Pointer call;
     Ip::Address client_addr;
     bool ispinned = false;
 
@@ -1398,24 +1397,24 @@ HttpStateData::processReplyBody()
     } else
         switch (persistentConnStatus()) {
         case INCOMPLETE_MSG:
+            {
             debugs(11, 5, "processReplyBody: INCOMPLETE_MSG from " << serverConnection);
             /* Wait for more data or EOF condition */
+            AsyncCall::Pointer nil;
             if (flags.keepalive_broken) {
-                call = NULL;
-                commSetTimeout(serverConnection->fd, 10, call);
+                commSetConnTimeout(serverConnection, 10, nil);
             } else {
-                call = NULL;
-                commSetTimeout(serverConnection->fd, Config.Timeout.read, call);
+                commSetConnTimeout(serverConnection, Config.Timeout.read, nil);
             }
 
             flags.do_next_read = 1;
+            }
             break;
 
         case COMPLETE_PERSISTENT_MSG:
             debugs(11, 5, "processReplyBody: COMPLETE_PERSISTENT_MSG from " << serverConnection);
             /* yes we have to clear all these! */
-            call = NULL;
-            commSetTimeout(serverConnection->fd, -1, call);
+            commUnsetConnTimeout(serverConnection);
             flags.do_next_read = 0;
 
             comm_remove_close_handler(serverConnection->fd, closeHandler);
@@ -1528,7 +1527,7 @@ HttpStateData::sendComplete()
     AsyncCall::Pointer timeoutCall =  JobCallback(11, 5,
                                       TimeoutDialer, this, HttpStateData::httpTimeout);
 
-    commSetTimeout(serverConnection->fd, Config.Timeout.read, timeoutCall);
+    commSetConnTimeout(serverConnection, Config.Timeout.read, timeoutCall);
 
     flags.request_sent = 1;
 
@@ -2072,7 +2071,7 @@ HttpStateData::sendRequest()
     typedef CommCbMemFunT<HttpStateData, CommTimeoutCbParams> TimeoutDialer;
     AsyncCall::Pointer timeoutCall =  JobCallback(11, 5,
                                       TimeoutDialer, this, HttpStateData::httpTimeout);
-    commSetTimeout(serverConnection->fd, Config.Timeout.lifetime, timeoutCall);
+    commSetConnTimeout(serverConnection, Config.Timeout.lifetime, timeoutCall);
     flags.do_next_read = 1;
     maybeReadVirginBody();
 
index edf2ee973f2ef6750a3e859b79290521493d662d..04a6ae87048489c04275730bfee8e9f0a77248fe 100644 (file)
@@ -69,7 +69,7 @@ typedef struct _IdentStateData {
 // TODO: make these all a series of Async job calls. They are self-contained callbacks now.
 static IOCB ReadReply;
 static PF Close;
-static PF Timeout;
+static CTCB Timeout;
 static CNCB ConnectDone;
 static hash_table *ident_hash = NULL;
 static void ClientAdd(IdentStateData * state, IDCB * callback, void *callback_data);
@@ -112,11 +112,10 @@ Ident::Close(int fdnotused, void *data)
 }
 
 void
-Ident::Timeout(int fd, void *data)
+Ident::Timeout(const CommTimeoutCbParams &io)
 {
-    IdentStateData *state = (IdentStateData *)data;
-    debugs(30, 3, HERE << "FD " << fd << ", " << state->conn->remote);
-    state->conn->close();
+    debugs(30, 3, HERE << io.conn);
+    io.conn->close();
 }
 
 void
@@ -157,10 +156,12 @@ Ident::ConnectDone(const Comm::ConnectionPointer &conn, comm_err_t status, int x
               conn->local.GetPort());
     AsyncCall::Pointer nil;
     Comm::Write(conn, &mb, nil);
-    AsyncCall::Pointer call = commCbCall(5,4, "Ident::ReadReply",
-                                         CommIoCbPtrFun(Ident::ReadReply, state));
-    comm_read(conn, state->buf, IDENT_BUFSIZE, call);
-    commSetTimeout(conn->fd, Ident::TheConfig.timeout, Ident::Timeout, state);
+    AsyncCall::Pointer readCall = commCbCall(5,4, "Ident::ReadReply",
+                                             CommIoCbPtrFun(Ident::ReadReply, state));
+    comm_read(conn, state->buf, IDENT_BUFSIZE, readCall);
+    AsyncCall::Pointer timeoutCall = commCbCall(5,4, "Ident::Timeout",
+                                                CommTimeoutCbPtrFun(Ident::Timeout, state));
+    commSetConnTimeout(conn, Ident::TheConfig.timeout, timeoutCall);
 }
 
 void
index 36303d799ede40877777357c058e850ac9494720..5eb6d39ecd593435e2476af781a7e6badba5f38e 100644 (file)
@@ -53,12 +53,12 @@ void Ipc::UdsOp::setTimeout(int seconds, const char *handlerName)
     typedef CommCbMemFunT<UdsOp, CommTimeoutCbParams> Dialer;
     AsyncCall::Pointer handler = asyncCall(54,5, handlerName,
                                            Dialer(CbcPointer<UdsOp>(this), &UdsOp::noteTimeout));
-    commSetTimeout(conn()->fd, seconds, handler);
+    commSetConnTimeout(conn(), seconds, handler);
 }
 
 void Ipc::UdsOp::clearTimeout()
 {
-    commSetTimeout(conn()->fd, -1, NULL, NULL); // TODO: add Comm::ClearTimeout(fd)
+    commUnsetConnTimeout(conn());
 }
 
 void Ipc::UdsOp::noteTimeout(const CommTimeoutCbParams &)
index 6162d5707f2d763e99e4417b92a40d4006495cb3..386ecfb9b564586a9c715400bb9edcaac539aa68 100644 (file)
@@ -118,7 +118,7 @@ IdleConnList::clearHandlers(const Comm::ConnectionPointer &conn)
 {
     debugs(48, 3, HERE << "removing close handler for " << conn);
     comm_read_cancel(conn->fd, IdleConnList::Read, this);
-    commSetTimeout(conn->fd, -1, NULL, NULL);
+    commUnsetConnTimeout(conn);
 }
 
 void
@@ -141,10 +141,12 @@ IdleConnList::push(const Comm::ConnectionPointer &conn)
     }
 
     theList_[size_++] = conn;
-    AsyncCall::Pointer call = commCbCall(5,4, "IdleConnList::Read",
-                                         CommIoCbPtrFun(IdleConnList::Read, this));
-    comm_read(conn, fakeReadBuf_, sizeof(fakeReadBuf_), call);
-    commSetTimeout(conn->fd, Config.Timeout.pconn, IdleConnList::Timeout, this);
+    AsyncCall::Pointer readCall = commCbCall(5,4, "IdleConnList::Read",
+                                             CommIoCbPtrFun(IdleConnList::Read, this));
+    comm_read(conn, fakeReadBuf_, sizeof(fakeReadBuf_), readCall);
+    AsyncCall::Pointer timeoutCall = commCbCall(5,4, "IdleConnList::Read",
+                                                CommTimeoutCbPtrFun(IdleConnList::Timeout, this));
+    commSetConnTimeout(conn, Config.Timeout.pconn, timeoutCall);
 }
 
 /*
@@ -219,19 +221,16 @@ IdleConnList::Read(const Comm::ConnectionPointer &conn, char *buf, size_t len, c
 }
 
 void
-IdleConnList::Timeout(int fd, void *data)
+IdleConnList::Timeout(const CommTimeoutCbParams &io)
 {
-    debugs(48, 3, HERE << "FD " << fd);
-    IdleConnList *list = (IdleConnList *) data;
-    Comm::ConnectionPointer temp = new Comm::Connection; // XXX: transition. make timeouts pass conn in
-    temp->fd = fd;
-    int index = list->findIndexOf(temp);
+    debugs(48, 3, HERE << io.conn);
+    IdleConnList *list = static_cast<IdleConnList *>(io.data);
+    int index = list->findIndexOf(io.conn);
     if (index >= 0) {
         /* might delete list */
         list->removeAt(index);
-        temp->close();
-    } else
-        temp->fd = -1; // XXX: transition. prevent temp erasure double-closing FD until timeout CB passess conn in.
+        io.conn->close();
+    }
 }
 
 /* ========== PconnPool PRIVATE FUNCTIONS ============================================ */
index f12ebac63eb661efe5a5f2bb4ae38d9bdb652fb8..26860b874fc22ef65df78f5dd0ff3b03cef7723a 100644 (file)
@@ -52,7 +52,7 @@ private:
     bool removeAt(int index);
     int findIndexOf(const Comm::ConnectionPointer &conn) const;
     static IOCB Read;
-    static PF Timeout;
+    static CTCB Timeout;
 
 public:
     hash_link hash;             /** must be first */
index f25d48e8411798449f66af21ca5c964e56ebb9d2..ed10495368afe91b422db8e33dfb8d6cec8d9fcc 100644 (file)
@@ -124,7 +124,7 @@ static CNCB tunnelConnectDone;
 static ERCB tunnelErrorComplete;
 static PF tunnelServerClosed;
 static PF tunnelClientClosed;
-static PF tunnelTimeout;
+static CTCB tunnelTimeout;
 static PSC tunnelPeerSelectComplete;
 static void tunnelStateFree(TunnelStateData * tunnelState);
 static void tunnelConnected(const Comm::ConnectionPointer &server, void *);
@@ -304,8 +304,11 @@ TunnelStateData::copy(size_t len, comm_err_t errcode, int xerrno, Connection &fr
     cbdataInternalLock(this);  /* ??? should be locked by the caller... */
 
     /* Bump the source connection read timeout on any activity */
-    if (Comm::IsConnOpen(from.conn))
-        commSetTimeout(from.conn->fd, Config.Timeout.read, tunnelTimeout, this);
+    if (Comm::IsConnOpen(from.conn)) {
+        AsyncCall::Pointer timeoutCall = commCbCall(5, 4, "tunnelTimeout",
+                                                    CommTimeoutCbPtrFun(tunnelTimeout, this));
+        commSetConnTimeout(from.conn, Config.Timeout.read, timeoutCall);
+    }
 
     if (len < 0 || errcode)
         from.error (xerrno);
@@ -434,10 +437,10 @@ TunnelStateData::writeClientDone(char *buf, size_t len, comm_err_t flag, int xer
 }
 
 static void
-tunnelTimeout(int fd, void *data)
+tunnelTimeout(const CommTimeoutCbParams &io)
 {
-    TunnelStateData *tunnelState = (TunnelStateData *)data;
-    debugs(26, 3, "tunnelTimeout: FD " << fd);
+    TunnelStateData *tunnelState = static_cast<TunnelStateData *>(io.data);
+    debugs(26, 3, HERE << io.conn);
     /* Temporary lock to protect our own feets (comm_close -> tunnelClientClosed -> Free) */
     cbdataInternalLock(tunnelState);
 
@@ -576,7 +579,9 @@ tunnelConnectDone(const Comm::ConnectionPointer &conn, comm_err_t status, int xe
         tunnelConnected(conn, tunnelState);
     }
 
-    commSetTimeout(conn->fd, Config.Timeout.read, tunnelTimeout, tunnelState);
+    AsyncCall::Pointer timeoutCall = commCbCall(5, 4, "tunnelTimeout",
+                                                CommTimeoutCbPtrFun(tunnelTimeout, tunnelState));
+    commSetConnTimeout(conn, Config.Timeout.read, timeoutCall);
 }
 
 extern tos_t GetTosToServer(HttpRequest * request);
@@ -633,10 +638,10 @@ tunnelStart(ClientHttpRequest * http, int64_t * size_ptr, int *status_ptr)
     comm_add_close_handler(tunnelState->client.conn->fd,
                            tunnelClientClosed,
                            tunnelState);
-    commSetTimeout(tunnelState->client.conn->fd,
-                   Config.Timeout.lifetime,
-                   tunnelTimeout,
-                   tunnelState);
+
+    AsyncCall::Pointer timeoutCall = commCbCall(5, 4, "tunnelTimeout",
+                                                CommTimeoutCbPtrFun(tunnelTimeout, tunnelState));
+    commSetConnTimeout(tunnelState->client.conn, Config.Timeout.lifetime, timeoutCall);
 
     peerSelect(&(tunnelState->serverDestinations), request,
                NULL,
@@ -668,10 +673,13 @@ tunnelRelayConnectRequest(const Comm::ConnectionPointer &srv, void *data)
     packerClean(&p);
     mb.append("\r\n", 2);
 
-    AsyncCall::Pointer call = commCbCall(5,5, "tunnelConnectedWriteDone",
-                                         CommIoCbPtrFun(tunnelConnectedWriteDone, tunnelState));
-    Comm::Write(srv, &mb, call);
-    commSetTimeout(srv->fd, Config.Timeout.read, tunnelTimeout, tunnelState);
+    AsyncCall::Pointer writeCall = commCbCall(5,5, "tunnelConnectedWriteDone",
+                                              CommIoCbPtrFun(tunnelConnectedWriteDone, tunnelState));
+    Comm::Write(srv, &mb, writeCall);
+
+    AsyncCall::Pointer timeoutCall = commCbCall(5, 4, "tunnelTimeout",
+                                                CommTimeoutCbPtrFun(tunnelTimeout, tunnelState));
+    commSetConnTimeout(srv, Config.Timeout.read, timeoutCall);
 }
 
 static void
index 0d81b99d832af4b40239af72e6a9b35f3c70a958..f0a4326f92d5477f11646016f6e65e4bfce51e2f 100644 (file)
@@ -60,7 +60,7 @@ public:
 };
 
 static PF whoisClose;
-static PF whoisTimeout;
+static CTCB whoisTimeout;
 static IOCB whoisReadReply;
 
 /* PUBLIC */
@@ -107,17 +107,19 @@ whoisStart(FwdState * fwd)
     AsyncCall::Pointer readCall = commCbCall(5,4, "whoisReadReply",
                                              CommIoCbPtrFun(whoisReadReply, p));
     comm_read(fwd->serverConnection(), p->buf, BUFSIZ, readCall);
-    commSetTimeout(fwd->serverConnection()->fd, Config.Timeout.read, whoisTimeout, p);
+    AsyncCall::Pointer timeoutCall = commCbCall(5, 4, "whoisTimeout",
+                                                CommTimeoutCbPtrFun(whoisTimeout, p));
+    commSetConnTimeout(fwd->serverConnection(), Config.Timeout.read, timeoutCall);
 }
 
 /* PRIVATE */
 
 static void
-whoisTimeout(int fd, void *data)
+whoisTimeout(const CommTimeoutCbParams &io)
 {
-    WhoisState *p = (WhoisState *)data;
-    debugs(75, 1, "whoisTimeout: " << p->entry->url()  );
-    whoisClose(fd, p);
+    WhoisState *p = static_cast<WhoisState *>(io.data);
+    debugs(75, 3, HERE << io.conn << ", URL " << p->entry->url());
+    io.conn->close();
 }
 
 static void