34#define POLLRDNORM POLLIN
37#define POLLWRNORM POLLOUT
44#define howmany(x, y) (((x)+((y)-1))/(y))
49#define FD_MASK_BYTES sizeof(fd_mask)
50#define FD_MASK_BITS (FD_MASK_BYTES*NBBY)
108#define MAX_INCOMING_INTEGER 256
109#define INCOMING_FACTOR 5
110#define MAX_INCOMING_INTERVAL (MAX_INCOMING_INTEGER << INCOMING_FACTOR)
117#define commCheckUdpIncoming (++udp_io_events > (incoming_udp_interval>> INCOMING_FACTOR))
118#define commCheckDnsIncoming (++dns_io_events > (incoming_dns_interval>> INCOMING_FACTOR))
119#define commCheckTcpIncoming (++tcp_io_events > (incoming_tcp_interval>> INCOMING_FACTOR))
127 debugs(5, 5,
"FD " << fd <<
", type=" << type <<
128 ", handler=" <<
handler <<
", client_data=" << client_data <<
129 ", timeout=" << timeout);
133 F->read_data = client_data;
138 F->write_data = client_data;
173 if (s->listenConn !=
nullptr && s->listenConn->fd == fd)
191 for (i = npfds = 0; i < nfds; ++i) {
204 pfds[npfds].events = events;
205 pfds[npfds].revents = 0;
216 if (poll(
pfds, npfds, 0) < 1)
219 for (i = 0; i < npfds; ++i) {
222 if (((revents =
pfds[i].revents) == 0) || ((fd =
pfds[i].fd) == -1))
225 if (revents & (
POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
226 if ((hdl =
fd_table[fd].read_handler)) {
227 fd_table[fd].read_handler =
nullptr;
233 if (revents & (
POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) {
234 if ((hdl =
fd_table[fd].write_handler)) {
235 fd_table[fd].write_handler =
nullptr;
321 struct pollfd
pfds[SQUID_MAXFD];
327 unsigned long npending;
329 int calldns = 0, calludp = 0, calltcp = 0;
346 calldns = calludp = calltcp = 0;
354 for (
int i = 0; i < maxfd; ++i) {
367 pfds[nfds].events = events;
368 pfds[nfds].revents = 0;
387 if (nfds == 0 && npending == 0) {
396 num = poll(
pfds, nfds, msec);
400 if (num >= 0 || npending > 0)
417 debugs(5, num ? 5 : 8,
"comm_poll: " << num <<
"+" << npending <<
" FDs ready");
420 if (num == 0 && npending == 0)
427 for (
size_t loopIndex = 0; loopIndex < nfds; ++loopIndex) {
429 int revents =
pfds[loopIndex].revents;
430 fd =
pfds[loopIndex].fd;
435 if (
fd_table[fd].flags.read_pending)
458 if (revents & (
POLLRDNORM | POLLIN | POLLHUP | POLLERR)) {
459 debugs(5, 6,
"comm_poll: FD " << fd <<
" ready for reading");
461 if ((hdl =
F->read_handler)) {
462 F->read_handler =
nullptr;
463 hdl(fd,
F->read_data);
477 if (revents & (
POLLWRNORM | POLLOUT | POLLHUP | POLLERR)) {
478 debugs(5, 6,
"comm_poll: FD " << fd <<
" ready for writing");
480 if ((hdl =
F->write_handler)) {
481 F->write_handler =
nullptr;
482 hdl(fd,
F->write_data);
496 if (revents & POLLNVAL) {
502 F->read_handler <<
" write:" <<
F->write_handler);
504 for (ch =
F->closeHandler; ch !=
nullptr; ch = ch->
Next())
507 if (
F->closeHandler !=
nullptr) {
509 }
else if (
F->timeoutHandler !=
nullptr) {
514 F->closeHandler =
nullptr;
515 F->timeoutHandler =
nullptr;
516 F->read_handler =
nullptr;
517 F->write_handler =
nullptr;
589 "comm_incoming() stats",
610 storeAppendPrintf(sentry,
"ICP Messages handled per comm_poll_udp_incoming() call:\n");
612 storeAppendPrintf(sentry,
"DNS Messages handled per comm_poll_dns_incoming() call:\n");
614 storeAppendPrintf(sentry,
"HTTP Messages handled per comm_poll_tcp_incoming() call:\n");
#define ScheduleCallHere(call)
static int incoming_udp_interval
#define commCheckTcpIncoming
static int incoming_tcp_interval
static int fdIsDns(int fd)
static void commPollRegisterWithCacheManager(void)
static int incoming_dns_interval
static int dns_io_events
I/O events passed since last DNS socket poll.
static int tcp_io_events
I/O events passed since last TCP listening socket poll.
static int comm_check_incoming_poll_handlers(int nfds, int *fds)
#define commCheckDnsIncoming
#define commCheckUdpIncoming
static int fdIsTcpListen(int fd)
static void comm_poll_dns_incoming(void)
static void comm_poll_tcp_incoming(void)
static OBJH commIncomingStats
static int udp_io_events
I/O events passed since last UDP receiver socket poll.
#define MAX_INCOMING_INTERVAL
static int fdIsUdpListen(int fd)
static void comm_poll_udp_incoming(void)
int HttpSockets[MAXTCPLISTENPORTS]
AnyP::PortCfgPointer HttpPortList
list of Squid http(s)_port configured
#define MAXTCPLISTENPORTS
StatHistBinDumper statHistIntDumper
AsyncCall::Pointer & Next()
struct SquidConfig::@112 comm_incoming
struct SquidConfig::@112::@119 udp
struct SquidConfig::@112::@119 tcp
struct SquidConfig::@112::@119 dns
struct StatCounters::@130 syscalls
StatHist comm_tcp_incoming
unsigned long int select_loops
StatHist comm_udp_incoming
StatHist comm_dns_incoming
void dump(StoreEntry *sentry, StatHistBinDumper *bd) const
void fd_close(const int fd)
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)