summaryrefslogtreecommitdiff
path: root/ares_getsock.c
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
commitff7137ad74295d4110a47a1b2e9877760ffe6495 (patch)
tree1d30ebf8ea418b477d347659bc8b520aed45a673 /ares_getsock.c
parent04e49e09dcfac29e7e90b5546672a9b42d0b935a (diff)
downloadc-ares-ff7137ad74295d4110a47a1b2e9877760ffe6495.tar.gz
c-ares-ff7137ad74295d4110a47a1b2e9877760ffe6495.tar.bz2
c-ares-ff7137ad74295d4110a47a1b2e9877760ffe6495.zip
Port the TCP socket fix made in ares_fds() to ares_getsock() as well.
Diffstat (limited to 'ares_getsock.c')
-rw-r--r--ares_getsock.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/ares_getsock.c b/ares_getsock.c
index 99419ae..38b8fef 100644
--- a/ares_getsock.c
+++ b/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);