git.iko.soy/distributed-process
on master help sign in
Cleanup
commitfdf266ff4b76f88ccfe7d98237948a48c1be2f4f authorEdsko de Vries <edsko@edsko.net> dateTue 24 Apr 2012, 13:36 (15 years ago) parent85860ae
2 files changed+16−16
network-transport-2/src/Network/Transport/Internal.hs+7−7 network-transport-2/src/Network/Transport/TCP.hs+9−9
network-transport-2/src/Network/Transport/Internal.hs+7−7
@@ -5,8 +5,8 @@ module Network.Transport.Internal ( -- * Encoders/decoders
55 , encodeInt16
66 , decodeInt16
77 -- * Miscellaneous abstractions
8− , maybeToErrorT
9− , maybeTToErrorT
8+ , failWith
9+ , failWithT
1010 ) where
1111
1212import Data.Int (Int16, Int32)
@@ -57,13 +57,13 @@ decodeInt16 bs = liftIO $ do
5757 return (fromIntegral (ntohs w16))
5858
5959-- | Convert 'Maybe' to an ErrorT value
60−maybeToErrorT :: (Monad m, Error a) => a -> Maybe b -> ErrorT a m b
61−maybeToErrorT err Nothing = throwError err
62−maybeToErrorT _ (Just x) = return x
60+failWith :: (Monad m, Error a) => a -> Maybe b -> ErrorT a m b
61+failWith err Nothing = throwError err
62+failWith _ (Just x) = return x
6363
6464-- | Convert 'MaybeT' to an 'ErrorT'
65−maybeTToErrorT :: (Monad m, Error a) => a -> MaybeT m b -> ErrorT a m b
66−maybeTToErrorT err valueT = do
65+failWithT :: (Monad m, Error a) => a -> MaybeT m b -> ErrorT a m b
66+failWithT err valueT = do
6767 mval <- lift $ runMaybeT valueT
6868 case mval of
6969 Nothing -> throwError err
network-transport-2/src/Network/Transport/TCP.hs+9−9
@@ -22,8 +22,8 @@ import Network.Transport.Internal.TCP ( forkServer
2222 , sendInt32
2323 )
2424import Network.Transport.Internal ( encodeInt16
25− , maybeToErrorT
26− , maybeTToErrorT
25+ , failWith
26+ , failWithT
2727 )
2828import qualified Network.Socket as N ( HostName
2929 , ServiceName
@@ -95,7 +95,7 @@ handleClient state sock = do
9595 mendpoint <- runMaybeT $ do
9696 ourEndPointId <- recvInt16 sock
9797 theirAddress <- BS.concat <$> recvWithLength sock
98− ourEndPoint <- MaybeT $ (^. endPointAt (fromIntegral ourEndPointId)) <$> readMVar state
98+ ourEndPoint <- MaybeT $ (^. endPointAt ourEndPointId) <$> readMVar state
9999 return (ourEndPoint, EndPointAddress theirAddress)
100100 case mendpoint of
101101 Just ((endPointCh, endPointSt), theirAddress) -> do
@@ -159,9 +159,9 @@ firstNonReservedConnectionId = 1024
159159tcpConnect :: EndPointAddress -> EndPointAddress -> Reliability -> IO (Either (FailedWith ConnectErrorCode) Connection)
160160tcpConnect myAddress theirAddress _ = runErrorT $ do
161161 sock <- socketForEndPoint myAddress theirAddress
162− connId <- maybeTToErrorT undefined $ requestNewConnection sock
162+ connId <- failWithT undefined $ requestNewConnection sock
163163 return Connection { send = runErrorT .
164− maybeTToErrorT (FailedWith SendFailed "Send failed") .
164+ failWithT (FailedWith SendFailed "Send failed") .
165165 sendWithLength sock (Just connId)
166166 , close = N.sClose sock
167167 }
@@ -180,10 +180,10 @@ socketForEndPoint :: EndPointAddress -- ^ Our address
180180 -> EndPointAddress -- ^ Their address
181181 -> ErrorT (FailedWith ConnectErrorCode) IO N.Socket
182182socketForEndPoint (EndPointAddress myAddress) theirAddress = do
183− (host, port, endPointId) <- maybeToErrorT invalidAddress (decodeEndPointAddress theirAddress)
184− sock <- maybeTToErrorT undefined (connectTo host port)
185− endPointBS <- encodeInt16 (fromIntegral endPointId)
186− maybeTToErrorT undefined $ sendWithLength sock (Just endPointBS) [myAddress]
183+ (host, port, endPointId) <- failWith invalidAddress (decodeEndPointAddress theirAddress)
184+ sock <- failWithT undefined (connectTo host port)
185+ endPointBS <- encodeInt16 endPointId
186+ failWithT undefined $ sendWithLength sock (Just endPointBS) [myAddress]
187187 return sock
188188 where
189189 invalidAddress = FailedWith ConnectInvalidAddress "Invalid address"