--------------------- PatchSet 6546 Date: 2008/01/19 19:15:57 Author: chtsanti Branch: async-calls Tag: (none) Log: Converting commSetTimeout to use CommCalls. Also the CommTimeoutCbParams and CommTimeoutCbPtrFun classes added. Members: src/CommCalls.cc:1.1.2.3->1.1.2.4 src/CommCalls.h:1.1.2.4->1.1.2.5 src/comm.cc:1.81.4.18->1.81.4.19 src/comm.h:1.26.4.12->1.26.4.13 src/comm_poll.cc:1.17.4.1->1.17.4.2 src/comm_select.cc:1.19.14.2->1.19.14.3 src/comm_select_win32.cc:1.5.20.1->1.5.20.2 src/fde.cc:1.8.4.1->1.8.4.2 src/fde.h:1.14.4.2->1.14.4.3 Index: squid3/src/CommCalls.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/CommCalls.cc,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid3/src/CommCalls.cc 24 Dec 2007 16:46:50 -0000 1.1.2.3 +++ squid3/src/CommCalls.cc 19 Jan 2008 19:15:57 -0000 1.1.2.4 @@ -80,6 +80,13 @@ { } +/* CommTimeoutCbParams */ + +CommTimeoutCbParams::CommTimeoutCbParams(void *aData): + CommCommonCbParams(aData) +{ +} + /* CommAcceptCbPtrFun */ @@ -174,3 +181,26 @@ params.print(os); os << ')'; } + +/* CommTimeoutCbPtrFun */ + +CommTimeoutCbPtrFun::CommTimeoutCbPtrFun(PF *aHandler, + const CommTimeoutCbParams &aParams): + CommDialerParamsT(aParams), + handler(aHandler) +{ +} + +void +CommTimeoutCbPtrFun::dial() +{ + handler(params.fd, params.data); +} + +void +CommTimeoutCbPtrFun::print(std::ostream &os) const +{ + os << '('; + params.print(os); + os << ')'; +} Index: squid3/src/CommCalls.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/CommCalls.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid3/src/CommCalls.h 24 Dec 2007 16:46:50 -0000 1.1.2.4 +++ squid3/src/CommCalls.h 19 Jan 2008 19:15:57 -0000 1.1.2.5 @@ -1,6 +1,6 @@ /* - * $Id: CommCalls.h,v 1.1.2.4 2007/12/24 16:46:50 chtsanti Exp $ + * $Id: CommCalls.h,v 1.1.2.5 2008/01/19 19:15:57 chtsanti Exp $ */ #ifndef SQUID_COMMCALLS_H @@ -90,6 +90,11 @@ CommCloseCbParams(void *aData); }; +class CommTimeoutCbParams: public CommCommonCbParams { +public: + CommTimeoutCbParams(void *aData); +}; + // Interface to expose comm callback parameters of all comm dialers. // GetCommParams() uses this interface to access comm parameters. template @@ -202,6 +207,20 @@ PF *handler; }; +class CommTimeoutCbPtrFun:public CallDialer, + public CommDialerParamsT +{ +public: + typedef CommTimeoutCbParams Params; + + CommTimeoutCbPtrFun(PF *aHandler, const Params &aParams); + void dial(); + + virtual void print(std::ostream &os) const; + +public: + PF *handler; +}; // AsyncCall to comm handlers implemented as global functions. // The dialer is one of the Comm*CbPtrFunT above Index: squid3/src/comm.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.cc,v retrieving revision 1.81.4.18 retrieving revision 1.81.4.19 diff -u -r1.81.4.18 -r1.81.4.19 --- squid3/src/comm.cc 15 Jan 2008 19:15:32 -0000 1.81.4.18 +++ squid3/src/comm.cc 19 Jan 2008 19:15:57 -0000 1.81.4.19 @@ -1,6 +1,6 @@ /* - * $Id: comm.cc,v 1.81.4.18 2008/01/15 19:15:32 chtsanti Exp $ + * $Id: comm.cc,v 1.81.4.19 2008/01/19 19:15:57 chtsanti Exp $ * * DEBUG: section 5 Socket Functions * AUTHOR: Harvest Derived @@ -1057,9 +1057,9 @@ } } } - +/* int -commSetTimeout(int fd, int timeout, PF * handler, void *data) +commSetTimeout_old(int fd, int timeout, PF * handler, void *data) { debugs(5, 3, "commSetTimeout: FD " << fd << " timeout " << timeout); assert(fd >= 0); @@ -1083,6 +1083,46 @@ return F->timeout; } +*/ + +int +commSetTimeout(int fd, int timeout, PF * handler, void *data) +{ + AsyncCall::Pointer call; + debugs(5, 3, "commSetTimeout: FD " << fd << " timeout " << timeout); + if(handler != NULL) + call=commCbCall(5,4, "SomeTimeoutHandler", CommTimeoutCbPtrFun(handler, data)); + else + call = NULL; + return commSetTimeout(fd, timeout, call); +} + + +int commSetTimeout(int fd, int timeout, AsyncCall::Pointer &callback) +{ + debugs(5, 3, "commSetTimeout: FD " << fd << " timeout " << timeout); + 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; + +} int comm_connect_addr(int sock, const IPAddress &address) @@ -1930,14 +1970,11 @@ if (F->flags.ipc) /* don't close inter-process sockets */ continue; - if (F->timeout_handler) { - PF *callback = F->timeout_handler; - void *cbdata = NULL; - F->timeout_handler = NULL; + if (F->timeoutHandler != NULL) { + AsyncCall::Pointer callback = F->timeoutHandler; + F->timeoutHandler = NULL; debugs(5, 5, "commCloseAllSockets: FD " << fd << ": Calling timeout handler"); - - if (cbdataReferenceValidDone(F->timeout_data, &cbdata)) - callback(fd, cbdata); + ScheduleCallHere(callback); } else { debugs(5, 5, "commCloseAllSockets: FD " << fd << ": calling comm_close()"); comm_close(fd); @@ -1963,7 +2000,7 @@ checkTimeouts(void) { int fd; fde *F = NULL; - PF *callback; + AsyncCall::Pointer callback; for (fd = 0; fd <= Biggest_FD; fd++) { F = &fd_table[fd]; @@ -1973,11 +2010,11 @@ debugs(5, 5, "checkTimeouts: FD " << fd << " Expired"); - if (F->timeout_handler) { + if (F->timeoutHandler != NULL) { debugs(5, 5, "checkTimeouts: FD " << fd << ": Call timeout handler"); - callback = F->timeout_handler; - F->timeout_handler = NULL; - callback(fd, F->timeout_data); + callback = F->timeoutHandler; + F->timeoutHandler = NULL; + ScheduleCallHere(callback); } else { debugs(5, 5, "checkTimeouts: FD " << fd << ": Forcing comm_close()"); comm_close(fd); Index: squid3/src/comm.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm.h,v retrieving revision 1.26.4.12 retrieving revision 1.26.4.13 diff -u -r1.26.4.12 -r1.26.4.13 --- squid3/src/comm.h 15 Jan 2008 21:36:13 -0000 1.26.4.12 +++ squid3/src/comm.h 19 Jan 2008 19:15:57 -0000 1.26.4.13 @@ -64,6 +64,7 @@ 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); SQUIDCEXTERN int ignoreErrno(int); SQUIDCEXTERN void commCloseAllSockets(void); SQUIDCEXTERN void checkTimeouts(void); Index: squid3/src/comm_poll.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm_poll.cc,v retrieving revision 1.17.4.1 retrieving revision 1.17.4.2 diff -u -r1.17.4.1 -r1.17.4.2 --- squid3/src/comm_poll.cc 13 Dec 2007 20:14:42 -0000 1.17.4.1 +++ squid3/src/comm_poll.cc 19 Jan 2008 19:15:57 -0000 1.17.4.2 @@ -1,6 +1,6 @@ /* - * $Id: comm_poll.cc,v 1.17.4.1 2007/12/13 20:14:42 rousskov Exp $ + * $Id: comm_poll.cc,v 1.17.4.2 2008/01/19 19:15:57 chtsanti Exp $ * * DEBUG: section 5 Socket Functions * @@ -513,25 +513,25 @@ } if (revents & POLLNVAL) { - close_handler *ch; + AsyncCall::Pointer ch; debugs(5, 0, "WARNING: FD " << fd << " has handlers, but it's invalid."); debugs(5, 0, "FD " << fd << " is a " << fdTypeStr[F->type]); debugs(5, 0, "--> " << F->desc); - debugs(5, 0, "tmout:" << F->timeout_handler << " read:" << + debugs(5, 0, "tmout:" << F->timeoutHandler << "read:" << F->read_handler << " write:" << F->write_handler); - for (ch = F->closeHandler; ch; ch = ch->next) - debugs(5, 0, " close handler: " << ch->handler); + for (ch = F->closeHandler; ch != NULL; ch = ch->Next()) + debugs(5, 0, " close handler: " << ch); - if (F->closeHandler) { + if (F->closeHandler != NULL) { commCallCloseHandlers(fd); - } else if (F->timeout_handler) { + } else if (F->timeoutHandler != NULL) { debugs(5, 0, "comm_poll: Calling Timeout Handler"); - F->timeout_handler(fd, F->timeout_data); + ScheduleCallHere(F->timeoutHandler); } F->closeHandler = NULL; - F->timeout_handler = NULL; + F->timeoutHandler = NULL; F->read_handler = NULL; F->write_handler = NULL; Index: squid3/src/comm_select.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm_select.cc,v retrieving revision 1.19.14.2 retrieving revision 1.19.14.3 diff -u -r1.19.14.2 -r1.19.14.3 --- squid3/src/comm_select.cc 29 Dec 2007 15:24:40 -0000 1.19.14.2 +++ squid3/src/comm_select.cc 19 Jan 2008 19:15:57 -0000 1.19.14.3 @@ -1,6 +1,6 @@ /* - * $Id: comm_select.cc,v 1.19.14.2 2007/12/29 15:24:40 chtsanti Exp $ + * $Id: comm_select.cc,v 1.19.14.3 2008/01/19 19:15:57 chtsanti Exp $ * * DEBUG: section 5 Socket Functions * @@ -696,7 +696,7 @@ fd_set write_x; struct timeval tv; - close_handler *ch = NULL; + AsyncCall::Pointer ch = NULL; fde *F = NULL; struct stat sb; @@ -731,20 +731,20 @@ debugs(5, 0, "FD " << fd << ": " << xstrerror()); debugs(5, 0, "WARNING: FD " << fd << " has handlers, but it's invalid."); debugs(5, 0, "FD " << fd << " is a " << fdTypeStr[F->type] << " called '" << F->desc << "'"); - debugs(5, 0, "tmout:" << F->timeout_handler << " read:" << F->read_handler << " write:" << F->write_handler); + debugs(5, 0, "tmout:" << F->timeoutHandler << " read:" << F->read_handler << " write:" << F->write_handler); - for (ch = F->closeHandler; ch; ch = ch->next) - debugs(5, 0, " close handler: " << ch->handler); + for (ch = F->closeHandler; ch != NULL; ch = ch->Next()) + debugs(5, 0, " close handler: " << ch); - if (F->closeHandler) { + if (F->closeHandler != NULL) { commCallCloseHandlers(fd); - } else if (F->timeout_handler) { + } else if (F->timeoutHandler != NULL) { debugs(5, 0, "examine_select: Calling Timeout Handler"); - F->timeout_handler(fd, F->timeout_data); + ScheduleCallHere(F->timeoutHandler); } F->closeHandler = NULL; - F->timeout_handler = NULL; + F->timeoutHandler = NULL; F->read_handler = NULL; F->write_handler = NULL; FD_CLR(fd, readfds); Index: squid3/src/comm_select_win32.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/comm_select_win32.cc,v retrieving revision 1.5.20.1 retrieving revision 1.5.20.2 diff -u -r1.5.20.1 -r1.5.20.2 --- squid3/src/comm_select_win32.cc 13 Dec 2007 20:14:42 -0000 1.5.20.1 +++ squid3/src/comm_select_win32.cc 19 Jan 2008 19:15:57 -0000 1.5.20.2 @@ -1,6 +1,6 @@ /* - * $Id: comm_select_win32.cc,v 1.5.20.1 2007/12/13 20:14:42 rousskov Exp $ + * $Id: comm_select_win32.cc,v 1.5.20.2 2008/01/19 19:15:57 chtsanti Exp $ * * DEBUG: section 5 Socket Functions * @@ -783,7 +783,7 @@ fd_set write_x; struct timeval tv; - close_handler *ch = NULL; + AsyncCall::Pointer ch = NULL; fde *F = NULL; struct stat sb; @@ -814,20 +814,20 @@ debugs(5, 0, "FD " << fd << ": " << xstrerror()); debugs(5, 0, "WARNING: FD " << fd << " has handlers, but it's invalid."); debugs(5, 0, "FD " << fd << " is a " << fdTypeStr[F->type] << " called '" << F->desc << "'"); - debugs(5, 0, "tmout:" << F->timeout_handler << " read:" << F->read_handler << " write:" << F->write_handler); + debugs(5, 0, "tmout:" << F->timeoutHandler << " read:" << F->read_handler << " write:" << F->write_handler); - for (ch = F->closeHandler; ch; ch = ch->next) - debugs(5, 0, " close handler: " << ch->handler); + for (ch = F->closeHandler; ch!= NULL; ch = ch->Next()) + debugs(5, 0, " close handler: " << ch); - if (F->closeHandler) { + if (F->closeHandler != NULL) { commCallCloseHandlers(fd); - } else if (F->timeout_handler) { + } else if (F->timeoutHandler != NULL) { debugs(5, 0, "examine_select: Calling Timeout Handler"); - F->timeout_handler(fd, F->timeout_data); + ScheduleCallHere(F->timeoutHandler); } F->closeHandler = NULL; - F->timeout_handler = NULL; + F->timeoutHandler = NULL; F->read_handler = NULL; F->write_handler = NULL; FD_CLR(fd, readfds); Index: squid3/src/fde.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fde.cc,v retrieving revision 1.8.4.1 retrieving revision 1.8.4.2 diff -u -r1.8.4.1 -r1.8.4.2 --- squid3/src/fde.cc 14 Dec 2007 06:06:29 -0000 1.8.4.1 +++ squid3/src/fde.cc 19 Jan 2008 19:15:57 -0000 1.8.4.2 @@ -1,6 +1,6 @@ /* - * $Id: fde.cc,v 1.8.4.1 2007/12/14 06:06:29 rousskov Exp $ + * $Id: fde.cc,v 1.8.4.2 2008/01/19 19:15:57 chtsanti Exp $ * * DEBUG: none FDE * AUTHOR: Robert Collins @@ -64,7 +64,7 @@ fdNumber, #endif fdTypeStr[type], - timeout_handler ? (int) (timeout - squid_curtime) / 60 : 0, + timeoutHandler != NULL ? (int) (timeout - squid_curtime) / 60 : 0, bytes_read, readPending(fdNumber) ? '*' : ' ', bytes_written, Index: squid3/src/fde.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fde.h,v retrieving revision 1.14.4.2 retrieving revision 1.14.4.3 diff -u -r1.14.4.2 -r1.14.4.3 --- squid3/src/fde.h 29 Dec 2007 15:24:40 -0000 1.14.4.2 +++ squid3/src/fde.h 19 Jan 2008 19:15:57 -0000 1.14.4.3 @@ -1,6 +1,6 @@ /* - * $Id: fde.h,v 1.14.4.2 2007/12/29 15:24:40 chtsanti Exp $ + * $Id: fde.h,v 1.14.4.3 2008/01/19 19:15:57 chtsanti Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -99,9 +99,8 @@ void *read_data; PF *write_handler; void *write_data; - PF *timeout_handler; + AsyncCall::Pointer timeoutHandler; time_t timeout; - void *timeout_data; void *lifetime_data; AsyncCall::Pointer closeHandler; CommWriteStateData *wstate; /* State data for comm_write */