Reputation: 46770
In porting some working unit tests from Linux to Windows I'm running across a strange problem. It appears that when my tests go to shutdown the server socket, shutdown() returns -1, but WSAGetLastError() returns 0 (and getsockopt( with SO_ERROR ) returns 0, and GetLastError() returns 0 )... So, shutdown() tells me there is an error, but all of the normal calls to see what that problem was are returning "no problem!"... Has anyone ever seen this before?
The code that calls shutdown looks like this:
int ret = ::shutdown( _sok, mode );
if( ret < 0 )
X_THROW(( XSDK::ModuleId, XSDK::F_OS_ERROR, "Unable to shutdown socket."));
When I catch the exception, I call all those GetLastError() functions... Does throwing reset the last errors?
Upvotes: 2
Views: 736
Reputation: 46770
The answer ended up being that nearly any system calls can clear Win32's "LastError()" errors... In my case, throwing an exception meant formatting and logging a message, which caused the error to be clear... And even though I was calling WSAGetLastError() immediately in my catch(...) it was already too late...
Upvotes: 2