on master help sign in
Fix the example and make it docspec in Streamly.Network.Socket
commit957b4221440315ec4f8ccbc7b3771bcfa151d068 authorAdithya Kumar <adithya@composewell.com> dateThu 27 Oct 2022, 01:05 (4 years ago) parent799531f
1 file changed+32−32
src/Streamly/Network/Socket.hs+32−32
src/Streamly/Network/Socket.hs+32−32
@@ -27,38 +27,38 @@
2727-- this example can be written even more succinctly by using higher level
2828-- operations from "Streamly.Network.Inet.TCP" module.
2929--
30−-- @
31−-- {-\# LANGUAGE FlexibleContexts #-}
32−--
33−-- import Data.Function ((&))
34−-- import Network.Socket
35−-- import Streamly.Network.Socket (SockSpec(..))
36−--
37−-- import qualified Streamly.Prelude as Stream
38−-- import qualified Streamly.Network.Socket as Socket
39−--
40−-- main = do
41−-- let spec = SockSpec
42−-- { sockFamily = AF_INET
43−-- , sockType = Stream
44−-- , sockProto = defaultProtocol
45−-- , sockOpts = []
46−-- }
47−-- addr = SockAddrInet 8090 (tupleToHostAddress (0,0,0,0))
48−-- in server spec addr
49−--
50−-- where
51−--
52−-- server spec addr =
53−-- Stream.unfold Socket.accept (maxListenQueue, spec, addr) -- ParallelT IO Socket
54−-- & Stream.mapM (Socket.forSocketM echo) -- ParallelT IO ()
55−-- & Stream.fromParallel -- Stream IO ()
56−-- & Stream.drain -- IO ()
57−--
58−-- echo sk =
59−-- Stream.unfold Socket.readChunks sk -- Stream IO (Array Word8)
60−-- & Stream.fold (Socket.writeChunks sk) -- IO ()
61−-- @
30+--
31+-- >>> :set -XFlexibleContexts
32+-- >>>
33+-- >>> import Data.Function ((&))
34+-- >>> import Network.Socket
35+-- >>> import Streamly.Network.Socket (SockSpec(..))
36+-- >>>
37+-- >>> import qualified Streamly.Data.Fold as Fold
38+-- >>> import qualified Streamly.Data.Stream as Stream
39+-- >>> import qualified Streamly.Data.Stream.Concurrent as Concur
40+-- >>> import qualified Streamly.Network.Socket as Socket
41+-- >>>
42+-- >>> :{
43+-- main :: IO ()
44+-- main = do
45+-- let spec = SockSpec
46+-- { sockFamily = AF_INET
47+-- , sockType = Stream
48+-- , sockProto = defaultProtocol
49+-- , sockOpts = []
50+-- }
51+-- addr = SockAddrInet 8090 (tupleToHostAddress (0,0,0,0))
52+-- in server spec addr
53+-- where
54+-- server spec addr =
55+-- Stream.unfold Socket.acceptor (maxListenQueue, spec, addr)
56+-- & Concur.mapMWith (Concur.eager True) (Socket.forSocketM echo)
57+-- & Stream.fold Fold.drain
58+-- echo sk =
59+-- Stream.unfold Socket.chunkReader sk -- Stream IO (Array Word8)
60+-- & Stream.fold (Socket.writeChunks sk) -- IO ()
61+-- :}
6262--
6363-- = Programmer Notes
6464--