aboutsummaryrefslogtreecommitdiff
path: root/ares
diff options
context:
space:
mode:
authorSteinar H. Gunderson <sesse@google.com>2007-09-29 19:26:59 +0000
committerSteinar H. Gunderson <sesse@google.com>2007-09-29 19:26:59 +0000
commit2694b970e87c06462bf83e8d98ade7c90d7b52a3 (patch)
tree521ee4bda7da56c1e14aca40c129fe89b552e5be /ares
parent23f5d145ec69e2a8b62e75cc49b591fef04ca48d (diff)
Port the TCP socket fix made in ares_fds() to ares_getsock() as well.
Diffstat (limited to 'ares')
-rw-r--r--ares/ares_getsock.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/ares/ares_getsock.c b/ares/ares_getsock.c
index 99419aee2..38b8fefac 100644
--- a/ares/ares_getsock.c
+++ b/ares/ares_getsock.c
@@ -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);