]> git.ipfire.org Git - thirdparty/squid.git/blob - src/comm/ModSelect.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / comm / ModSelect.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 05 Socket Functions
5 *
6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
8 *
9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 *
32 */
33 #include "squid.h"
34
35 #if USE_SELECT
36
37 #include "anyp/PortCfg.h"
38 #include "comm/Connection.h"
39 #include "comm/Loops.h"
40 #include "fde.h"
41 #include "globals.h"
42 #include "ICP.h"
43 #include "mgr/Registration.h"
44 #include "SquidTime.h"
45 #include "StatCounters.h"
46 #include "StatHist.h"
47 #include "Store.h"
48
49 #if HAVE_SYS_STAT_H
50 #include <sys/stat.h>
51 #endif
52 #if HAVE_ERRNO_H
53 #include <errno.h>
54 #endif
55
56 static int MAX_POLL_TIME = 1000; /* see also Comm::QuickPollRequired() */
57
58 #ifndef howmany
59 #define howmany(x, y) (((x)+((y)-1))/(y))
60 #endif
61 #ifndef NBBY
62 #define NBBY 8
63 #endif
64 #define FD_MASK_BYTES sizeof(fd_mask)
65 #define FD_MASK_BITS (FD_MASK_BYTES*NBBY)
66
67 /* STATIC */
68 static int examine_select(fd_set *, fd_set *);
69 static int fdIsTcpListener(int fd);
70 static int fdIsUdpListener(int fd);
71 static int fdIsDns(int fd);
72 static OBJH commIncomingStats;
73 static int comm_check_incoming_select_handlers(int nfds, int *fds);
74 static void comm_select_dns_incoming(void);
75 static void commUpdateReadBits(int fd, PF * handler);
76 static void commUpdateWriteBits(int fd, PF * handler);
77
78 static struct timeval zero_tv;
79 static fd_set global_readfds;
80 static fd_set global_writefds;
81 static int nreadfds;
82 static int nwritefds;
83
84 /*
85 * Automatic tuning for incoming requests:
86 *
87 * INCOMING sockets are the ICP and HTTP ports. We need to check these
88 * fairly regularly, but how often? When the load increases, we
89 * want to check the incoming sockets more often. If we have a lot
90 * of incoming ICP, then we need to check these sockets more than
91 * if we just have HTTP.
92 *
93 * The variables 'incoming_udp_interval' and 'incoming_tcp_interval'
94 * determine how many normal I/O events to process before checking
95 * incoming sockets again. Note we store the incoming_interval
96 * multipled by a factor of (2^INCOMING_FACTOR) to have some
97 * pseudo-floating point precision.
98 *
99 * The variable 'udp_io_events' and 'tcp_io_events' counts how many normal
100 * I/O events have been processed since the last check on the incoming
101 * sockets. When io_events > incoming_interval, its time to check incoming
102 * sockets.
103 *
104 * Every time we check incoming sockets, we count how many new messages
105 * or connections were processed. This is used to adjust the
106 * incoming_interval for the next iteration. The new incoming_interval
107 * is calculated as the current incoming_interval plus what we would
108 * like to see as an average number of events minus the number of
109 * events just processed.
110 *
111 * incoming_interval = incoming_interval + target_average - number_of_events_processed
112 *
113 * There are separate incoming_interval counters for DNS, UDP and TCP events
114 *
115 * You can see the current values of the incoming_interval's, as well as
116 * a histogram of 'incoming_events' by asking the cache manager
117 * for 'comm_incoming', e.g.:
118 *
119 * % ./client mgr:comm_incoming
120 *
121 * Caveats:
122 *
123 * - We have MAX_INCOMING_INTEGER as a magic upper limit on
124 * incoming_interval for both types of sockets. At the
125 * largest value the cache will effectively be idling.
126 *
127 * - The higher the INCOMING_FACTOR, the slower the algorithm will
128 * respond to load spikes/increases/decreases in demand. A value
129 * between 3 and 8 is recommended.
130 */
131
132 #define MAX_INCOMING_INTEGER 256
133 #define INCOMING_FACTOR 5
134 #define MAX_INCOMING_INTERVAL (MAX_INCOMING_INTEGER << INCOMING_FACTOR)
135 static int udp_io_events = 0;
136 static int dns_io_events = 0;
137 static int tcp_io_events = 0;
138 static int incoming_udp_interval = 16 << INCOMING_FACTOR;
139 static int incoming_dns_interval = 16 << INCOMING_FACTOR;
140 static int incoming_tcp_interval = 16 << INCOMING_FACTOR;
141 #define commCheckUdpIncoming (++udp_io_events > (incoming_udp_interval>> INCOMING_FACTOR))
142 #define commCheckDnsIncoming (++dns_io_events > (incoming_dns_interval>> INCOMING_FACTOR))
143 #define commCheckTcpIncoming (++tcp_io_events > (incoming_tcp_interval>> INCOMING_FACTOR))
144
145 void
146 Comm::SetSelect(int fd, unsigned int type, PF * handler, void *client_data, time_t timeout)
147 {
148 fde *F = &fd_table[fd];
149 assert(fd >= 0);
150 assert(F->flags.open);
151 debugs(5, 5, HERE << "FD " << fd << ", type=" << type <<
152 ", handler=" << handler << ", client_data=" << client_data <<
153 ", timeout=" << timeout);
154
155 if (type & COMM_SELECT_READ) {
156 F->read_handler = handler;
157 F->read_data = client_data;
158 commUpdateReadBits(fd, handler);
159 }
160
161 if (type & COMM_SELECT_WRITE) {
162 F->write_handler = handler;
163 F->write_data = client_data;
164 commUpdateWriteBits(fd, handler);
165 }
166
167 if (timeout)
168 F->timeout = squid_curtime + timeout;
169 }
170
171 void
172 Comm::ResetSelect(int fd)
173 {
174 }
175
176 static int
177 fdIsUdpListener(int fd)
178 {
179 if (icpIncomingConn != NULL && fd == icpIncomingConn->fd)
180 return 1;
181
182 if (icpOutgoingConn != NULL && fd == icpOutgoingConn->fd)
183 return 1;
184
185 return 0;
186 }
187
188 static int
189 fdIsDns(int fd)
190 {
191 if (fd == DnsSocketA)
192 return 1;
193
194 if (fd == DnsSocketB)
195 return 1;
196
197 return 0;
198 }
199
200 static int
201 fdIsTcpListener(int fd)
202 {
203 for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) {
204 if (s->listenConn != NULL && s->listenConn->fd == fd)
205 return 1;
206 }
207
208 return 0;
209 }
210
211 static int
212 comm_check_incoming_select_handlers(int nfds, int *fds)
213 {
214 int i;
215 int fd;
216 int maxfd = 0;
217 PF *hdl = NULL;
218 fd_set read_mask;
219 fd_set write_mask;
220 FD_ZERO(&read_mask);
221 FD_ZERO(&write_mask);
222 incoming_sockets_accepted = 0;
223
224 for (i = 0; i < nfds; ++i) {
225 fd = fds[i];
226
227 if (fd_table[fd].read_handler) {
228 FD_SET(fd, &read_mask);
229
230 if (fd > maxfd)
231 maxfd = fd;
232 }
233
234 if (fd_table[fd].write_handler) {
235 FD_SET(fd, &write_mask);
236
237 if (fd > maxfd)
238 maxfd = fd;
239 }
240 }
241
242 if (maxfd++ == 0)
243 return -1;
244
245 getCurrentTime();
246
247 ++ statCounter.syscalls.selects;
248
249 if (select(maxfd, &read_mask, &write_mask, NULL, &zero_tv) < 1)
250 return incoming_sockets_accepted;
251
252 for (i = 0; i < nfds; ++i) {
253 fd = fds[i];
254
255 if (FD_ISSET(fd, &read_mask)) {
256 if ((hdl = fd_table[fd].read_handler) != NULL) {
257 fd_table[fd].read_handler = NULL;
258 commUpdateReadBits(fd, NULL);
259 hdl(fd, fd_table[fd].read_data);
260 } else {
261 debugs(5, DBG_IMPORTANT, "comm_select_incoming: FD " << fd << " NULL read handler");
262 }
263 }
264
265 if (FD_ISSET(fd, &write_mask)) {
266 if ((hdl = fd_table[fd].write_handler) != NULL) {
267 fd_table[fd].write_handler = NULL;
268 commUpdateWriteBits(fd, NULL);
269 hdl(fd, fd_table[fd].write_data);
270 } else {
271 debugs(5, DBG_IMPORTANT, "comm_select_incoming: FD " << fd << " NULL write handler");
272 }
273 }
274 }
275
276 return incoming_sockets_accepted;
277 }
278
279 static void
280 comm_select_udp_incoming(void)
281 {
282 int nfds = 0;
283 int fds[2];
284 int nevents;
285 udp_io_events = 0;
286
287 if (Comm::IsConnOpen(icpIncomingConn)) {
288 fds[nfds] = icpIncomingConn->fd;
289 ++nfds;
290 }
291
292 if (Comm::IsConnOpen(icpOutgoingConn) && icpIncomingConn != icpOutgoingConn) {
293 fds[nfds] = icpOutgoingConn->fd;
294 ++nfds;
295 }
296
297 if (nfds == 0)
298 return;
299
300 nevents = comm_check_incoming_select_handlers(nfds, fds);
301
302 incoming_udp_interval += Config.comm_incoming.udp.average - nevents;
303
304 if (incoming_udp_interval < 0)
305 incoming_udp_interval = 0;
306
307 if (incoming_udp_interval > MAX_INCOMING_INTERVAL)
308 incoming_udp_interval = MAX_INCOMING_INTERVAL;
309
310 if (nevents > INCOMING_UDP_MAX)
311 nevents = INCOMING_UDP_MAX;
312
313 statCounter.comm_udp_incoming.count(nevents);
314 }
315
316 static void
317 comm_select_tcp_incoming(void)
318 {
319 int nfds = 0;
320 int fds[MAXTCPLISTENPORTS];
321 int nevents;
322 tcp_io_events = 0;
323
324 // XXX: only poll sockets that won't be deferred. But how do we identify them?
325
326 for (const AnyP::PortCfg *s = Config.Sockaddr.http; s; s = s->next) {
327 if (Comm::IsConnOpen(s->listenConn)) {
328 fds[nfds] = s->listenConn->fd;
329 ++nfds;
330 }
331 }
332
333 nevents = comm_check_incoming_select_handlers(nfds, fds);
334 incoming_tcp_interval += Config.comm_incoming.tcp.average - nevents;
335
336 if (incoming_tcp_interval < 0)
337 incoming_tcp_interval = 0;
338
339 if (incoming_tcp_interval > MAX_INCOMING_INTERVAL)
340 incoming_tcp_interval = MAX_INCOMING_INTERVAL;
341
342 if (nevents > INCOMING_TCP_MAX)
343 nevents = INCOMING_TCP_MAX;
344
345 statCounter.comm_tcp_incoming.count(nevents);
346 }
347
348 #define DEBUG_FDBITS 0
349 /* Select on all sockets; call handlers for those that are ready. */
350 comm_err_t
351 Comm::DoSelect(int msec)
352 {
353 fd_set readfds;
354 fd_set pendingfds;
355 fd_set writefds;
356
357 PF *hdl = NULL;
358 int fd;
359 int maxfd;
360 int num;
361 int pending;
362 int calldns = 0, calludp = 0, calltcp = 0;
363 int maxindex;
364 unsigned int k;
365 int j;
366 #if DEBUG_FDBITS
367
368 int i;
369 #endif
370
371 fd_mask *fdsp;
372 fd_mask *pfdsp;
373 fd_mask tmask;
374
375 struct timeval poll_time;
376 double timeout = current_dtime + (msec / 1000.0);
377 fde *F;
378
379 do {
380 double start;
381 getCurrentTime();
382 start = current_dtime;
383
384 if (commCheckUdpIncoming)
385 comm_select_udp_incoming();
386
387 if (commCheckDnsIncoming)
388 comm_select_dns_incoming();
389
390 if (commCheckTcpIncoming)
391 comm_select_tcp_incoming();
392
393 calldns = calludp = calltcp = 0;
394
395 maxfd = Biggest_FD + 1;
396
397 memcpy(&readfds, &global_readfds,
398 howmany(maxfd, FD_MASK_BITS) * FD_MASK_BYTES);
399
400 memcpy(&writefds, &global_writefds,
401 howmany(maxfd, FD_MASK_BITS) * FD_MASK_BYTES);
402
403 /* remove stalled FDs, and deal with pending descriptors */
404 pending = 0;
405
406 FD_ZERO(&pendingfds);
407
408 maxindex = howmany(maxfd, FD_MASK_BITS);
409
410 fdsp = (fd_mask *) & readfds;
411
412 for (j = 0; j < maxindex; ++j) {
413 if ((tmask = fdsp[j]) == 0)
414 continue; /* no bits here */
415
416 for (k = 0; k < FD_MASK_BITS; ++k) {
417 if (!EBIT_TEST(tmask, k))
418 continue;
419
420 /* Found a set bit */
421 fd = (j * FD_MASK_BITS) + k;
422
423 if (FD_ISSET(fd, &readfds) && fd_table[fd].flags.read_pending) {
424 FD_SET(fd, &pendingfds);
425 ++pending;
426 }
427 }
428 }
429
430 #if DEBUG_FDBITS
431 for (i = 0; i < maxfd; ++i) {
432 /* Check each open socket for a handler. */
433
434 if (fd_table[i].read_handler) {
435 assert(FD_ISSET(i, &readfds));
436 }
437
438 if (fd_table[i].write_handler) {
439 assert(FD_ISSET(i, &writefds));
440 }
441 }
442
443 #endif
444 if (nreadfds + nwritefds == 0) {
445 assert(shutting_down);
446 return COMM_SHUTDOWN;
447 }
448
449 if (msec > MAX_POLL_TIME)
450 msec = MAX_POLL_TIME;
451
452 if (pending)
453 msec = 0;
454
455 for (;;) {
456 poll_time.tv_sec = msec / 1000;
457 poll_time.tv_usec = (msec % 1000) * 1000;
458 ++ statCounter.syscalls.selects;
459 num = select(maxfd, &readfds, &writefds, NULL, &poll_time);
460 ++ statCounter.select_loops;
461
462 if (num >= 0 || pending > 0)
463 break;
464
465 if (ignoreErrno(errno))
466 break;
467
468 debugs(5, DBG_CRITICAL, "comm_select: select failure: " << xstrerror());
469
470 examine_select(&readfds, &writefds);
471
472 return COMM_ERROR;
473
474 /* NOTREACHED */
475 }
476
477 if (num < 0 && !pending)
478 continue;
479
480 getCurrentTime();
481
482 debugs(5, num ? 5 : 8, "comm_select: " << num << "+" << pending << " FDs ready");
483
484 statCounter.select_fds_hist.count(num);
485
486 if (num == 0 && pending == 0)
487 continue;
488
489 /* Scan return fd masks for ready descriptors */
490 fdsp = (fd_mask *) & readfds;
491
492 pfdsp = (fd_mask *) & pendingfds;
493
494 maxindex = howmany(maxfd, FD_MASK_BITS);
495
496 for (j = 0; j < maxindex; ++j) {
497 if ((tmask = (fdsp[j] | pfdsp[j])) == 0)
498 continue; /* no bits here */
499
500 for (k = 0; k < FD_MASK_BITS; ++k) {
501 if (tmask == 0)
502 break; /* no more bits left */
503
504 if (!EBIT_TEST(tmask, k))
505 continue;
506
507 /* Found a set bit */
508 fd = (j * FD_MASK_BITS) + k;
509
510 EBIT_CLR(tmask, k); /* this will be done */
511
512 #if DEBUG_FDBITS
513
514 debugs(5, 9, "FD " << fd << " bit set for reading");
515
516 assert(FD_ISSET(fd, &readfds));
517
518 #endif
519
520 if (fdIsUdpListener(fd)) {
521 calludp = 1;
522 continue;
523 }
524
525 if (fdIsDns(fd)) {
526 calldns = 1;
527 continue;
528 }
529
530 if (fdIsTcpListener(fd)) {
531 calltcp = 1;
532 continue;
533 }
534
535 F = &fd_table[fd];
536 debugs(5, 6, "comm_select: FD " << fd << " ready for reading");
537
538 if (NULL == (hdl = F->read_handler))
539 (void) 0;
540 else {
541 F->read_handler = NULL;
542 F->flags.read_pending = 0;
543 commUpdateReadBits(fd, NULL);
544 hdl(fd, F->read_data);
545 ++ statCounter.select_fds;
546
547 if (commCheckUdpIncoming)
548 comm_select_udp_incoming();
549
550 if (commCheckDnsIncoming)
551 comm_select_dns_incoming();
552
553 if (commCheckTcpIncoming)
554 comm_select_tcp_incoming();
555 }
556 }
557 }
558
559 fdsp = (fd_mask *) & writefds;
560
561 for (j = 0; j < maxindex; ++j) {
562 if ((tmask = fdsp[j]) == 0)
563 continue; /* no bits here */
564
565 for (k = 0; k < FD_MASK_BITS; ++k) {
566 if (tmask == 0)
567 break; /* no more bits left */
568
569 if (!EBIT_TEST(tmask, k))
570 continue;
571
572 /* Found a set bit */
573 fd = (j * FD_MASK_BITS) + k;
574
575 EBIT_CLR(tmask, k); /* this will be done */
576
577 #if DEBUG_FDBITS
578
579 debugs(5, 9, "FD " << fd << " bit set for writing");
580
581 assert(FD_ISSET(fd, &writefds));
582
583 #endif
584
585 if (fdIsUdpListener(fd)) {
586 calludp = 1;
587 continue;
588 }
589
590 if (fdIsDns(fd)) {
591 calldns = 1;
592 continue;
593 }
594
595 if (fdIsTcpListener(fd)) {
596 calltcp = 1;
597 continue;
598 }
599
600 F = &fd_table[fd];
601 debugs(5, 6, "comm_select: FD " << fd << " ready for writing");
602
603 if ((hdl = F->write_handler)) {
604 F->write_handler = NULL;
605 commUpdateWriteBits(fd, NULL);
606 hdl(fd, F->write_data);
607 ++ statCounter.select_fds;
608
609 if (commCheckUdpIncoming)
610 comm_select_udp_incoming();
611
612 if (commCheckDnsIncoming)
613 comm_select_dns_incoming();
614
615 if (commCheckTcpIncoming)
616 comm_select_tcp_incoming();
617 }
618 }
619 }
620
621 if (calludp)
622 comm_select_udp_incoming();
623
624 if (calldns)
625 comm_select_dns_incoming();
626
627 if (calltcp)
628 comm_select_tcp_incoming();
629
630 getCurrentTime();
631
632 statCounter.select_time += (current_dtime - start);
633
634 return COMM_OK;
635 } while (timeout > current_dtime);
636 debugs(5, 8, "comm_select: time out: " << squid_curtime);
637
638 return COMM_TIMEOUT;
639 }
640
641 static void
642 comm_select_dns_incoming(void)
643 {
644 int nfds = 0;
645 int fds[3];
646 int nevents;
647 dns_io_events = 0;
648
649 if (DnsSocketA < 0 && DnsSocketB < 0)
650 return;
651
652 if (DnsSocketA >= 0) {
653 fds[nfds] = DnsSocketA;
654 ++nfds;
655 }
656
657 if (DnsSocketB >= 0) {
658 fds[nfds] = DnsSocketB;
659 ++nfds;
660 }
661
662 nevents = comm_check_incoming_select_handlers(nfds, fds);
663
664 if (nevents < 0)
665 return;
666
667 incoming_dns_interval += Config.comm_incoming.dns.average - nevents;
668
669 if (incoming_dns_interval < Config.comm_incoming.dns.min_poll)
670 incoming_dns_interval = Config.comm_incoming.dns.min_poll;
671
672 if (incoming_dns_interval > MAX_INCOMING_INTERVAL)
673 incoming_dns_interval = MAX_INCOMING_INTERVAL;
674
675 if (nevents > INCOMING_DNS_MAX)
676 nevents = INCOMING_DNS_MAX;
677
678 statCounter.comm_dns_incoming.count(nevents);
679 }
680
681 void
682 Comm::SelectLoopInit(void)
683 {
684 zero_tv.tv_sec = 0;
685 zero_tv.tv_usec = 0;
686 FD_ZERO(&global_readfds);
687 FD_ZERO(&global_writefds);
688 nreadfds = nwritefds = 0;
689
690 Mgr::RegisterAction("comm_select_incoming",
691 "comm_incoming() stats",
692 commIncomingStats, 0, 1);
693 }
694
695 /*
696 * examine_select - debug routine.
697 *
698 * I spend the day chasing this core dump that occurs when both the client
699 * and the server side of a cache fetch simultaneoulsy abort the
700 * connection. While I haven't really studied the code to figure out how
701 * it happens, the snippet below may prevent the cache from exitting:
702 *
703 * Call this from where the select loop fails.
704 */
705 static int
706 examine_select(fd_set * readfds, fd_set * writefds)
707 {
708 int fd = 0;
709 fd_set read_x;
710 fd_set write_x;
711
712 struct timeval tv;
713 AsyncCall::Pointer ch = NULL;
714 fde *F = NULL;
715
716 struct stat sb;
717 debugs(5, DBG_CRITICAL, "examine_select: Examining open file descriptors...");
718
719 for (fd = 0; fd < Squid_MaxFD; ++fd) {
720 FD_ZERO(&read_x);
721 FD_ZERO(&write_x);
722 tv.tv_sec = tv.tv_usec = 0;
723
724 if (FD_ISSET(fd, readfds))
725 FD_SET(fd, &read_x);
726 else if (FD_ISSET(fd, writefds))
727 FD_SET(fd, &write_x);
728 else
729 continue;
730
731 ++ statCounter.syscalls.selects;
732 errno = 0;
733
734 if (!fstat(fd, &sb)) {
735 debugs(5, 5, "FD " << fd << " is valid.");
736 continue;
737 }
738
739 F = &fd_table[fd];
740 debugs(5, DBG_CRITICAL, "FD " << fd << ": " << xstrerror());
741 debugs(5, DBG_CRITICAL, "WARNING: FD " << fd << " has handlers, but it's invalid.");
742 debugs(5, DBG_CRITICAL, "FD " << fd << " is a " << fdTypeStr[F->type] << " called '" << F->desc << "'");
743 debugs(5, DBG_CRITICAL, "tmout:" << F->timeoutHandler << " read:" << F->read_handler << " write:" << F->write_handler);
744
745 for (ch = F->closeHandler; ch != NULL; ch = ch->Next())
746 debugs(5, DBG_CRITICAL, " close handler: " << ch);
747
748 if (F->closeHandler != NULL) {
749 commCallCloseHandlers(fd);
750 } else if (F->timeoutHandler != NULL) {
751 debugs(5, DBG_CRITICAL, "examine_select: Calling Timeout Handler");
752 ScheduleCallHere(F->timeoutHandler);
753 }
754
755 F->closeHandler = NULL;
756 F->timeoutHandler = NULL;
757 F->read_handler = NULL;
758 F->write_handler = NULL;
759 FD_CLR(fd, readfds);
760 FD_CLR(fd, writefds);
761 }
762
763 return 0;
764 }
765
766 static void
767 commIncomingStats(StoreEntry * sentry)
768 {
769 storeAppendPrintf(sentry, "Current incoming_udp_interval: %d\n",
770 incoming_udp_interval >> INCOMING_FACTOR);
771 storeAppendPrintf(sentry, "Current incoming_dns_interval: %d\n",
772 incoming_dns_interval >> INCOMING_FACTOR);
773 storeAppendPrintf(sentry, "Current incoming_tcp_interval: %d\n",
774 incoming_tcp_interval >> INCOMING_FACTOR);
775 storeAppendPrintf(sentry, "\n");
776 storeAppendPrintf(sentry, "Histogram of events per incoming socket type\n");
777 storeAppendPrintf(sentry, "ICP Messages handled per comm_select_udp_incoming() call:\n");
778 statCounter.comm_udp_incoming.dump(sentry, statHistIntDumper);
779 storeAppendPrintf(sentry, "DNS Messages handled per comm_select_dns_incoming() call:\n");
780 statCounter.comm_dns_incoming.dump(sentry, statHistIntDumper);
781 storeAppendPrintf(sentry, "HTTP Messages handled per comm_select_tcp_incoming() call:\n");
782 statCounter.comm_tcp_incoming.dump(sentry, statHistIntDumper);
783 }
784
785 void
786 commUpdateReadBits(int fd, PF * handler)
787 {
788 if (handler && !FD_ISSET(fd, &global_readfds)) {
789 FD_SET(fd, &global_readfds);
790 ++nreadfds;
791 } else if (!handler && FD_ISSET(fd, &global_readfds)) {
792 FD_CLR(fd, &global_readfds);
793 --nreadfds;
794 }
795 }
796
797 void
798 commUpdateWriteBits(int fd, PF * handler)
799 {
800 if (handler && !FD_ISSET(fd, &global_writefds)) {
801 FD_SET(fd, &global_writefds);
802 ++nwritefds;
803 } else if (!handler && FD_ISSET(fd, &global_writefds)) {
804 FD_CLR(fd, &global_writefds);
805 --nwritefds;
806 }
807 }
808
809 /* Called by async-io or diskd to speed up the polling */
810 void
811 Comm::QuickPollRequired(void)
812 {
813 MAX_POLL_TIME = 10;
814 }
815
816 #endif /* USE_SELECT */