36#define howmany(x, y) (((x)+((y)-1))/(y))
41#define FD_MASK_BYTES sizeof(fd_mask)
42#define FD_MASK_BITS (FD_MASK_BYTES*NBBY)
62Comm::SetSelect(
int fd,
unsigned int type,
PF * handler,
void *client_data, time_t timeout)
67 debugs(5, 5,
"FD " << fd <<
", type=" << type <<
68 ", handler=" << handler <<
", client_data=" << client_data <<
69 ", timeout=" << timeout);
115 if (s->listenConn !=
nullptr && s->listenConn->fd == fd)
132 FD_ZERO(&write_mask);
135 for (i = 0; i < nfds; ++i) {
139 FD_SET(fd, &read_mask);
146 FD_SET(fd, &write_mask);
160 if (
xselect(maxfd, &read_mask, &write_mask,
nullptr, &
zero_tv) < 1)
163 for (i = 0; i < nfds; ++i) {
166 if (FD_ISSET(fd, &read_mask)) {
167 if ((hdl =
fd_table[fd].read_handler) !=
nullptr) {
168 fd_table[fd].read_handler =
nullptr;
176 if (FD_ISSET(fd, &write_mask)) {
177 if ((hdl =
fd_table[fd].write_handler) !=
nullptr) {
178 fd_table[fd].write_handler =
nullptr;
222 fds[nfds] = s->listenConn->fd;
246 int calldns = 0, calludp = 0, calltcp = 0;
254 struct timeval poll_time;
272 calldns = calludp = calltcp = 0;
285 FD_ZERO(&pendingfds);
291 for (j = 0; j < maxindex; ++j) {
292 if ((tmask = fdsp[j]) == 0)
302 if (FD_ISSET(fd, &readfds) &&
fd_table[fd].flags.read_pending) {
303 FD_SET(fd, &pendingfds);
321 poll_time.tv_sec = msec / 1000;
322 poll_time.tv_usec = (msec % 1000) * 1000;
324 num =
xselect(maxfd, &readfds, &writefds,
nullptr, &poll_time);
328 if (num >= 0 || pending > 0)
343 if (num < 0 && !pending)
348 debugs(5, num ? 5 : 8,
"comm_select: " << num <<
"+" << pending <<
" FDs ready");
352 if (num == 0 && pending == 0)
358 pfdsp = (
fd_mask *) & pendingfds;
362 for (j = 0; j < maxindex; ++j) {
363 if ((tmask = (fdsp[j] | pfdsp[j])) == 0)
394 debugs(5, 6,
"comm_select: FD " << fd <<
" ready for reading");
396 if (
nullptr == (hdl = F->read_handler))
399 F->read_handler =
nullptr;
401 hdl(fd, F->read_data);
418 for (j = 0; j < maxindex; ++j) {
419 if ((tmask = fdsp[j]) == 0)
450 debugs(5, 6,
"comm_select: FD " << fd <<
" ready for writing");
452 if ((hdl = F->write_handler)) {
453 F->write_handler =
nullptr;
455 hdl(fd, F->write_data);
522 "comm_incoming() stats",
553 tv.tv_sec = tv.tv_usec = 0;
555 if (FD_ISSET(fd, readfds))
557 else if (FD_ISSET(fd, writefds))
558 FD_SET(fd, &write_x);
565 if (!fstat(fd, &sb)) {
566 debugs(5, 5,
"FD " << fd <<
" is valid.");
577 for (ch = F->
closeHandler; ch !=
nullptr; ch = ch->Next())
592 FD_CLR(fd, writefds);
609 storeAppendPrintf(sentry,
"ICP Messages handled per comm_select_udp_incoming() call:\n");
611 storeAppendPrintf(sentry,
"DNS Messages handled per comm_select_dns_incoming() call:\n");
613 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 fdIsDns(int fd)
static void commUpdateReadBits(int fd, PF *handler)
static void comm_select_udp_incoming(void)
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
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
void finishPolling(int, SquidConfig::CommIncoming::Measure &)
struct SquidConfig::CommIncoming comm_incoming
unsigned long int select_loops
struct StatCounters::@112 syscalls
void dump(StoreEntry *sentry, StatHistBinDumper *bd) const
AsyncCall::Pointer timeoutHandler
struct fde::_fde_flags flags
AsyncCall::Pointer closeHandler
void commCallCloseHandlers(int fd)
int ignoreErrno(int ierrno)
#define debugs(SECTION, LEVEL, CONTENT)
#define EBIT_CLR(flag, bit)
#define COMM_SELECT_WRITE
#define EBIT_TEST(flag, bit)
int incoming_sockets_accepted
Comm::ConnectionPointer icpOutgoingConn
Comm::ConnectionPointer icpIncomingConn
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, Protected, Atomic, Format)
int xselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
POSIX select(2) equivalent.
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
struct SquidConfig::CommIncoming::Measure udp
struct SquidConfig::CommIncoming::Measure dns
struct SquidConfig::CommIncoming::Measure tcp
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)