summaryrefslogtreecommitdiff
path: root/Presence/ServerC.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Presence/ServerC.hs')
-rw-r--r--Presence/ServerC.hs11
1 files changed, 9 insertions, 2 deletions
diff --git a/Presence/ServerC.hs b/Presence/ServerC.hs
index 881ce5d2..3933c812 100644
--- a/Presence/ServerC.hs
+++ b/Presence/ServerC.hs
@@ -5,6 +5,8 @@
5module ServerC 5module ServerC
6 ( doServer 6 ( doServer
7 , ConnId(..) 7 , ConnId(..)
8 , ServerHandle
9 , quitListening
8 ) where 10 ) where
9 11
10import Network.Socket as Socket 12import Network.Socket as Socket
@@ -46,6 +48,11 @@ import SocketLike
46newtype ConnId = ConnId Int 48newtype ConnId = ConnId Int
47 deriving Eq 49 deriving Eq
48 50
51newtype ServerHandle = ServerHandle Socket
52
53quitListening :: ServerHandle -> IO ()
54quitListening (ServerHandle socket) = sClose socket
55
49 56
50data AcceptResult = 57data AcceptResult =
51 GotConnection (Socket,SockAddr) 58 GotConnection (Socket,SockAddr)
@@ -59,7 +66,7 @@ doServer ::
59 -> Source m S.ByteString 66 -> Source m S.ByteString
60 -> Sink S.ByteString m () 67 -> Sink S.ByteString m ()
61 -> IO ()) 68 -> IO ())
62 -> IO Socket 69 -> IO ServerHandle
63doServer (HCons family port) g = runServer port (runConn g) 70doServer (HCons family port) g = runServer port (runConn g)
64 where 71 where
65 runServer (HCons port st) go = do 72 runServer (HCons port st) go = do
@@ -72,7 +79,7 @@ doServer (HCons family port) g = runServer port (runConn g)
72 forkIO $ do 79 forkIO $ do
73 mainLoop sock (ConnId 0) go 80 mainLoop sock (ConnId 0) go
74 -- L.putStrLn $ "quit accept loop" 81 -- L.putStrLn $ "quit accept loop"
75 return sock 82 return (ServerHandle sock)
76 where 83 where
77 mainLoop sock idnum@(ConnId n) go = do 84 mainLoop sock idnum@(ConnId n) go = do
78 let doException ioerror = do 85 let doException ioerror = do