summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--simplechat.hs25
1 files changed, 13 insertions, 12 deletions
diff --git a/simplechat.hs b/simplechat.hs
index 54545b9b..bf592db3 100644
--- a/simplechat.hs
+++ b/simplechat.hs
@@ -5,7 +5,6 @@ import Data.HList.TypeEqGeneric1()
5import Data.HList.TypeCastGeneric1() 5import Data.HList.TypeCastGeneric1()
6import ByteStringOperators 6import ByteStringOperators
7 7
8import Server
9import Data.ByteString.Lazy.Char8 as L 8import Data.ByteString.Lazy.Char8 as L
10 ( ByteString 9 ( ByteString
11 , hPutStrLn 10 , hPutStrLn
@@ -17,6 +16,8 @@ import Control.Concurrent (forkIO)
17import Control.Concurrent.Chan 16import Control.Concurrent.Chan
18import Data.HList 17import Data.HList
19 18
19import Server
20
20 21
21startCon socket st = do 22startCon socket st = do
22 let chan = hOccursFst st 23 let chan = hOccursFst st
@@ -42,17 +43,17 @@ startCon socket st = do
42 return (name .*. ConnectionFinalizer quit .*. st) 43 return (name .*. ConnectionFinalizer quit .*. st)
43 44
44doCon st bs cont = do 45doCon st bs cont = do
45 let hdl = hOccursFst st :: Handle 46 let hdl = hOccursFst st :: Handle
46 nr = hOccursFst st :: ConnId 47 nr = hOccursFst st :: ConnId
47 chan = hOccursFst st 48 chan = hOccursFst st
48 broadcast msg = writeChan chan (nr,Just msg) 49 broadcast msg = writeChan chan (nr,Just msg)
49 name = hHead st 50 name = hHead st
50 Prelude.putStrLn $ "read: " ++ show bs 51 Prelude.putStrLn $ "read: " ++ show bs
51 case bs of 52 case bs of
52 "quit\n" -> hPutStrLn hdl "Bye!" 53 "quit\n" -> hPutStrLn hdl "Bye!"
53 _ -> do 54 _ -> do
54 broadcast (name <++> ": " <++> L.init bs) 55 broadcast (name <++> ": " <++> L.init bs)
55 cont () 56 cont ()
56 57
57 58
58main = do 59main = do