summaryrefslogtreecommitdiff
path: root/utils/iserv
diff options
context:
space:
mode:
authorTamar Christina <tamar@zhox.com>2022-01-18 01:30:42 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-04-28 22:19:34 -0400
commit905206d67854edbc89978bd554724f57dc8553c2 (patch)
tree1e5bb9ba25985b0f3adca6194533ac52c4a83914 /utils/iserv
parent292e39713e2e17ca902e575d6a41a6f95ee444b2 (diff)
downloadhaskell-905206d67854edbc89978bd554724f57dc8553c2.tar.gz
winio: add support to iserv.
Diffstat (limited to 'utils/iserv')
-rw-r--r--utils/iserv/src/Main.hs32
1 files changed, 26 insertions, 6 deletions
diff --git a/utils/iserv/src/Main.hs b/utils/iserv/src/Main.hs
index a73efacb2b..95e43b93c9 100644
--- a/utils/iserv/src/Main.hs
+++ b/utils/iserv/src/Main.hs
@@ -21,6 +21,14 @@ import Data.IORef
import System.Environment
import System.Exit
import Text.Printf
+#if defined(WINDOWS)
+import Foreign.Ptr (wordPtrToPtr)
+# if defined(__IO_MANAGER_WINIO__)
+import GHC.IO.SubSystem ((<!>))
+import GHC.IO.Handle.Windows (handleToHANDLE)
+import GHC.Event.Windows (associateHandle')
+# endif
+#endif
dieWithUsage :: IO a
dieWithUsage = do
@@ -36,12 +44,27 @@ dieWithUsage = do
main :: IO ()
main = do
args <- getArgs
- (wfd1, rfd2, rest) <-
+ (outh, inh, rest) <-
case args of
arg0:arg1:rest -> do
+#if defined(WINDOWS)
+ let wfd1 = wordPtrToPtr (read arg0)
+ rfd2 = wordPtrToPtr (read arg1)
+# if defined(__IO_MANAGER_WINIO__)
+ -- register the handles we received with
+ -- our I/O manager otherwise we can't use
+ -- them correctly.
+ return () <!> (do
+ associateHandle' wfd1
+ associateHandle' rfd2)
+# endif
+#else
let wfd1 = read arg0
rfd2 = read arg1
- return (wfd1, rfd2, rest)
+#endif
+ inh <- getGhcHandle rfd2
+ outh <- getGhcHandle wfd1
+ return (outh, inh, rest)
_ -> dieWithUsage
(verbose, rest') <- case rest of
@@ -56,10 +79,7 @@ main = do
dieWithUsage
when verbose $
- printf "GHC iserv starting (in: %d; out: %d)\n"
- (fromIntegral rfd2 :: Int) (fromIntegral wfd1 :: Int)
- inh <- getGhcHandle rfd2
- outh <- getGhcHandle wfd1
+ printf "GHC iserv starting (in: %s; out: %s)\n" (show inh) (show outh)
installSignalHandlers
lo_ref <- newIORef Nothing
let pipe = Pipe{pipeRead = inh, pipeWrite = outh, pipeLeftovers = lo_ref}