Reputation: 11651
I am retrieving data from the socket using the following code
iResult = recv(Socket,data_array,sizeof(data_array),0);
Now the documentation states that if recv is succefull it would return the no. of bytes retrieved otherwise it would return an error code. How do I check for that error code. I mean what if the data retrieved is the same amount as the value of error code.
Upvotes: 0
Views: 906
Reputation: 310859
Now the documentation states that if recv is succefull it would return the no. of bytes retrieved otherwise it would return an error code.
No, it doesn't say that at all. Read it again. It says it returns the number of bytes transferred if successful, otherwise -1
, with the error available in errno,
or in Windows via WSAGetLastError().
How do I check for that error code. I mean what if the data retrieved is the same amount as the value of error code.
You can't transfer -1 bytes. There is no ambiguity.
Upvotes: 0
Reputation: 311
Check this link to get some more detail.
Basically, when an error occurs, SOCKET_ERROR
(-1) gets returned, and you then have to call WSAGetLastError()
, or read errno
or other platform-specific equivalent, to get the specific error code.
Upvotes: 2
Reputation: 5459
If the return value is negative (i.e. SOCKET_ERROR or -1), that's an error.
Upvotes: 3