From: Amos Jeffries Date: Mon, 10 Jan 2011 09:43:43 +0000 (-0700) Subject: SourceLayout: shuffle comm IO loops into libcomm and Comm namespace X-Git-Tag: take00~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d841c88;p=thirdparty%2Fsquid.git SourceLayout: shuffle comm IO loops into libcomm and Comm namespace --- diff --git a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc index f143bd8277..6d054e3056 100644 --- a/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc +++ b/src/DiskIO/DiskDaemon/DiskdIOStrategy.cc @@ -34,6 +34,7 @@ */ #include "squid.h" +#include "comm/Loops.h" #include #include @@ -203,10 +204,8 @@ DiskdIOStrategy::init() fd_note(wfd, "squid -> diskd"); commSetTimeout(wfd, -1, NULL, NULL); - commSetNonBlocking(wfd); - - comm_quick_poll_required(); + Comm::QuickPollRequired(); } /* diff --git a/src/Makefile.am b/src/Makefile.am index 1d7345666c..dc061644c3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -236,19 +236,6 @@ DiskIO/DiskIOModules_gen.cc: Makefile $(SHELL) $(srcdir)/DiskIO/modules.sh $(DISK_MODULES) > DiskIO/DiskIOModules_gen.cc -squid_COMMSOURCES = \ - comm_select.cc \ - comm_select.h \ - comm_select_win32.cc \ - comm_poll.cc \ - comm_poll.h \ - comm_devpoll.cc \ - comm_epoll.cc \ - comm_epoll.h \ - comm_kqueue.cc \ - comm_kqueue.h - - # common library for all the binaries and tests. This is kindof a catch all # and smaller libraries split from this are encouraged. Using lt convenience # libraries, dependencies should not be a problem either. @@ -295,7 +282,6 @@ squid_SOURCES = \ CommIO.h \ CompletionDispatcher.cc \ CompletionDispatcher.h \ - $(squid_COMMSOURCES) \ CommRead.h \ ConfigOption.cc \ ConfigParser.cc \ @@ -1170,7 +1156,6 @@ tests_testCacheManager_SOURCES = \ client_side_request.cc \ ClientInfo.h \ clientStream.cc \ - $(squid_COMMSOURCES) \ ConfigOption.cc \ ConfigParser.cc \ CpuAffinityMap.cc \ @@ -1373,7 +1358,6 @@ tests_testEvent_SOURCES = \ client_side_request.cc \ ClientInfo.h \ clientStream.cc \ - $(squid_COMMSOURCES) \ ConfigOption.cc \ ConfigParser.cc \ CpuAffinityMap.cc \ @@ -1534,7 +1518,6 @@ tests_testEventLoop_SOURCES = \ client_side_request.cc \ ClientInfo.h \ clientStream.cc \ - $(squid_COMMSOURCES) \ ConfigOption.cc \ ConfigParser.cc \ CpuAffinityMap.cc \ @@ -1682,7 +1665,6 @@ tests_test_http_range_SOURCES = \ client_side_request.cc \ ClientInfo.h \ clientStream.cc \ - $(squid_COMMSOURCES) \ ConfigOption.cc \ ConfigParser.cc \ CpuAffinityMap.cc \ @@ -1850,7 +1832,6 @@ tests_testHttpRequest_SOURCES = \ client_side_request.cc \ ClientInfo.h \ clientStream.cc \ - $(squid_COMMSOURCES) \ ConfigOption.cc \ ConfigParser.cc \ CpuAffinityMap.cc \ @@ -2266,7 +2247,6 @@ tests_testURL_SOURCES = \ client_side_request.cc \ ClientInfo.h \ clientStream.cc \ - $(squid_COMMSOURCES) \ ConfigOption.cc \ ConfigParser.cc \ CpuAffinityMap.cc \ diff --git a/src/client_side.cc b/src/client_side.cc index f9c3960e80..d961801a5f 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -85,16 +85,20 @@ #include "acl/FilledChecklist.h" #include "auth/UserRequest.h" +#include "base/TextException.h" #include "ChunkedCodingParser.h" #include "client_side.h" #include "client_side_reply.h" #include "client_side_request.h" +#if USE_DELAY_POOLS +#include "ClientInfo.h" +#endif #include "ClientRequestContext.h" #include "clientStream.h" #include "comm.h" #include "comm/Write.h" #include "comm/ListenStateData.h" -#include "base/TextException.h" +#include "comm/Loops.h" #include "ConnectionDetail.h" #include "eui/Config.h" #include "fde.h" @@ -110,12 +114,6 @@ #include "ProtoPort.h" #include "rfc1738.h" #include "SquidTime.h" -#include "Store.h" - -#if USE_DELAY_POOLS -#include "ClientInfo.h" -#endif - #if USE_SSL #include "ssl/context_storage.h" #include "ssl/helper.h" @@ -126,6 +124,7 @@ #include "ssl/crtd_message.h" #include "ssl/certificate_db.h" #endif +#include "Store.h" #if HAVE_LIMITS #include @@ -3045,7 +3044,7 @@ ConnStateData::requestTimeout(const CommTimeoutCbParams &io) /* * Aha, but we don't want a read handler! */ - commSetSelect(io.fd, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(io.fd, COMM_SELECT_READ, NULL, NULL, 0); } #else @@ -3262,11 +3261,11 @@ clientNegotiateSSL(int fd, void *data) switch (ssl_error) { case SSL_ERROR_WANT_READ: - commSetSelect(fd, COMM_SELECT_READ, clientNegotiateSSL, conn, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, clientNegotiateSSL, conn, 0); return; case SSL_ERROR_WANT_WRITE: - commSetSelect(fd, COMM_SELECT_WRITE, clientNegotiateSSL, conn, 0); + Comm::SetSelect(fd, COMM_SELECT_WRITE, clientNegotiateSSL, conn, 0); return; case SSL_ERROR_SYSCALL: @@ -3415,7 +3414,7 @@ httpsAccept(int sock, int newfd, ConnectionDetail *details, commSetTcpKeepalive(newfd, s->http.tcp_keepalive.idle, s->http.tcp_keepalive.interval, s->http.tcp_keepalive.timeout); } - commSetSelect(newfd, COMM_SELECT_READ, clientNegotiateSSL, connState, 0); + Comm::SetSelect(newfd, COMM_SELECT_READ, clientNegotiateSSL, connState, 0); clientdbEstablished(details->peer, 1); @@ -3532,10 +3531,8 @@ ConnStateData::getSslContextDone(SSL_CTX * sslContext, bool isNew) // commSetTimeout() was called for this request before we switched. // Disable the client read handler until peer selection is complete - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); - - commSetSelect(fd, COMM_SELECT_READ, clientNegotiateSSL, this, 0); - + Comm::SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, clientNegotiateSSL, this, 0); switchedToHttps_ = true; return true; } diff --git a/src/comm.cc b/src/comm.cc index cc78e490fc..ad28dd1cea 100644 --- a/src/comm.cc +++ b/src/comm.cc @@ -42,6 +42,7 @@ #include "comm/IoCallback.h" #include "comm/Write.h" #include "comm/ListenStateData.h" +#include "comm/Loops.h" #include "CommIO.h" #include "CommRead.h" #include "ConnectionDetail.h" @@ -183,7 +184,7 @@ commHandleRead(int fd, void *data) } /* Nope, register for some more IO */ - commSetSelect(fd, COMM_SELECT_READ, commHandleRead, data, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, commHandleRead, data, 0); } /** @@ -219,7 +220,7 @@ comm_read(int fd, char *buf, int size, AsyncCall::Pointer &callback) /* Queue the read */ ccb->setCallback(Comm::IOCB_READ, callback, (char *)buf, NULL, size); - commSetSelect(fd, COMM_SELECT_READ, commHandleRead, ccb, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, commHandleRead, ccb, 0); } /** @@ -319,7 +320,7 @@ comm_read_cancel(int fd, IOCB *callback, void *data) cb->cancel("old comm_read_cancel"); /* And the IO event */ - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); } void @@ -349,7 +350,7 @@ comm_read_cancel(int fd, AsyncCall::Pointer &callback) cb->cancel("comm_read_cancel"); /* And the IO event */ - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); } @@ -936,7 +937,7 @@ ConnectStateData::commResetFD() F->local_addr.FreeAddrInfo(AI); return 0; } - commResetSelect(fd); + Comm::ResetSelect(fd); close(fd2); @@ -1036,7 +1037,7 @@ ConnectStateData::connect() case COMM_INPROGRESS: debugs(5, 5, HERE << "FD " << fd << ": COMM_INPROGRESS"); - commSetSelect(fd, COMM_SELECT_WRITE, ConnectStateData::Connect, this, 0); + Comm::SetSelect(fd, COMM_SELECT_WRITE, ConnectStateData::Connect, this, 0); break; case COMM_OK: @@ -1356,7 +1357,7 @@ comm_lingering_close(int fd) fd_note(fd, "lingering close"); commSetTimeout(fd, 10, commLingerTimeout, NULL); - commSetSelect(fd, COMM_SELECT_READ, commLingerClose, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, commLingerClose, NULL, 0); } #endif @@ -1468,11 +1469,11 @@ _comm_close(int fd, char const *file, int line) // notify read/write handlers after canceling select reservations, if any if (COMMIO_FD_WRITECB(fd)->active()) { - commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); COMMIO_FD_WRITECB(fd)->finish(COMM_ERR_CLOSING, errno); } if (COMMIO_FD_READCB(fd)->active()) { - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); COMMIO_FD_READCB(fd)->finish(COMM_ERR_CLOSING, errno); } @@ -1810,6 +1811,9 @@ comm_init(void) conn_close_pool = memPoolCreate("close_handler", sizeof(close_handler)); TheHalfClosed = new DescriptorSet; + + /* setup the select loop module */ + Comm::SelectLoopInit(); } void @@ -1851,7 +1855,7 @@ commHandleWriteHelper(void * data) !fd_table[head].closing()) { // wait for the head descriptor to become ready for writing - commSetSelect(head, COMM_SELECT_WRITE, Comm::HandleWrite, ccb, 0); + Comm::SetSelect(head, COMM_SELECT_WRITE, Comm::HandleWrite, ccb, 0); clientInfo->selectWaiting = true; return; } @@ -2154,7 +2158,7 @@ checkTimeouts(void) if (writeTimedOut(fd)) { // We have an active write callback and we are timed out debugs(5, 5, "checkTimeouts: FD " << fd << " auto write timeout"); - commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); COMMIO_FD_WRITECB(fd)->finish(COMM_ERROR, ETIMEDOUT); } else if (AlreadyTimedOut(F)) continue; @@ -2184,7 +2188,7 @@ void CommIO::Initialise() fd_open(DoneFD, FD_PIPE, "async-io completetion event: threads"); commSetNonBlocking(DoneReadFD); commSetNonBlocking(DoneFD); - commSetSelect(DoneReadFD, COMM_SELECT_READ, NULLFDHandler, NULL, 0); + Comm::SetSelect(DoneReadFD, COMM_SELECT_READ, NULLFDHandler, NULL, 0); Initialised = true; } @@ -2215,7 +2219,7 @@ void CommIO::NULLFDHandler(int fd, void *data) { FlushPipe(); - commSetSelect(fd, COMM_SELECT_READ, NULLFDHandler, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, NULLFDHandler, NULL, 0); } void @@ -2458,7 +2462,7 @@ CommSelectEngine::checkEvents(int timeout) checkTimeouts(); } - switch (comm_select(timeout)) { + switch (Comm::DoSelect(timeout)) { case COMM_OK: diff --git a/src/comm.h b/src/comm.h index ed3217c8b8..fb206c93de 100644 --- a/src/comm.h +++ b/src/comm.h @@ -61,9 +61,6 @@ SQUIDCEXTERN int comm_open_listener(int sock_type, int proto, Ip::Address &addr, SQUIDCEXTERN int comm_openex(int, int, Ip::Address &, int, tos_t tos, nfmark_t nfmark, const char *); SQUIDCEXTERN u_short comm_local_port(int fd); -SQUIDCEXTERN void commSetSelect(int, unsigned int, PF *, void *, time_t); -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 *); @@ -73,13 +70,6 @@ SQUIDCEXTERN void commCloseAllSockets(void); SQUIDCEXTERN void checkTimeouts(void); -/* - * comm_select.c - */ -SQUIDCEXTERN void comm_select_init(void); -SQUIDCEXTERN comm_err_t comm_select(int); -SQUIDCEXTERN void comm_quick_poll_required(void); - class ConnectionDetail; typedef void IOACB(int fd, int nfd, ConnectionDetail *details, comm_err_t flag, int xerrno, void *data); extern void comm_add_close_handler(int fd, PF *, void *); diff --git a/src/comm/IoCallback.cc b/src/comm/IoCallback.cc index 4e5b2bdf56..4026737754 100644 --- a/src/comm/IoCallback.cc +++ b/src/comm/IoCallback.cc @@ -1,6 +1,7 @@ #include "config.h" #include "ClientInfo.h" #include "comm/IoCallback.h" +#include "comm/Loops.h" #include "comm/Write.h" #include "CommCalls.h" #include "fde.h" @@ -65,7 +66,7 @@ Comm::IoCallback::selectOrQueueWrite() } #endif - commSetSelect(fd, COMM_SELECT_WRITE, Comm::HandleWrite, this, 0); + SetSelect(fd, COMM_SELECT_WRITE, Comm::HandleWrite, this, 0); } void diff --git a/src/comm/ListenStateData.cc b/src/comm/ListenStateData.cc index 838d7ff5f7..62816145f5 100644 --- a/src/comm/ListenStateData.cc +++ b/src/comm/ListenStateData.cc @@ -37,6 +37,7 @@ #include "comm/AcceptLimiter.h" #include "comm/comm_internal.h" #include "comm/ListenStateData.h" +#include "comm/Loops.h" #include "ConnectionDetail.h" #include "fde.h" #include "protos.h" @@ -88,7 +89,7 @@ Comm::ListenStateData::ListenStateData(int aFd, AsyncCall::Pointer &call, bool a debugs(5, 5, HERE << "FD " << fd << " AsyncCall: " << call); assert(isOpen(aFd)); setListen(); - commSetSelect(fd, COMM_SELECT_READ, doAccept, this, 0); + SetSelect(fd, COMM_SELECT_READ, doAccept, this, 0); } Comm::ListenStateData::~ListenStateData() @@ -119,7 +120,7 @@ Comm::ListenStateData::doAccept(int fd, void *data) } else { afd->acceptNext(); } - commSetSelect(fd, COMM_SELECT_READ, Comm::ListenStateData::doAccept, afd, 0); + SetSelect(fd, COMM_SELECT_READ, Comm::ListenStateData::doAccept, afd, 0); } bool @@ -157,7 +158,7 @@ Comm::ListenStateData::acceptOne() if (newfd == COMM_NOMESSAGE) { /* register interest again */ debugs(5, 5, HERE << "try later: FD " << fd << " handler: " << theCallback); - commSetSelect(fd, COMM_SELECT_READ, doAccept, this, 0); + SetSelect(fd, COMM_SELECT_READ, doAccept, this, 0); return; } diff --git a/src/comm/Loops.h b/src/comm/Loops.h new file mode 100644 index 0000000000..6d5ec34d93 --- /dev/null +++ b/src/comm/Loops.h @@ -0,0 +1,32 @@ +#ifndef _SQUID_SRC_COMM_LOOPS_H +#define _SQUID_SRC_COMM_LOOPS_H + +#include "comm_err_t.h" + +/* Comm layer select loops API. + * + * These API functions must be implemented by all FD IO loops used by Squid. + * Defines are provided short-term for legacy code. These will disappear soon. + */ + +namespace Comm { + +/// Initialize the module on Squid startup +extern void SelectLoopInit(void); + +/// Mark an FD to be watched for its IO status. +extern void SetSelect(int, unsigned int, PF *, void *, time_t); + +/// reset/undo/unregister the watch for an FD which was set by Comm::SetSelect() +extern void ResetSelect(int); + +/** Perform a select() or equivalent call. + * This is used by the main select loop engine to check for FD with IO available. + */ +extern comm_err_t DoSelect(int); + +extern void QuickPollRequired(void); + +} // namespace Comm + +#endif /* _SQUID_SRC_COMM_LOOPS_H */ diff --git a/src/comm/Makefile.am b/src/comm/Makefile.am index 6a2c3f3871..3ddf7797da 100644 --- a/src/comm/Makefile.am +++ b/src/comm/Makefile.am @@ -9,6 +9,13 @@ libcomm_la_SOURCES= \ AcceptLimiter.h \ ListenStateData.cc \ ListenStateData.h \ + Loops.h \ + ModDevPoll.cc \ + ModEpoll.cc \ + ModKqueue.cc \ + ModPoll.cc \ + ModSelect.cc \ + ModSelectWin32.cc \ \ IoCallback.cc \ IoCallback.h \ diff --git a/src/comm_devpoll.cc b/src/comm/ModDevPoll.cc similarity index 96% rename from src/comm_devpoll.cc rename to src/comm/ModDevPoll.cc index c42ecea31f..7cf65131a0 100644 --- a/src/comm_devpoll.cc +++ b/src/comm/ModDevPoll.cc @@ -44,21 +44,22 @@ * Last modified 2010-10-08 */ - -#include "squid.h" - /* * There are several poll types in Squid, ALL of which are compiled and linked * in. Thus conditional compile-time flags are used to prevent the different * modules from creating several versions of the same function simultaneously. */ +#include "config.h" + #if USE_DEVPOLL -#include "Store.h" +#include "squid.h" +#include "comm/Loops.h" #include "fde.h" #include "mgr/Registration.h" #include "SquidTime.h" +#include "Store.h" #if HAVE_SYS_DEVPOLL_H /* Solaris /dev/poll support, see "man -s 7D poll" */ @@ -198,7 +199,7 @@ commDevPollRegisterWithCacheManager(void) * Allocates memory, opens /dev/poll device handle. */ void -comm_select_init(void) +Comm::SelectLoopInit(void) { /* allocate memory first before attempting to open poll device */ /* This tracks the FD devpoll offset+state */ @@ -243,8 +244,7 @@ comm_select_init(void) * @param timeout if non-zero then timeout relative to now */ void -commSetSelect(int fd, unsigned int type, PF * handler, - void *client_data, time_t timeout) +Comm::SetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout) { assert(fd >= 0); debugs( @@ -325,10 +325,10 @@ commSetSelect(int fd, unsigned int type, PF * handler, * @param fd file descriptor to clear polling on */ void -commResetSelect(int fd) +Comm::ResetSelect(int fd) { - commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + SetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); + SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); } @@ -346,7 +346,7 @@ commResetSelect(int fd) * @param msec milliseconds to poll for (limited by max_poll_time) */ comm_err_t -comm_select(int msec) +Comm::DoSelect(int msec) { int num, i; fde *F; @@ -432,7 +432,7 @@ comm_select(int msec) HERE << "no read handler for FD " << fd ); // remove interest since no handler exist for this event. - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); } } @@ -456,7 +456,7 @@ comm_select(int msec) HERE << "no write handler for FD " << fd ); // remove interest since no handler exist for this event. - commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); + SetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); } } } @@ -465,9 +465,8 @@ comm_select(int msec) return COMM_OK; } - void -comm_quick_poll_required(void) +Comm::QuickPollRequired(void) { max_poll_time = 10; } diff --git a/src/comm_epoll.cc b/src/comm/ModEpoll.cc similarity index 86% rename from src/comm_epoll.cc rename to src/comm/ModEpoll.cc index d46279c206..af9790ace8 100644 --- a/src/comm_epoll.cc +++ b/src/comm/ModEpoll.cc @@ -51,14 +51,16 @@ * */ +#include "config.h" + +#if USE_EPOLL + #include "squid.h" -#include "comm_epoll.h" -#include "mgr/Registration.h" -#include "Store.h" +#include "comm/Loops.h" #include "fde.h" +#include "mgr/Registration.h" #include "SquidTime.h" - -#if USE_EPOLL +#include "Store.h" #define DEBUG_EPOLL 0 @@ -79,15 +81,12 @@ static void commEPollRegisterWithCacheManager(void); /* - * comm_select_init - * * This is a needed exported function which will be called to initialise * the network loop code. */ void -comm_select_init(void) +Comm::SelectLoopInit(void) { - pevents = (struct epoll_event *) xmalloc(SQUID_MAXFD * sizeof(struct epoll_event)); if (!pevents) { @@ -121,25 +120,21 @@ static const char* epolltype_atoi(int x) } } -/* - * comm_setselect - * +/** * This is a needed exported function which will be called to register * and deregister interest in a pending IO state for a given FD. - * */ void -commSetSelect(int fd, unsigned int type, PF * handler, - void *client_data, time_t timeout) +Comm::SetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout) { fde *F = &fd_table[fd]; int epoll_ctl_type = 0; struct epoll_event ev; assert(fd >= 0); - debugs(5, DEBUG_EPOLL ? 0 : 8, "commSetSelect(FD " << fd << ",type=" << type << - ",handler=" << handler << ",client_data=" << client_data << - ",timeout=" << timeout << ")"); + debugs(5, DEBUG_EPOLL ? 0 : 8, HERE << "FD " << fd << ", type=" << type << + ", handler=" << handler << ", client_data=" << client_data << + ", timeout=" << timeout); if (RUNNING_ON_VALGRIND) { /* Keep valgrind happy.. complains about uninitialized bytes otherwise */ @@ -198,7 +193,7 @@ commSetSelect(int fd, unsigned int type, PF * handler, F->epoll_state = ev.events; if (epoll_ctl(kdpfd, epoll_ctl_type, fd, &ev) < 0) { - debugs(5, DEBUG_EPOLL ? 0 : 8, "commSetSelect: epoll_ctl(," << epolltype_atoi(epoll_ctl_type) << + debugs(5, DEBUG_EPOLL ? 0 : 8, HERE << "epoll_ctl(," << epolltype_atoi(epoll_ctl_type) << ",,): failed on FD " << fd << ": " << xstrerror()); } } @@ -208,11 +203,11 @@ commSetSelect(int fd, unsigned int type, PF * handler, } void -commResetSelect(int fd) +Comm::ResetSelect(int fd) { fde *F = &fd_table[fd]; F->epoll_state = 0; - commSetSelect(fd, 0, NULL, NULL, 0); + SetSelect(fd, 0, NULL, NULL, 0); } @@ -235,8 +230,7 @@ commIncomingStats(StoreEntry * sentry) statHistDump(&f->select_fds_hist, sentry, statHistIntDumper); } -/* - * comm_select +/** * Check all connections for new connections and input data that is to be * processed. Also check for connections with data queued and whether we can * write it out. @@ -246,9 +240,8 @@ commIncomingStats(StoreEntry * sentry) * comm_setselect and fd_table[] and calls callbacks for IO ready * events. */ - comm_err_t -comm_select(int msec) +Comm::DoSelect(int msec) { int num, i,fd; fde *F; @@ -291,7 +284,7 @@ comm_select(int msec) for (i = 0, cevents = pevents; i < num; i++, cevents++) { fd = cevents->data.fd; F = &fd_table[fd]; - debugs(5, DEBUG_EPOLL ? 0 : 8, "comm_select(): got FD " << fd << " events=" << + debugs(5, DEBUG_EPOLL ? 0 : 8, HERE << "got FD " << fd << " events=" << std::hex << cevents->events << " monitoring=" << F->epoll_state << " F->read_handler=" << F->read_handler << " F->write_handler=" << F->write_handler); @@ -299,7 +292,7 @@ comm_select(int msec) if (cevents->events & (EPOLLIN|EPOLLHUP|EPOLLERR) || F->flags.read_pending) { if ((hdl = F->read_handler) != NULL) { - debugs(5, DEBUG_EPOLL ? 0 : 8, "comm_select(): Calling read handler on FD " << fd); + debugs(5, DEBUG_EPOLL ? 0 : 8, HERE << "Calling read handler on FD " << fd); PROF_start(comm_write_handler); F->flags.read_pending = 0; F->read_handler = NULL; @@ -307,24 +300,24 @@ comm_select(int msec) PROF_stop(comm_write_handler); statCounter.select_fds++; } else { - debugs(5, DEBUG_EPOLL ? 0 : 8, "comm_select(): no read handler for FD " << fd); + debugs(5, DEBUG_EPOLL ? 0 : 8, HERE << "no read handler for FD " << fd); // remove interest since no handler exist for this event. - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); } } if (cevents->events & (EPOLLOUT|EPOLLHUP|EPOLLERR)) { if ((hdl = F->write_handler) != NULL) { - debugs(5, DEBUG_EPOLL ? 0 : 8, "comm_select(): Calling write handler on FD " << fd); + debugs(5, DEBUG_EPOLL ? 0 : 8, HERE << "Calling write handler on FD " << fd); PROF_start(comm_read_handler); F->write_handler = NULL; hdl(fd, F->write_data); PROF_stop(comm_read_handler); statCounter.select_fds++; } else { - debugs(5, DEBUG_EPOLL ? 0 : 8, "comm_select(): no write handler for FD " << fd); + debugs(5, DEBUG_EPOLL ? 0 : 8, HERE << "no write handler for FD " << fd); // remove interest since no handler exist for this event. - commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); + SetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); } } } @@ -335,7 +328,7 @@ comm_select(int msec) } void -comm_quick_poll_required(void) +Comm::QuickPollRequired(void) { max_poll_time = 10; } diff --git a/src/comm_kqueue.cc b/src/comm/ModKqueue.cc similarity index 97% rename from src/comm_kqueue.cc rename to src/comm/ModKqueue.cc index 70b94ddeba..01aa65a519 100644 --- a/src/comm_kqueue.cc +++ b/src/comm/ModKqueue.cc @@ -52,14 +52,14 @@ * so deferred reads aren't required. * -- adrian */ - -#include "squid.h" +#include "config.h" #if USE_KQUEUE -#include "comm_kqueue.h" -#include "Store.h" +#include "squid.h" +#include "comm/Loops.h" #include "fde.h" +#include "Store.h" #include "SquidTime.h" #if HAVE_SYS_EVENT_H @@ -165,7 +165,7 @@ kq_update_events(int fd, short filter, PF * handler) * the network loop code. */ void -comm_select_init(void) +Comm::SelectLoopInit(void) { kq = kqueue(); @@ -189,8 +189,7 @@ comm_select_init(void) * and deregister interest in a pending IO state for a given FD. */ void -commSetSelect(int fd, unsigned int type, PF * handler, - void *client_data, time_t timeout) +Comm::SetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout) { fde *F = &fd_table[fd]; assert(fd >= 0); @@ -214,7 +213,7 @@ commSetSelect(int fd, unsigned int type, PF * handler, } void -commResetSelect(int fd) +Comm::ResetSelect(int fd) { fde *F = &fd_table[fd]; if (F->read_handler) { @@ -241,7 +240,7 @@ commResetSelect(int fd) */ comm_err_t -comm_select(int msec) +Comm::Select(int msec) { int num, i; @@ -322,7 +321,7 @@ comm_select(int msec) } void -comm_quick_poll_required(void) +Comm::QuickPollRequired(void) { max_poll_time = 10; } diff --git a/src/comm_poll.cc b/src/comm/ModPoll.cc similarity index 98% rename from src/comm_poll.cc rename to src/comm/ModPoll.cc index 60bc70a29a..095d0b56e4 100644 --- a/src/comm_poll.cc +++ b/src/comm/ModPoll.cc @@ -30,15 +30,16 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ +#include "config.h" + +#if USE_POLL #include "squid.h" -#include "comm_poll.h" +#include "comm/Loops.h" +#include "fde.h" #include "mgr/Registration.h" #include "SquidTime.h" #include "Store.h" -#include "fde.h" - -#if USE_POLL #if HAVE_POLL_H #include @@ -54,7 +55,7 @@ #endif #endif -static int MAX_POLL_TIME = 1000; /* see also comm_quick_poll_required() */ +static int MAX_POLL_TIME = 1000; /* see also Comm::QuickPollRequired() */ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) @@ -136,8 +137,7 @@ static int incoming_http_interval = 16 << INCOMING_FACTOR; void -commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, - time_t timeout) +Comm::SetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout) { fde *F = &fd_table[fd]; assert(fd >= 0); @@ -159,7 +159,7 @@ commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, } void -commResetSelect(int fd) +Comm::ResetSelect(int fd) { } @@ -341,9 +341,8 @@ comm_poll_http_incoming(void) /* poll all sockets; call handlers for those that are ready. */ comm_err_t -comm_select(int msec) +Comm::DoSelect(int msec) { - struct pollfd pfds[SQUID_MAXFD]; PF *hdl = NULL; @@ -631,7 +630,7 @@ commPollRegisterWithCacheManager(void) } void -comm_select_init(void) +Comm::SelectLoopInit(void) { commPollRegisterWithCacheManager(); } @@ -658,7 +657,7 @@ commIncomingStats(StoreEntry * sentry) /* Called by async-io or diskd to speed up the polling */ void -comm_quick_poll_required(void) +Comm::QuickPollRequired(void) { MAX_POLL_TIME = 10; } diff --git a/src/comm_select.cc b/src/comm/ModSelect.cc similarity index 97% rename from src/comm_select.cc rename to src/comm/ModSelect.cc index ee8617d617..a32b47bbc0 100644 --- a/src/comm_select.cc +++ b/src/comm/ModSelect.cc @@ -30,17 +30,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ +#include "config.h" + +#if USE_SELECT #include "squid.h" -#include "comm_select.h" +#include "comm/Loops.h" #include "mgr/Registration.h" #include "SquidTime.h" - -#if USE_SELECT #include "Store.h" #include "fde.h" -static int MAX_POLL_TIME = 1000; /* see also comm_quick_poll_required() */ +static int MAX_POLL_TIME = 1000; /* see also Comm::QuickPollRequired() */ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) @@ -131,13 +132,12 @@ static int incoming_http_interval = 16 << INCOMING_FACTOR; #define commCheckHTTPIncoming (++http_io_events > (incoming_http_interval>> INCOMING_FACTOR)) void -commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, - time_t timeout) +Comm::SetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout) { fde *F = &fd_table[fd]; assert(fd >= 0); assert(F->flags.open); - debugs(5, 5, "commSetSelect: FD " << fd << " type " << type); + debugs(5, 5, HERE << "FD " << fd << " type " << type); if (type & COMM_SELECT_READ) { F->read_handler = handler; @@ -156,7 +156,7 @@ commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, } void -commResetSelect(int fd) +Comm::ResetSelect(int fd) { } @@ -333,7 +333,7 @@ comm_select_http_incoming(void) #define DEBUG_FDBITS 0 /* Select on all sockets; call handlers for those that are ready. */ comm_err_t -comm_select(int msec) +Comm::DoSelect(int msec) { fd_set readfds; fd_set pendingfds; @@ -660,16 +660,8 @@ comm_select_dns_incoming(void) statHistCount(&statCounter.comm_dns_incoming, nevents); } -static void -commSelectRegisterWithCacheManager(void) -{ - Mgr::RegisterAction("comm_select_incoming", - "comm_incoming() stats", - commIncomingStats, 0, 1); -} - void -comm_select_init(void) +Comm::SelectLoopInit(void) { zero_tv.tv_sec = 0; zero_tv.tv_usec = 0; @@ -677,7 +669,9 @@ comm_select_init(void) FD_ZERO(&global_writefds); nreadfds = nwritefds = 0; - commSelectRegisterWithCacheManager(); + Mgr::RegisterAction("comm_select_incoming", + "comm_incoming() stats", + commIncomingStats, 0, 1); } /* @@ -798,7 +792,7 @@ commUpdateWriteBits(int fd, PF * handler) /* Called by async-io or diskd to speed up the polling */ void -comm_quick_poll_required(void) +Comm::QuickPollRequired(void) { MAX_POLL_TIME = 10; } diff --git a/src/comm_select_win32.cc b/src/comm/ModSelectWin32.cc similarity index 98% rename from src/comm_select_win32.cc rename to src/comm/ModSelectWin32.cc index 74a13089f7..2e190904fa 100644 --- a/src/comm_select_win32.cc +++ b/src/comm/ModSelectWin32.cc @@ -31,16 +31,18 @@ * */ +#include "config.h" + +#if USE_SELECT_WIN32 + #include "squid.h" -#include "comm_select.h" +#include "comm/Loops.h" +#include "fde.h" #include "mgr/Registration.h" #include "SquidTime.h" - -#if USE_SELECT_WIN32 #include "Store.h" -#include "fde.h" -static int MAX_POLL_TIME = 1000; /* see also comm_quick_poll_required() */ +static int MAX_POLL_TIME = 1000; /* see also Comm::QuickPollRequired() */ #ifndef howmany #define howmany(x, y) (((x)+((y)-1))/(y)) @@ -131,8 +133,7 @@ static int incoming_http_interval = 16 << INCOMING_FACTOR; #define commCheckHTTPIncoming (++http_io_events > (incoming_http_interval>> INCOMING_FACTOR)) void -commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, - time_t timeout) +Comm::SetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout) { fde *F = &fd_table[fd]; assert(fd >= 0); @@ -156,7 +157,7 @@ commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, } void -commResetSelect(int fd) +Comm::ResetSelect(int fd) { } @@ -336,7 +337,7 @@ comm_select_http_incoming(void) #define DEBUG_FDBITS 0 /* Select on all sockets; call handlers for those that are ready. */ comm_err_t -comm_select(int msec) +Comm::DoSelect(int msec) { fd_set readfds; fd_set pendingfds; @@ -682,16 +683,8 @@ comm_select_dns_incoming(void) statHistCount(&statCounter.comm_dns_incoming, nevents); } -static void -commSelectRegisterWithCacheManager(void) -{ - Mgr::RegisterAction("comm_select_incoming", - "comm_incoming() stats", - commIncomingStats, 0, 1); -} - void -comm_select_init(void) +Comm::SelectLoopInit(void) { zero_tv.tv_sec = 0; zero_tv.tv_usec = 0; @@ -699,7 +692,9 @@ comm_select_init(void) FD_ZERO(&global_writefds); nreadfds = nwritefds = 0; - commSelectRegisterWithCacheManager(); + Mgr::RegisterAction("comm_select_incoming", + "comm_incoming() stats", + commIncomingStats, 0, 1); } /* @@ -820,7 +815,7 @@ commUpdateWriteBits(int fd, PF * handler) /* Called by async-io or diskd to speed up the polling */ void -comm_quick_poll_required(void) +Comm::QuickPollRequired(void) { MAX_POLL_TIME = 10; } diff --git a/src/comm_epoll.h b/src/comm_epoll.h deleted file mode 100644 index 90c10a46ee..0000000000 --- a/src/comm_epoll.h +++ /dev/null @@ -1,37 +0,0 @@ - -/* - * $Id$ - * - * - * SQUID Web Proxy Cache http://www.squid-cache.org/ - * ---------------------------------------------------------- - * - * Squid is the result of efforts by numerous individuals from - * the Internet community; see the CONTRIBUTORS file for full - * details. Many organizations have provided support for Squid's - * development; see the SPONSORS file for full details. Squid is - * Copyrighted (C) 2001 by the Regents of the University of - * California; see the COPYRIGHT file for full details. Squid - * incorporates software developed and/or copyrighted by other - * sources; see the CREDITS file for full details. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. - * - */ - -#ifndef SQUID_COMM_EPOLL_H -#define SQUID_COMM_EPOLL_H - -#endif /* SQUID_COMM_EPOLL_H */ diff --git a/src/comm_kqueue.h b/src/comm_kqueue.h deleted file mode 100644 index 0c8e248886..0000000000 --- a/src/comm_kqueue.h +++ /dev/null @@ -1,37 +0,0 @@ - -/* - * $Id$ - * - * - * SQUID Web Proxy Cache http://www.squid-cache.org/ - * ---------------------------------------------------------- - * - * Squid is the result of efforts by numerous individuals from - * the Internet community; see the CONTRIBUTORS file for full - * details. Many organizations have provided support for Squid's - * development; see the SPONSORS file for full details. Squid is - * Copyrighted (C) 2001 by the Regents of the University of - * California; see the COPYRIGHT file for full details. Squid - * incorporates software developed and/or copyrighted by other - * sources; see the CREDITS file for full details. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. - * - */ - -#ifndef SQUID_COMM_KQUEUE_H -#define SQUID_COMM_KQUEUE_H - -#endif /* SQUID_COMM_KQUEUE_H */ diff --git a/src/comm_select.h b/src/comm_select.h deleted file mode 100644 index 9365f83e83..0000000000 --- a/src/comm_select.h +++ /dev/null @@ -1,38 +0,0 @@ - -/* - * $Id$ - * - * - * SQUID Web Proxy Cache http://www.squid-cache.org/ - * ---------------------------------------------------------- - * - * Squid is the result of efforts by numerous individuals from - * the Internet community; see the CONTRIBUTORS file for full - * details. Many organizations have provided support for Squid's - * development; see the SPONSORS file for full details. Squid is - * Copyrighted (C) 2001 by the Regents of the University of - * California; see the COPYRIGHT file for full details. Squid - * incorporates software developed and/or copyrighted by other - * sources; see the CREDITS file for full details. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. - * - */ - -#ifndef SQUID_COMM_SELECT_H -#define SQUID_COMM_SELECT_H - - -#endif /* SQUID_COMM_SELECT_H */ diff --git a/src/disk.cc b/src/disk.cc index 828353219b..b2cb3cdda7 100644 --- a/src/disk.cc +++ b/src/disk.cc @@ -33,6 +33,7 @@ */ #include "squid.h" +#include "comm/Loops.h" #include "fde.h" #include "MemBuf.h" @@ -329,7 +330,7 @@ diskHandleWrite(int fd, void *notused) } else { /* another block is queued */ diskCombineWrites(fdd); - commSetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, NULL, 0); F->flags.write_daemon = 1; } @@ -458,7 +459,7 @@ diskHandleRead(int fd, void *data) if (len < 0) { if (ignoreErrno(errno)) { - commSetSelect(fd, COMM_SELECT_READ, diskHandleRead, ctrl_dat, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, diskHandleRead, ctrl_dat, 0); PROF_stop(diskHandleRead); return; } diff --git a/src/dns_internal.cc b/src/dns_internal.cc index 95dd38a277..f859e9dcb7 100644 --- a/src/dns_internal.cc +++ b/src/dns_internal.cc @@ -1,4 +1,3 @@ - /* * $Id$ * @@ -33,13 +32,13 @@ * */ -#include "config.h" #include "squid.h" +#include "comm.h" +#include "comm/Loops.h" +#include "comm/Write.h" #include "event.h" #include "SquidTime.h" #include "Store.h" -#include "comm.h" -#include "comm/Write.h" #include "fde.h" #include "ip/tools.h" #include "MemBuf.h" @@ -1238,7 +1237,7 @@ idnsRead(int fd, void *data) // Always keep reading. This stops (or at least makes harder) several // attacks on the DNS client. - commSetSelect(fd, COMM_SELECT_READ, idnsRead, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, idnsRead, NULL, 0); /* BUG (UNRESOLVED) * two code lines after returning from comm_udprecvfrom() @@ -1496,12 +1495,12 @@ idnsInit(void) if (DnsSocketB >= 0) { port = comm_local_port(DnsSocketB); debugs(78, 1, "DNS Socket created at " << addrB << ", FD " << DnsSocketB); - commSetSelect(DnsSocketB, COMM_SELECT_READ, idnsRead, NULL, 0); + Comm::SetSelect(DnsSocketB, COMM_SELECT_READ, idnsRead, NULL, 0); } if (DnsSocketA >= 0) { port = comm_local_port(DnsSocketA); debugs(78, 1, "DNS Socket created at " << addrA << ", FD " << DnsSocketA); - commSetSelect(DnsSocketA, COMM_SELECT_READ, idnsRead, NULL, 0); + Comm::SetSelect(DnsSocketA, COMM_SELECT_READ, idnsRead, NULL, 0); } } diff --git a/src/fd.cc b/src/fd.cc index e895d9c1f4..d3e685c63f 100644 --- a/src/fd.cc +++ b/src/fd.cc @@ -34,6 +34,7 @@ */ #include "squid.h" +#include "comm/Loops.h" #include "fde.h" #include "SquidTime.h" #include "Debug.h" @@ -110,8 +111,8 @@ fd_close(int fd) } debugs(51, 3, "fd_close FD " << fd << " " << F->desc); - commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); - commSetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_WRITE, NULL, NULL, 0); F->flags.open = 0; fdUpdateBiggest(fd, 0); Number_FD--; diff --git a/src/forward.cc b/src/forward.cc index b30b3d6aea..930a110629 100644 --- a/src/forward.cc +++ b/src/forward.cc @@ -36,6 +36,7 @@ #include "acl/FilledChecklist.h" #include "acl/Gadgets.h" #include "CacheManager.h" +#include "comm/Loops.h" #include "event.h" #include "errorpage.h" #include "fde.h" @@ -585,11 +586,11 @@ FwdState::negotiateSSL(int fd) switch (ssl_error) { case SSL_ERROR_WANT_READ: - commSetSelect(fd, COMM_SELECT_READ, fwdNegotiateSSLWrapper, this, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, fwdNegotiateSSLWrapper, this, 0); return; case SSL_ERROR_WANT_WRITE: - commSetSelect(fd, COMM_SELECT_WRITE, fwdNegotiateSSLWrapper, this, 0); + Comm::SetSelect(fd, COMM_SELECT_WRITE, fwdNegotiateSSLWrapper, this, 0); return; default: diff --git a/src/htcp.cc b/src/htcp.cc index df13aa591f..0f6b307197 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -34,20 +34,21 @@ */ #include "squid.h" -#include "htcp.h" +#include "AccessLogEntry.h" #include "acl/FilledChecklist.h" #include "acl/Acl.h" -#include "ip/tools.h" -#include "SquidTime.h" -#include "Store.h" -#include "StoreClient.h" -#include "HttpRequest.h" #include "comm.h" -#include "MemBuf.h" +#include "comm/Loops.h" +#include "htcp.h" #include "http.h" +#include "HttpRequest.h" #include "icmp/net_db.h" -#include "AccessLogEntry.h" #include "ipc/StartListening.h" +#include "ip/tools.h" +#include "MemBuf.h" +#include "SquidTime.h" +#include "Store.h" +#include "StoreClient.h" /// dials htcpIncomingConnectionOpened call class HtcpListeningStartedDialer: public CallDialer, @@ -1484,7 +1485,7 @@ htcpRecv(int fd, void *data) htcpHandleMsg(buf, len, from); - commSetSelect(fd, COMM_SELECT_READ, htcpRecv, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_READ, htcpRecv, NULL, 0); } /* @@ -1547,7 +1548,7 @@ htcpInit(void) if (htcpOutSocket < 0) fatal("Cannot open Outgoing HTCP Socket"); - commSetSelect(htcpOutSocket, COMM_SELECT_READ, htcpRecv, NULL, 0); + Comm::SetSelect(htcpOutSocket, COMM_SELECT_READ, htcpRecv, NULL, 0); debugs(31, 1, "Outgoing HTCP messages on port " << Config.Port.htcp << ", FD " << htcpOutSocket << "."); @@ -1567,7 +1568,7 @@ htcpIncomingConnectionOpened(int fd, int errNo) if (htcpInSocket < 0) fatal("Cannot open HTCP Socket"); - commSetSelect(htcpInSocket, COMM_SELECT_READ, htcpRecv, NULL, 0); + Comm::SetSelect(htcpInSocket, COMM_SELECT_READ, htcpRecv, NULL, 0); debugs(31, 1, "Accepting HTCP messages on port " << Config.Port.htcp << ", FD " << htcpInSocket << "."); @@ -1733,7 +1734,7 @@ htcpSocketShutdown(void) */ assert(htcpOutSocket > -1); - commSetSelect(htcpOutSocket, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(htcpOutSocket, COMM_SELECT_READ, NULL, NULL, 0); } void diff --git a/src/icmp/IcmpSquid.cc b/src/icmp/IcmpSquid.cc index 708f4f4866..d530553164 100644 --- a/src/icmp/IcmpSquid.cc +++ b/src/icmp/IcmpSquid.cc @@ -33,10 +33,11 @@ */ #include "squid.h" +#include "comm.h" +#include "comm/Loops.h" #include "icmp/IcmpSquid.h" #include "icmp/net_db.h" #include "ip/tools.h" -#include "comm.h" #include "SquidTime.h" // Instance global to be available in main() and elsewhere. @@ -144,7 +145,7 @@ IcmpSquid::Recv() pingerReplyData preply; static Ip::Address F; - commSetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0); + Comm::SetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0); memset(&preply, '\0', sizeof(pingerReplyData)); n = comm_udp_recv(icmp_sock, (char *) &preply, @@ -247,7 +248,7 @@ IcmpSquid::Open(void) fd_note(icmp_sock, "pinger"); - commSetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0); + Comm::SetSelect(icmp_sock, COMM_SELECT_READ, icmpSquidRecv, NULL, 0); commSetTimeout(icmp_sock, -1, NULL, NULL); diff --git a/src/icp_v2.cc b/src/icp_v2.cc index d09aea28aa..2f1d326517 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -38,6 +38,7 @@ #include "squid.h" #include "Store.h" #include "comm.h" +#include "comm/Loops.h" #include "ICP.h" #include "HttpRequest.h" #include "acl/FilledChecklist.h" @@ -337,7 +338,7 @@ icpUdpSend(int fd, IcpQueueTail = queue; } - commSetSelect(fd, COMM_SELECT_WRITE, icpUdpSendQueue, NULL, 0); + Comm::SetSelect(fd, COMM_SELECT_WRITE, icpUdpSendQueue, NULL, 0); statCounter.icp.replies_queued++; } else { /* don't queue it */ @@ -616,7 +617,7 @@ icpHandleUdp(int sock, void *data) int len; int icp_version; int max = INCOMING_ICP_MAX; - commSetSelect(sock, COMM_SELECT_READ, icpHandleUdp, NULL, 0); + Comm::SetSelect(sock, COMM_SELECT_READ, icpHandleUdp, NULL, 0); while (max--) { len = comm_udp_recvfrom(sock, @@ -729,11 +730,7 @@ icpConnectionsOpen(void) if (theOutIcpConnection < 0) fatal("Cannot open Outgoing ICP Port"); - commSetSelect(theOutIcpConnection, - COMM_SELECT_READ, - icpHandleUdp, - NULL, - 0); + Comm::SetSelect(theOutIcpConnection, COMM_SELECT_READ, icpHandleUdp, NULL, 0); debugs(12, 1, "Outgoing ICP messages on port " << addr.GetPort() << ", FD " << theOutIcpConnection << "."); @@ -765,11 +762,7 @@ icpIncomingConnectionOpened(int fd, int errNo, Ip::Address& addr) if (theInIcpConnection < 0) fatal("Cannot open ICP Port"); - commSetSelect(theInIcpConnection, - COMM_SELECT_READ, - icpHandleUdp, - NULL, - 0); + Comm::SetSelect(theInIcpConnection, COMM_SELECT_READ, icpHandleUdp, NULL, 0); for (const wordlist *s = Config.mcast_group_list; s; s = s->next) ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL); @@ -815,7 +808,7 @@ icpConnectionShutdown(void) */ assert(theOutIcpConnection > -1); - commSetSelect(theOutIcpConnection, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(theOutIcpConnection, COMM_SELECT_READ, NULL, NULL, 0); } void diff --git a/src/log/ModDaemon.cc b/src/log/ModDaemon.cc index d1f0fcf5e5..59bf69b761 100644 --- a/src/log/ModDaemon.cc +++ b/src/log/ModDaemon.cc @@ -32,6 +32,7 @@ #include "squid.h" #include "cbdata.h" +#include "comm/Loops.h" #include "fde.h" #include "log/Config.h" #include "log/File.h" @@ -151,7 +152,7 @@ logfileHandleWrite(int fd, void *data) /* there is, so schedule more */ reschedule: - commSetSelect(ll->wfd, COMM_SELECT_WRITE, logfileHandleWrite, lf, 0); + Comm::SetSelect(ll->wfd, COMM_SELECT_WRITE, logfileHandleWrite, lf, 0); ll->flush_pending = 1; finish: return; @@ -171,7 +172,7 @@ logfileQueueWrite(Logfile * lf) logfile_mod_daemon_append(lf, "F\n", 2); } /* Ok, schedule a write-event */ - commSetSelect(ll->wfd, COMM_SELECT_WRITE, logfileHandleWrite, lf, 0); + Comm::SetSelect(ll->wfd, COMM_SELECT_WRITE, logfileHandleWrite, lf, 0); } static void diff --git a/src/main.cc b/src/main.cc index d2fd0c1ec2..662c6ef629 100644 --- a/src/main.cc +++ b/src/main.cc @@ -42,6 +42,7 @@ #if USE_DELAY_POOLS #include "ClientDelayConfig.h" #endif +#include "comm.h" #include "ConfigParser.h" #include "CpuAffinity.h" #if USE_DELAY_POOLS @@ -62,23 +63,10 @@ #include "htcp.h" #include "StoreFileSystem.h" #include "DiskIO/DiskIOModule.h" -#include "comm.h" #include "ipc/Kids.h" #include "ipc/Coordinator.h" #include "ipc/Strand.h" #include "ip/tools.h" -#if USE_EPOLL -#include "comm_epoll.h" -#endif -#if USE_KQUEUE -#include "comm_kqueue.h" -#endif -#if USE_POLL -#include "comm_poll.h" -#endif -#if defined(USE_SELECT) || defined(USE_SELECT_WIN32) -#include "comm_select.h" -#endif #include "SquidTime.h" #include "SwapDir.h" #include "forward.h" @@ -1383,8 +1371,6 @@ SquidMain(int argc, char **argv) comm_init(); - comm_select_init(); - mainInitialize(); test_access(); @@ -1436,8 +1422,6 @@ SquidMain(int argc, char **argv) /* init comm module */ comm_init(); - comm_select_init(); - if (opt_no_daemon) { /* we have to init fdstat here. */ fd_open(0, FD_LOG, "stdin"); diff --git a/src/snmp_core.cc b/src/snmp_core.cc index f3d13f8951..555ee882ac 100644 --- a/src/snmp_core.cc +++ b/src/snmp_core.cc @@ -33,6 +33,7 @@ #include "acl/FilledChecklist.h" #include "cache_snmp.h" #include "comm.h" +#include "comm/Loops.h" #include "ipc/StartListening.h" #include "ip/Address.h" #include "ip/tools.h" @@ -356,8 +357,7 @@ snmpIncomingConnectionOpened(int fd, int errNo) if (theInSnmpConnection < 0) fatal("Cannot open Incoming SNMP Port"); - commSetSelect(theInSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL, - 0); + Comm::SetSelect(theInSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL, 0); debugs(1, 1, "Accepting SNMP messages on " << Config.Addrs.snmp_incoming << ", FD " << theInSnmpConnection << "."); @@ -373,8 +373,7 @@ snmpOutgoingConnectionOpened(int fd, int errNo) if (theOutSnmpConnection < 0) fatal("Cannot open Outgoing SNMP Port"); - commSetSelect(theOutSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL, - 0); + Comm::SetSelect(theOutSnmpConnection, COMM_SELECT_READ, snmpHandleUdp, NULL, 0); debugs(1, 1, "Outgoing SNMP messages on " << Config.Addrs.snmp_outgoing << ", FD " << theOutSnmpConnection << "."); @@ -426,7 +425,7 @@ snmpConnectionShutdown(void) */ assert(theOutSnmpConnection > -1); - commSetSelect(theOutSnmpConnection, COMM_SELECT_READ, NULL, NULL, 0); + Comm::SetSelect(theOutSnmpConnection, COMM_SELECT_READ, NULL, NULL, 0); } void @@ -459,7 +458,7 @@ snmpHandleUdp(int sock, void *not_used) debugs(49, 5, "snmpHandleUdp: Called."); - commSetSelect(sock, COMM_SELECT_READ, snmpHandleUdp, NULL, 0); + Comm::SetSelect(sock, COMM_SELECT_READ, snmpHandleUdp, NULL, 0); memset(buf, '\0', SNMP_REQUEST_SIZE); diff --git a/src/tests/stub_comm.cc b/src/tests/stub_comm.cc index 45f8a8b906..a2007ae538 100644 --- a/src/tests/stub_comm.cc +++ b/src/tests/stub_comm.cc @@ -34,6 +34,7 @@ #include "squid.h" #include "comm.h" +#include "comm/Loops.h" #include "CommRead.h" #include "fde.h" @@ -90,14 +91,13 @@ commSetCloseOnExec(int fd) } void -commSetSelect(int fd, unsigned int type, PF * handler, void *client_data, - time_t timeout) +Comm::SetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout) { /* all test code runs synchronously at the moment */ } void -comm_quick_poll_required() +Comm::QuickPollRequired() { /* for tests ... ignore */ } diff --git a/src/wccp.cc b/src/wccp.cc index 6e01a0824c..fdad1a0a82 100644 --- a/src/wccp.cc +++ b/src/wccp.cc @@ -32,12 +32,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ +#include "config.h" + +#if USE_WCCP + #include "squid.h" #include "comm.h" +#include "comm/Loops.h" #include "event.h" -#if USE_WCCP - #define WCCP_PORT 2048 #define WCCP_REVISION 0 #define WCCP_ACTIVE_CACHES 32 @@ -157,11 +160,7 @@ wccpConnectionOpen(void) if (theWccpConnection < 0) fatal("Cannot open WCCP Port"); - commSetSelect(theWccpConnection, - COMM_SELECT_READ, - wccpHandleUdp, - NULL, - 0); + Comm::SetSelect(theWccpConnection, COMM_SELECT_READ, wccpHandleUdp, NULL, 0); debugs(80, 1, "Accepting WCCPv1 messages on " << Config.Wccp.address << ", FD " << theWccpConnection << "."); @@ -208,7 +207,7 @@ wccpHandleUdp(int sock, void *not_used) debugs(80, 6, "wccpHandleUdp: Called."); - commSetSelect(sock, COMM_SELECT_READ, wccpHandleUdp, NULL, 0); + Comm::SetSelect(sock, COMM_SELECT_READ, wccpHandleUdp, NULL, 0); memset(&wccp_i_see_you, '\0', sizeof(wccp_i_see_you)); diff --git a/src/wccp2.cc b/src/wccp2.cc index 6f49e7af4a..6e8cb568fd 100644 --- a/src/wccp2.cc +++ b/src/wccp2.cc @@ -35,6 +35,7 @@ #if USE_WCCPv2 #include "comm.h" +#include "comm/Loops.h" #include "compat/strsep.h" #include "event.h" #include "ip/Address.h" @@ -1009,11 +1010,7 @@ wccp2ConnectionOpen(void) } #endif - commSetSelect(theWccp2Connection, - COMM_SELECT_READ, - wccp2HandleUdp, - NULL, - 0); + Comm::SetSelect(theWccp2Connection, COMM_SELECT_READ, wccp2HandleUdp, NULL, 0); debugs(80, 1, "Accepting WCCPv2 messages on port " << WCCP_PORT << ", FD " << theWccp2Connection << "."); debugs(80, 1, "Initialising all WCCPv2 lists"); @@ -1174,7 +1171,7 @@ wccp2HandleUdp(int sock, void *not_used) debugs(80, 6, "wccp2HandleUdp: Called."); - commSetSelect(sock, COMM_SELECT_READ, wccp2HandleUdp, NULL, 0); + Comm::SetSelect(sock, COMM_SELECT_READ, wccp2HandleUdp, NULL, 0); /* FIXME INET6 : drop conversion boundary */ Ip::Address from_tmp;