on master help sign in
Move Network/Server module to Network/Socket/Inet/TCP
49d3698Harendra Kumar
examples/EchoServer.hs+8−5
@@ -1,13 +1,16 @@
1-- A concurrent TCP server that echoes everything that it receives.
1-- A concurrent TCP server that echoes everything that it receives.
2
2
3+import Control.Exception (finally)
4+import Control.Monad.IO.Class (liftIO)
3import Streamly
5import Streamly
4−import Streamly.Internal.Network.Socket (useSocketM, readArrays)
5import Streamly.Network.Socket
6import Streamly.Network.Socket
7+import qualified Network.Socket as Net
6−import Streamly.Network.Server
8+import qualified Streamly.Network.Socket.Inet.TCP as TCP
7import qualified Streamly.Prelude as S
9import qualified Streamly.Prelude as S
8
10
9main :: IO ()
11main :: IO ()
10main = S.drain
12main = S.drain
11− $ parallely $ S.mapM (flip useSocketM echo)
13+ $ parallely $ S.mapM (useWith echo)
12− $ serially $ S.unfold listenOnPort 8090
14+ $ serially $ S.unfold TCP.listenOnPort 8090
13− where echo sk = S.fold (writeArrays sk) $ S.unfold readArrays sk
15+ where echo sk = S.fold (writeArrays sk) $ S.unfold readArraysOf (32768, sk)
16+ useWith f sk = finally (liftIO (Net.close sk)) (f sk)
examples/FileSinkServer.hs+2−2
@@ -14,7 +14,7 @@ import Streamly.Data.String
14import qualified Streamly.FileSystem.Handle as FH
14import qualified Streamly.FileSystem.Handle as FH
15import qualified Streamly.Memory.Array as A
15import qualified Streamly.Memory.Array as A
16import qualified Streamly.Network.Socket as NS
16import qualified Streamly.Network.Socket as NS
17−import qualified Streamly.Network.Server as NS
17+import qualified Streamly.Network.Socket.Inet.TCP as TCP
18import qualified Streamly.Prelude as S
18import qualified Streamly.Prelude as S
19
19
20import System.IO (withFile, IOMode(..))
20import System.IO (withFile, IOMode(..))
@@ -27,7 +27,7 @@ main = do
27 $ encodeChar8Unchecked
27 $ encodeChar8Unchecked
28 $ S.concatUnfold A.read
28 $ S.concatUnfold A.read
29 $ S.concatMapWith parallel use
29 $ S.concatMapWith parallel use
30− $ S.unfold NS.listenOnPort 8090)
30+ $ S.unfold TCP.listenOnPort 8090)
31
31
32 where
32 where
33
33
src/Streamly/Network/Server.hs → src/Streamly/Network/Socket/Inet/TCP.hsrenamed+2−2
@@ -7,12 +7,12 @@
7-- Stability : experimental
7-- Stability : experimental
8-- Portability : GHC
8-- Portability : GHC
9--
9--
10−-- Combinators to build network servers.
10+-- Combinators to build TCP servers.
11--
11--
12-- > import qualified Streamly.Network.Server as Server
12-- > import qualified Streamly.Network.Server as Server
13--
13--
14
14
15−module Streamly.Network.Server
15+module Streamly.Network.Socket.Inet.TCP
16 (
16 (
17 -- * Accept Connections
17 -- * Accept Connections
18 listenOnAddr
18 listenOnAddr
streamly.cabal+2−1
@@ -316,7 +316,7 @@ library
316 if !impl(ghcjs)
316 if !impl(ghcjs)
317 exposed-modules:
317 exposed-modules:
318 Streamly.Network.Socket
318 Streamly.Network.Socket
319− , Streamly.Network.Server
319+ , Streamly.Network.Socket.Inet.TCP
320 , Streamly.Network.Client
320 , Streamly.Network.Client
321
321
322 , Streamly.Internal.Network.Socket
322 , Streamly.Internal.Network.Socket
@@ -903,6 +903,7 @@ executable EchoServer
903 build-Depends:
903 build-Depends:
904 streamly
904 streamly
905 , base >= 4.8 && < 5
905 , base >= 4.8 && < 5
906+ , network >= 2.6 && < 4
906 else
907 else
907 buildable: False
908 buildable: False
908
909