summaryrefslogtreecommitdiff
path: root/Presence/Server.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/Server.hs')
-rw-r--r--Presence/Server.hs20
1 files changed, 16 insertions, 4 deletions
diff --git a/Presence/Server.hs b/Presence/Server.hs
index 5dce323c..feefea2b 100644
--- a/Presence/Server.hs
+++ b/Presence/Server.hs
@@ -1,5 +1,6 @@
1{-# LANGUAGE TypeFamilies #-} 1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE TypeOperators #-} 2{-# LANGUAGE TypeOperators #-}
3{-# LANGUAGE OverloadedStrings #-}
3module Server where 4module Server where
4 5
5import Network.Socket 6import Network.Socket
@@ -73,10 +74,21 @@ doServer port g startCon = runServer2 port (runConn2 g)
73 setSocketOption sock ReuseAddr 1 74 setSocketOption sock ReuseAddr 1
74 bindSocket sock (SockAddrInet port iNADDR_ANY) 75 bindSocket sock (SockAddrInet port iNADDR_ANY)
75 listen sock 2 76 listen sock 2
76 mainLoop sock (ConnId 0) go 77 forkIO $ do
78 mainLoop sock (ConnId 0) go
79 L.putStrLn $ "quit accept loop"
80 return sock
77 where 81 where
78 mainLoop sock idnum@(ConnId n) go = do 82 mainLoop sock idnum@(ConnId n) go = do
79 con <- accept sock 83 let doException (SomeException e) = do
80 forkIO $ go (idnum .*. st) con 84 Prelude.putStrLn ("\n\naccept-loop exception: " ++ show e ++ "\n\n")
81 mainLoop sock (ConnId (n+1)) go 85 return Nothing
86 mcon <- handle doException $ fix $ \loop -> do
87 con <- accept sock
88 return $ Just con
89 case mcon of
90 Just con -> do
91 forkIO $ go (idnum .*. st) con
92 mainLoop sock (ConnId (n+1)) go
93 Nothing -> return ()
82 94