mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
DNS_Mgr: Remove usage of ares_getsock from Lookup
This commit is contained in:
parent
6739fca645
commit
d95057d618
1 changed files with 20 additions and 16 deletions
|
@ -887,30 +887,34 @@ void DNS_Mgr::Lookup(const std::string& name, int request_type, LookupCallback*
|
||||||
void DNS_Mgr::Resolve() {
|
void DNS_Mgr::Resolve() {
|
||||||
int nfds = 0;
|
int nfds = 0;
|
||||||
struct timeval *tvp, tv;
|
struct timeval *tvp, tv;
|
||||||
struct pollfd pollfds[ARES_GETSOCK_MAXNUM];
|
struct pollfd pollfds[1024];
|
||||||
ares_socket_t socks[ARES_GETSOCK_MAXNUM];
|
|
||||||
|
|
||||||
tv.tv_sec = DNS_TIMEOUT;
|
tv.tv_sec = DNS_TIMEOUT;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
for ( int i = 0; i < MAX_PENDING_REQUESTS; i++ ) {
|
for ( int i = 0; i < MAX_PENDING_REQUESTS; i++ ) {
|
||||||
int nfds = 0;
|
if ( socket_fds.empty() && write_socket_fds.empty() )
|
||||||
int bitmap = ares_getsock(channel, socks, ARES_GETSOCK_MAXNUM);
|
break;
|
||||||
|
|
||||||
for ( int i = 0; i < ARES_GETSOCK_MAXNUM; i++ ) {
|
memset(pollfds, 0, sizeof(pollfd) * 1024);
|
||||||
bool rd = ARES_GETSOCK_READABLE(bitmap, i);
|
|
||||||
bool wr = ARES_GETSOCK_WRITABLE(bitmap, i);
|
for ( int fd : socket_fds ) {
|
||||||
if ( rd || wr ) {
|
if ( nfds == 1024 )
|
||||||
pollfds[nfds].fd = socks[i];
|
break;
|
||||||
pollfds[nfds].events = rd ? POLLIN : 0;
|
|
||||||
pollfds[nfds].events |= wr ? POLLOUT : 0;
|
pollfds[nfds].fd = fd;
|
||||||
++nfds;
|
pollfds[nfds].events = POLLIN;
|
||||||
}
|
++nfds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we have any sockets that are read or writable?
|
for ( int fd : write_socket_fds ) {
|
||||||
if ( nfds == 0 )
|
if ( nfds == 1024 )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
pollfds[nfds].fd = fd;
|
||||||
|
pollfds[nfds].events = POLLIN | POLLOUT;
|
||||||
|
++nfds;
|
||||||
|
}
|
||||||
|
|
||||||
// poll() timeout is in milliseconds.
|
// poll() timeout is in milliseconds.
|
||||||
tvp = ares_timeout(channel, &tv, &tv);
|
tvp = ares_timeout(channel, &tv, &tv);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue