So I am trying to setup a multithreaded server with ACE. I am using non-blocking client sockets to prevent recv()/send() from blocking. The problem is when I use recv() and the client disconnects ungraceful, the result of recv() does not give me a hind that the client disconnected. Is there any other methode to check the connectivity.
Here is a short snippet
char buffer[4096];
ssize_t bytesReceived = peer.recv(buffer, sizeof(buffer));
if (bytesReceived < 1 && errno != EWOULDBLOCK)
{
printf("Disconnected:\n");
}
else if (bytesReceived > 0)
{
buffer[bytesReceived] = '\0';
printf(buffer);
}
So if the client disconnects, recv returns -1 but errno is still EWOULDBLOCK.
I also tried to use a short timeout in recv, but it leads to the same result as without just with errno = ETIME(TIME-Out).