diff options
author | James Crayne <jim.crayne@gmail.com> | 2015-06-22 18:58:47 -0400 |
---|---|---|
committer | James Crayne <jim.crayne@gmail.com> | 2015-06-22 18:59:39 -0400 |
commit | 2966db997f43c063389285ddc40579acad5c6a29 (patch) | |
tree | 76a2aaa39aae69d892162fc16754c5993329ce70 /kikid.hs | |
parent | aed7356d85229ae0ee19d55edb682e6212b5a8a0 (diff) |
kikid: Serialization...
Diffstat (limited to 'kikid.hs')
-rw-r--r-- | kikid.hs | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -16,8 +16,11 @@ import Control.Monad.Loops | |||
16 | import Control.Exception | 16 | import Control.Exception |
17 | import Data.Monoid | 17 | import Data.Monoid |
18 | import qualified Data.ByteString.Char8 as B | 18 | import qualified Data.ByteString.Char8 as B |
19 | import Data.Serialize | 19 | --import Data.Serialize |
20 | import qualified Data.Map as M | 20 | import qualified Data.Map as M |
21 | import qualified Data.Bytes.Serial as Bytes | ||
22 | import 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 |
23 | port = 9800 | 26 | port = 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 | ||
67 | data ClientState = CState {cs_queue :: TBMQueue KikiDMessage} | 70 | data ClientState = CState {csQueue :: TBMQueue KikiDMessage} |
68 | type ClientID = ThreadId | 71 | type ClientID = ThreadId |
69 | threadIdToClient = id | 72 | threadIdToClient = id |
70 | 73 | ||
@@ -96,12 +99,14 @@ purgeClosedConnections quit currentClients = whileM_ (fmap not quit) $ do | |||
96 | handleMessage hdl outq = do | 99 | handleMessage 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 | ||
106 | consumeMessage currentClients msg = void $ syslog Notice ("Recieved Message: " ++ show msg) | 111 | consumeMessage currentClients msg = void $ syslog Notice ("Recieved Message: " ++ show msg) |
107 | -- TODO: Do more here... | 112 | -- TODO: Do more here... |