summaryrefslogtreecommitdiff
path: root/ares_process.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2007-09-22 21:23:10 +0000
committerDaniel Stenberg <daniel@haxx.se>2007-09-22 21:23:10 +0000
commitb17bb1bb67ad2ff42cc99d1d434df5c26b1e37fb (patch)
tree00290a46ec15c26502d6cb7388f712ae4d3ff5e1 /ares_process.c
parenteee17fc8548ca3a399df9994e3937c674b9c197c (diff)
downloadc-ares-b17bb1bb67ad2ff42cc99d1d434df5c26b1e37fb.tar.gz
c-ares-b17bb1bb67ad2ff42cc99d1d434df5c26b1e37fb.tar.bz2
c-ares-b17bb1bb67ad2ff42cc99d1d434df5c26b1e37fb.zip
Steinar H. Gunderson fixed: Correctly clear sockets from the fd_set on in
several functions (write_tcp_data, read_tcp_data, read_udp_packets) so that if it fails and the socket is closed the following code doesn't try to use the file descriptor.
Diffstat (limited to 'ares_process.c')
-rw-r--r--ares_process.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ares_process.c b/ares_process.c
index 66007f0..082fb4d 100644
--- a/ares_process.c
+++ b/ares_process.c
@@ -167,6 +167,13 @@ static void write_tcp_data(ares_channel channel,
continue;
}
+ /* If there's an error and we close this socket, then open
+ * another with the same fd to talk to another server, then we
+ * don't want to think that it was the new socket that was
+ * ready. This is not disastrous, but is likely to result in
+ * extra system calls and confusion. */
+ FD_CLR(server->tcp_socket, write_fds);
+
/* Count the number of send queue items. */
n = 0;
for (sendreq = server->qhead; sendreq; sendreq = sendreq->next)
@@ -280,6 +287,13 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds,
continue;
}
+ /* If there's an error and we close this socket, then open
+ * another with the same fd to talk to another server, then we
+ * don't want to think that it was the new socket that was
+ * ready. This is not disastrous, but is likely to result in
+ * extra system calls and confusion. */
+ FD_CLR(server->tcp_socket, read_fds);
+
if (server->tcp_lenbuf_pos != 2)
{
/* We haven't yet read a length word, so read that (or
@@ -370,6 +384,13 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
continue;
}
+ /* If there's an error and we close this socket, then open
+ * another with the same fd to talk to another server, then we
+ * don't want to think that it was the new socket that was
+ * ready. This is not disastrous, but is likely to result in
+ * extra system calls and confusion. */
+ FD_CLR(server->udp_socket, read_fds);
+
count = sread(server->udp_socket, buf, sizeof(buf));
if (count == -1 && try_again(SOCKERRNO))
continue;