Re: creating a socket connection timeout in "C" linux
- From: Rainer Weikusat <rweikusat@xxxxxxxxxxx>
- Date: Sun, 08 Jun 2008 19:25:19 +0200
Alex Fraser <me@xxxxxxxxxxx> writes:
Rainer Weikusat wrote:
Alex Fraser <me@xxxxxxxxxxx> writes:
Rainer Weikusat wrote:[...]
d-fan <rafel.coyle@xxxxxxxxxxxxxx> writes:
How can I open a socket connection with a timeout?
I was being too imprecise. The 'easy, unreliable timeout' is settingthe easy, unreliable way to enforce a shorter timeout is alarm(3).What makes alarm() unreliable?
up a no-op handler for SIGALRM and relying on the alarm signal to
interrupt the connect. The problem is that 'setting up an alarm' and
'starting to connect' are two operations instead of one atomic
operation and their can be a near arbitrary delay between them because
other processes could be scheduled. This means there is a chance that
the SIGALRM may actually be posted to the process before the connect
ever blocks.
But you'd have the same "near arbitrary delay" even if there was an
atomic "connect() with timeout" call, between timeout/connect success
and the thread being scheduled again. So are you any worse off?
"Well, a piece of orbital junk could smash the building you are living
in at any time so it would clearly be useless to prevent it from
burning down by not making a large fire in the living room before
leaving for a three week holiday trip."
Relying on (a single) SIGALRM to interrupt a blocked system call could
lead to a lost wakeup in particular circumstances. This potential
problem can be avoided by suitable code, ie by longjumping from the
handler instead. This still doesn't mean that connect was ever
actually called, but that the program has done every possible thing to
regain control after the timeout expired. Which in no way implies that
some other problem could not cause a similar effect.
.
- References:
- creating a socket connection timeout in "C" linux
- From: d-fan
- Re: creating a socket connection timeout in "C" linux
- From: Rainer Weikusat
- Re: creating a socket connection timeout in "C" linux
- From: Alex Fraser
- Re: creating a socket connection timeout in "C" linux
- From: Rainer Weikusat
- Re: creating a socket connection timeout in "C" linux
- From: Alex Fraser
- creating a socket connection timeout in "C" linux
- Prev by Date: Will the Expect suit to me? ( maybe NOT a wrong post )
- Next by Date: Re: Will the Expect suit to me? ( maybe NOT a wrong post )
- Previous by thread: Re: creating a socket connection timeout in "C" linux
- Next by thread: Question on select() and sockets
- Index(es):
Relevant Pages
|