Hi Folks,
I've written a multithreaded server application with the following problem:
On a client connect, a new thread will start.
Clients will send a pingsignal for validating server accessibility, the other way arround I want to have something like a timeout for the server.
If for example no data is received for 1 minute, the server should drop that client. Code looks like this:
with that code, the server thread won't detect if a client hang, crashes or just reboot.Code:do {
rec=recv(ss,buffer,BUFLEN,0);
if(rec>0){
printf("Thread %u (%s): - received bytes: %d\n", pid, remoteaddr, rec);
}
else if(rec==0){
sprintf(errormsg,"Thread %u:\Connection was closed. %s(%s)\n\n",pid,remoteaddr,data->h_name);
printf(errormsg);
error = TRUE;
break;
}
else{
printf("Thread %u (%s): error while reading(recv()): %d\nConnection interrupted.\n", pid, remoteaddr, WSAGetLastError());
}
// cut
memset(buffer,0,BUFLEN);
}while(rec>0);
So now my question, can I setup a timeout for recv() or have I to do this on my own with some kind of timer?
Thanks in Advance,
Andy
