summaryrefslogtreecommitdiff
path: root/Presence/ServerC.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2013-06-28 21:19:13 -0400
committerjoe <joe@jerkface.net>2013-06-28 21:19:13 -0400
commit31cca9914be082552119e0be863f7a16629c079c (patch)
tree79fdab3f628adcc6624f2a179370de166d1a8598 /Presence/ServerC.hs
parentb7e6f3164af9149c432451e7ffc344f8d7a2f55a (diff)
Attempt to control buffer sends with renderBytes...
Diffstat (limited to 'Presence/ServerC.hs')
-rw-r--r--Presence/ServerC.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/Presence/ServerC.hs b/Presence/ServerC.hs
index 36e2d7bf..ae0bf154 100644
--- a/Presence/ServerC.hs
+++ b/Presence/ServerC.hs
@@ -18,6 +18,7 @@ import Data.ByteString.Char8
18 ) 18 )
19import qualified Data.ByteString.Char8 as S 19import qualified Data.ByteString.Char8 as S
20 ( hPutStr 20 ( hPutStr
21 , hPutStrLn
21 ) 22 )
22import System.IO 23import System.IO
23 ( IOMode(..) 24 ( IOMode(..)
@@ -115,18 +116,20 @@ doServer (HCons family port) g = runServer port (runConn g)
115 116
116packets :: MonadIO m => Handle -> Source m S.ByteString 117packets :: MonadIO m => Handle -> Source m S.ByteString
117packets h = do 118packets h = do
118 packet <- lift $ liftIO $ getPacket h 119 packet <- liftIO $ getPacket h
119 yield packet 120 yield packet
120 isEof <- lift $ liftIO $ hIsEOF h 121 isEof <- liftIO $ hIsEOF h
121 when (not isEof) (packets h) 122 when (not isEof) (packets h)
122 where 123 where
123 getPacket h = do { hWaitForInput h (-1) ; hGetNonBlocking h 1024 } 124 getPacket h = do { hWaitForInput h (-1) ; hGetNonBlocking h 1024 }
124 125
125outgoing :: MonadIO m => Handle -> Sink S.ByteString m () 126outgoing :: MonadIO m => Handle -> Sink S.ByteString m ()
126outgoing h = do 127outgoing h = do
128 liftIO . L.putStrLn $ "outgoing: waiting"
127 mpacket <- await 129 mpacket <- await
130 liftIO . L.putStrLn $ "outgoing: got packet " <++> bshow mpacket
128 maybe (return ()) 131 maybe (return ())
129 (\r -> (lift . liftIO . S.hPutStr h $ r) >> outgoing h) 132 (\r -> (liftIO . S.hPutStrLn h $ r) >> outgoing h)
130 mpacket 133 mpacket
131 134
132 135