[GHC] #1198: Windows: hWaitForInput returns False for file handles, and doesn't work properly for consoles

GHC trac at galois.com
Fri Jun 20 06:23:22 EDT 2008


#1198: Windows: hWaitForInput returns False for file handles, and doesn't work
properly for consoles
-------------------------------------+--------------------------------------
 Reporter:  igloo                    |          Owner:         
     Type:  bug                      |         Status:  new    
 Priority:  low                      |      Milestone:  _|_    
Component:  libraries/base           |        Version:  6.6    
 Severity:  normal                   |     Resolution:         
 Keywords:                           |     Difficulty:  Unknown
 Testcase:  readwrite002, hReady001  |   Architecture:  Unknown
       Os:  Windows                  |  
-------------------------------------+--------------------------------------
Changes (by simonmar):

  * summary:  Windows: hWaitForInput returns False for file handles =>
              Windows: hWaitForInput returns False for file
              handles, and doesn't work properly for consoles

Comment:

 I've just spent a while trying to make `hReady/hWaitForInput` do the right
 thing for consoles on Windows, and concluded that it basically isn't
 possible (or at least, I can't find a way to do it).

 The problem is that the Windows console tracks all kinds of events, and
 `WaitForMultipleObjects` will return true if the console has any pending
 events, but the trouble is that these events might not be actual
 characters that can be read (e.g. focus events or key-up events), so when
 you subsequently call `read()` on the console it will block.  So you can
 try to filter out all the uninteresting events, but then you have to worry
 about the fact that e.g. pressing "shift" is a key-down event but doesn't
 generate a character.  At this point I gave up.

 So the upshot is that `hReady` often bogusly returns `True` for `stdin` on
 Windows, in addition to the problems mentioned above with file handles.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1198#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list