Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fileevent on socket timeout

96 views
Skip to first unread message

de...@scratters.com

unread,
May 6, 2012, 4:33:51 AM5/6/12
to
I'd be grateful if someone could clarify the behaviour I appear to be seeing...

I need to open a socket on a machine which may or may not be behind a packet filter. I therefore open with the -async flag to the socket command. I then set up a fileevent waiting for the socket to become readable. When it does I do a [gets] (unless it's [eof]). Fine.

It seems that if I attempt to open the socket on a filtered machine the socket command comes back immediately (which is what I want from the -async flag) and in due course the socket open times out. At that point my fileevent gets called. [eof] is false so I attempt the [gets] which fails with a timeout error. Oops.

This all seems reasonable, so I've put a catch around the [gets] to stop that error. However, since I can't find it documented anywhere can someone confirm that what I think is going on is indeed going on? And that the behaviour will be consistent cross platform - I need this to work on Linux (my development platform) but also Windows and Mac OS X.

Thanks!

Harald Oehlmann

unread,
May 6, 2012, 4:55:16 AM5/6/12
to
Two pennies from my side:

- to check if a socket gets connected in general, one may set a write
event on it.
(works well on Unix)
- I suppose your readable event gets called due to a read error.
set error [fconfigure $id -error]
switch $error {
"" { #ok
}
"connection time out" - "connection refused" { # react on error }
default { # generic error }
}
This snipped is from the IMHO brilliant book (but from a write event
error handler):
http://wiki.tcl.tk/27614

-Harald

Gerald W. Lester

unread,
May 6, 2012, 3:26:55 PM5/6/12
to
According to the man/help page, [eof] does not go true until you attempt to
read past the EOF.


--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+
0 new messages