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?
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.
There is no Winsock error-code with value 0, therefore my best guess is that you did not call WSAStartup.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With