DNS_Mgr: Remove usage of ares_getsock from GetNextTimeout

This commit is contained in:
Tim Wojtulewicz 2024-08-30 10:24:45 -07:00
parent 16474ed77f
commit 6739fca645

View file

@ -1315,23 +1315,19 @@ double DNS_Mgr::GetNextTimeout() {
if ( asyncs_pending == 0 ) if ( asyncs_pending == 0 )
return -1; return -1;
int nfds = 0; struct timeval tv;
ares_socket_t socks[ARES_GETSOCK_MAXNUM]; struct timeval* tvp = ares_timeout(channel, NULL, &tv);
int bitmap = ares_getsock(channel, socks, ARES_GETSOCK_MAXNUM);
for ( int i = 0; i < ARES_GETSOCK_MAXNUM; i++ ) {
if ( ARES_GETSOCK_READABLE(bitmap, i) || ARES_GETSOCK_WRITABLE(bitmap, i) )
++nfds;
}
// Do we have any sockets that are read or writable? // If you pass NULL as the max time argument to ares_timeout, it will return null if there
if ( nfds == 0 ) // isn't anything waiting to be processed.
if ( ! tvp )
return -1; return -1;
struct timeval tv; // Clamp the timeout to our desired max, since we passed NULl to ares_timeout.
tv.tv_sec = DNS_TIMEOUT; if ( tvp->tv_sec > DNS_TIMEOUT ) {
tv.tv_usec = 0; tvp->tv_sec = DNS_TIMEOUT;
tvp->tv_usec = 0;
struct timeval* tvp = ares_timeout(channel, &tv, &tv); }
return static_cast<double>(tvp->tv_sec) + (static_cast<double>(tvp->tv_usec) / 1e6); return static_cast<double>(tvp->tv_sec) + (static_cast<double>(tvp->tv_usec) / 1e6);
} }