From: Amos Jeffries Date: Sat, 4 Dec 2010 15:48:48 +0000 (+1300) Subject: Update comm timeout handlers to use CommTimeoutCbParams X-Git-Tag: take08~55^2~124^2~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8d77a37c11e162e67396629434c1f754da92912c;p=thirdparty%2Fsquid.git Update comm timeout handlers to use CommTimeoutCbParams --- diff --git a/src/CommCalls.cc b/src/CommCalls.cc index b656b81040..ef9456894c 100644 --- a/src/CommCalls.cc +++ b/src/CommCalls.cc @@ -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(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 diff --git a/src/CommCalls.h b/src/CommCalls.h index cb8a9fc540..5268dd50f7 100644 --- a/src/CommCalls.h +++ b/src/CommCalls.h @@ -15,16 +15,20 @@ * 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 ¶ms); + /* * 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. diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index 04bda5a1d9..da21616223 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -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 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); } } diff --git a/src/client_side.cc b/src/client_side.cc index 33348fb9e6..765d491154 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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 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 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(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 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 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); diff --git a/src/comm.cc b/src/comm.cc index 52fd50eda2..9c5e32a2e4 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -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) { diff --git a/src/comm.h b/src/comm.h index 10bd170a7f..d021258d52 100644 --- a/src/comm.h +++ b/src/comm.h @@ -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); diff --git a/src/comm/ConnOpener.cc b/src/comm/ConnOpener.cc index 36fdf70ba2..de81be255b 100644 --- a/src/comm/ConnOpener.cc +++ b/src/comm/ConnOpener.cc @@ -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 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 &) diff --git a/src/dns_internal.cc b/src/dns_internal.cc index c18626ef59..ae460a5276 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -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)); diff --git a/src/ftp.cc b/src/ftp.cc index 916ab5aaf3..9aae0fc162 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -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 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 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 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 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 Dialer; AsyncCall::Pointer reader = JobCallback(9, 5, Dialer, this, FtpStateData::ftpReadControlReply); @@ -2571,8 +2569,7 @@ ftpSendPassive(FtpStateData * ftpState) typedef CommCbMemFunT 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 diff --git a/src/gopher.cc b/src/gopher.cc index b87ab15995..b5eeccf9f6 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -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(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); } diff --git a/src/http.cc b/src/http.cc index d153802b2d..dee62d3b91 100644 --- a/src/http.cc +++ b/src/http.cc @@ -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 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(); diff --git a/src/ident/Ident.cc b/src/ident/Ident.cc index edf2ee973f..04a6ae8704 100644 --- a/src/ident/Ident.cc +++ b/src/ident/Ident.cc @@ -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 diff --git a/src/ipc/UdsOp.cc b/src/ipc/UdsOp.cc index 36303d799e..5eb6d39ecd 100644 --- a/src/ipc/UdsOp.cc +++ b/src/ipc/UdsOp.cc @@ -53,12 +53,12 @@ void Ipc::UdsOp::setTimeout(int seconds, const char *handlerName) typedef CommCbMemFunT Dialer; AsyncCall::Pointer handler = asyncCall(54,5, handlerName, Dialer(CbcPointer(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 &) diff --git a/src/pconn.cc b/src/pconn.cc index 6162d5707f..386ecfb9b5 100644 --- a/src/pconn.cc +++ b/src/pconn.cc @@ -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(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 ============================================ */ diff --git a/src/pconn.h b/src/pconn.h index f12ebac63e..26860b874f 100644 --- a/src/pconn.h +++ b/src/pconn.h @@ -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 */ diff --git a/src/tunnel.cc b/src/tunnel.cc index f25d48e841..ed10495368 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -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(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 diff --git a/src/whois.cc b/src/whois.cc index 0d81b99d83..f0a4326f92 100644 --- a/src/whois.cc +++ b/src/whois.cc @@ -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(io.data); + debugs(75, 3, HERE << io.conn << ", URL " << p->entry->url()); + io.conn->close(); } static void