From: Amos Jeffries Date: Sat, 17 Dec 2011 03:42:43 +0000 (-0700) Subject: Cleanup: comm Timeout API X-Git-Tag: BumpSslServerFirst.take05~12^2~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=933dd095fa4602c53703c8bc384c82ed16b86881;p=thirdparty%2Fsquid.git Cleanup: comm Timeout API * accept Comm::Connection when setting timeout - use commSetConnTimeout() now * drop old cbdata wrapper function * drop raw-FD timeout setting (unused) --- diff --git a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc index 2f271b336e..b509722ae0 100644 --- a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc +++ b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc @@ -210,7 +210,7 @@ DiskdIOStrategy::init() fd_note(wfd, "squid -> diskd"); - commSetTimeout(wfd, -1, NULL, NULL); + commUnsetFdTimeout(wfd); commSetNonBlocking(wfd); Comm::QuickPollRequired(); } diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index 4a13a596c3..6148426ae6 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -234,8 +234,7 @@ void Adaptation::Icap::Xaction::noteCommConnected(const CommConnectCbParams &io) typedef CommCbMemFunT TimeoutDialer; AsyncCall::Pointer timeoutCall = asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommTimedout", TimeoutDialer(this,&Adaptation::Icap::Xaction::noteCommTimedout)); - commSetTimeout(io.conn->fd, TheConfig.connect_timeout( - service().cfg().bypass), timeoutCall); + commSetConnTimeout(io.conn, TheConfig.connect_timeout(service().cfg().bypass), timeoutCall); typedef CommCbMemFunT CloseDialer; closer = asyncCall(93, 5, "Adaptation::Icap::Xaction::noteCommClosed", diff --git a/src/comm.cc b/src/comm.cc index 881a3c8a69..e69b5314b5 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -728,45 +728,19 @@ comm_import_opened(const Comm::ConnectionPointer &conn, */ } -// Legacy pre-AsyncCalls API for FD timeouts. -int -commSetTimeout(int fd, int timeout, CTCB * handler, void *data) -{ - AsyncCall::Pointer call; - debugs(5, 3, HERE << "FD " << fd << " timeout " << timeout); - if (handler != NULL) - call=commCbCall(5,4, "SomeTimeoutHandler", CommTimeoutCbPtrFun(handler, data)); - else - call = NULL; - 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) +// XXX: now that raw-FD timeouts are only unset for pipes and files this SHOULD be a no-op. +// With handler already unset. Leaving this present until that can be verified for all code paths. +void +commUnsetFdTimeout(int fd) { - debugs(5, 3, HERE << "FD " << fd << " timeout " << timeout); + debugs(5, 3, HERE << "Remove timeout for FD " << fd); assert(fd >= 0); assert(fd < Squid_MaxFD); fde *F = &fd_table[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.fd = fd; - F->timeoutHandler = callback; - } - - F->timeout = squid_curtime + (time_t) timeout; - } - - return F->timeout; + F->timeoutHandler = NULL; + F->timeout = 0; } int @@ -987,10 +961,10 @@ commLingerClose(int fd, void *unused) } static void -commLingerTimeout(int fd, void *unused) +commLingerTimeout(const FdeCbParams ¶ms) { - debugs(5, 3, "commLingerTimeout: FD " << fd); - comm_close(fd); + debugs(5, 3, "commLingerTimeout: FD " << params.fd); + comm_close(params.fd); } /* @@ -1010,7 +984,18 @@ comm_lingering_close(int fd) } fd_note(fd, "lingering close"); - commSetTimeout(fd, 10, commLingerTimeout, NULL); + AsyncCall::Pointer call = commCbCall(5,4, "commLingerTimeout", FdeCbPtrFun(commLingerTimeout, NULL)); + + debugs(5, 3, HERE << "FD " << fd << " timeout " << timeout); + assert(fd_table[fd].flags.open); + if (callback != NULL) { + typedef FdeCbParams Params; + Params ¶ms = GetCommParams(callback); + params.fd = fd; + fd_table[fd].timeoutHandler = callback; + fd_table[fd].timeout = squid_curtime + static_cast(10); + } + Comm::SetSelect(fd, COMM_SELECT_READ, commLingerClose, NULL, 0); } @@ -1131,7 +1116,7 @@ _comm_close(int fd, char const *file, int line) // a half-closed fd may lack a reader, so we stop monitoring explicitly if (commHasHalfClosedMonitor(fd)) commStopHalfClosedMonitor(fd); - commSetTimeout(fd, -1, NULL, NULL); + commUnsetFdTimeout(fd); // notify read/write handlers after canceling select reservations, if any if (COMMIO_FD_WRITECB(fd)->active()) { diff --git a/src/comm.h b/src/comm.h index 5e79dd486a..34c4461b9b 100644 --- a/src/comm.h +++ b/src/comm.h @@ -56,8 +56,9 @@ SQUIDCEXTERN unsigned short comm_local_port(int fd); 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, CTCB *, void *); -extern int commSetTimeout(int fd, int, AsyncCall::Pointer &callback); + +/// clear a timeout handler by FD number +extern void commUnsetFdTimeout(int fd); /** * Set or clear the timeout for some action on an active connection. diff --git a/src/icmp/IcmpSquid.cc b/src/icmp/IcmpSquid.cc index 125867f715..9d46004bd6 100644 --- a/src/icmp/IcmpSquid.cc +++ b/src/icmp/IcmpSquid.cc @@ -250,7 +250,7 @@ IcmpSquid::Open(void) Comm::SetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0); - commSetTimeout(icmp_sock, -1, NULL, NULL); + commUnsetFdTimeout(icmp_sock); debugs(37, 1, HERE << "Pinger socket opened on FD " << icmp_sock); diff --git a/src/ipc.cc b/src/ipc.cc index 763050fc1b..4883131f15 100644 --- a/src/ipc.cc +++ b/src/ipc.cc @@ -268,7 +268,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name return ipcCloseAllFD(prfd, pwfd, crfd, cwfd); } - commSetTimeout(prfd, -1, NULL, NULL); + commUnsetFdTimeout(prfd); commSetNonBlocking(prfd); commSetNonBlocking(pwfd); diff --git a/src/ipc_win32.cc b/src/ipc_win32.cc index 4665d7ffa7..9a72f01474 100644 --- a/src/ipc_win32.cc +++ b/src/ipc_win32.cc @@ -303,7 +303,7 @@ ipcCreate(int type, const char *prog, const char *const args[], const char *name hello_buf[x] = '\0'; pid = atol(hello_buf); - commSetTimeout(prfd, -1, NULL, NULL); + commUnsetFdTimeout(prfd); commSetNonBlocking(prfd); commSetNonBlocking(pwfd); commSetCloseOnExec(prfd); diff --git a/src/tests/stub_comm.cc b/src/tests/stub_comm.cc index 07031e57a1..25b90c364f 100644 --- a/src/tests/stub_comm.cc +++ b/src/tests/stub_comm.cc @@ -112,11 +112,10 @@ ignoreErrno(int ierrno) return -1; } -int -commSetTimeout(int fd, int timeout, PF * handler, void *data) +void +commUnsetFdTimeout(int fd) { fatal ("Not implemented"); - return -1; } int diff --git a/src/unlinkd.cc b/src/unlinkd.cc index f79d9634b8..5779d3b41c 100644 --- a/src/unlinkd.cc +++ b/src/unlinkd.cc @@ -243,9 +243,8 @@ unlinkdInit(void) fd_note(unlinkd_rfd, "unlinkd -> squid"); - commSetTimeout(unlinkd_rfd, -1, NULL, NULL); - - commSetTimeout(unlinkd_wfd, -1, NULL, NULL); + commUnsetFdTimeout(unlinkd_rfd); + commUnsetFdTimeout(unlinkd_wfd); /* * unlinkd_rfd should already be non-blocking because of