summaryrefslogtreecommitdiffhomepage
path: root/ControlSocket.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-28 17:50:20 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-28 17:50:20 -0400
commit85914371f31952b30b062624feec35706382af95 (patch)
tree03f4af1b7c2a0f85b6fc4a52cf81ddc38479efb7 /ControlSocket.hs
parent476b271a96598f5aa6aae330f95fdaed46a62437 (diff)
downloaddebug-me-85914371f31952b30b062624feec35706382af95.tar.gz
reorg
Diffstat (limited to 'ControlSocket.hs')
-rw-r--r--ControlSocket.hs20
1 files changed, 3 insertions, 17 deletions
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.