Go to the documentation of this file.
35 #define howmany(x, y) (((x)+((y)-1))/(y))
40 #define FD_MASK_BYTES sizeof(fd_mask)
41 #define FD_MASK_BITS (FD_MASK_BYTES*NBBY)
61 Comm::SetSelect(
int fd,
unsigned int type,
PF * handler,
void *client_data, time_t timeout)
65 assert(
F->flags.open || (!handler && !client_data && !timeout));
66 debugs(5, 5,
"FD " << fd <<
", type=" << type <<
67 ", handler=" << handler <<
", client_data=" << client_data <<
68 ", timeout=" << timeout);
71 F->read_handler = handler;
72 F->read_data = client_data;
77 F->write_handler = handler;
78 F->write_data = client_data;
114 if (s->listenConn !=
nullptr && s->listenConn->fd == fd)
131 FD_ZERO(&write_mask);
134 for (i = 0; i < nfds; ++i) {
138 FD_SET(fd, &read_mask);
145 FD_SET(fd, &write_mask);
159 if (select(maxfd, &read_mask, &write_mask,
nullptr, &
zero_tv) < 1)
162 for (i = 0; i < nfds; ++i) {
165 if (FD_ISSET(fd, &read_mask)) {
166 if ((hdl =
fd_table[fd].read_handler) !=
nullptr) {
167 fd_table[fd].read_handler =
nullptr;
175 if (FD_ISSET(fd, &write_mask)) {
176 if ((hdl =
fd_table[fd].write_handler) !=
nullptr) {
177 fd_table[fd].write_handler =
nullptr;
221 fds[nfds] = s->listenConn->fd;
245 int calldns = 0, calludp = 0, calltcp = 0;
253 struct timeval poll_time;
271 calldns = calludp = calltcp = 0;
284 FD_ZERO(&pendingfds);
290 for (j = 0; j < maxindex; ++j) {
291 if ((tmask = fdsp[j]) == 0)
301 if (FD_ISSET(fd, &readfds) &&
fd_table[fd].flags.read_pending) {
302 FD_SET(fd, &pendingfds);
320 poll_time.tv_sec = msec / 1000;
321 poll_time.tv_usec = (msec % 1000) * 1000;
323 num = select(maxfd, &readfds, &writefds,
nullptr, &poll_time);
327 if (num >= 0 || pending > 0)
342 if (num < 0 && !pending)
347 debugs(5, num ? 5 : 8,
"comm_select: " << num <<
"+" << pending <<
" FDs ready");
351 if (num == 0 && pending == 0)
357 pfdsp = (
fd_mask *) & pendingfds;
361 for (j = 0; j < maxindex; ++j) {
362 if ((tmask = (fdsp[j] | pfdsp[j])) == 0)
393 debugs(5, 6,
"comm_select: FD " << fd <<
" ready for reading");
395 if (
nullptr == (hdl =
F->read_handler))
398 F->read_handler =
nullptr;
400 hdl(fd,
F->read_data);
417 for (j = 0; j < maxindex; ++j) {
418 if ((tmask = fdsp[j]) == 0)
449 debugs(5, 6,
"comm_select: FD " << fd <<
" ready for writing");
451 if ((hdl =
F->write_handler)) {
452 F->write_handler =
nullptr;
454 hdl(fd,
F->write_data);
521 "comm_incoming() stats",
552 tv.tv_sec = tv.tv_usec = 0;
554 if (FD_ISSET(fd, readfds))
556 else if (FD_ISSET(fd, writefds))
557 FD_SET(fd, &write_x);
564 if (!fstat(fd, &sb)) {
565 debugs(5, 5,
"FD " << fd <<
" is valid.");
574 debugs(5,
DBG_CRITICAL,
"tmout:" <<
F->timeoutHandler <<
" read:" <<
F->read_handler <<
" write:" <<
F->write_handler);
576 for (ch =
F->closeHandler; ch !=
nullptr; ch = ch->Next())
579 if (
F->closeHandler !=
nullptr) {
581 }
else if (
F->timeoutHandler !=
nullptr) {
586 F->closeHandler =
nullptr;
587 F->timeoutHandler =
nullptr;
588 F->read_handler =
nullptr;
589 F->write_handler =
nullptr;
591 FD_CLR(fd, writefds);
608 storeAppendPrintf(sentry,
"ICP Messages handled per comm_select_udp_incoming() call:\n");
610 storeAppendPrintf(sentry,
"DNS Messages handled per comm_select_dns_incoming() call:\n");
612 storeAppendPrintf(sentry,
"HTTP Messages handled per comm_select_tcp_incoming() call:\n");
#define EBIT_CLR(flag, bit)
const char * xstrerr(int error)
double current_dtime
the current UNIX time in seconds (with microsecond precision)
static struct timeval zero_tv
int incoming_sockets_accepted
AnyP::PortCfgPointer HttpPortList
list of Squid http(s)_port configured
#define ScheduleCallHere(call)
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
void commCallCloseHandlers(int fd)
struct SquidConfig::CommIncoming comm_incoming
Comm::ConnectionPointer icpOutgoingConn
Comm::Flag DoSelect(int)
Do poll and trigger callback functions as appropriate.
static void comm_select_dns_incoming(void)
static uint32 F(uint32 X, uint32 Y, uint32 Z)
static int fdIsTcpListener(int fd)
static int fdIsUdpListener(int fd)
bool IsConnOpen(const Comm::ConnectionPointer &conn)
struct SquidConfig::CommIncoming::Measure udp
static void comm_select_tcp_incoming(void)
struct StatCounters::@119 syscalls
time_t getCurrentTime() STUB_RETVAL(0) int tvSubUsec(struct timeval
void dump(StoreEntry *sentry, StatHistBinDumper *bd) const
struct SquidConfig::CommIncoming::Measure dns
#define EBIT_TEST(flag, bit)
static int examine_select(fd_set *, fd_set *)
static fd_set global_writefds
void SelectLoopInit(void)
Initialize the module on Squid startup.
static OBJH commIncomingStats
static fd_set global_readfds
Comm::ConnectionPointer icpIncomingConn
int ignoreErrno(int ierrno)
static void comm_select_udp_incoming(void)
static void commUpdateWriteBits(int fd, PF *handler)
struct SquidConfig::CommIncoming::Measure tcp
static void commUpdateReadBits(int fd, PF *handler)
unsigned long int select_loops
StatHistBinDumper statHistIntDumper
void SetSelect(int, unsigned int, PF *, void *, time_t)
Mark an FD to be watched for its IO status.
static int comm_check_incoming_select_handlers(int nfds, int *fds)
void RegisterAction(char const *action, char const *desc, OBJH *handler, Protected, Atomic, Format)
void finishPolling(int, SquidConfig::CommIncoming::Measure &)
#define MAXTCPLISTENPORTS
static int fdIsDns(int fd)
#define debugs(SECTION, LEVEL, CONTENT)
#define COMM_SELECT_WRITE
void QuickPollRequired(void)