|
-
April 13th, 2007, 03:50 AM
#1
Timeout for recv() ?
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:
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);
with that code, the server thread won't detect if a client hang, crashes or just reboot.
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|