git.iko.soy/distributed-process
on master help sign in
Layout
1ab2f85Edsko de Vries
network-transport-tcp/src/Network/Transport/TCP.hs+84−77
@@ -10,23 +10,24 @@
10-- Applications that use the TCP transport should use
10-- Applications that use the TCP transport should use
11-- 'Network.Socket.withSocketsDo' in their main function for Windows
11-- 'Network.Socket.withSocketsDo' in their main function for Windows
12-- compatibility (see "Network.Socket").
12-- compatibility (see "Network.Socket").
13−module Network.Transport.TCP ( -- * Main API
13+module Network.Transport.TCP
14+ ( -- * Main API
14− createTransport
15+ createTransport
15− , TCPParameters(..)
16+ , TCPParameters(..)
16− , defaultTCPParameters
17+ , defaultTCPParameters
17− -- * Internals (exposed for unit tests)
18+ -- * Internals (exposed for unit tests)
18− , createTransportExposeInternals
19+ , createTransportExposeInternals
19− , TransportInternals(..)
20+ , TransportInternals(..)
20− , EndPointId
21+ , EndPointId
21− , encodeEndPointAddress
22+ , encodeEndPointAddress
22− , decodeEndPointAddress
23+ , decodeEndPointAddress
23− , ControlHeader(..)
24+ , ControlHeader(..)
24− , ConnectionRequestResponse(..)
25+ , ConnectionRequestResponse(..)
25− , firstNonReservedConnectionId
26+ , firstNonReservedConnectionId
26− , socketToEndPoint
27+ , socketToEndPoint
27− -- * Design notes
28+ -- * Design notes
28− -- $design
29+ -- $design
29− ) where
30+ ) where
30
31
31import Prelude hiding
32import Prelude hiding
32 ( mapM_
33 ( mapM_
@@ -36,64 +37,69 @@ import Prelude hiding
36 )
37 )
37
38
38import Network.Transport
39import Network.Transport
39−import Network.Transport.TCP.Internal ( forkServer
40+import Network.Transport.TCP.Internal
41+ ( forkServer
40− , recvWithLength
42+ , recvWithLength
41− , recvInt32
43+ , recvInt32
42− , tryCloseSocket
44+ , tryCloseSocket
43− )
45+ )
44−import Network.Transport.Internal ( encodeInt32
46+import Network.Transport.Internal
47+ ( encodeInt32
45− , decodeInt32
48+ , decodeInt32
46− , prependLength
49+ , prependLength
47− , mapIOException
50+ , mapIOException
48− , tryIO
51+ , tryIO
49− , tryToEnum
52+ , tryToEnum
50− , void
53+ , void
51− , timeoutMaybe
54+ , timeoutMaybe
52− , asyncWhenCancelled
55+ , asyncWhenCancelled
53− )
56+ )
54−import qualified Network.Socket as N ( HostName
57+import qualified Network.Socket as N
58+ ( HostName
55− , ServiceName
59+ , ServiceName
56− , Socket
60+ , Socket
57− , getAddrInfo
61+ , getAddrInfo
58− , socket
62+ , socket
59− , addrFamily
63+ , addrFamily
60− , addrAddress
64+ , addrAddress
61− , SocketType(Stream)
65+ , SocketType(Stream)
62− , defaultProtocol
66+ , defaultProtocol
63− , setSocketOption
67+ , setSocketOption
64− , SocketOption(ReuseAddr)
68+ , SocketOption(ReuseAddr)
65− , connect
69+ , connect
66− , sOMAXCONN
70+ , sOMAXCONN
67− , AddrInfo
71+ , AddrInfo
68− )
72+ )
69import Network.Socket.ByteString (sendMany)
73import Network.Socket.ByteString (sendMany)
70import Control.Concurrent (forkIO, ThreadId, killThread, myThreadId)
74import Control.Concurrent (forkIO, ThreadId, killThread, myThreadId)
71import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
75import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan)
72−import Control.Concurrent.MVar ( MVar
76+import Control.Concurrent.MVar
77+ ( MVar
73− , newMVar
78+ , newMVar
74− , modifyMVar
79+ , modifyMVar
75− , modifyMVar_
80+ , modifyMVar_
76− , readMVar
81+ , readMVar
77− , takeMVar
82+ , takeMVar
78− , putMVar
83+ , putMVar
79− , newEmptyMVar
84+ , newEmptyMVar
80− , withMVar
85+ , withMVar
81− )
86+ )
82import Control.Category ((>>>))
87import Control.Category ((>>>))
83import Control.Applicative ((<$>))
88import Control.Applicative ((<$>))
84import Control.Monad (when, unless)
89import Control.Monad (when, unless)
85−import Control.Exception ( IOException
90+import Control.Exception
91+ ( IOException
86− , SomeException
92+ , SomeException
87− , AsyncException
93+ , AsyncException
88− , handle
94+ , handle
89− , throw
95+ , throw
90− , throwIO
96+ , throwIO
91− , try
97+ , try
92− , bracketOnError
98+ , bracketOnError
93− , mask
99+ , mask
94− , onException
100+ , onException
95− , fromException
101+ , fromException
96− )
102+ )
97import Data.IORef (IORef, newIORef, writeIORef, readIORef)
103import Data.IORef (IORef, newIORef, writeIORef, readIORef)
98import Data.ByteString (ByteString)
104import Data.ByteString (ByteString)
99import qualified Data.ByteString as BS (concat)
105import qualified Data.ByteString as BS (concat)
@@ -102,14 +108,15 @@ import Data.Int (Int32)
102import Data.IntMap (IntMap)
108import Data.IntMap (IntMap)
103import qualified Data.IntMap as IntMap (empty)
109import qualified Data.IntMap as IntMap (empty)
104import Data.IntSet (IntSet)
110import Data.IntSet (IntSet)
105−import qualified Data.IntSet as IntSet ( empty
111+import qualified Data.IntSet as IntSet
112+ ( empty
106− , insert
113+ , insert
107− , elems
114+ , elems
108− , singleton
115+ , singleton
109− , null
116+ , null
110− , delete
117+ , delete
111− , member
118+ , member
112− )
119+ )
113import Data.Map (Map)
120import Data.Map (Map)
114import qualified Data.Map as Map (empty)
121import qualified Data.Map as Map (empty)
115import Data.Accessor (Accessor, accessor, (^.), (^=), (^:))
122import Data.Accessor (Accessor, accessor, (^.), (^=), (^:))
network-transport-tcp/src/Network/Transport/TCP/Internal.hs+25−23
@@ -1,33 +1,35 @@
1-- | Utility functions for TCP sockets
1-- | Utility functions for TCP sockets
2−module Network.Transport.TCP.Internal ( forkServer
2+module Network.Transport.TCP.Internal
3+ ( forkServer
3− , recvWithLength
4+ , recvWithLength
4− , recvExact
5+ , recvExact
5− , recvInt32
6+ , recvInt32
6− , tryCloseSocket
7+ , tryCloseSocket
7− ) where
8+ ) where
8
9
9#if ! MIN_VERSION_base(4,6,0)
10#if ! MIN_VERSION_base(4,6,0)
10import Prelude hiding (catch)
11import Prelude hiding (catch)
11#endif
12#endif
12
13
13import Network.Transport.Internal (decodeInt32, void, tryIO, forkIOWithUnmask)
14import Network.Transport.Internal (decodeInt32, void, tryIO, forkIOWithUnmask)
14−import qualified Network.Socket as N ( HostName
15+import qualified Network.Socket as N
16+ ( HostName
15− , ServiceName
17+ , ServiceName
16− , Socket
18+ , Socket
17− , SocketType(Stream)
19+ , SocketType(Stream)
18− , SocketOption(ReuseAddr)
20+ , SocketOption(ReuseAddr)
19− , getAddrInfo
21+ , getAddrInfo
20− , defaultHints
22+ , defaultHints
21− , socket
23+ , socket
22− , bindSocket
24+ , bindSocket
23− , listen
25+ , listen
24− , addrFamily
26+ , addrFamily
25− , addrAddress
27+ , addrAddress
26− , defaultProtocol
28+ , defaultProtocol
27− , setSocketOption
29+ , setSocketOption
28− , accept
30+ , accept
29− , sClose
31+ , sClose
30− )
32+ )
31import qualified Network.Socket.ByteString as NBS (recv)
33import qualified Network.Socket.ByteString as NBS (recv)
32import Control.Concurrent (ThreadId)
34import Control.Concurrent (ThreadId)
33import Control.Monad (forever, when)
35import Control.Monad (forever, when)
network-transport/src/Network/Transport.hs+23−22
@@ -1,26 +1,27 @@
1-- | Network Transport
1-- | Network Transport
2−module Network.Transport ( -- * Types
2+module Network.Transport
3+ ( -- * Types
3− Transport(..)
4+ Transport(..)
4− , EndPoint(..)
5+ , EndPoint(..)
5− , Connection(..)
6+ , Connection(..)
6− , Event(..)
7+ , Event(..)
7− , ConnectionId
8+ , ConnectionId
8− , Reliability(..)
9+ , Reliability(..)
9− , MulticastGroup(..)
10+ , MulticastGroup(..)
10− , EndPointAddress(..)
11+ , EndPointAddress(..)
11− , MulticastAddress(..)
12+ , MulticastAddress(..)
12− -- * Hints
13+ -- * Hints
13− , ConnectHints(..)
14+ , ConnectHints(..)
14− , defaultConnectHints
15+ , defaultConnectHints
15− -- * Error codes
16+ -- * Error codes
16− , TransportError(..)
17+ , TransportError(..)
17− , NewEndPointErrorCode(..)
18+ , NewEndPointErrorCode(..)
18− , ConnectErrorCode(..)
19+ , ConnectErrorCode(..)
19− , NewMulticastGroupErrorCode(..)
20+ , NewMulticastGroupErrorCode(..)
20− , ResolveMulticastGroupErrorCode(..)
21+ , ResolveMulticastGroupErrorCode(..)
21− , SendErrorCode(..)
22+ , SendErrorCode(..)
22− , EventErrorCode(..)
23+ , EventErrorCode(..)
23− ) where
24+ ) where
24
25
25import Data.ByteString (ByteString)
26import Data.ByteString (ByteString)
26import qualified Data.ByteString as BS (copy)
27import qualified Data.ByteString as BS (copy)
network-transport/src/Network/Transport/Internal.hs+35−31
@@ -1,22 +1,23 @@
1-- | Internal functions
1-- | Internal functions
2−module Network.Transport.Internal ( -- * Encoders/decoders
2+module Network.Transport.Internal
3+ ( -- * Encoders/decoders
3− encodeInt32
4+ encodeInt32
4− , decodeInt32
5+ , decodeInt32
5− , encodeInt16
6+ , encodeInt16
6− , decodeInt16
7+ , decodeInt16
7− , prependLength
8+ , prependLength
8− -- * Miscellaneous abstractions
9+ -- * Miscellaneous abstractions
9− , mapIOException
10+ , mapIOException
10− , tryIO
11+ , tryIO
11− , tryToEnum
12+ , tryToEnum
12− , timeoutMaybe
13+ , timeoutMaybe
13− , asyncWhenCancelled
14+ , asyncWhenCancelled
14− -- * Replicated functionality from "base"
15+ -- * Replicated functionality from "base"
15− , void
16+ , void
16− , forkIOWithUnmask
17+ , forkIOWithUnmask
17− -- * Debugging
18+ -- * Debugging
18− , tlog
19+ , tlog
19− ) where
20+ ) where
20
21
21#if ! MIN_VERSION_base(4,6,0)
22#if ! MIN_VERSION_base(4,6,0)
22import Prelude hiding (catch)
23import Prelude hiding (catch)
@@ -27,20 +28,23 @@ import Foreign.C (CInt(..), CShort(..))
27import Foreign.ForeignPtr (withForeignPtr)
28import Foreign.ForeignPtr (withForeignPtr)
28import Data.ByteString (ByteString)
29import Data.ByteString (ByteString)
29import qualified Data.ByteString as BS (length)
30import qualified Data.ByteString as BS (length)
30−import qualified Data.ByteString.Internal as BSI ( unsafeCreate
31+import qualified Data.ByteString.Internal as BSI
32+ ( unsafeCreate
31− , toForeignPtr
33+ , toForeignPtr
32− , inlinePerformIO)
34+ , inlinePerformIO
35+ )
33import Control.Monad.IO.Class (MonadIO, liftIO)
36import Control.Monad.IO.Class (MonadIO, liftIO)
34−import Control.Exception ( IOException
37+import Control.Exception
38+ ( IOException
35− , SomeException
39+ , SomeException
36− , AsyncException
40+ , AsyncException
37− , Exception
41+ , Exception
38− , catch
42+ , catch
39− , try
43+ , try
40− , throw
44+ , throw
41− , throwIO
45+ , throwIO
42− , mask_
46+ , mask_
43− )
47+ )
44import Control.Concurrent (ThreadId, forkIO)
48import Control.Concurrent (ThreadId, forkIO)
45import Control.Concurrent.MVar (MVar, newEmptyMVar, takeMVar, putMVar)
49import Control.Concurrent.MVar (MVar, newEmptyMVar, takeMVar, putMVar)
46import GHC.IO (unsafeUnmask)
50import GHC.IO (unsafeUnmask)
network-transport/src/Network/Transport/Util.hs+6−5
@@ -3,11 +3,12 @@
3-- Note: this module is bound to change even more than the rest of the API :)
3-- Note: this module is bound to change even more than the rest of the API :)
4module Network.Transport.Util (spawn) where
4module Network.Transport.Util (spawn) where
5
5
6−import Network.Transport ( Transport
6+import Network.Transport
7+ ( Transport
7− , EndPoint(..)
8+ , EndPoint(..)
8− , EndPointAddress
9+ , EndPointAddress
9− , newEndPoint
10+ , newEndPoint
10− )
11+ )
11import Control.Concurrent (forkIO)
12import Control.Concurrent (forkIO)
12import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
13import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar)
13
14