#2189: hSetBuffering stdin NoBuffering doesn't work on Windows
-----------------------------------------------+----------------------------
Reporter: FalconNL | Owner:
Type: bug | Status: new
Priority: normal | Milestone: 6.10.2
Component: libraries/base | Version: 6.8.2
Severity: normal | Resolution:
Keywords: hsetbuffering buffering buffer | Difficulty: Unknown
Testcase: | Os: Windows
Architecture: x86 |
-----------------------------------------------+----------------------------
Comment (by sof):
ok, not futzing with making this a proper patch:
{{{
--- old-base/cbits/consUtils.c 2009-02-25 10:06:10.631125000 -0800
+++ new-base/cbits/consUtils.c 2009-02-25 10:06:10.646750000 -0800
@@ -25,10 +25,13 @@
DWORD flgs = ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT;
if ( (h = (HANDLE)_get_osfhandle(fd)) != INVALID_HANDLE_VALUE ) {
+ /* Only for console-connected Handles */
+ if ( GetFileType(h) == FILE_TYPE_CHAR ) {
if ( GetConsoleMode(h,&st) &&
- SetConsoleMode(h, cooked ? (st | ENABLE_LINE_INPUT) : st &
~flgs) ) {
+ SetConsoleMode(h, cooked ? (st | flgs) : st & ~flgs) ) {
return 0;
}
+ }
}
return -1;
}
--- old-base/GHC/Handle.hs 2009-02-25 10:06:10.631125000 -0800
+++ new-base/GHC/Handle.hs 2009-02-25 10:06:10.646750000 -0800
@@ -1374,13 +1374,10 @@
is_tty <- fdIsTTY (haFD handle_)
when (is_tty && isReadableHandleType (haType handle_)) $
case mode of
-#ifndef mingw32_HOST_OS
- -- 'raw' mode under win32 is a bit too specialised (and
troublesome
- -- for most common uses), so simply disable its use here.
+ -- Note: we used to disable 'cooked' mode setting
+ -- for mingw / win32 here, but it is now back on (and
well
+ -- behaved for Console-connected Handles.)
NoBuffering -> setCooked (haFD handle_) False
-#else
- NoBuffering -> return ()
-#endif
_ -> setCooked (haFD handle_) True
-- throw away spare buffers, they might be the wrong size
}}}
i.e., reliably (un)setting the line buffering flags of the underlying
Console handle (if there's one) takes care of this.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2189#comment:20>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs