Skip to content

Commit d6b7134

Browse files
authored
Merge pull request #471 from tmcgilchrist/fsm-warnings
Various minor fixes
2 parents fb03dc3 + 3d35221 commit d6b7134

File tree

9 files changed

+52
-29
lines changed

9 files changed

+52
-29
lines changed

packages/distributed-process-fsm/src/Control/Distributed/Process/FSM.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
-- > ^. ((event :: Event ButtonPush)
128128
-- > ~> ( (On ~@ enter Off))
129129
-- > .| (Off ~@ (set_ (+1) >> enter On))
130-
-- > ) |> (reply currentState))
130+
-- > ) |> (reply currentState)
131131
--
132132
-- Our client code will need to use the @call@ function from the Client module,
133133
-- although it /is/ possible to interact synchronously with an FSM process (e.g.

packages/distributed-process-fsm/src/Control/Distributed/Process/FSM/Client.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ callTimeout pid msg ti = bracket (monitor pid) unmonitor $ \mRef -> do
8080
Just m -> do mR <- unwrapMessage m
8181
case mR of
8282
Just r -> return $ Just r
83-
_ -> die $ ExitOther $ baseErr ++ ".Client:InvalidResponseType"
83+
Nothing -> die $ ExitOther $ baseErr ++ ".Client:InvalidResponseType"
8484

8585
-- | Make a synchronous /call/ to the FSM process at "ProcessId". If a
8686
-- "Step" exists that upon receiving an event of type @m@ will eventually
@@ -98,4 +98,4 @@ call pid msg = bracket (monitor pid) unmonitor $ \mRef -> do
9898
mR <- unwrapMessage msg'
9999
case mR of
100100
Just r -> return r
101-
_ -> die $ ExitOther $ baseErr ++ ".Client:InvalidResponseType"
101+
Nothing -> die $ ExitOther $ baseErr ++ ".Client:InvalidResponseType"

packages/distributed-process-fsm/src/Control/Distributed/Process/FSM/Internal/Process.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ walkPFSM st acc
121121
handleRpcRawInputs :: forall s d . (Show s) => State s d
122122
-> (P.Message, SendPort P.Message)
123123
-> Action (State s d)
124-
handleRpcRawInputs st@State{..} (msg, port) =
124+
handleRpcRawInputs st (msg, port) =
125125
handleInput msg $ st { stReply = (sendChan port), stTrans = Q.empty, stInput = Just msg }
126126

127127
handleAllRawInputs :: forall s d. (Show s) => State s d
128128
-> P.Message
129129
-> Action (State s d)
130-
handleAllRawInputs st@State{..} msg =
130+
handleAllRawInputs st msg =
131131
handleInput msg $ st { stReply = noOp, stTrans = Q.empty, stInput = Just msg }
132132

133133
handleExitReason :: forall s d. (Show s) => State s d
134134
-> P.Message
135135
-> Process (Maybe (ProcessAction (State s d)))
136-
handleExitReason st@State{..} msg =
136+
handleExitReason st msg =
137137
let st' = st { stReply = noOp, stTrans = Q.empty, stInput = Just msg }
138138
in tryHandleInput st' msg
139139

packages/distributed-process-fsm/src/Control/Distributed/Process/FSM/Internal/Types.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import Data.Sequence
9393
)
9494
import qualified Data.Sequence as Q (null)
9595
import Data.Typeable (Typeable, typeOf)
96-
import Data.Tuple (swap, uncurry)
96+
import Data.Tuple (swap)
9797
import GHC.Generics
9898

9999
-- | The internal state of an FSM process.
@@ -312,7 +312,6 @@ apply st msg step
312312
setProcessState s'
313313
-- (_, st') <- runFSM st (addTransition ev)
314314
return $ enqueue st (Just ev)
315-
| otherwise = error $ baseErr ++ ".Internal.Types.apply:InvalidStep"
316315
where
317316
mstash = return . uncurry enqueue . swap
318317
stash (o, s) = return $ enqueue s (Just o)

packages/distributed-process-fsm/tests/TestFSM.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import Test.Tasty.HUnit (testCase, assertEqual, assertBool)
2929
import Network.Transport.TCP
3030
import qualified Network.Transport as NT
3131

32-
-- import Control.Distributed.Process.Serializable (Serializable)
33-
-- import Control.Monad (void)
3432
import Data.Binary (Binary)
3533
import Data.Maybe (fromJust)
3634
import Data.Typeable (Typeable)
@@ -157,7 +155,7 @@ republicationOfEvents = do
157155
send pid "yo"
158156
send pid On
159157

160-
res' <- receiveChanTimeout (asTimeout $ seconds 20) rp :: Process (Maybe ())
158+
_ <- receiveChanTimeout (asTimeout $ seconds 20) rp :: Process (Maybe ())
161159
liftIO $ assertEqual mempty (Just ()) res
162160

163161
kill pid "thankyou byebye"

packages/network-transport-tcp/network-transport-tcp.cabal

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ Test-Suite TestQC
9292
data-accessor,
9393
data-accessor-transformers,
9494
mtl,
95-
transformers,
9695
lockfree-queue
9796
Else
9897
Buildable: False
@@ -105,3 +104,27 @@ Test-Suite TestQC
105104
DeriveDataTypeable
106105
MultiParamTypeClasses
107106
default-language: Haskell2010
107+
108+
executable chat-server
109+
import: warnings
110+
main-is: ChatServer.hs
111+
hs-source-dirs: tests/chat
112+
Default-Language: Haskell2010
113+
build-depends: base >= 4.14 && < 5,
114+
bytestring,
115+
containers,
116+
mtl,
117+
network-transport,
118+
network-transport-tcp
119+
120+
executable chat-client
121+
import: warnings
122+
main-is: ChatClient.hs
123+
hs-source-dirs: tests/chat
124+
Default-Language: Haskell2010
125+
build-depends: base >= 4.14 && < 5,
126+
bytestring,
127+
containers,
128+
network-transport,
129+
network-transport-tcp
130+

packages/network-transport/tests/chat/ChatClient.hs renamed to packages/network-transport-tcp/tests/chat/ChatClient.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
module Main (main) where
2+
13
import System.Environment (getArgs)
24
import Network.Transport
3-
import Network.Transport.TCP (createTransport)
5+
import Network.Transport.TCP (createTransport, defaultTCPAddr, defaultTCPParameters)
46
import Control.Concurrent.MVar (MVar, newEmptyMVar, takeMVar, putMVar, newMVar, readMVar, modifyMVar_, modifyMVar)
57
import Control.Concurrent (forkIO)
68
import Control.Monad (forever, forM, unless, when)
@@ -11,12 +13,12 @@ import qualified Data.Map as Map (fromList, elems, insert, member, empty, size,
1113

1214
chatClient :: MVar () -> EndPoint -> EndPointAddress -> IO ()
1315
chatClient done endpoint serverAddr = do
14-
connect endpoint serverAddr ReliableOrdered
16+
_ <- connect endpoint serverAddr ReliableOrdered defaultConnectHints
1517
cOut <- getPeers >>= connectToPeers
1618
cIn <- newMVar Map.empty
1719

1820
-- Listen for incoming messages
19-
forkIO . forever $ do
21+
_ <- forkIO . forever $ do
2022
event <- receive endpoint
2123
case event of
2224
Received _ msg ->
@@ -26,7 +28,7 @@ chatClient done endpoint serverAddr = do
2628
didAdd <- modifyMVar cOut $ \conns ->
2729
if not (Map.member addr conns)
2830
then do
29-
Right conn <- connect endpoint addr ReliableOrdered
31+
Right conn <- connect endpoint addr ReliableOrdered defaultConnectHints
3032
return (Map.insert addr conn conns, True)
3133
else
3234
return (conns, False)
@@ -38,8 +40,7 @@ chatClient done endpoint serverAddr = do
3840
close (conns Map.! addr)
3941
return (Map.delete addr conns)
4042
showNumPeers cOut
41-
42-
43+
_ -> pure () -- DO nothing for unrecognised events
4344

4445
{-
4546
chatState <- newMVar (Map.fromList peerConns)
@@ -67,7 +68,7 @@ chatClient done endpoint serverAddr = do
6768
let go = do
6869
msg <- BSC.getLine
6970
unless (BS.null msg) $ do
70-
readMVar cOut >>= \conns -> forM (Map.elems conns) $ \conn -> send conn [msg]
71+
_ <- readMVar cOut >>= \conns -> forM (Map.elems conns) $ \conn -> send conn [msg]
7172
go
7273
go
7374
putMVar done ()
@@ -83,7 +84,7 @@ chatClient done endpoint serverAddr = do
8384
connectToPeers :: [EndPointAddress] -> IO (MVar (Map EndPointAddress Connection))
8485
connectToPeers addrs = do
8586
conns <- forM addrs $ \addr -> do
86-
Right conn <- connect endpoint addr ReliableOrdered
87+
Right conn <- connect endpoint addr ReliableOrdered defaultConnectHints
8788
return (addr, conn)
8889
newMVar (Map.fromList conns)
8990

@@ -97,11 +98,11 @@ chatClient done endpoint serverAddr = do
9798
main :: IO ()
9899
main = do
99100
host:port:server:_ <- getArgs
100-
Right transport <- createTransport host port
101+
Right transport <- createTransport (defaultTCPAddr host port) defaultTCPParameters
101102
Right endpoint <- newEndPoint transport
102103
clientDone <- newEmptyMVar
103104

104-
forkIO $ chatClient clientDone endpoint (EndPointAddress . BSC.pack $ server)
105+
_ <- forkIO $ chatClient clientDone endpoint (EndPointAddress . BSC.pack $ server)
105106

106107
takeMVar clientDone
107108

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
module Main (main) where
2+
13
import System.Environment (getArgs)
24
import Network.Transport
3-
import Network.Transport.TCP (createTransport)
5+
import Network.Transport.TCP (createTransport, defaultTCPAddr, defaultTCPParameters)
46
import Control.Monad.State (evalStateT, modify, get)
57
import Control.Monad (forever)
68
import Control.Monad.IO.Class (liftIO)
@@ -10,7 +12,7 @@ import qualified Data.ByteString.Char8 as BSC (pack)
1012
main :: IO ()
1113
main = do
1214
host:port:_ <- getArgs
13-
Right transport <- createTransport host port
15+
Right transport <- createTransport (defaultTCPAddr host port) defaultTCPParameters
1416
Right endpoint <- newEndPoint transport
1517

1618
putStrLn $ "Chat server ready at " ++ (show . endPointAddressToByteString . address $ endpoint)
@@ -20,9 +22,10 @@ main = do
2022
case event of
2123
ConnectionOpened cid _ addr -> do
2224
get >>= \clients -> liftIO $ do
23-
Right conn <- connect endpoint addr ReliableOrdered
24-
send conn [BSC.pack . show . IntMap.elems $ clients]
25+
Right conn <- connect endpoint addr ReliableOrdered defaultConnectHints
26+
_ <- send conn [BSC.pack . show . IntMap.elems $ clients]
2527
close conn
26-
modify $ IntMap.insert cid (endPointAddressToByteString addr)
28+
modify $ IntMap.insert (fromIntegral cid) (endPointAddressToByteString addr)
2729
ConnectionClosed cid ->
28-
modify $ IntMap.delete cid
30+
modify $ IntMap.delete (fromIntegral cid)
31+
_ -> liftIO . putStrLn $ "Other event received"

packages/network-transport/network-transport.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ Library
8181
binary >= 0.8 && < 0.9,
8282
bytestring >= 0.10 && < 0.13,
8383
hashable >= 1.2.0.5 && < 1.6,
84-
transformers >= 0.2 && < 0.7,
8584
deepseq >= 1.0 && < 1.7
8685
Exposed-Modules: Network.Transport
8786
Network.Transport.Util

0 commit comments

Comments
 (0)