// server
bool is_server_disconnected(int client_socket)
{
//
set_flag(client_socket, O_NONBLOCK);
char buffer[10];
int length = recv(client_socket, buffer, 10, 0);
clr_flag(client_socket, O_NONBLOCK);
return length == 0;
}
set client_socket to non-blocking, and then if recv returns 0, it means remote socket is closed.
When a stream socket peer has performed an orderly shutdown, the< H1 > other methods < / H1 >
return value will be 0 (the traditional "end-of-file" return).
tcp disconnect is not considered for the time being. I wonder if there is a simpler and better way?