@@ -1,5 +1,87 @@
1+From a6edc06e205848ea1e15456b24238e0f7cb001cd Mon Sep 17 00:00:00 2001
2+From: Moritz Angermann <moritz.angermann@gmail.com>
3+Date: Wed, 30 Jan 2019 09:47:20 +0800
4+Subject: [PATCH] Cleanup iserv/iserv-proxy
5+
6+This adds trace messages that include the processes name and as such
7+make debugging and following the communication easier.
8+
9+It also adds a note regarding the fwd*Call proxy-communication logic
10+between the proxy and the slave.
11+
12+The proxy will now also poll for 60s to wait for the remote iserv
13+to come up. (Alternatively you can start the remote process
14+beforehand; and just have iserv-proxy connect to it)
15+---
16+ .gitignore | 1 +
17+ configure.ac | 2 +-
18+ docs/users_guide/ghci.rst | 32 +++++
19+ libraries/libiserv/libiserv.cabal.in | 2 +-
20+ libraries/libiserv/proxy-src/Remote.hs | 3 +-
21+ libraries/libiserv/src/Lib.hs | 23 +++-
22+ libraries/libiserv/src/Remote/Slave.hs | 24 ++--
23+ testsuite/tests/iserv-remote/Lib.hs | 7 ++
24+ testsuite/tests/iserv-remote/Main.hs | 5 +
25+ testsuite/tests/iserv-remote/Makefile | 38 ++++++
26+ testsuite/tests/iserv-remote/Setup.hs | 2 +
27+ testsuite/tests/iserv-remote/all.T | 11 ++
28+ .../tests/iserv-remote/iserv-remote.stderr | 1 +
29+ .../tests/iserv-remote/iserv-remote.stdout | 1 +
30+ testsuite/tests/iserv-remote/iserv-wrapper | 12 ++
31+ .../tests/iserv-remote/remote-iserv.stderr | 2 +
32+ .../tests/iserv-remote/remote-iserv.stdout | 4 +
33+ utils/iserv-proxy/Makefile | 4 +-
34+ utils/iserv-proxy/iserv-proxy.cabal.in | 2 +-
35+ utils/iserv-proxy/src/Main.hs | 89 ++++++++++----
36+ utils/remote-iserv/Makefile | 15 +++
37+ utils/remote-iserv/Setup.hs | 2 +
38+ utils/remote-iserv/ghc.mk | 113 ++++++++++++++++++
39+ utils/remote-iserv/remote-iserv.cabal.in | 27 +++++
40+ utils/remote-iserv/src/Cli.hs | 30 +++++
41+ 25 files changed, 415 insertions(+), 37 deletions(-)
42+ create mode 100644 testsuite/tests/iserv-remote/Lib.hs
43+ create mode 100644 testsuite/tests/iserv-remote/Main.hs
44+ create mode 100644 testsuite/tests/iserv-remote/Makefile
45+ create mode 100644 testsuite/tests/iserv-remote/Setup.hs
46+ create mode 100644 testsuite/tests/iserv-remote/all.T
47+ create mode 100644 testsuite/tests/iserv-remote/iserv-remote.stderr
48+ create mode 100644 testsuite/tests/iserv-remote/iserv-remote.stdout
49+ create mode 100755 testsuite/tests/iserv-remote/iserv-wrapper
50+ create mode 100644 testsuite/tests/iserv-remote/remote-iserv.stderr
51+ create mode 100644 testsuite/tests/iserv-remote/remote-iserv.stdout
52+ create mode 100644 utils/remote-iserv/Makefile
53+ create mode 100644 utils/remote-iserv/Setup.hs
54+ create mode 100644 utils/remote-iserv/ghc.mk
55+ create mode 100644 utils/remote-iserv/remote-iserv.cabal.in
56+ create mode 100644 utils/remote-iserv/src/Cli.hs
57+
58+diff --git a/.gitignore b/.gitignore
59+index b205b2441e..453f7e3ada 100644
60+--- a/.gitignore
61++++ b/.gitignore
62+@@ -181,6 +181,7 @@ _darcs/
63+ /testlog*
64+ /utils/iserv/iserv.cabal
65+ /utils/iserv-proxy/iserv-proxy.cabal
66++/utils/remote-iserv/remote-iserv.cabal
67+ /utils/mkUserGuidePart/mkUserGuidePart.cabal
68+ /utils/runghc/runghc.cabal
69+ /utils/gen-dll/gen-dll.cabal
70+diff --git a/configure.ac b/configure.ac
71+index e4c4b02fb4..434aa4e29c 100644
72+--- a/configure.ac
73++++ b/configure.ac
74+@@ -1329,7 +1329,7 @@ checkMake380() {
75+ checkMake380 make
76+ checkMake380 gmake
77+
78+-AC_CONFIG_FILES([mk/config.mk mk/install.mk mk/project.mk rts/rts.cabal compiler/ghc.cabal ghc/ghc-bin.cabal utils/iserv/iserv.cabal utils/iserv-proxy/iserv-proxy.cabal utils/runghc/runghc.cabal utils/gen-dll/gen-dll.cabal libraries/ghc-boot/ghc-boot.cabal libraries/ghc-boot-th/ghc-boot-th.cabal libraries/ghci/ghci.cabal libraries/ghc-heap/ghc-heap.cabal libraries/libiserv/libiserv.cabal settings docs/users_guide/ghc_config.py docs/index.html libraries/prologue.txt distrib/configure.ac])
79++AC_CONFIG_FILES([mk/config.mk mk/install.mk mk/project.mk rts/rts.cabal compiler/ghc.cabal ghc/ghc-bin.cabal utils/iserv/iserv.cabal utils/iserv-proxy/iserv-proxy.cabal utils/remote-iserv/remote-iserv.cabal utils/runghc/runghc.cabal utils/gen-dll/gen-dll.cabal libraries/ghc-boot/ghc-boot.cabal libraries/ghc-boot-th/ghc-boot-th.cabal libraries/ghci/ghci.cabal libraries/ghc-heap/ghc-heap.cabal libraries/libiserv/libiserv.cabal settings docs/users_guide/ghc_config.py docs/index.html libraries/prologue.txt distrib/configure.ac])
80+ AC_OUTPUT
81+ [
82+ if test "$print_make_warning" = "true"; then
183diff --git a/docs/users_guide/ghci.rst b/docs/users_guide/ghci.rst
2−index 49a96caa0b..e974840d7d 100644
84+index 544b8604ef..fa6e6c4780 100644
385--- a/docs/users_guide/ghci.rst
486+++ b/docs/users_guide/ghci.rst
587@@ -3287,6 +3287,38 @@ dynamically-linked) from GHC itself. So for example:
@@ -41,11 +123,38 @@ index 49a96caa0b..e974840d7d 100644
41123 .. _ghci-faq:
42124
43125 FAQ and Things To Watch Out For
126+diff --git a/libraries/libiserv/libiserv.cabal.in b/libraries/libiserv/libiserv.cabal.in
127+index 31eaaeb838..3721a853cc 100644
128+--- a/libraries/libiserv/libiserv.cabal.in
129++++ b/libraries/libiserv/libiserv.cabal.in
130+@@ -33,7 +33,7 @@ Library
131+ if flag(network)
132+ Exposed-Modules: Remote.Message
133+ , Remote.Slave
134+- Build-Depends: network >= 2.6 && < 2.7,
135++ Build-Depends: network >= 2.6 && < 3,
136+ directory >= 1.3 && < 1.4,
137+ filepath >= 1.4 && < 1.5
138+
139+diff --git a/libraries/libiserv/proxy-src/Remote.hs b/libraries/libiserv/proxy-src/Remote.hs
140+index c91b2d08c6..d07220ba7f 100644
141+--- a/libraries/libiserv/proxy-src/Remote.hs
142++++ b/libraries/libiserv/proxy-src/Remote.hs
143+@@ -107,7 +107,8 @@ main = do
144+ putStrLn ("Trying to connect to " ++ host_ip ++ ":" ++ (show port))
145+ out_pipe <- connectTo host_ip port >>= socketToPipe
146+
147+- putStrLn "Starting proxy"
148++ when verbose $
149++ putStrLn "Starting proxy"
150+ proxy verbose in_pipe out_pipe
151+
152+ -- | A hook, to transform outgoing (proxy -> slave)
44153diff --git a/libraries/libiserv/src/Lib.hs b/libraries/libiserv/src/Lib.hs
45−index 57e65706c3..707966dc2d 100644
154+index 57e65706c3..69741fdd73 100644
46155--- a/libraries/libiserv/src/Lib.hs
47156+++ b/libraries/libiserv/src/Lib.hs
48−@@ -10,25 +10,33 @@ import Control.Exception
157+@@ -10,16 +10,24 @@ import Control.Exception
49158 import Control.Monad
50159 import Data.Binary
51160
@@ -63,19 +172,15 @@ index 57e65706c3..707966dc2d 100644
63172 loop = do
64173+ when verbose $ trace "reading pipe..."
65174 Msg msg <- readPipe pipe getMessage >>= hook
66−- discardCtrlC
175++
176+ discardCtrlC
67177
68178- when verbose $ putStrLn ("iserv: " ++ show msg)
69−+ discardCtrlC verbose
70−+
71179+ when verbose $ trace ("msg: " ++ (show msg))
72180 case msg of
73181 Shutdown -> return ()
74−- RunTH st q ty loc -> wrapRunTH $ runTH pipe st q ty loc
75−- RunModFinalizers st qrefs -> wrapRunTH $ runModFinalizerRefs pipe st qrefs
76−+ RunTH st q ty loc -> wrapRunTH verbose $ runTH pipe st q ty loc
77−+ RunModFinalizers st qrefs -> wrapRunTH verbose $ runModFinalizerRefs pipe st qrefs
78− _other -> run msg >>= reply
182+ RunTH st q ty loc -> wrapRunTH $ runTH pipe st q ty loc
183+@@ -28,7 +36,7 @@ serv verbose hook pipe@Pipe{..} restore = loop
79184
80185 reply :: forall a. (Binary a, Show a) => a -> IO ()
81186 reply r = do
@@ -84,17 +189,12 @@ index 57e65706c3..707966dc2d 100644
84189 writePipe pipe (put r)
85190 loop
86191
87−@@ -36,36 +44,43 @@ serv verbose hook pipe@Pipe{..} restore = loop
88− -- THMessage requests, and then finally send RunTHDone followed by a
89− -- QResult. For an overview of how TH works with Remote GHCi, see
192+@@ -38,23 +46,29 @@ serv verbose hook pipe@Pipe{..} restore = loop
90193 -- Note [Remote Template Haskell] in libraries/ghci/GHCi/TH.hs.
91−- wrapRunTH :: forall a. (Binary a, Show a) => IO a -> IO ()
92−- wrapRunTH io = do
93−- r <- try io
94−+ wrapRunTH :: forall a. (Binary a, Show a) => Bool -> IO a -> IO ()
95−+ wrapRunTH verbose io = do
194+ wrapRunTH :: forall a. (Binary a, Show a) => IO a -> IO ()
195+ wrapRunTH io = do
96196+ when verbose $ trace "wrapRunTH..."
97−+ r <- Right <$> io -- try io
197+ r <- try io
98198+ when verbose $ trace "wrapRunTH done."
99199+ when verbose $ trace "writing RunTHDone."
100200 writePipe pipe (putTHMessage RunTHDone)
@@ -105,8 +205,7 @@ index 57e65706c3..707966dc2d 100644
105205+ when verbose $ trace ("QFail " ++ show err)
106206 reply (QFail err :: QResult a)
107207 | otherwise -> do
108−- str <- showException e
109−+ str <- showException verbose e
208+ str <- showException e
110209+ when verbose $ trace ("QException " ++ str)
111210 reply (QException str :: QResult a)
112211 Right a -> do
@@ -116,29 +215,20 @@ index 57e65706c3..707966dc2d 100644
116215
117216 -- carefully when showing an exception, there might be other exceptions
118217 -- lurking inside it. If so, we return the inner exception instead.
119−- showException :: SomeException -> IO String
120−- showException e0 = do
121−+ showException :: Bool -> SomeException -> IO String
122−+ showException verbose e0 = do
218+ showException :: SomeException -> IO String
219+ showException e0 = do
123220+ when verbose $ trace "showException"
124221 r <- try $ evaluate (force (show (e0::SomeException)))
125222 case r of
126−- Left e -> showException e
127−+ Left e -> showException verbose e
128− Right str -> return str
129−
130− -- throw away any pending ^C exceptions while we're not running
223+ Left e -> showException e
224+@@ -64,6 +78,7 @@ serv verbose hook pipe@Pipe{..} restore = loop
131225 -- interpreted code. GHC will also get the ^C, and either ignore it
132226 -- (if this is GHCi), or tell us to quit with a Shutdown message.
133−- discardCtrlC = do
134−+ discardCtrlC verbose = do
227+ discardCtrlC = do
135228+ when verbose $ trace "discardCtrlC"
136229 r <- try $ restore $ return ()
137230 case r of
138−- Left UserInterrupt -> return () >> discardCtrlC
139−+ Left UserInterrupt -> return () >> discardCtrlC verbose
140− Left e -> throwIO e
141− _ -> return ()
231+ Left UserInterrupt -> return () >> discardCtrlC
142232diff --git a/libraries/libiserv/src/Remote/Slave.hs b/libraries/libiserv/src/Remote/Slave.hs
143233index b80d09592f..577161f35f 100644
144234--- a/libraries/libiserv/src/Remote/Slave.hs
@@ -204,6 +294,149 @@ index b80d09592f..577161f35f 100644
204294 handleLoad pipe path (base_path <//> path)
205295 return $ Msg (LoadDLL (base_path <//> path))
206296 _other -> return m
297+diff --git a/testsuite/tests/iserv-remote/Lib.hs b/testsuite/tests/iserv-remote/Lib.hs
298+new file mode 100644
299+index 0000000000..f34fc9d8ab
300+--- /dev/null
301++++ b/testsuite/tests/iserv-remote/Lib.hs
302+@@ -0,0 +1,7 @@
303++{-# LANGUAGE TemplateHaskell #-}
304++module Lib where
305++
306++import Language.Haskell.TH
307++
308++x :: Int -> ExpQ
309++x n = [| 3 + n |]
310+diff --git a/testsuite/tests/iserv-remote/Main.hs b/testsuite/tests/iserv-remote/Main.hs
311+new file mode 100644
312+index 0000000000..dcc2354287
313+--- /dev/null
314++++ b/testsuite/tests/iserv-remote/Main.hs
315+@@ -0,0 +1,5 @@
316++{-# LANGUAGE TemplateHaskell #-}
317++
318++import Lib (x)
319++
320++main = putStrLn "Hello World" >> print $(x 10)
321+diff --git a/testsuite/tests/iserv-remote/Makefile b/testsuite/tests/iserv-remote/Makefile
322+new file mode 100644
323+index 0000000000..409e33be09
324+--- /dev/null
325++++ b/testsuite/tests/iserv-remote/Makefile
326+@@ -0,0 +1,38 @@
327++TOP=../..
328++include $(TOP)/mk/boilerplate.mk
329++include $(TOP)/mk/test.mk
330++
331++SETUP='$(PWD)/Setup' -v0
332++CONFIGURE=$(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db='$(PWD)/tmp.d' --prefix='$(PWD)/inst'
333++
334++remote-iserv: clean
335++ '$(GHC_PKG)' init tmp.d
336++
337++ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make Setup
338++
339++ cp -r $(TOP)/../libraries/libiserv .
340++ cd libiserv && $(CONFIGURE) -fnetwork
341++ cd libiserv && $(SETUP) build
342++ cd libiserv && $(SETUP) copy
343++ cd libiserv && $(SETUP) register
344++
345++ cp -r $(TOP)/../utils/iserv-proxy .
346++ cd iserv-proxy && $(CONFIGURE)
347++ cd iserv-proxy && $(SETUP) build
348++ cd iserv-proxy && $(SETUP) copy
349++ cd iserv-proxy && $(SETUP) register
350++
351++ cp -r $(TOP)/../utils/remote-iserv .
352++ cd remote-iserv && $(CONFIGURE)
353++ cd remote-iserv && $(SETUP) build
354++ cd remote-iserv && $(SETUP) copy
355++ cd remote-iserv && $(SETUP) register
356++
357++ '$(TEST_HC)' $(TEST_HC_OPTS) -fexternal-interpreter -pgmi $(PWD)/iserv-wrapper Main.hs
358++
359++ifneq "$(CLEANUP)" ""
360++ $(MAKE) -s --no-print-directory clean
361++endif
362++
363++clean :
364++ $(RM) -rf tmp *.o *.hi Main libiserv iserv-proxy remote-iserv tmp.d inst dist Setup$(exeext)
365+diff --git a/testsuite/tests/iserv-remote/Setup.hs b/testsuite/tests/iserv-remote/Setup.hs
366+new file mode 100644
367+index 0000000000..9a994af677
368+--- /dev/null
369++++ b/testsuite/tests/iserv-remote/Setup.hs
370+@@ -0,0 +1,2 @@
371++import Distribution.Simple
372++main = defaultMain
373+diff --git a/testsuite/tests/iserv-remote/all.T b/testsuite/tests/iserv-remote/all.T
374+new file mode 100644
375+index 0000000000..f8f0920835
376+--- /dev/null
377++++ b/testsuite/tests/iserv-remote/all.T
378+@@ -0,0 +1,11 @@
379++def normalise_port(str):
380++ str = re.sub(r'on port [0-9]+', r'on port ****', str)
381++ return str
382++
383++test('remote-iserv'
384++ , [ reqlib('network')
385++ , normalise_fun(normalise_port)
386++ , normalise_errmsg_fun(normalise_port)
387++ , extra_files(['Main.hs', 'Lib.hs', 'iserv-wrapper', 'Setup.hs'])]
388++ , makefile_test
389++ , [])
390+diff --git a/testsuite/tests/iserv-remote/iserv-remote.stderr b/testsuite/tests/iserv-remote/iserv-remote.stderr
391+new file mode 100644
392+index 0000000000..8b13789179
393+--- /dev/null
394++++ b/testsuite/tests/iserv-remote/iserv-remote.stderr
395+@@ -0,0 +1 @@
396++
397+diff --git a/testsuite/tests/iserv-remote/iserv-remote.stdout b/testsuite/tests/iserv-remote/iserv-remote.stdout
398+new file mode 100644
399+index 0000000000..8b13789179
400+--- /dev/null
401++++ b/testsuite/tests/iserv-remote/iserv-remote.stdout
402+@@ -0,0 +1 @@
403++
404+diff --git a/testsuite/tests/iserv-remote/iserv-wrapper b/testsuite/tests/iserv-remote/iserv-wrapper
405+new file mode 100755
406+index 0000000000..6c7da86214
407+--- /dev/null
408++++ b/testsuite/tests/iserv-remote/iserv-wrapper
409+@@ -0,0 +1,12 @@
410++#!/bin/bash
411++PORT=$(($((5000+$RANDOM)) % 10000))
412++
413++(>&2 echo "starting remote-iserv on port $PORT")
414++
415++./inst/bin/remote-iserv tmp $PORT &
416++REMOTE="$!"
417++
418++(>&2 echo "starting iserv-proxy with $@")
419++./inst/bin/iserv-proxy $@ 127.0.0.1 $PORT
420++
421++kill $REMOTE
422+diff --git a/testsuite/tests/iserv-remote/remote-iserv.stderr b/testsuite/tests/iserv-remote/remote-iserv.stderr
423+new file mode 100644
424+index 0000000000..cd6f9d4385
425+--- /dev/null
426++++ b/testsuite/tests/iserv-remote/remote-iserv.stderr
427+@@ -0,0 +1,2 @@
428++starting remote-iserv on port 2051
429++starting iserv-proxy with 13 14
430+diff --git a/testsuite/tests/iserv-remote/remote-iserv.stdout b/testsuite/tests/iserv-remote/remote-iserv.stdout
431+new file mode 100644
432+index 0000000000..b062df0c31
433+--- /dev/null
434++++ b/testsuite/tests/iserv-remote/remote-iserv.stdout
435+@@ -0,0 +1,4 @@
436++[1 of 2] Compiling Lib ( Lib.hs, Lib.o )
437++[2 of 2] Compiling Main ( Main.hs, Main.o )
438++Listening on port 2051
439++Linking Main ...
207440diff --git a/utils/iserv-proxy/Makefile b/utils/iserv-proxy/Makefile
208441index f160978c19..dec92996f7 100644
209442--- a/utils/iserv-proxy/Makefile
@@ -217,8 +450,21 @@ index f160978c19..dec92996f7 100644
217450+dir = iserv-proxy
218451+TOP = ../..
219452 include $(TOP)/mk/sub-makefile.mk
453+diff --git a/utils/iserv-proxy/iserv-proxy.cabal.in b/utils/iserv-proxy/iserv-proxy.cabal.in
454+index 0819064601..cd36426f81 100644
455+--- a/utils/iserv-proxy/iserv-proxy.cabal.in
456++++ b/utils/iserv-proxy/iserv-proxy.cabal.in
457+@@ -73,7 +73,7 @@ Executable iserv-proxy
458+ base >= 4 && < 5,
459+ binary >= 0.7 && < 0.9,
460+ bytestring >= 0.10 && < 0.11,
461+- containers >= 0.5 && < 0.6,
462++ containers >= 0.5 && < 0.8,
463+ deepseq >= 1.4 && < 1.5,
464+ directory >= 1.3 && < 1.4,
465+ network >= 2.6,
220466diff --git a/utils/iserv-proxy/src/Main.hs b/utils/iserv-proxy/src/Main.hs
221−index c91b2d08c6..3970ad5df1 100644
467+index c91b2d08c6..5901ffe562 100644
222468--- a/utils/iserv-proxy/src/Main.hs
223469+++ b/utils/iserv-proxy/src/Main.hs
224470@@ -1,4 +1,4 @@
@@ -250,7 +496,7 @@ index c91b2d08c6..3970ad5df1 100644
250496 args <- getArgs
251497 (wfd1, rfd2, host_ip, port, rest) <-
252498 case args of
253−@@ -104,10 +113,16 @@ main = do
499+@@ -104,10 +113,17 @@ main = do
254500 let in_pipe = Pipe{pipeRead = inh, pipeWrite = outh, pipeLeftovers = lo_ref}
255501
256502 when verbose $
@@ -260,17 +506,18 @@ index c91b2d08c6..3970ad5df1 100644
260506
261507- putStrLn "Starting proxy"
262508+ out_pipe <- do
263−+ let go n = E.try (connectTo host_ip port >>= socketToPipe) >>= \case
509++ let go n = E.try (connectTo verbose host_ip port >>= socketToPipe) >>= \case
264510+ Left e | n == 0 -> E.throw (e :: E.SomeException)
265511+ | n > 0 -> threadDelay 500000 >> go (n - 1)
266512+ Right a -> return a
267513+ in go 120 -- wait for up to 60seconds (polling every 0.5s).
268514+
269−+ trace "Starting proxy"
515++ when verbose $
516++ trace "Starting proxy"
270517 proxy verbose in_pipe out_pipe
271518
272519 -- | A hook, to transform outgoing (proxy -> slave)
273−@@ -131,19 +146,24 @@ fwdTHMsg local msg = do
520+@@ -131,19 +147,24 @@ fwdTHMsg local msg = do
274521 -- | Fowarard a @Message@ call and handle @THMessages@.
275522 fwdTHCall :: (Binary a) => Bool -> Pipe -> Pipe -> Message a -> IO a
276523 fwdTHCall verbose local remote msg = do
@@ -297,7 +544,7 @@ index c91b2d08c6..3970ad5df1 100644
297544 writePipe remote (put res)
298545 case msg' of
299546 RunTHDone -> return ()
300−@@ -161,8 +181,10 @@ fwdTHCall verbose local remote msg = do
547+@@ -161,8 +182,10 @@ fwdTHCall verbose local remote msg = do
301548 --
302549 fwdLoadCall :: (Binary a, Show a) => Bool -> Pipe -> Pipe -> Message a -> IO a
303550 fwdLoadCall verbose _ remote msg = do
@@ -308,7 +555,7 @@ index c91b2d08c6..3970ad5df1 100644
308555 readPipe remote get
309556 where
310557 truncateMsg :: Int -> String -> String
311−@@ -171,17 +193,19 @@ fwdLoadCall verbose _ remote msg = do
558+@@ -171,17 +194,20 @@ fwdLoadCall verbose _ remote msg = do
312559 reply :: (Binary a, Show a) => a -> IO ()
313560 reply m = do
314561 when verbose $
@@ -326,11 +573,12 @@ index c91b2d08c6..3970ad5df1 100644
326573 case msg' of
327574 Done -> return ()
328575 Missing path -> do
329−+ trace $ "fwdLoadCall: missing path: " ++ path
576++ when verbose $
577++ trace $ "fwdLoadCall: missing path: " ++ path
330578 reply =<< BS.readFile path
331579 loopLoad
332580 Have path remoteHash -> do
333−@@ -198,21 +222,33 @@ proxy verbose local remote = loop
581+@@ -198,21 +224,33 @@ proxy verbose local remote = loop
334582 where
335583 fwdCall :: (Binary a, Show a) => Message a -> IO a
336584 fwdCall msg = do
@@ -366,7 +614,7 @@ index c91b2d08c6..3970ad5df1 100644
366614 case msg' of
367615 -- TH might send some message back to ghc.
368616 RunTH{} -> do
369−@@ -233,6 +269,10 @@ proxy verbose local remote = loop
617+@@ -233,6 +271,10 @@ proxy verbose local remote = loop
370618 resp <- fwdLoadCall verbose local remote msg'
371619 reply resp
372620 loop
@@ -377,10 +625,12 @@ index c91b2d08c6..3970ad5df1 100644
377625 LoadDLL path | isAbsolute path -> do
378626 resp <- fwdLoadCall verbose local remote msg'
379627 reply resp
380−@@ -243,14 +283,19 @@ proxy verbose local remote = loop
628+@@ -241,16 +283,23 @@ proxy verbose local remote = loop
629+ _other -> fwdCall msg' >>= reply >> loop
630+
381631
382− connectTo :: String -> PortNumber -> IO Socket
383− connectTo host port = do
632+-connectTo :: String -> PortNumber -> IO Socket
633+-connectTo host port = do
384634- let hints = defaultHints { addrFlags = [AI_NUMERICHOST, AI_NUMERICSERV]
385635- , addrSocketType = Stream }
386636- addr:_ <- getAddrInfo (Just hints) (Just host) (Just (show port))
@@ -389,6 +639,8 @@ index c91b2d08c6..3970ad5df1 100644
389639- connect sock (addrAddress addr)
390640- putStrLn "connected"
391641- return sock
642++connectTo :: Bool -> String -> PortNumber -> IO Socket
643++connectTo verbose host port = do
392644+ addr <- resolve host (show port)
393645+ open addr
394646+ where
@@ -398,9 +650,11 @@ index c91b2d08c6..3970ad5df1 100644
398650+ return addr
399651+ open addr = do
400652+ sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr)
401−+ trace $ "Created socket for " ++ host ++ ":" ++ show port
653++ when verbose $
654++ trace $ "Created socket for " ++ host ++ ":" ++ show port
402655+ connect sock $ addrAddress addr
403−+ trace "connected"
656++ when verbose $
657++ trace "connected"
404658+ return sock
405659
406660 -- | Turn a socket into an unbuffered pipe.
@@ -555,13 +809,13 @@ index 0000000000..db8f32fc22
555809+all_ghc_stage2 : $(remote-iserv-stage2_dyn_INPLACE)
556810diff --git a/utils/remote-iserv/remote-iserv.cabal.in b/utils/remote-iserv/remote-iserv.cabal.in
557811new file mode 100644
558−index 0000000000..2e9123bf5e
812+index 0000000000..a1cba01301
559813--- /dev/null
560814+++ b/utils/remote-iserv/remote-iserv.cabal.in
561815@@ -0,0 +1,27 @@
562−+-- WARNING: iserv-proxy.cabal is automatically generated from iserv-proxy.cabal.in by
563−+-- ../../configure. Make sure you are editing iserv-proxy.cabal.in, not
564−+-- iserv-proxy.cabal.
816++-- WARNING: iserv-proxy.cabal is automatically generated from remote-iserv.cabal.in by
817++-- ../../configure. Make sure you are editing remote-iserv.cabal.in, not
818++-- remote-iserv.cabal.
565819+
566820+Name: remote-iserv
567821+Version: @ProjectVersion@
@@ -622,3 +876,6 @@ index 0000000000..eb8f92c39c
622876+ _ -> dieWithUsage
623877+
624878+ startSlave' verbose path port
879+--
880+2.24.1
881+