summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2017-04-11 23:37:30 +0200
committertv <tv@krebsco.de>2017-04-11 23:37:30 +0200
commitde13fa04339b8085d6b7bbdc1dd3ec31ec981701 (patch)
tree33607ad4f518d64d86e4af53cee32bddaeb3bc9f
parentfecb08ad50c2688836acf006e4b0ab6e0ad99066 (diff)
inline talk
-rw-r--r--main.hs30
1 files changed, 13 insertions, 17 deletions
diff --git a/main.hs b/main.hs
index bc62770..8ae5f54 100644
--- a/main.hs
+++ b/main.hs
@@ -33,8 +33,12 @@ warp_port = 10080
main :: IO ()
main = withSocketsDo $ do
- h <- connectTo server_hostname (PortNumber server_port)
- talk h `finally` hClose h
+ h <- connectTo server_hostname (PortNumber server_port)
+ (`finally` hClose h) $ do
+ hSetNewlineMode h universalNewlineMode
+ hSetBuffering h LineBuffering
+
+ handshake h >> race (fromServer h) (warp h) >>= print
handshake :: Handle -> IO ()
handshake h = do
@@ -42,21 +46,13 @@ handshake h = do
hPutStrLn h ("USER " ++ nick ++ " * 0 :" ++ nick)
hPutStrLn h ("JOIN " ++ chan)
-talk :: Handle -> IO ()
-talk h = do
- hSetNewlineMode h universalNewlineMode
- hSetBuffering h LineBuffering
- handshake h
- _ <- race fromServer (warp h)
- return ()
- where
- fromServer = forever $ do
- line <- hGetLine h
- --case line of
- if (isPrefixOf "PING" (pack line)) then
- hPutStrLn h (unpack (replace "PING" "PONG" (pack line)))
- else
- print line
+fromServer :: Handle -> IO ()
+fromServer h = forever $ do
+ line <- hGetLine h
+ if (isPrefixOf "PING" (pack line)) then
+ hPutStrLn h (unpack (replace "PING" "PONG" (pack line)))
+ else
+ print line
warp :: Handle -> IO ()
warp h =