summaryrefslogtreecommitdiff
path: root/KikiD
diff options
context:
space:
mode:
Diffstat (limited to 'KikiD')
-rw-r--r--KikiD/ClientState.hs14
-rw-r--r--KikiD/Message.hs7
2 files changed, 20 insertions, 1 deletions
diff --git a/KikiD/ClientState.hs b/KikiD/ClientState.hs
new file mode 100644
index 0000000..a80a392
--- /dev/null
+++ b/KikiD/ClientState.hs
@@ -0,0 +1,14 @@
1module KikiD.ClientState where
2
3import KikiD.Message
4import Control.Concurrent.STM.TBMQueue
5import Control.Concurrent
6
7data ClientState = CState {cliQueue :: TBMQueue KikiDMessage}
8
9mkClient = CState
10 { cliQueue = error "ERROR CState: cliQueue parameter is required"
11 }
12
13type ClientID = ThreadId
14threadIdToClient = id
diff --git a/KikiD/Message.hs b/KikiD/Message.hs
index cd3ee71..efefdc6 100644
--- a/KikiD/Message.hs
+++ b/KikiD/Message.hs
@@ -12,6 +12,7 @@ import Data.Bytes.Put as Put
12import Data.Bytes.Get as Get 12import Data.Bytes.Get as Get
13import Codec.LineReady 13import Codec.LineReady
14import Control.Monad.Loops 14import Control.Monad.Loops
15import Data.Word
15 16
16data KikiDMessage = TODO deriving (Show,Read) 17data KikiDMessage = TODO deriving (Show,Read)
17 18
@@ -31,7 +32,11 @@ instance Serialize KikiDMessage where
31instance Serial KikiDMessage where 32instance Serial KikiDMessage where
32 serialize m = Put.putByteString . toLineReady . Cereal.encode $ m 33 serialize m = Put.putByteString . toLineReady . Cereal.encode $ m
33 deserialize = do 34 deserialize = do
34 xs <- unfoldWhileM (/= '\n') (fmap (chr . fromIntegral) Get.getWord8) 35 xs <- unfoldM $ do
36 flag <- Get.isEmpty
37 if flag then return Nothing else do
38 c <- fmap (chr . fromIntegral) Get.getWord8
39 if (c == '\n') then return Nothing else return (Just c)
35 case (Cereal.decode . fromLineReady $ B.pack xs) of 40 case (Cereal.decode . fromLineReady $ B.pack xs) of
36 Left str -> fail str 41 Left str -> fail str
37 Right x -> return x 42 Right x -> return x