summaryrefslogtreecommitdiff
path: root/kikid.hs
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2015-06-22 18:58:47 -0400
committerJames Crayne <jim.crayne@gmail.com>2015-06-22 18:59:39 -0400
commit2966db997f43c063389285ddc40579acad5c6a29 (patch)
tree76a2aaa39aae69d892162fc16754c5993329ce70 /kikid.hs
parentaed7356d85229ae0ee19d55edb682e6212b5a8a0 (diff)
kikid: Serialization...
Diffstat (limited to 'kikid.hs')
-rw-r--r--kikid.hs15
1 files changed, 10 insertions, 5 deletions
diff --git a/kikid.hs b/kikid.hs
index 31426a3..04e06d3 100644
--- a/kikid.hs
+++ b/kikid.hs
@@ -16,8 +16,11 @@ import Control.Monad.Loops
16import Control.Exception 16import Control.Exception
17import Data.Monoid 17import Data.Monoid
18import qualified Data.ByteString.Char8 as B 18import qualified Data.ByteString.Char8 as B
19import Data.Serialize 19--import Data.Serialize
20import qualified Data.Map as M 20import qualified Data.Map as M
21import qualified Data.Bytes.Serial as Bytes
22import qualified Data.Bytes.Get as Bytes
23--import qualified Data.Bytes.Put as Bytes
21 24
22-- TODO: Set this in config file 25-- TODO: Set this in config file
23port = 9800 26port = 9800
@@ -64,7 +67,7 @@ kikidMain _ = do
64 atomically $ closeTBMQueue newchans 67 atomically $ closeTBMQueue newchans
65 atomically $ closeTBMQueue incomming 68 atomically $ closeTBMQueue incomming
66 69
67data ClientState = CState {cs_queue :: TBMQueue KikiDMessage} 70data ClientState = CState {csQueue :: TBMQueue KikiDMessage}
68type ClientID = ThreadId 71type ClientID = ThreadId
69threadIdToClient = id 72threadIdToClient = id
70 73
@@ -96,12 +99,14 @@ purgeClosedConnections quit currentClients = whileM_ (fmap not quit) $ do
96handleMessage hdl outq = do 99handleMessage hdl outq = do
97 line <- B.hGetLine hdl 100 line <- B.hGetLine hdl
98 tid <- myThreadId 101 tid <- myThreadId
99 case (decode line :: Either String KikiDMessage) of 102 case (Bytes.runGetS Bytes.deserialize (B.snoc line '\n') :: Either String KikiDMessage) of
100 Right _ -> 103 Right msg -> do
101 syslog Notice ("Message decoded on thread=" <> show tid) 104 syslog Notice ("Message decoded on thread=" <> show tid)
105 syslog Notice ("Message: " <> show msg)
102 Left str -> do 106 Left str -> do
107 syslog Notice ("ERROR: " <> show line)
103 syslog Notice ("ERROR: Unable to decode message on thread=" <> show tid) 108 syslog Notice ("ERROR: Unable to decode message on thread=" <> show tid)
104 syslog Notice str 109 syslog Notice ("ERROR: " ++ str)
105 110
106consumeMessage currentClients msg = void $ syslog Notice ("Recieved Message: " ++ show msg) 111consumeMessage currentClients msg = void $ syslog Notice ("Recieved Message: " ++ show msg)
107-- TODO: Do more here... 112-- TODO: Do more here...