Permalink
Browse files

Tweaked windows Socket_Listen

  • Loading branch information...
1 parent a6c5dfc commit 32ca6e7fb3a3afad9322291003de5bba879a55d2 John committed Oct 22, 2012
Showing with 12 additions and 10 deletions.
  1. +12 −10 Socket.c
View
@@ -185,39 +185,41 @@ SAL_Socket SAL_Socket_Listen(const int8* const port) {
ADDRINFO* addressInfo;
ADDRINFO hints;
SOCKET listener;
+ int32 errorCode;
if (!winsockInitialized) {
WSADATA startupData;
WSAStartup(514, &startupData);
winsockInitialized = true;
}
-
+
+ listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (listener == INVALID_SOCKET)
+ return NULL;
+
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;
- if (!getaddrinfo(NULL, port, &hints, &addressInfo)) {
- freeaddrinfo(addressInfo);
- return NULL;
- }
-
- listener = socket(addressInfo->ai_family, addressInfo->ai_socktype, addressInfo->ai_protocol);
- if (listener == INVALID_SOCKET) {
+ errorCode = getaddrinfo(NULL, port, &hints, &addressInfo);
+ if (errorCode != 0) {
freeaddrinfo(addressInfo);
return NULL;
}
- if (!bind(listener, addressInfo->ai_addr, (int32)addressInfo->ai_addrlen)) {
+ errorCode = bind(listener, addressInfo->ai_addr, (int32)addressInfo->ai_addrlen);
+ if (errorCode != 0) {
freeaddrinfo(addressInfo);
closesocket(listener);
return NULL;
}
freeaddrinfo(addressInfo);
- if (!listen(listener, SOMAXCONN))
+ errorCode = listen(listener, SOMAXCONN);
+ if (errorCode != 0)
return NULL;
return (SAL_Socket)listener;

0 comments on commit 32ca6e7

Please sign in to comment.