29#define howmany(x, y) (((x)+((y)-1))/(y))
34#define FD_MASK_BYTES sizeof(fd_mask)
35#define FD_MASK_BITS (FD_MASK_BYTES*NBBY)
102#define MAX_INCOMING_INTEGER 256
103#define INCOMING_FACTOR 5
104#define MAX_INCOMING_INTERVAL (MAX_INCOMING_INTEGER << INCOMING_FACTOR)
111#define commCheckUdpIncoming (++udp_io_events > (incoming_udp_interval>> INCOMING_FACTOR))
112#define commCheckDnsIncoming (++dns_io_events > (incoming_dns_interval>> INCOMING_FACTOR))
113#define commCheckTcpIncoming (++tcp_io_events > (incoming_tcp_interval>> INCOMING_FACTOR))
121 debugs(5, 5,
"FD " << fd <<
", type=" << type <<
122 ", handler=" <<
handler <<
", client_data=" << client_data <<
123 ", timeout=" << timeout);
127 F->read_data = client_data;
133 F->write_data = client_data;
169 if (s->listenConn !=
NULL && s->listenConn->fd == fd)
186 FD_ZERO(&write_mask);
189 for (i = 0; i < nfds; ++i) {
193 FD_SET(fd, &read_mask);
200 FD_SET(fd, &write_mask);
214 if (select(maxfd, &read_mask, &write_mask,
NULL, &
zero_tv) < 1)
217 for (i = 0; i < nfds; ++i) {
220 if (FD_ISSET(fd, &read_mask)) {
230 if (FD_ISSET(fd, &write_mask)) {
293 fds[nfds] = s->listenConn->fd;
326 int calldns = 0, calludp = 0, calltcp = 0;
328 struct timeval poll_time;
350 calldns = calludp = calltcp = 0;
363 FD_ZERO(&pendingfds);
365 for (j = 0; j < (
int) readfds.fd_count; ++j) {
366 register int readfds_handle = readfds.fd_array[j];
370 if (
fd_table[fd].win32.handle == readfds_handle ) {
381 if (FD_ISSET(fd, &readfds) &&
fd_table[fd].flags.read_pending) {
382 FD_SET(fd, &pendingfds);
399 poll_time.tv_sec = msec / 1000;
400 poll_time.tv_usec = (msec % 1000) * 1000;
402 num = select(maxfd, &readfds, &writefds, &errfds, &poll_time);
406 if (num >= 0 || pending > 0)
421 if (num < 0 && !pending)
426 debugs(5, num ? 5 : 8,
"comm_select: " << num <<
"+" << pending <<
" FDs ready");
430 if (num == 0 && pending == 0)
437 for (j = 0; j < (
int) readfds.fd_count; ++j) {
438 register int readfds_handle = readfds.fd_array[j];
439 register int pendingfds_handle = pendingfds.fd_array[j];
440 register int osfhandle;
444 osfhandle =
fd_table[fd].win32.handle;
446 if (( osfhandle == readfds_handle ) ||
447 ( osfhandle == pendingfds_handle )) {
474 debugs(5, 6,
"comm_select: FD " << fd <<
" ready for reading");
476 if ((hdl =
F->read_handler)) {
477 F->read_handler =
NULL;
479 hdl(fd,
F->read_data);
495 for (j = 0; j < (
int) errfds.fd_count; ++j) {
496 register int errfds_handle = errfds.fd_array[j];
499 if (
fd_table[fd].win32.handle == errfds_handle )
506 if ((hdl =
F->write_handler)) {
507 F->write_handler =
NULL;
509 hdl(fd,
F->write_data);
517 for (j = 0; j < (
int) writefds.fd_count; ++j) {
518 register int writefds_handle = writefds.fd_array[j];
522 if (
fd_table[fd].win32.handle == writefds_handle ) {
549 debugs(5, 6,
"comm_select: FD " << fd <<
" ready for writing");
551 if ((hdl =
F->write_handler)) {
552 F->write_handler =
NULL;
554 hdl(fd,
F->write_data);
638 "comm_incoming() stats",
669 tv.tv_sec = tv.tv_usec = 0;
671 if (FD_ISSET(fd, readfds))
673 else if (FD_ISSET(fd, writefds))
674 FD_SET(fd, &write_x);
681 if (!fstat(fd, &
sb)) {
682 debugs(5, 5,
"FD " << fd <<
" is valid.");
691 debugs(5,
DBG_CRITICAL,
"tmout:" <<
F->timeoutHandler <<
" read:" <<
F->read_handler <<
" write:" <<
F->write_handler);
693 for (ch =
F->closeHandler; ch !=
NULL; ch = ch->Next())
696 if (
F->closeHandler !=
NULL) {
698 }
else if (
F->timeoutHandler !=
NULL) {
703 F->closeHandler =
NULL;
704 F->timeoutHandler =
NULL;
705 F->read_handler =
NULL;
706 F->write_handler =
NULL;
708 FD_CLR(fd, writefds);
725 storeAppendPrintf(sentry,
"ICP Messages handled per comm_select_udp_incoming() call:\n");
727 storeAppendPrintf(sentry,
"DNS Messages handled per comm_select_dns_incoming() call:\n");
729 storeAppendPrintf(sentry,
"HTTP Messages handled per comm_select_tcp_incoming() call:\n");
#define ScheduleCallHere(call)
static fd_set global_readfds
static int fdIsTcpListener(int fd)
static int incoming_udp_interval
#define commCheckTcpIncoming
static int incoming_tcp_interval
static int fdIsDns(int fd)
static void commUpdateReadBits(int fd, PF *handler)
static void comm_select_udp_incoming(void)
static int incoming_dns_interval
#define commCheckDnsIncoming
#define commCheckUdpIncoming
static void comm_select_tcp_incoming(void)
static struct timeval zero_tv
static int examine_select(fd_set *, fd_set *)
static int fdIsUdpListener(int fd)
static int comm_check_incoming_select_handlers(int nfds, int *fds)
static OBJH commIncomingStats
#define MAX_INCOMING_INTERVAL
static void commUpdateWriteBits(int fd, PF *handler)
static fd_set global_writefds
static void comm_select_dns_incoming(void)
AnyP::PortCfgPointer HttpPortList
list of Squid http(s)_port configured
#define MAXTCPLISTENPORTS
StatHistBinDumper statHistIntDumper
struct SquidConfig::@112 comm_incoming
struct SquidConfig::@112::@120 dns
struct SquidConfig::@112::@120 tcp
struct SquidConfig::@112::@120 udp
StatHist comm_tcp_incoming
struct StatCounters::@131 syscalls
unsigned long int select_loops
StatHist comm_udp_incoming
StatHist comm_dns_incoming
void dump(StoreEntry *sentry, StatHistBinDumper *bd) const
void commCallCloseHandlers(int fd)
int ignoreErrno(int ierrno)
#define debugs(SECTION, LEVEL, CONTENT)
#define COMM_SELECT_WRITE
int incoming_sockets_accepted
Comm::ConnectionPointer icpOutgoingConn
Comm::ConnectionPointer icpIncomingConn
static uint32 F(uint32 X, uint32 Y, uint32 Z)
void QuickPollRequired(void)
bool IsConnOpen(const Comm::ConnectionPointer &conn)
Comm::Flag DoSelect(int)
Do poll and trigger callback functions as appropriate.
void SelectLoopInit(void)
Initialize the module on Squid startup.
void SetSelect(int, unsigned int, PF *, void *, time_t)
Mark an FD to be watched for its IO status.
void RegisterAction(char const *action, char const *desc, OBJH *handler, int pw_req_flag, int atomic)
static void handler(int signo)
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
double current_dtime
the current UNIX time in seconds (with microsecond precision)
time_t getCurrentTime() STUB_RETVAL(0) int tvSubUsec(struct timeval
const char * xstrerr(int error)