Share

Tcl

Tracker: Bugs

2 [fconfigure $socket -error] broken - ID: 218945
Last Update: Settings changed ( dgp )

OriginalBugID: 2868 Bug
Version: 8.2
SubmitDate: '1999-09-23'
LastModified: '1999-09-29'
Severity: SER
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: Windows 95
Machine: X86
FixedDate: '1999-09-28'
FixedInVersion: 8.2.1
ClosedDate: '2000-10-25'


Name:
Don Porter

ReproducibleScript:
#!/bin/sh
# FILE: async
# Usage: async <host> <port>
# exec tclsh "$0" ${1+"$@"}

proc AsyncConnect {host port} {
puts "creating socket..."
set s [socket -async $host $port]
puts "socket created"
fileevent $s writable [list VerifyConnection $s $host $port]
}

proc VerifyConnection {s host port} {
global connected
fileevent $s writable {}

# If there's an error condition on the socket (failure to
connect),
# then [fconfigure -error] should provide an error message
#
set msg [fconfigure $s -error]
if {![string match {} $msg]} {
puts "Connection to $host:$port failed: $msg"
set connected 0
catch {close $s}
return
}

# Connection reportedly successful. At this point we normally
# configure the socket for whatever communications we want and
# set up fileevent handlers to manage protocols over the socket.
#
# Here, as a simple check, print out the peername information
# as a check of a good connection. If we really are connected,
# we print information about the far end of the connection. If
# not, print an error message indicating that Tcl's fileevent,
# fconfigure, and socket are not working as advertised.
#
if {[catch {fconfigure $s -peername} peerInfo]} {
puts "Tcl is broken: $peerInfo"
} else {
puts "Connected: $peerInfo"
}
set connected 1
close $s
}

proc tick {} {
# Demonstrate event loop is active, and provide eventual timeout
global tick connected
incr tick
puts "tick $tick"
if {$tick >= 6000} {set connected 0; return}
after 10 tick
}

set connected 0
set tick 0
tick
eval AsyncConnect $argv
vwait connected
# END FILE: async

ObservedBehavior:
C:> tclsh82 async www.w3.org 90
tick 1
creating socket...
socket created
tick 2
...
tick 895
Tcl is broken: can't get peername: socket is not connected

DesiredBehavior:
If the socket is not connected, I expect [fconfigure $socket -error]
to return a non-empty error message, so that failure to connect can
be detected by the callback routine after a [socket -async $host
$port].

Currently it appears the only way to check the socket for a successful
connection is to catch [fconfigure $socket -peername]. That is an
expensive operation which may block for awhile. If I didn't mind
blocking, I wouldn't be using [socket -async] in the first place.



I am moving this to either fixed (or closed) for 8.2.1, because it
gives me:

(tkcon) 51 % AsyncConnect pop 90
creating socket...
socket created
## some waiting occurs here
Connection to pop:90 failed: connection refused

Which seems to be what the user wanted. This is on NT/SP4.
-- 09/28/1999 hobbs
Further notes from the user indicate that this works as expected
for 98 and NT, but not 95. This could either be a Tcl or MS
problem, but not high priority for us to examine further.
-- 09/29/1999 hobbs


Nobody/Anonymous ( nobody ) - 2000-10-26 01:08

2

Closed

Wont Fix

Nobody/Anonymous

27. Channel Types

obsolete: 8.2

Public


Comments

No follow-up comments have been posted.

Attached File

No Files Currently Attached

Changes ( 7 )

Field Old Value Date By
resolution_id Fixed 2001-04-18 20:31 dgp
category_id 69. Other 2001-04-18 20:31 dgp
close_date 2000-10-26 01:32 2001-04-18 20:31 dgp
status_id Open 2000-10-26 01:32 welch
close_date - 2000-10-26 01:32 welch
priority 5 2000-10-26 01:32 welch
resolution_id None 2000-10-26 01:32 welch