Port the TCP socket fix made in ares_fds() to ares_getsock() as well.

This commit is contained in:
Steinar H. Gunderson 2007-09-29 19:26:59 +00:00
parent 23f5d145ec
commit 2694b970e8
1 changed files with 11 additions and 5 deletions

View File

@ -34,16 +34,18 @@ int ares_getsock(ares_channel channel,
ares_socket_t *socks = (ares_socket_t *)s;
/* No queries, no file descriptors. */
if (ares__is_list_empty(&(channel->all_queries)))
return 0;
/* Are there any active queries? */
int active_queries = !ares__is_list_empty(&(channel->all_queries));
for (i = 0;
(i < channel->nservers) && (sockindex < ARES_GETSOCK_MAXNUM);
i++)
{
server = &channel->servers[i];
if (server->udp_socket != ARES_SOCKET_BAD)
/* We only need to register interest in UDP sockets if we have
* outstanding queries.
*/
if (active_queries && server->udp_socket != ARES_SOCKET_BAD)
{
if(sockindex >= numsocks)
break;
@ -51,6 +53,10 @@ int ares_getsock(ares_channel channel,
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
sockindex++;
}
/* We always register for TCP events, because we want to know
* when the other side closes the connection, so we don't waste
* time trying to use a broken connection.
*/
if (server->tcp_socket != ARES_SOCKET_BAD)
{
if(sockindex >= numsocks)
@ -58,7 +64,7 @@ int ares_getsock(ares_channel channel,
socks[sockindex] = server->tcp_socket;
bitmap |= ARES_GETSOCK_READABLE(setbits, sockindex);
if (server->qhead)
if (server->qhead && active_queries)
/* then the tcp socket is also writable! */
bitmap |= ARES_GETSOCK_WRITABLE(setbits, sockindex);