From: Harald O. <har...@el...> - 2014-03-11 17:36:43
|
Dear TCL'ers, I am sorry to ask for help. There is something I am stuck with. What happens: - take current bug-13d3af3ad5 branch https://core.tcl.tk/tcl/info/cb1a6a0924 on windows (Vista for me) - start tclsh and do the following, while there is no server on port 9999, socket should report "connection refused": set s [socket -async localhost 9999] fconfigure $s -blocking 0 puts $s ok fileevent $s writable { set x 1; puts "w" } vwait x close $s This works well. Now insert a flush: set s [socket -async localhost 9999] fconfigure $s -blocking 0 puts $s ok flush $s fileevent $s writable { set x 1; puts "w" } vwait x close $s The fileevent is never delivered and thus the program stalls What happens inside: - when the socket connect code knows that the connect will fail, it invokes (Line 1409 of tclWinSock.c): Tcl_NotifyChannel(infoPtr->channel, TCL_WRITABLE); This is implemented in tclIO.c and comes to the line 8039: /* * If we are flushing in the background, be sure to call FlushChannel for * writable events. Note that we have to discard the writable event so we * don't call any write handlers before the flush is complete. */ if (GotFlag(statePtr, BG_FLUSH_SCHEDULED) && (mask & TCL_WRITABLE)) { FlushChannel(NULL, chanPtr, 1); mask &= ~TCL_WRITABLE; } Well, it happens exactly what is described. The writable event is not executed due to a pending flush. The flush will never succeed as this is a callback to report an error. How is this supposed to work ? Thank you all for any light in the dark. Harald |