git.iko.soy/distributed-process
on master help sign in
Cleanup
fdf266fEdsko de Vries
network-transport-2/src/Network/Transport/Internal.hs+7−7
@@ -5,8 +5,8 @@ module Network.Transport.Internal ( -- * Encoders/decoders
5 , encodeInt16
5 , encodeInt16
6 , decodeInt16
6 , decodeInt16
7 -- * Miscellaneous abstractions
7 -- * Miscellaneous abstractions
8− , maybeToErrorT
8+ , failWith
9− , maybeTToErrorT
9+ , failWithT
10 ) where
10 ) where
11
11
12import Data.Int (Int16, Int32)
12import Data.Int (Int16, Int32)
@@ -57,13 +57,13 @@ decodeInt16 bs = liftIO $ do
57 return (fromIntegral (ntohs w16))
57 return (fromIntegral (ntohs w16))
58
58
59-- | Convert 'Maybe' to an ErrorT value
59-- | Convert 'Maybe' to an ErrorT value
60−maybeToErrorT :: (Monad m, Error a) => a -> Maybe b -> ErrorT a m b
60+failWith :: (Monad m, Error a) => a -> Maybe b -> ErrorT a m b
61−maybeToErrorT err Nothing = throwError err
61+failWith err Nothing = throwError err
62−maybeToErrorT _ (Just x) = return x
62+failWith _ (Just x) = return x
63
63
64-- | Convert 'MaybeT' to an 'ErrorT'
64-- | Convert 'MaybeT' to an 'ErrorT'
65−maybeTToErrorT :: (Monad m, Error a) => a -> MaybeT m b -> ErrorT a m b
65+failWithT :: (Monad m, Error a) => a -> MaybeT m b -> ErrorT a m b
66−maybeTToErrorT err valueT = do
66+failWithT err valueT = do
67 mval <- lift $ runMaybeT valueT
67 mval <- lift $ runMaybeT valueT
68 case mval of
68 case mval of
69 Nothing -> throwError err
69 Nothing -> throwError err
network-transport-2/src/Network/Transport/TCP.hs+9−9
@@ -22,8 +22,8 @@ import Network.Transport.Internal.TCP ( forkServer
22 , sendInt32
22 , sendInt32
23 )
23 )
24import Network.Transport.Internal ( encodeInt16
24import Network.Transport.Internal ( encodeInt16
25− , maybeToErrorT
25+ , failWith
26− , maybeTToErrorT
26+ , failWithT
27 )
27 )
28import qualified Network.Socket as N ( HostName
28import qualified Network.Socket as N ( HostName
29 , ServiceName
29 , ServiceName
@@ -95,7 +95,7 @@ handleClient state sock = do
95 mendpoint <- runMaybeT $ do
95 mendpoint <- runMaybeT $ do
96 ourEndPointId <- recvInt16 sock
96 ourEndPointId <- recvInt16 sock
97 theirAddress <- BS.concat <$> recvWithLength sock
97 theirAddress <- BS.concat <$> recvWithLength sock
98− ourEndPoint <- MaybeT $ (^. endPointAt (fromIntegral ourEndPointId)) <$> readMVar state
98+ ourEndPoint <- MaybeT $ (^. endPointAt ourEndPointId) <$> readMVar state
99 return (ourEndPoint, EndPointAddress theirAddress)
99 return (ourEndPoint, EndPointAddress theirAddress)
100 case mendpoint of
100 case mendpoint of
101 Just ((endPointCh, endPointSt), theirAddress) -> do
101 Just ((endPointCh, endPointSt), theirAddress) -> do
@@ -159,9 +159,9 @@ firstNonReservedConnectionId = 1024
159tcpConnect :: EndPointAddress -> EndPointAddress -> Reliability -> IO (Either (FailedWith ConnectErrorCode) Connection)
159tcpConnect :: EndPointAddress -> EndPointAddress -> Reliability -> IO (Either (FailedWith ConnectErrorCode) Connection)
160tcpConnect myAddress theirAddress _ = runErrorT $ do
160tcpConnect myAddress theirAddress _ = runErrorT $ do
161 sock <- socketForEndPoint myAddress theirAddress
161 sock <- socketForEndPoint myAddress theirAddress
162− connId <- maybeTToErrorT undefined $ requestNewConnection sock
162+ connId <- failWithT undefined $ requestNewConnection sock
163 return Connection { send = runErrorT .
163 return Connection { send = runErrorT .
164− maybeTToErrorT (FailedWith SendFailed "Send failed") .
164+ failWithT (FailedWith SendFailed "Send failed") .
165 sendWithLength sock (Just connId)
165 sendWithLength sock (Just connId)
166 , close = N.sClose sock
166 , close = N.sClose sock
167 }
167 }
@@ -180,10 +180,10 @@ socketForEndPoint :: EndPointAddress -- ^ Our address
180 -> EndPointAddress -- ^ Their address
180 -> EndPointAddress -- ^ Their address
181 -> ErrorT (FailedWith ConnectErrorCode) IO N.Socket
181 -> ErrorT (FailedWith ConnectErrorCode) IO N.Socket
182socketForEndPoint (EndPointAddress myAddress) theirAddress = do
182socketForEndPoint (EndPointAddress myAddress) theirAddress = do
183− (host, port, endPointId) <- maybeToErrorT invalidAddress (decodeEndPointAddress theirAddress)
183+ (host, port, endPointId) <- failWith invalidAddress (decodeEndPointAddress theirAddress)
184− sock <- maybeTToErrorT undefined (connectTo host port)
184+ sock <- failWithT undefined (connectTo host port)
185− endPointBS <- encodeInt16 (fromIntegral endPointId)
185+ endPointBS <- encodeInt16 endPointId
186− maybeTToErrorT undefined $ sendWithLength sock (Just endPointBS) [myAddress]
186+ failWithT undefined $ sendWithLength sock (Just endPointBS) [myAddress]
187 return sock
187 return sock
188 where
188 where
189 invalidAddress = FailedWith ConnectInvalidAddress "Invalid address"
189 invalidAddress = FailedWith ConnectInvalidAddress "Invalid address"