Jump to content

  • Log In with Google      Sign In   
  • Create Account


Blocking... for a while


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 gimp   Members   -  Reputation: 142

Like
Likes
Like

Posted 21 June 2000 - 07:32 PM

I''ve got a thread that contains a looping procedure that does a recvfrom() and places the data on a queue. Trouble is, if my client doesnt recieve data then the thread will never end and the loop will never roll over. What I need is a way to tell recvfrom() to block for 500ms then drop through with a errorcode. That way I can guarantee that if I loose the network connection then the thread won''t hang. I''m sure I read about this somewhere in my early days in winsock but can seem to find it now... Many thanks gimp

Sponsor:

#2 genovov   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 June 2000 - 02:27 AM

Not sure if you can specify a delay for the recvfrom call, but you could use select, and specify a timeout. If select returns, and your socket isn''t in the recv set, then treat that as your error condition.

- g

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 22 June 2000 - 04:29 AM

I believe that if the connection fails recv returns with either a socket error or a read of 0 bytes which indicates an EOF condition for a closed or broken connection. You''ll have to check on this though. So the thread unblocks when the connection fails or is closed and you''ll just have to put code in which handle those condition, no need to implement any complicated escape routines.

Good Luck

-ddn

#4 Jeff K   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 June 2000 - 09:50 AM


{
fd_set readfds;
struct timeval timeout;
FD_ZERO(&readfds);
FD_SET(sock, &readfds);
timeout.tv_sec = 0;
timeout.tv_usec = 500000; //microseconds
select(sock+1, &readfds, NULL, NULL, &timeout);
if (FD_ISSET(sock, &readfds)) {
len = recvfrom(sock, buf, bufsize, 0, &addr, &addrlen);
}
}


#5 gimp   Members   -  Reputation: 142

Like
Likes
Like

Posted 22 June 2000 - 04:36 PM

Cool!

Thanks a lot, especially for including code with recvfrom(), I''d hate to have to use that old trick of connect()''ing a UDP socket just to use this

again thanks

gimp




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS