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