Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSAGetLastError returning zero

Tags:

winapi

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

like image 773
truthseeker Avatar asked Feb 11 '11 15:02

truthseeker


3 Answers

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

More info at MSDN.

like image 157
Burn Avatar answered Nov 10 '22 00:11

Burn


There is no Winsock error-code with value 0, therefore my best guess is that you did not call WSAStartup.

like image 1
Bernd Elkemann Avatar answered Nov 10 '22 00:11

Bernd Elkemann


The winsock recv function can return an error (SOCKET_ERROR) and then even if the very next call is to WSAGetLastError this can still return a 0 as an error code.

I first found this 'bug' when switching from debug mode to release mode. My code worked fine when debugging but would disconnect clients when in release mode.

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

Simply increasing the size of the buffer will resolve the problem (the 3rd param in recv.

Hope this help. good luck

like image 1
Paul Spain Avatar answered Nov 10 '22 01:11

Paul Spain