(tcp_connect, hostconnect) [_WIN32]: Replace close() with

closesocket() as Windows close() does not support closing
socket connections.
This commit is contained in:
Ron Koenderink 2007-08-20 19:59:12 +00:00
parent b5c4250099
commit d9ddf9b24a

View file

@ -48,7 +48,7 @@
#include <netdb.h>
#include <unistd.h>
#else
#include <io.h>
#include <winsock2.h>
#endif
#include "misc.h"
@ -82,8 +82,11 @@ tcp_connect(char *host, char *serv)
if (connect(sockfd, res->ai_addr, res->ai_addrlen) == 0)
break; /* success */
#ifdef _WIN32
closesocket(sockfd); /* ignore this one */
#else
close(sockfd); /* ignore this one */
#endif
} while ((res = res->ai_next) != NULL);
if (res == NULL) { /* errno set from final connect() */
@ -152,8 +155,10 @@ hostconnect(struct sockaddr_in *addr)
if (connect(s, (struct sockaddr *)addr, sizeof(*addr)) < 0) {
#ifdef _WIN32
errno = WSAGetLastError();
#endif
(void)closesocket(s);
#else
(void)close(s);
#endif
return -1;
}
return s;