diff options
Diffstat (limited to 'src/wsocket.c')
-rw-r--r-- | src/wsocket.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/wsocket.c b/src/wsocket.c index f33e154..fcd2fff 100644 --- a/src/wsocket.c +++ b/src/wsocket.c | |||
@@ -75,12 +75,10 @@ void sock_shutdown(p_sock ps, int how) | |||
75 | \*-------------------------------------------------------------------------*/ | 75 | \*-------------------------------------------------------------------------*/ |
76 | const char *sock_create(p_sock ps, int domain, int type, int protocol) | 76 | const char *sock_create(p_sock ps, int domain, int type, int protocol) |
77 | { | 77 | { |
78 | int val = 1; | ||
79 | t_sock sock = socket(domain, type, protocol); | 78 | t_sock sock = socket(domain, type, protocol); |
80 | if (sock == SOCK_INVALID) | 79 | if (sock == SOCK_INVALID) |
81 | return sock_createstrerror(WSAGetLastError()); | 80 | return sock_createstrerror(WSAGetLastError()); |
82 | *ps = sock; | 81 | *ps = sock; |
83 | setsockopt(*ps, SOL_SOCKET, SO_REUSEADDR, (char *) &val, sizeof(val)); | ||
84 | sock_setnonblocking(ps); | 82 | sock_setnonblocking(ps); |
85 | return NULL; | 83 | return NULL; |
86 | } | 84 | } |
@@ -112,8 +110,12 @@ const char *sock_connect(p_sock ps, SA *addr, socklen_t addr_len, p_tm tm) | |||
112 | /* if was in efds, we failed */ | 110 | /* if was in efds, we failed */ |
113 | if (FD_ISSET(sock, &efds)) { | 111 | if (FD_ISSET(sock, &efds)) { |
114 | int why, len = sizeof(why); | 112 | int why, len = sizeof(why); |
113 | /* give windows time to set the error (disgusting) */ | ||
114 | Sleep(0); | ||
115 | /* find out why we failed */ | 115 | /* find out why we failed */ |
116 | getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&why, &len); | 116 | getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&why, &len); |
117 | /* we KNOW there was an error. if why is 0, we will return | ||
118 | * "unknown error", but it's not really our fault */ | ||
117 | return sock_connectstrerror(why); | 119 | return sock_connectstrerror(why); |
118 | /* otherwise it must be in wfds, so we succeeded */ | 120 | /* otherwise it must be in wfds, so we succeeded */ |
119 | } else return NULL; | 121 | } else return NULL; |