**Purpose** This page is dedicated to the asyncroneous socket connect, started by 'socket -async'. See the [socket] page for a general description. It also serves as communication page for development and compares current TCL 8.5.15, TCL 8.6.1 and future versions. Async connect got more complicated in TCL 8.6, as multiple destination IPs are internally supported (due to IPV6 or DNS lookup resulting in multiple IPs). **Command behaviour** ***socket -async*** 'socket -async' ''host'' first does a syncroneous DNS lookup. Then the connect is started as background process. * In TCL8.5, this terminates without any interaction by background processes. * In TCL8.6, the event loop or command invocation is required to check multiple IPs. %|Version|Status|% &|8.5.15|ok|& &|8.5.16+|ok|& &|8.6.1 unix|ok, requires event loop|& &|8.6.1 win|only first IP (broken)|& &|8.6.2+|ok, requires event loop|& &|ideas|may be moved in own thread to not require event loop and not to pause between connect tries|& ***update,vwait*** Starting the event loop allows in TCL8.6 to continue with the next try or to fail finally ***fileevent writable*** Fires when async connect terminates with success or error. %|Version|Status|% &|8.5.15|ok, see bugs|& &|8.5.16+|ok|& &|8.6.1 win|only first IP (broken)|& &|8.6.1 unix|ok|& &|8.6.2+|ok|& ***fileevent readable*** Fires when async connect terminates with error. %|Version|Status|% &|8.5.15 unix|ok|& &|8.5.15 win|only works when also writable event installed, see bugs|& &|8.5.16+|ok|& &|8.6.1 win|only first IP and only with writable event (broken)|& &|8.6.1 unix|ok|& &|8.6.2+|ok|& ***blocking gets,read*** A read on a connecting socket fails in **Bugs** ***Win connect ignored*** [https://core.tcl.tk/tcl/info/336441ed59%|%Bug 336441ed59%|%] When a connect terminates to quick so the notifier is not ready jet, the connect is ignored and thus it waits forever for it. %|Version|Status|% &|8.5.15|bug present|& &|8.5.16+|fixed|& &|8.6.1|bug present|& &|8.6.2+|fixed|& Test is missing. One may use an IP which fails quickly by definition. ***Empty error message on close on failed background flush*** [https://core.tcl.tk/tcl/info/97069ea11a%|%Bug 97069ea11a%|%] %|Version|Status|% &|8.5.15 win|bug present|& &|8.5.16+|fixed|& &|8.6.1 win|bug present|& &|8.6.2+|fixed|& Fix available. The test is still difficult, as an async connect must fail after a puts is issued on the channel. Idea: write a dummy channel driver, which may be set to an error state by fconfigure -seterror and where the readbale/writable state may be set. So one could: ======tcl set h [open dummy] fconfigure $h -seterror EWOULDBLOCK fileevent $h writable {set x writable} fconfigure $h -blocking 0 puts $h abc fconfigure $h -setwritable 1 vwait x catch {close $h} e d ====== **ToDo's** The branch of [https://core.tcl.tk/tcl/info/13d3af3ad5%|%Bug 13d3af3ad5%|%] requires fine tuning. The current test failures on windows are: ======none ==== socket-14.7.2 pending [socket -async] and blocking [gets], no listener FAILED ==== Contents of test case: set sock [socket -async localhost [randport]] catch {gets $sock} x list $x [fconfigure $sock -error] ---- Result was: {error reading "sock01B57690": connection refused} {} ---- Result should have been (glob matching): {error reading "sock*": socket is not connected} {connection refused} ==== socket-14.7.2 FAILED ==== socket-14.11.0 pending [socket -async] and blocking [puts], no listener, no flush FAILED ==== Contents of test case: set sock [socket -async localhost [randport]] fconfigure $sock -blocking 0 puts $sock ok fileevent $sock writable {set x 1} vwait x close $sock ---- Result was: socket is not connected ---- Result should have been (exact matching): broken pipe ==== socket-14.11.0 FAILED ==== socket-14.11.1 pending [socket -async] and blocking [puts], no listener, flush FAILED ==== Contents of test case: set sock [socket -async localhost [randport]] fconfigure $sock -blocking 0 puts $sock ok flush $sock fileevent $sock writable {set x 1} vwait x close $sock ---- Result was: socket is not connected ---- Result should have been (exact matching): broken pipe ==== socket-14.11.1 FAILED ====== <>sockets,core