WSAGetLastError returns zero

I am calling a method ConnectEx(). It returns FALSE, so I check the error code when called WSAGetLastError. Sometimes it happens that the return value is zero. What does it mean?

+5
source share
3 answers

WSAGetLastError should be raised immediately when an error occurs. Some functions may reset the last extended error code to 0

Additional information on MSDN .

+4
source

There is no Winsock error code with a value of 0, so as far as I understand, you did not call WSAStartup.

+1
source

recins winsock (SOCKET_ERROR), - WSAGetLastError, 0 .

I first found this error when switching from debug mode to release mode. My code worked fine while debugging, but would disable clients in release mode.

The reason for this is that the receive buffer is not large enough. But this is not documented anywhere. In my case, the release mode made things fast enough to overflow the buffer.

Simply increasing the size of the buffer will solve the problem (the third parameter in recv.

I hope for this help. good luck

0
source

All Articles