Skip to content
Tcl Source Code View Ticket
Login

View Ticket

socket -async behaves differently on Win95 and NT

Closed / Out of Date219298ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 23 years ago
Descriptionplain2000-10-26 05:10:20
OriginalBugID: 2634 Bug
Version: 8.2
SubmitDate: '1999-08-31'
LastModified: '2000-04-14'
Severity: LOW
Status: UnAssn
Submitter: techsupp
ChangedBy: hobbs
RelatedBugIDs: 1776
OS: Windows NT
Machine: X86
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'


Name:
Waidelich

Comments:
winsock reports the failed close correctly. only a peer 'shutdown' is
    not reported correctly.
    
    I want Tcl to become cleaner every release. Workarounds are a real pain.

ReproducibleScript:
# SOCKET BUG (Win95 and NT?) is portability problem
    # =================================================
    # checked with Tcl 8.0.3, 8.0.4, 8.1.0 and 8.2.0
    # reported to Scriptics when 8.0.3 was released
    #
    # test-script follows
    #
    # connect to non-existent port fails without error report
    # fconfigure -error does not work on Win95 and only half on WinNT (no
    posix)
    # there is a workaround (fconfigure -peername)
    #
    #
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    # QUESTION: shouldn't a failed connect be reported by a READable
    socket?
    # I think this is how it worked with C on SCO-UNIX. the read can then
    # reports the error. A WRITEable socket does not mean
    # we have data to send. So no system call, no error report...
    #
    
    wm geometry . +300+10
    
    text .t -yscrollcommand ".s set" -bg yellow -width 60 -height 25
    scrollbar .s  -command ".t yview"
    
    pack .s -side right -fill y
    pack .t -fill both -expand yes
    
    proc debug  t {
    .t insert end "$t\n"
    .t see end
    update idletasks
    }
    
    proc rrr sock {
    debug "$sock readable"
    catch {read $sock} x
    global errorCode
    debug "read <$x> errno=$errorCode"
    }
    
    proc www sock {
    debug "$sock writable"
    global errorCode
    # from the manual: ...determine if an asynchronous connect operation
    succeeded.
    # I expected to get ECONNREFUSED (winsock 10061)
    # but got nothing
    catch {fconfigure $sock -error} r
    debug "-error <$r> <$errorCode>"
    # A workaround gives ENOTCONN --> I coude fake a ECONNREFUSED to user
    catch {fconfigure $sock -peername} r
            debug "-peername <$r> <$errorCode>"
    #
    fileevent $sock writable {} ;# don't loop
    #
    catch {close $sock} r
    debug "close <$r> <$errorCode>"
    }
    
    proc ccc {} {
    debug "connecting to localhost:6666 (change if exists!)"
    set sock [socket -async localhost 6666]
    debug "$sock opened"
    fconfigure $sock -blocking no
    fileevent $sock readable "rrr $sock"
    fileevent $sock writable "www $sock" ;# writeable on connect!
    debug "waiting for fileevents..."
    }
    
    ccc ;# connect now
    
    #from the log:
    #==============
    # connecting to localhost:6666 (change if exists!)
    # sock14 opened
    # waiting for fileevents...
    # sock14 writable
    # 95: -error <> <>
    # NT: -error <connection refused> <>     ... no POSIX in errno
    #
    # -peername <can't get peername: socket is not connected> <POSIX
    ENOTCONN {socket is not connected}>
    # close <> <POSIX ENOTCONN {socket is not connected}>

ObservedBehavior:
async connect gets reported differently on Win95 and NT
    
    although there is a workaround, it should be done how it was
    intended by the socket-abstraction

DesiredBehavior:
on failed async connect I expect the socket to become readable (and
    maybe writeable too?)
    
    on success I expect it to become writeable. And readable only if data is
    available.
dkfplain2001-01-16 21:29:17
I read somewhere that the difference between 95 and NT was due to the brokenness of 95.  I could believe that...
dkf Ticket [219298ffff]: 1 change [History diff]2001-02-07 22:58:26
dgp Ticket [219298ffff]: 1 change [History diff]2001-04-01 01:47:31
hobbs Closed ticket [219298ffff]. [History diff]2003-07-19 03:37:44
Log in (anonymous is fine) to add a comment.