on master help sign in
sync server example with changes in the library

Use the file API instead of handle API

commit75ef6c21c15bd92f565fab801d6fbd3b174783ff authorHarendra Kumar <harendra.kumar@gmail.com> dateThu 30 May 2019, 12:10 (7 years ago) parent610941f
1 file changed+11−16
examples/FileSinkServer.hs+11−16
examples/FileSinkServer.hs+11−16
@@ -5,33 +5,28 @@
55-- * lines from concurrent connections are merged into a single srteam
66-- * writes the line stream to an output file
77
8−import Control.Monad.IO.Class (liftIO)
9−import Data.Char (ord, chr)
10−import System.IO (openFile, IOMode(..), hClose, hPutStrLn)
118import System.Environment (getArgs)
129
1310import Streamly
11+import Streamly.String
12+import qualified Streamly.FileSystem.File as File
1413import qualified Streamly.Fold as FL
1514import qualified Streamly.Mem.Array as A
1615import qualified Streamly.Network.Socket as NS
17−import qualified Network.Socket as NS
1816import qualified Streamly.Prelude as S
1917
2018main :: IO ()
2119main = do
22− h <- openOutput
23− S.mapM_ (hPutLines h)
24− $ S.concatMapBy parallel (withSocket recv)
25− $ fmap fst (NS.recvConnectionsOn 8090)
26− hClose h
20+ file <- fmap head getArgs
21+ File.append file
22+ $ encodeChar8Unchecked
23+ $ S.concatMap A.read
24+ $ S.concatMapBy parallel recv
25+ $ NS.recvConnectionsOn 8090
2726
2827 where
2928
30− openOutput = fmap head getArgs >>= \file -> openFile file AppendMode
31−
32− withSocket f sk = S.finally (liftIO (NS.close sk)) (f sk)
33− hPutLines h = hPutStrLn h . map (chr . fromIntegral) . A.toList
34− ord' = (fromIntegral . ord)
3529 recv =
36− FL.splitSuffixBy (== ord' '\n') (A.toArrayN 1024)
37− . NS.read
30+ FL.splitSuffixBy' (== '\n') (A.toArrayN 1024)
31+ . decodeChar8
32+ . NS.fromSocket