diff options
Diffstat (limited to 'server/src/Network/StreamServer.hs')
-rw-r--r-- | server/src/Network/StreamServer.hs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/server/src/Network/StreamServer.hs b/server/src/Network/StreamServer.hs index 4fc477c5..c60ba99d 100644 --- a/server/src/Network/StreamServer.hs +++ b/server/src/Network/StreamServer.hs | |||
@@ -5,7 +5,7 @@ | |||
5 | {-# LANGUAGE OverloadedStrings #-} | 5 | {-# LANGUAGE OverloadedStrings #-} |
6 | {-# LANGUAGE RankNTypes #-} | 6 | {-# LANGUAGE RankNTypes #-} |
7 | module Network.StreamServer | 7 | module Network.StreamServer |
8 | ( streamServer | 8 | ( forkStreamServer |
9 | , ServerHandle | 9 | , ServerHandle |
10 | , getAcceptLoopThreadId | 10 | , getAcceptLoopThreadId |
11 | , ServerConfig(..) | 11 | , ServerConfig(..) |
@@ -71,8 +71,9 @@ dummyServerHandle = do | |||
71 | -} | 71 | -} |
72 | 72 | ||
73 | removeSocketFile :: SockAddr -> IO () | 73 | removeSocketFile :: SockAddr -> IO () |
74 | removeSocketFile (SockAddrUnix fname) = removeFile fname | 74 | removeSocketFile (SockAddrUnix ('\0':_)) = return () |
75 | removeSocketFile _ = return () | 75 | removeSocketFile (SockAddrUnix fname) = removeFile fname |
76 | removeSocketFile _ = return () | ||
76 | 77 | ||
77 | -- | Terminate the server accept-loop. Call this to shut down the server. | 78 | -- | Terminate the server accept-loop. Call this to shut down the server. |
78 | quitListening :: ServerHandle -> IO () | 79 | quitListening :: ServerHandle -> IO () |
@@ -106,15 +107,22 @@ data ServerConfig = ServerConfig | |||
106 | withSession :: ((RestrictedSocket,(Local SockAddr,Remote SockAddr)) -> Int -> Handle -> IO ()) -> ServerConfig | 107 | withSession :: ((RestrictedSocket,(Local SockAddr,Remote SockAddr)) -> Int -> Handle -> IO ()) -> ServerConfig |
107 | withSession session = ServerConfig warnStderr session | 108 | withSession session = ServerConfig warnStderr session |
108 | 109 | ||
109 | -- | Launch a thread to listen at the given bind address and dispatch | 110 | -- | Launch a thread to listen at the given bind address and dispatch to |
110 | -- to session handler threads on every incoming connection. Supports | 111 | -- session handler threads on every incoming connection. Supports IPv4 and |
111 | -- IPv4 and IPv6, TCP and unix sockets. | 112 | -- IPv6, TCP and unix sockets. |
112 | -- | 113 | -- |
113 | -- The returned handle can be used with 'quitListening' to terminate the | 114 | -- Arguments: |
114 | -- thread and prevent any new sessions from starting. Currently active | 115 | -- |
115 | -- session threads will not be terminated or signaled in any way. | 116 | -- [cfg] Functions for handling incomming sessions and logging prints. |
116 | streamServer :: ServerConfig -> [SockAddr] -> IO ServerHandle | 117 | -- |
117 | streamServer cfg addrs0 = do | 118 | -- [addrs] A list of bind addresses that will be tried one after another |
119 | -- until a successful listening socket is created. | ||
120 | -- | ||
121 | -- The returned handle can be used with 'quitListening' to terminate the thread | ||
122 | -- and prevent any new sessions from starting. Currently active session | ||
123 | -- threads will not be terminated or signaled in any way. | ||
124 | forkStreamServer :: ServerConfig -> [SockAddr] -> IO ServerHandle | ||
125 | forkStreamServer cfg addrs0 = do | ||
118 | let warn = serverWarn cfg | 126 | let warn = serverWarn cfg |
119 | family = case addrs0 of | 127 | family = case addrs0 of |
120 | SockAddrInet {}:_ -> AF_INET | 128 | SockAddrInet {}:_ -> AF_INET |