Re: timeout for "socket"?
- From: "Donal K. Fellows" <donal.k.fellows@xxxxxxxxx>
- Date: Sun, 29 Jun 2008 17:24:56 -0700 (PDT)
ZB wrote:
If I use "-async", there will be a handle for a connection returned
immediately - therefore I'll have to test the connection different way,
for example using fileevent, like in your script.
But I've got a feeling, "async & after" gives me nothing more: just instead
of setting the timeout when testing the connection immediately (no "async"),
I'm testing the connection using "fileevent" (for example) - 2000 ms later,
but still not setting test duration. Just the testing process itself starts
2 seconds later.
I would to make it try to connect, say, 5 seconds - and not to test the
connection 5 seconds later. It's not the same.
In a normal blocking socket connection, there are two phases that can
block. The first is during the lookup of the IP address for the name
you supplied, and the second is during the actual connection forming.
The -async option allows you to return to processing your script after
the first phase; the socket will become writable (in a [fileevent]
sense) when the connection is made or fails. But the first phase can
still block (name resolution is *disgusting*; if only we could assume
that we were using DNS...) and the only way to avoid that is to supply
an IP address in the first place; Tcl parses those immediately.
So, to test whether a service is up properly, you need to do this:
1) create a socket with -async set using the numeric IP address of
the machine you're contacting
2) then set up the timeout with [after]
3) then set up a writable [fileevent]
4) now you either get a writable event or a timer event first; if
you get the writable event, you need to use [fconfigure -error] to see
if there was an error happened (IIRC)
5) you only have a successful check if you didn't timeout and didn't
get an error connecting.
Hope that explains better what's going on with this sort of checking.
Donal.
.
- References:
- timeout for "socket"?
- From: ZB
- Re: timeout for "socket"?
- From: Pat Thoyts
- Re: timeout for "socket"?
- From: ZB
- timeout for "socket"?
- Prev by Date: Re: timeout for "socket"?
- Next by Date: Re: Autoproxy behind a corporate firewall that uses a website to configure proxy
- Previous by thread: Re: timeout for "socket"?
- Next by thread: ANNOUNCE: Tcl/Tk 8.6a1 RELEASED
- Index(es):
Relevant Pages
|