-
May 1st, 2009, 01:00 AM
#1
recv() hang
i have server and client application running on different system. server is just sending data and client is receiving. when server side app's network disconnected(not client side N/W down) then client app's recv() hang waiting for data(recv() is blocking fun and i dont want it to be non-blocking) so my app hang. can anyone tell me how to come out from blocking recv()
-
May 1st, 2009, 04:02 AM
#2
Re: recv() hang
At the time of closing the server send the closing status to all connected client.
In the client side, simple close the socket.
-
May 1st, 2009, 05:40 AM
#3
Re: recv() hang
server is not closing but server network is closing and at that time server does not send any status, tell me another thing
-
May 1st, 2009, 07:51 AM
#4
Re: recv() hang
It's hard to say what might be going on without seeing any code. You say you want recv() to block for some reason. Would it be acceptable to use select on your recv() calls? That might be all it takes. Try something like this: replace your recv() call with this call:
Code:
#define _MY_TIMEOUT_ 5 //block for up to 5 seconds for each select()
int w_recv(unsigned s,void *ph,int len,int flags)
{
fd_set r,e;
struct timeval tval;
int i,retval,done=0,total=0;
while(!done){
FD_ZERO(&r);FD_ZERO(&e);
FD_SET(s,&r);FD_SET(s,&e);
tval.tv_sec=_MY_TIMEOUT_;
tval.tv_usec=0;
retval=select(s+1,&r,NULL,&e,&tval);
if(retval==0){
//Timeout elapsed with no activity
return 0;
}
if(retval==-1){
//Socket error with select().
return -1;
}
if(FD_ISSET(s,&e)){
//some other TCP/IP error triggered select()
return -1;
}
if(FD_ISSET(s,&r)){
//data is available on the socket Gather it up
i=recv(s,((char *)ph)+total,len-total,flags);
if(i==-1){
//Socket error with recv().
return -1;
}
if(i==0){
//something is wrong. select trigged but there is no data
return 0;
}
//loop until all requested data is received
total+=i;
if(total==len){
done=1;
}
}
}//done
return total;
}
-
May 1st, 2009, 08:59 AM
#5
Re: recv() hang
i will try it and reply accordingly on monday
-
May 4th, 2009, 12:04 AM
#6
Re: recv() hang
i try select func but with time 0 bcoz i dont want to block select func for 5 second bcoz i m getting data continusly, when i used this select always returning -1 and i m also getting data continusly.
-
May 4th, 2009, 12:21 AM
#7
Re: recv() hang
setsockopt and SO_KEEPALIVE
-
May 4th, 2009, 12:49 AM
#8
Re: recv() hang
would u plz tell me about this flag n i think this flag used in tcp/ip connection, but i m not using tcp/ip connection
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
|