I'm writing a C function to check if a socket connection from client is available. I use 'recv' function with MSG_PEEK not to alter the input buffer.
However, when the socket connection is closed by client, 'recv' is supposed to return -1, but it doesn't. After client closed, 'recv' in the function below returns 0 all the times.
char is_avail(int connection) {
char buffer;
int result = recv(connection,&buffer,1,MSG_PEEK);
if (result<0)
return 0;
else
return 1;
}
Any reason to this matter? and also I want to combine MSG_PEEK with MSG_WAITALL. I tried:
recv(connection,&buffer,1,MSG_PEEK|MSG_WAITALL);
but it doesn't take effect.