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