Re: use alarm() to achieve timeout.
- From: David Schwartz <davids@xxxxxxxxxxxxx>
- Date: Wed, 17 Dec 2008 10:42:29 -0800 (PST)
On Dec 16, 7:27 pm, hellog...@xxxxxxxxx wrote:
Thanks for your reply. So you mean what I concern is right and the
implementation of timeout using alarm() from
UNP(<<unix network programming ,3rd, by Richard stevens>>)
is not perfect(the code I wrote above is from UNP)
You are correct. That code has a race condition.
just because of the small window between alarm() and recvfrom().
then could you please show me a correct solution to implement
timeout using alarm() when doing socket i/o?
I don't have the code handy, but the basic idea is to have the signal
handler call longjmp. You only call the function you want to timeout
if 'setjmp' returns zero. Since the signal handler calls 'longjmp',
the signal handler will ensure 'setjmp' does not return zero. So there
is no way you can call 'recvfrom' (or whatever) after the signal has
fired.
DS
.
- Follow-Ups:
- Re: use alarm() to achieve timeout.
- From: helloghui
- Re: use alarm() to achieve timeout.
- References:
- use alarm() to achieve timeout.
- From: guanghui
- Re: use alarm() to achieve timeout.
- From: David Schwartz
- Re: use alarm() to achieve timeout.
- From: guanghui
- Re: use alarm() to achieve timeout.
- From: David Schwartz
- Re: use alarm() to achieve timeout.
- From: helloghui
- use alarm() to achieve timeout.
- Prev by Date: Re: load-balancing twin 10GbE?
- Next by Date: SO_BINDTODEVICE
- Previous by thread: Re: use alarm() to achieve timeout.
- Next by thread: Re: use alarm() to achieve timeout.
- Index(es):
Relevant Pages
|