View Full Version : timeouts in recv/send
hello all,
does blocking calls like recv and/or send have inbuild timeout mechanisums? say eg:-
server is talking to client ans suddenly client goes down, the server is waiting on a recv(), will it automatically genrate error and thus server can understand that client is down?
else
how to implement timeouts ? does we have to provide for all call?(i think , have to) and how can we provide it for blocking calls like send and recv?
-dev
mlampkin
05-26-2003, 08:18 PM
Using setsockopt( ) should work... the options SO_RCVTIMEO and SO_SNDTIMEO control ...
Michael
RobSeace
05-27-2003, 05:09 PM
Um, except for the little fact that Michael failed to mention: many
systems don't even bother implementing those particular
sockopts, and even those that do may not behave how you'd
actually expect them to... ;-)
I never ever rely on SO_{RCV,SND}TIMEO for anything... You're
better off just writing your own timeout code... If you have to use
blocking I/O, then use an alarm()-based timeout... (Assuming
you've got a single-threaded app, anyway... For multi-threaded
apps, well, you probably just want to go with non-blocking I/O and
a select()-based timeout...) But, quite honestly, I wouldn't
recommend SO_{RCV,SND}TIMEO for ANY use, whatsoever...
mlampkin
05-27-2003, 11:44 PM
I seem to have deleted part of my previous post... oops...
Rob is of course correct about the fact that many systems do no implement those options... and those which do sometimes actually give what they consider the "closest compatible" value for their implementation... which means you have to set the option, then get it to see what value the system actually used... :-/
Darn this touch pad mouse on my computer!!!
Michael
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.