Re: The Tcl notifier and Console on Windows
- From: David Gravereaux <davygrvy@xxxxxxxxx>
- Date: Tue, 23 May 2006 10:24:31 -0700
Alex wrote:
David Gravereaux wrote:
Yup, it is funny. Apparently the WaitFor.. is too sensitive and
responds to all events (like mouse, too) and ends up blocking on
ReadFile waiting for just characters instead which seems to be corrupted
by the WaitFor..
Take out the WaitFor.. and the corruption disappears. So in this case,
ReadFile is expected to be used in blocking mode.
Wow. I'm having a hard time silencing my anti-Windows rant here...
Do they call THAT an OS ? ^H^H^H^H^H^H^H^H^H^H sorry :-)
So let me guess... So when you are waiting on a handle that can be
triggered for numerous types of events and you're just looking for a
subset of those types with no way of setting a mask (like
WSAEventSelect), its the fault of the OS?
For doing overlapped-I/O, you'd use ReadFileEx and either use APC or a
CompletionRoutine to allow the filled buffers to come back. It gets a
bit complicated, but has great performance (or low overhead, whichever
your perspective).
Imagine we want to reimplement [vwait] with no extra threads, and we
have a fileevent readable on stdin. So the thing to wait for is
GetStdHandle(STD_INPUT_HANDLE), or an event object bound to it through
an OVERLAPPED structure.
Well, no actually. All the generic aspects of the notifier/event loop
are just fine the way they are. The part that could change is only
tclWinConsole.c
Yes, you could event trigger on an overlapped ReadFileEx coming back or
instead have a single thread dedicated to servicing a completion port.
I prefer the later myself.
The notifier (the main thread) itself does wait in an APC compliant
manner and *could* be used to service an APC completion routine, but
there could be a starvation issue when you need to emulate blocking in
the Tcl_DriverOutputProc. I guess as long as the block is APC happy, it
could work _without_ the use of additional service threads. APC
compliant waits are functions such as WaitForMultipleObjectsEx that set
bAlertable to TRUE.
Hmm.. Now you got me thinking about the details :)
But how do we alter this existing handle to be in overlapped mode,
since it is already opened (it may be a pipe, file, or console), in
non-overlapped mode ???
Change the opening code in tclWinChan.c:TclpOpenFileChannel prior to
creating the channel for it with TclWinOpenConsoleChannel(). There is
an example of that already for serial channels.
All that's really important is that when the channel becomes serviceable
and we have an async path for it to let us know, that we call
Tcl_AlertNotifier so the notifier wait ends and the open channel list is
queried for new jobs. Oh.. and blocking emulation is working, too.
So in summary, I think ReadFileEx using a completion routine operated in
overlapped mode would be an excellent way to do asynchronous/alertable
reads from a console for just characters.
.
- Follow-Ups:
- Re: The Tcl notifier and Console on Windows
- From: Alex
- Re: The Tcl notifier and Console on Windows
- From: David Gravereaux
- Re: The Tcl notifier and Console on Windows
- References:
- The Tcl notifier and Console on Windows
- From: Alex
- Re: The Tcl notifier and Console on Windows
- From: David Gravereaux
- Re: The Tcl notifier and Console on Windows
- From: Alex
- Re: The Tcl notifier and Console on Windows
- From: David Gravereaux
- Re: The Tcl notifier and Console on Windows
- From: Alex
- The Tcl notifier and Console on Windows
- Prev by Date: Re: ing by symbolic constants
- Next by Date: Supporting file associaions.
- Previous by thread: Re: The Tcl notifier and Console on Windows
- Next by thread: Re: The Tcl notifier and Console on Windows
- Index(es):
Relevant Pages
|