sleak
March 29th, 2007, 01:28 AM
I am just wondering if anyone here would please be able to tell me what will happen when I call WSACleanup() as a result of a socket related failure (some WinSock function returning an error). will a call to WSACleanup() clean up any last errors? for example, right now here is my code for one of the functions:
if(bind(lsock, (PSOCKADDR)&sin, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) {
err = WSAGetLastError();
closesocket(lsock);
WSACleanup();
return err;
}
looks ok, but I'm crazy for finding and using the smallest, most efficient methods of getting stuff done. err is a local variable declared as an int. the reason why I'm asking this question is because I'd like to know if I could omit the local variable and do something like this:
if(bind(lsock, (PSOCKADDR)&sin, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) {
closesocket(lsock);
WSACleanup();
return WSAGetLastError();
}
its a pretty simple question, however I don't see anything mentioned on msdn about WSACleanup() and last errors. do you think it would be okay if I used the second code, and that WSAGetLastError() will still return the error code for the error that caused bind() to fail (the last error)?
another question that comes to mind is will I even be able to call WSAGetLastError() after a call to WSACleanup() without some access violation or the like?
any help here is greatly appreciated. thank you in advance.
if(bind(lsock, (PSOCKADDR)&sin, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) {
err = WSAGetLastError();
closesocket(lsock);
WSACleanup();
return err;
}
looks ok, but I'm crazy for finding and using the smallest, most efficient methods of getting stuff done. err is a local variable declared as an int. the reason why I'm asking this question is because I'd like to know if I could omit the local variable and do something like this:
if(bind(lsock, (PSOCKADDR)&sin, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) {
closesocket(lsock);
WSACleanup();
return WSAGetLastError();
}
its a pretty simple question, however I don't see anything mentioned on msdn about WSACleanup() and last errors. do you think it would be okay if I used the second code, and that WSAGetLastError() will still return the error code for the error that caused bind() to fail (the last error)?
another question that comes to mind is will I even be able to call WSAGetLastError() after a call to WSACleanup() without some access violation or the like?
any help here is greatly appreciated. thank you in advance.