aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2008-10-21 01:58:23 +0000
committerYang Tse <yangsita@gmail.com>2008-10-21 01:58:23 +0000
commit3f2de3d1019140571a59c04249de085a318f9266 (patch)
tree86f6d26884d1c9101358710a84f45947a2a533e4
parent6bd91936ff9d525d3e1dee8f6d97d887072cb480 (diff)
Charles Hardin patch:
- handles the EINPROGRESS for UDP connects - uses closesocket instead of close on some paths that were noticed
-rw-r--r--ares/CHANGES3
-rw-r--r--ares/ares_process.c29
2 files changed, 21 insertions, 11 deletions
diff --git a/ares/CHANGES b/ares/CHANGES
index c64ad799e..dd9bac6c9 100644
--- a/ares/CHANGES
+++ b/ares/CHANGES
@@ -1,5 +1,8 @@
Changelog for the c-ares project
+* Oct 21 2008 (Yang Tse)
+ Charles Hardin added handling of EINPROGRESS for UDP connects.
+
* Oct 18 2008 (Daniel Stenberg)
Charles Hardin made adig support a regular numerical dotted IP address for the
-s option as well.
diff --git a/ares/ares_process.c b/ares/ares_process.c
index 798df7a21..675af489d 100644
--- a/ares/ares_process.c
+++ b/ares/ares_process.c
@@ -906,7 +906,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
/* Configure it. */
if (configure_socket(s, channel) < 0)
{
- close(s);
+ closesocket(s);
return -1;
}
@@ -920,7 +920,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
(void *)&opt, sizeof(opt)) == -1)
{
- close(s);
+ closesocket(s);
return -1;
}
@@ -929,14 +929,16 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
sockin.sin_family = AF_INET;
sockin.sin_addr = server->addr;
sockin.sin_port = (unsigned short)(channel->tcp_port & 0xffff);
- if (connect(s, (struct sockaddr *) &sockin, sizeof(sockin)) == -1) {
- int err = SOCKERRNO;
+ if (connect(s, (struct sockaddr *) &sockin, sizeof(sockin)) == -1)
+ {
+ int err = SOCKERRNO;
- if (err != EINPROGRESS && err != EWOULDBLOCK) {
- closesocket(s);
- return -1;
+ if (err != EINPROGRESS && err != EWOULDBLOCK)
+ {
+ closesocket(s);
+ return -1;
+ }
}
- }
SOCK_STATE_CALLBACK(channel, s, 1, 0);
server->tcp_buffer_pos = 0;
@@ -958,7 +960,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
/* Set the socket non-blocking. */
if (configure_socket(s, channel) < 0)
{
- close(s);
+ closesocket(s);
return -1;
}
@@ -969,8 +971,13 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
sockin.sin_port = (unsigned short)(channel->udp_port & 0xffff);
if (connect(s, (struct sockaddr *) &sockin, sizeof(sockin)) == -1)
{
- closesocket(s);
- return -1;
+ int err = SOCKERRNO;
+
+ if (err != EINPROGRESS && err != EWOULDBLOCK)
+ {
+ closesocket(s);
+ return -1;
+ }
}
SOCK_STATE_CALLBACK(channel, s, 1, 0);