Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: ad13b01c0a5c74e8c609e0e58fa9e1a3910b519e
Ticket: 218945ffffffffffffffffffffffffffffffffff
[fconfigure $socket -error] broken
User & Date: nobody on 2000-10-26 01:08:27
Changes

  1. assignee changed to: "nobody"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    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
    
  4. foundin changed to: "obsolete: 8.2"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "nobody"
  9. subsystem changed to: "69. Other"
  10. title changed to: "[fconfigure $socket -error] broken"
  11. type changed to: "Bug"