Skip to content
Tcl Source Code View Ticket
Login

View Ticket

async sockets: readable vs writable fileevents

Closed / Fixed794839ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-08-25 18:43:18
Try to async-connect to a host/port which refuses the
connection:

    proc foo {fd} {
      puts "$fd: errstat [fconfigure -error $fd]"
      close $fd
    }

    # chose any port which is not open on local machine
    set port_not_open 65432
    set fd [socket -async localhost $port_not_open]

Now we need some means to get informed when the
conection is
available, the manpage tells use to use fileevent.

I find that on IRIX both readable and writable
fileevents work to
detect the failed connection:

  fileevent $fd readable [list foo $fd]
  fileevent $fd writable [list foo $fd]

both immediately show the failed connection.

However on Windows, only the `writable' fileevent
triggers, the
`readable' just hangs around forever.  The same goes
for connection
timeouts (host offline): readable fileevents do not
time out,
`writables' do.

David Gravereaux said: "... I agree this is a problem.
Please post this bug to the sourceforge bug db."

So here we are...
davygrvy Ticket [794839ffff]: 2 changes [History diff]2003-09-06 18:51:17
davygrvyplain2004-05-06 01:30:25
Logged In: YES 
user_id=7549

Using the following test case:

proc foo {fd which} {
  puts "$fd: errstat $which [fconfigure $fd -error]"
  catch {close $fd}
}
set port_not_open 65432
set fd [socket -async localhost $port_not_open]
fileevent $fd readable [list foo $fd readable]
fileevent $fd writable [list foo $fd writable]

I found that when I added the ability for an async connection 
that returned an error to fire both read and write handlers, 
only the first would be called due to the 'close $fd'.  If neither 
closed, both would be called relentlessly.

[committed fix to HEAD]
davygrvy Closed ticket [794839ffff]. [History diff]2004-05-06 01:50:38
davygrvy Ticket [794839ffff]: 1 change [History diff]2004-05-06 01:51:21
Log in (anonymous is fine) to add a comment.