From 85914371f31952b30b062624feec35706382af95 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 28 Apr 2017 17:50:20 -0400 Subject: reorg --- ControlSocket.hs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'ControlSocket.hs') diff --git a/ControlSocket.hs b/ControlSocket.hs index 8aa68cd..6512f4b 100644 --- a/ControlSocket.hs +++ b/ControlSocket.hs @@ -36,29 +36,15 @@ instance FromJSON ControlOutput defaultSocketFile :: IO FilePath defaultSocketFile = ( "control") <$> dotDir --- | Opens the control window, or if that can't be done, tells the user --- to run debug-me --control. --- --- Returns once either of the TMChans is closed. -openControlWindow :: IO (TMChan ControlInput, TMChan ControlOutput) -openControlWindow = do - socketfile <- defaultSocketFile +bindSocket :: FilePath -> IO S.Socket +bindSocket socketfile = do -- Delete any existing socket file. _ <- try (removeLink socketfile) :: IO (Either IOException ()) soc <- S.socket S.AF_UNIX S.Stream S.defaultProtocol S.bind soc (S.SockAddrUnix socketfile) setFileMode socketfile (unionFileModes ownerWriteMode ownerReadMode) S.listen soc 2 - ichan <- newTMChanIO - ochan <- newTMChanIO - _ <- async $ serveControlSocket soc ichan ochan - -- Wait for message from control process. - putStrLn "You need to open another shell prompt, and run: debug-me --control" - v <- atomically $ readTMChan ochan - case v of - Just ControlWindowOpened -> return () - _ -> error "unexpected message from control process" - return (ichan, ochan) + return soc -- | Serve connections to the control socket, feeding data between it and -- the TMChans. -- cgit v1.2.3