#1292 socket -async behaves differently on Win95 and NT

obsolete: 8.2

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'


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.

# 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
# there is a workaround (fconfigure -peername)
# QUESTION: shouldn't a failed connect be reported by a READable
# 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
# 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}>

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

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


  • Donal K. Fellows

    • labels: 104250 --> 104681
  • Donal K. Fellows

    I read somewhere that the difference between 95 and NT was due to the brokenness of 95. I could believe that...

  • Donal K. Fellows

    • labels: 104681 --> 104250
  • Don Porter

    Don Porter - 2001-03-31
    • labels: 104250 --> 27. Channel Types
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2003-07-18
    • status: open --> closed-out-of-date

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks