- if (IsPing(cptr))
- {
- ping++;
- Debug((DEBUG_NOTICE, "open ping on %p %d", cptr, i));
- if (!cptr->firsttime || now <= cptr->firsttime)
- {
- RFD_SET(i, &read_set, currfd_index, cptr);
- delay2 = 1;
- if (DoPing(cptr) && now > cptr->lasttime)
- RWFD_SET(i, &write_set, currfd_index);
- }
- else
- {
- del_queries((char *)cptr);
- end_ping(cptr);
- }
-#ifdef USE_POLL
- if (added)
- currfd_index++;
-#endif /* USE_POLL */
- continue;
- }
- if (DoingDNS(cptr) || DoingAuth(cptr))
- {
-#ifdef USE_POLL
- if (added)
- currfd_index++;
-#endif /* USE_POLL */
- continue;
- }
- if (IsMe(cptr) && IsListening(cptr))
- RFD_SET(i, &read_set, currfd_index, cptr);
- else if (!IsMe(cptr))
- {
- if (DBufLength(&cptr->recvQ) && delay2 > 2)
- delay2 = 1;
- if (DBufLength(&cptr->recvQ) < 4088)
- RFD_SET(i, &read_set, currfd_index, cptr);
- if (DBufLength(&cptr->sendQ) || IsConnecting(cptr) ||
- (cptr->listing && DBufLength(&cptr->sendQ) < 2048))
-#ifndef pyr
- WFD_SET(i, &write_set, currfd_index, cptr);
-#else /* pyr */
- {
- if (!(cptr->flags & FLAGS_BLOCKED))
- WFD_SET(i, &write_set, currfd_index, cptr);
- else
- delay2 = 0, usec = 500000;
- }
- if (now - cptr->lw.tv_sec && nowt.tv_usec - cptr->lw.tv_usec < 0)
- us = 1000000;
- else
- us = 0;
- us += nowt.tv_usec;
- if (us - cptr->lw.tv_usec > 500000)
- cptr->flags &= ~FLAGS_BLOCKED;
-#endif /* pyr */
- }
-#ifdef USE_POLL
- if (added)
- currfd_index++;
-#endif /* USE_POLL */
- }
-
- if (udpfd >= 0)
- {
- RFD_SET(udpfd, &read_set, currfd_index, NULL);
-#ifdef USE_POLL
- udpfdindex = currfd_index;
- currfd_index++;
-#endif /* USE_POLL */
- }
- if (resfd >= 0)
- {
- RFD_SET(resfd, &read_set, currfd_index, NULL);
-#ifdef USE_POLL
- resfdindex = currfd_index;
- currfd_index++;
-#endif /* USE_POLL */
- }
-
- wait.tv_sec = MIN(delay2, delay);
- wait.tv_usec = usec;
-#ifndef USE_POLL
-#ifdef HPUX
- nfds = select(FD_SETSIZE, (int *)&read_set, (int *)&write_set, 0, &wait);
-#else
- nfds = select(FD_SETSIZE, &read_set, &write_set, 0, &wait);
-#endif
-#else /* USE_POLL */
- timeout = (wait.tv_sec * 1000) + (wait.tv_usec / 1000);
- nfds = poll(poll_fds, currfd_index, timeout);
-#endif /* USE_POLL */
- now = time(NULL);
- if (nfds == -1 && errno == EINTR)
- return -1;
- else if (nfds >= 0)
- break;
- report_error("select %s: %s", &me);
- res++;
- if (res > 5)
- restart("too many select errors");
- sleep(10);
- now += 10;
- }
-
- if (udpfd >= 0 && RFD_ISSET(udpfd, &read_set, udpfdindex))
- {
- polludp();
- nfds--;
- RFD_CLR_OUT(udpfd, &read_set, udpfdindex);
- }
- /*
- * Check fd sets for the ping fd's (if set and valid!) first
- * because these can not be processed using the normal loops below.
- * And we want them to be as fast as possible.
- * -Run
- */
- for (i = HIGHEST_INDEX; (ping > 0) && (i >= 0); i--)
- {
- if (!(cptr = LOC_CLIENTS(i)))
- continue;
- if (!IsPing(cptr))
- continue;
- ping--;
- if ((nfds > 0) && RFD_ISSET(cptr->fd, &read_set, i))
- {
- nfds--;
- RFD_CLR_OUT(cptr->fd, &read_set, i);
- read_ping(cptr); /* This can RunFree(cptr) ! */
- }
- else if ((nfds > 0) && WFD_ISSET(cptr->fd, &write_set, i))
- {
- nfds--;
- cptr->lasttime = now;
- WFD_CLR_OUT(cptr->fd, &write_set, i);
- send_ping(cptr); /* This can RunFree(cptr) ! */
- }
- }
- if (resfd >= 0 && RFD_ISSET(resfd, &read_set, resfdindex))
- {
- do_dns_async();
- nfds--;
- RFD_CLR_OUT(resfd, &read_set, resfdindex);
- }
- /*
- * Check fd sets for the auth fd's (if set and valid!) first
- * because these can not be processed using the normal loops below.
- * -avalon
- */
- for (i = HIGHEST_INDEX; (auth > 0) && (i >= 0); i--)
- {
- if (!(cptr = LOC_CLIENTS(i)))
- continue;
- if (cptr->authfd < 0)
- continue;
- auth--;
- if ((nfds > 0) && WFD_ISSET(cptr->authfd, &write_set, i))
- {
- nfds--;
- send_authports(cptr);
- }
- else if ((nfds > 0) && RFD_ISSET(cptr->authfd, &read_set, i))
- {
- nfds--;
- read_authports(cptr);
- }
- }
- for (i = HIGHEST_INDEX; i >= 0; i--)
- if ((cptr = LOC_CLIENTS(i)) && RFD_ISSET(i, &read_set, i) &&
- IsListening(cptr))
- {
- RFD_CLR_OUT(i, &read_set, i);
- nfds--;
- cptr->lasttime = now;