/** Read the response from an outbound uping. * @param[in] pptr UPing to check. */ void uping_read(struct UPing* pptr) { struct irc_sockaddr sin; struct timeval tv; unsigned int len; unsigned int pingtime; char* s; char buf[BUFSIZE + 1]; IOResult ior; assert(0 != pptr); gettimeofday(&tv, NULL); ior = os_recvfrom_nonb(pptr->fd, buf, BUFSIZE, &len, &sin); if (IO_BLOCKED == ior) return; else if (IO_FAILURE == ior) { const char* msg = strerror(errno); if (!msg) msg = "Unknown error"; sendcmdto_one(&me, CMD_NOTICE, pptr->client, "%C :UPING: receive error: " "%s", pptr->client, msg); uping_end(pptr); return; } if (len < 19) return; /* Broken packet */ ++pptr->received; buf[len] = 0; pingtime = (tv.tv_sec - atol(&buf[1])) * 1000 + (tv.tv_usec - atol(buf + strlen(buf) + 1)) / 1000; pptr->ms_ave += pingtime; if (!pptr->ms_min || pptr->ms_min > pingtime) pptr->ms_min = pingtime; if (pingtime > pptr->ms_max) pptr->ms_max = pingtime; timer_chg(&pptr->killer, TT_RELATIVE, UPINGTIMEOUT); s = pptr->buf + strlen(pptr->buf); sprintf(s, " %u", pingtime); if (pptr->received == pptr->count) uping_end(pptr); return; }
/** Make sure that a timeout event will happen by the given time. * @param[in] when Latest time for timeout to run. */ static void check_resolver_timeout(time_t when) { if (when > CurrentTime + AR_TTL) when = CurrentTime + AR_TTL; /* TODO after 2.10.12: Rewrite the timer API because there should be * no need for clients to know this kind of implementation detail. */ if (when > t_expire(&res_timeout)) /* do nothing */; else if (t_onqueue(&res_timeout) && !(res_timeout.t_header.gh_flags & GEN_MARKED)) timer_chg(&res_timeout, TT_ABSOLUTE, when); else timer_add(&res_timeout, timeout_resolver, NULL, TT_ABSOLUTE, when); }