#if USE_SELECT
-#include "squid-old.h"
#include "anyp/PortCfg.h"
#include "comm/Connection.h"
#include "comm/Loops.h"
#include "fde.h"
+#include "globals.h"
#include "ICP.h"
#include "mgr/Registration.h"
#include "SquidTime.h"
#include "StatHist.h"
#include "Store.h"
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
static int MAX_POLL_TIME = 1000; /* see also Comm::QuickPollRequired() */
#ifndef howmany
static void commUpdateReadBits(int fd, PF * handler);
static void commUpdateWriteBits(int fd, PF * handler);
-
static struct timeval zero_tv;
static fd_set global_readfds;
static fd_set global_writefds;
FD_ZERO(&write_mask);
incoming_sockets_accepted = 0;
- for (i = 0; i < nfds; i++) {
+ for (i = 0; i < nfds; ++i) {
fd = fds[i];
if (fd_table[fd].read_handler) {
getCurrentTime();
- statCounter.syscalls.selects++;
+ ++ statCounter.syscalls.selects;
if (select(maxfd, &read_mask, &write_mask, NULL, &zero_tv) < 1)
return incoming_sockets_accepted;
- for (i = 0; i < nfds; i++) {
+ for (i = 0; i < nfds; ++i) {
fd = fds[i];
if (FD_ISSET(fd, &read_mask)) {
commUpdateReadBits(fd, NULL);
hdl(fd, fd_table[fd].read_data);
} else {
- debugs(5, 1, "comm_select_incoming: FD " << fd << " NULL read handler");
+ debugs(5, DBG_IMPORTANT, "comm_select_incoming: FD " << fd << " NULL read handler");
}
}
commUpdateWriteBits(fd, NULL);
hdl(fd, fd_table[fd].write_data);
} else {
- debugs(5, 1, "comm_select_incoming: FD " << fd << " NULL write handler");
+ debugs(5, DBG_IMPORTANT, "comm_select_incoming: FD " << fd << " NULL write handler");
}
}
}
int nevents;
udp_io_events = 0;
- if (Comm::IsConnOpen(icpIncomingConn))
- fds[nfds++] = icpIncomingConn->fd;
+ if (Comm::IsConnOpen(icpIncomingConn)) {
+ fds[nfds] = icpIncomingConn->fd;
+ ++nfds;
+ }
- if (Comm::IsConnOpen(icpOutgoingConn) && icpIncomingConn != icpOutgoingConn)
- fds[nfds++] = icpOutgoingConn->fd;
+ if (Comm::IsConnOpen(icpOutgoingConn) && icpIncomingConn != icpOutgoingConn) {
+ fds[nfds] = icpOutgoingConn->fd;
+ ++nfds;
+ }
if (nfds == 0)
return;
// XXX: only poll sockets that won't be deferred. But how do we identify them?
for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) {
- if (Comm::IsConnOpen(s->listenConn))
- fds[nfds++] = s->listenConn->fd;
+ if (Comm::IsConnOpen(s->listenConn)) {
+ fds[nfds] = s->listenConn->fd;
+ ++nfds;
+ }
}
nevents = comm_check_incoming_select_handlers(nfds, fds);
fdsp = (fd_mask *) & readfds;
- for (j = 0; j < maxindex; j++) {
+ for (j = 0; j < maxindex; ++j) {
if ((tmask = fdsp[j]) == 0)
continue; /* no bits here */
- for (k = 0; k < FD_MASK_BITS; k++) {
+ for (k = 0; k < FD_MASK_BITS; ++k) {
if (!EBIT_TEST(tmask, k))
continue;
if (FD_ISSET(fd, &readfds) && fd_table[fd].flags.read_pending) {
FD_SET(fd, &pendingfds);
- pending++;
+ ++pending;
}
}
}
#if DEBUG_FDBITS
- for (i = 0; i < maxfd; i++) {
+ for (i = 0; i < maxfd; ++i) {
/* Check each open socket for a handler. */
if (fd_table[i].read_handler) {
for (;;) {
poll_time.tv_sec = msec / 1000;
poll_time.tv_usec = (msec % 1000) * 1000;
- statCounter.syscalls.selects++;
+ ++ statCounter.syscalls.selects;
num = select(maxfd, &readfds, &writefds, NULL, &poll_time);
- ++statCounter.select_loops;
+ ++ statCounter.select_loops;
if (num >= 0 || pending > 0)
break;
if (ignoreErrno(errno))
break;
- debugs(5, 0, "comm_select: select failure: " << xstrerror());
+ debugs(5, DBG_CRITICAL, "comm_select: select failure: " << xstrerror());
examine_select(&readfds, &writefds);
maxindex = howmany(maxfd, FD_MASK_BITS);
- for (j = 0; j < maxindex; j++) {
+ for (j = 0; j < maxindex; ++j) {
if ((tmask = (fdsp[j] | pfdsp[j])) == 0)
continue; /* no bits here */
- for (k = 0; k < FD_MASK_BITS; k++) {
+ for (k = 0; k < FD_MASK_BITS; ++k) {
if (tmask == 0)
break; /* no more bits left */
F->flags.read_pending = 0;
commUpdateReadBits(fd, NULL);
hdl(fd, F->read_data);
- statCounter.select_fds++;
+ ++ statCounter.select_fds;
if (commCheckUdpIncoming)
comm_select_udp_incoming();
fdsp = (fd_mask *) & writefds;
- for (j = 0; j < maxindex; j++) {
+ for (j = 0; j < maxindex; ++j) {
if ((tmask = fdsp[j]) == 0)
continue; /* no bits here */
- for (k = 0; k < FD_MASK_BITS; k++) {
+ for (k = 0; k < FD_MASK_BITS; ++k) {
if (tmask == 0)
break; /* no more bits left */
F->write_handler = NULL;
commUpdateWriteBits(fd, NULL);
hdl(fd, F->write_data);
- statCounter.select_fds++;
+ ++ statCounter.select_fds;
if (commCheckUdpIncoming)
comm_select_udp_incoming();
if (DnsSocketA < 0 && DnsSocketB < 0)
return;
- if (DnsSocketA >= 0)
- fds[nfds++] = DnsSocketA;
+ if (DnsSocketA >= 0) {
+ fds[nfds] = DnsSocketA;
+ ++nfds;
+ }
- if (DnsSocketB >= 0)
- fds[nfds++] = DnsSocketB;
+ if (DnsSocketB >= 0) {
+ fds[nfds] = DnsSocketB;
+ ++nfds;
+ }
nevents = comm_check_incoming_select_handlers(nfds, fds);
fde *F = NULL;
struct stat sb;
- debugs(5, 0, "examine_select: Examining open file descriptors...");
+ debugs(5, DBG_CRITICAL, "examine_select: Examining open file descriptors...");
- for (fd = 0; fd < Squid_MaxFD; fd++) {
+ for (fd = 0; fd < Squid_MaxFD; ++fd) {
FD_ZERO(&read_x);
FD_ZERO(&write_x);
tv.tv_sec = tv.tv_usec = 0;
else
continue;
- statCounter.syscalls.selects++;
+ ++ statCounter.syscalls.selects;
errno = 0;
if (!fstat(fd, &sb)) {
}
F = &fd_table[fd];
- debugs(5, 0, "FD " << fd << ": " << xstrerror());
- debugs(5, 0, "WARNING: FD " << fd << " has handlers, but it's invalid.");
- debugs(5, 0, "FD " << fd << " is a " << fdTypeStr[F->type] << " called '" << F->desc << "'");
- debugs(5, 0, "tmout:" << F->timeoutHandler << " read:" << F->read_handler << " write:" << F->write_handler);
+ debugs(5, DBG_CRITICAL, "FD " << fd << ": " << xstrerror());
+ debugs(5, DBG_CRITICAL, "WARNING: FD " << fd << " has handlers, but it's invalid.");
+ debugs(5, DBG_CRITICAL, "FD " << fd << " is a " << fdTypeStr[F->type] << " called '" << F->desc << "'");
+ debugs(5, DBG_CRITICAL, "tmout:" << F->timeoutHandler << " read:" << F->read_handler << " write:" << F->write_handler);
for (ch = F->closeHandler; ch != NULL; ch = ch->Next())
- debugs(5, 0, " close handler: " << ch);
+ debugs(5, DBG_CRITICAL, " close handler: " << ch);
if (F->closeHandler != NULL) {
commCallCloseHandlers(fd);
} else if (F->timeoutHandler != NULL) {
- debugs(5, 0, "examine_select: Calling Timeout Handler");
+ debugs(5, DBG_CRITICAL, "examine_select: Calling Timeout Handler");
ScheduleCallHere(F->timeoutHandler);
}
return 0;
}
-
static void
commIncomingStats(StoreEntry * sentry)
{
{
if (handler && !FD_ISSET(fd, &global_readfds)) {
FD_SET(fd, &global_readfds);
- nreadfds++;
+ ++nreadfds;
} else if (!handler && FD_ISSET(fd, &global_readfds)) {
FD_CLR(fd, &global_readfds);
- nreadfds--;
+ --nreadfds;
}
}
{
if (handler && !FD_ISSET(fd, &global_writefds)) {
FD_SET(fd, &global_writefds);
- nwritefds++;
+ ++nwritefds;
} else if (!handler && FD_ISSET(fd, &global_writefds)) {
FD_CLR(fd, &global_writefds);
- nwritefds--;
+ --nwritefds;
}
}