|
From: Joe E. <jen...@fl...> - 2008-06-15 05:50:03
|
Alexandre Ferrieux wrote: > > While reviewing [patch 1960647] Add ability to use poll() in > TclUnixWaitForFile() > https://sourceforge.net/tracker/index.php?func=detail&aid=1960647&group_id=10 > 894&atid=310894 > > I discovered the existence of this strange function. Can somebody give > me the rationale for it ? I was looking at this too not too long ago. Some things I found out: (1) TclUnixWaitForFile() is only used in one place in the core proper, namely WaitForConnect(). (2) In WaitForConnect(), the "timeout" parameter is always either '0' (do not wait) or -1 (wait forever). So TclUnixWaitForFile() is much more complicated than it needs to be -- it doesn't need the "mini-event loop" or all the timeout processing at all. (3) WaitForConnect() and the TCP_ASYNC_SOCKET/TCP_ASYNC_CONNECT logic is also more complicated than it needs to be (and might not be necessary at all). (4) TclUnixWaitForFile() is also used in the test suite, this time with timeout values > 0. Whether the test suite is calling it simply to test TclUnixWaitForFile() itself or if it's needed to test something "real", I was not able to determine. (5) TclUnixWaitForFile also appears in the internal stubs table. Whether there are any callers outside of the core is difficult to determine. > Its clear and documented effect is to resynchronize the async > connection of a socket prior to honoring an I/O request on the socket. > What I don't understand is: > > (a) why resync in that case, instead of just throwing an error "not > yet connected", relying on the caller to use the event loop as usual > to detect the completion of the connect phase ? (I know it's way too > late to change, I just want to understand) The idea is that [connect -async ...] won't block immediately, but subsequent reads or writes on the channel will. If you set the channel to nonblocking in the meantime, then subsequent reads and writes return immediately (EWOULDBLOCK isn't considered an error). > (b) why is it unix-specific ? Probably because the Windows implementation uses a different algorithm for async connections. --Joe English jen...@fl... |