Skip to content

Commit

Permalink
Qualify Control.Exception imports.
Browse files Browse the repository at this point in the history
In older versions of base, Prelude exported "catch". The qualified
lets us avoid warnings with older or newer versions of base.
  • Loading branch information
acowley committed Feb 7, 2013
1 parent d1be04d commit 65bf2c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions src/Ros/RosTcp.hs
Expand Up @@ -5,7 +5,7 @@ import Control.Arrow (first)
import Control.Concurrent (forkIO, killThread, newEmptyMVar, takeMVar, putMVar)
import Control.Concurrent.STM (atomically)
import Control.Concurrent.STM.TVar
import Control.Exception (catch, SomeException)
import qualified Control.Exception as E
import Control.Monad.Reader
import Data.Binary.Put (runPut, putWord32le)
import Data.Binary.Get (runGet, getWord32le)
Expand Down Expand Up @@ -88,20 +88,21 @@ acceptClients sock clients negotiate mkBuffer = forever acceptClient
let cleanup1 =
do debug "Closing client socket"
liftIO $
shutdown client ShutdownBoth `catch`
\(_::SomeException) -> return ()
shutdown client ShutdownBoth `E.catch`
\(_::E.SomeException) -> return ()
r <- ask
t <- liftIO . forkIO $
serviceClient chan client `catch`
\(_::SomeException) -> runReaderT cleanup1 r
serviceClient chan client `E.catch`
\(_::E.SomeException) -> runReaderT cleanup1 r
let cleanup2 = cleanup1 >>
(liftIO $ killThread t)
liftIO . atomically $
readTVar clients >>=
writeTVar clients . ((cleanup2,chan) :)

-- |Publish each item obtained from a 'Topic' to each connected client.
pubStream :: RosBinary a => Topic IO a -> TVar [(b, RingChan ByteString)] -> Config ()
pubStream :: RosBinary a
=> Topic IO a -> TVar [(b, RingChan ByteString)] -> Config ()
pubStream t0 clients = liftIO $ go 0 t0
where go !n t = do (x, t') <- runTopic t
let bytes = runPut $ putMsg n x
Expand Down
11 changes: 6 additions & 5 deletions src/Ros/RunNode.hs
@@ -1,7 +1,7 @@
module Ros.RunNode (runNode) where
import Control.Concurrent (readMVar,forkIO, killThread)
import qualified Control.Concurrent.SSem as Sem
import Control.Exception (catch, SomeException)
import qualified Control.Exception as E
import Control.Monad.IO.Class
import System.Posix.Signals (installHandler, Handler(..), sigINT)
import Ros.Core.RosTypes
Expand Down Expand Up @@ -49,13 +49,14 @@ runNode name s = do (wait, _port) <- liftIO $ runSlave s
registerNode name s
debug "Spinning"
allDone <- liftIO $ Sem.new 0
let ignoreEx :: SomeException -> IO ()
let ignoreEx :: E.SomeException -> IO ()
ignoreEx _ = return ()
shutdown = do putStrLn "Shutting down"
cleanupNode s `catch` ignoreEx
cleanupNode s `E.catch` ignoreEx
Sem.signal allDone
liftIO $ setShutdownAction s shutdown
_ <- liftIO $ installHandler sigINT (CatchOnce shutdown) Nothing
_ <- liftIO $
installHandler sigINT (CatchOnce shutdown) Nothing
t <- liftIO . forkIO $ wait >> Sem.signal allDone
liftIO $ Sem.wait allDone
liftIO $ killThread t `catch` ignoreEx
liftIO $ killThread t `E.catch` ignoreEx

0 comments on commit 65bf2c3

Please sign in to comment.