remotedaemon: avoid extraneous stdout output

This commit is contained in:
Joey Hess 2014-04-08 14:02:25 -04:00
parent 9a4a3bfb43
commit cbcb7f50d8
3 changed files with 24 additions and 23 deletions

View file

@ -26,18 +26,19 @@ import qualified Data.Map as M
runForeground :: IO ()
runForeground = do
(readh, writeh) <- ioHandles
ichan <- newChan :: IO (Chan Consumed)
ochan <- newChan :: IO (Chan Emitted)
let reader = forever $ do
l <- getLine
l <- hGetLine readh
case parseMessage l of
Nothing -> error $ "protocol error: " ++ l
Just cmd -> writeChan ichan cmd
let writer = forever $ do
msg <- readChan ochan
putStrLn $ unwords $ formatMessage msg
hFlush stdout
hPutStrLn writeh $ unwords $ formatMessage msg
hFlush writeh
let controller = runController ichan ochan
-- If any thread fails, the rest will be killed.