From 0e3c922142177b093d90cba81d0b6712172e1f57 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 11 Jan 2020 12:27:39 -0500 Subject: Renamed streamServer to forkStreamServer. --- dht/examples/dhtd.hs | 2 +- server/src/Connection/Tcp.hs | 2 +- server/src/Network/StreamServer.hs | 30 +++++++++++++++++++----------- test/resourceExhausted.hs | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs index ed0feacb..984afeed 100644 --- a/dht/examples/dhtd.hs +++ b/dht/examples/dhtd.hs @@ -1909,7 +1909,7 @@ main = do , mbTox = mbtox , sessionsVar = ssvar } - srv <- streamServer (withSession session) [SockAddrUnix "dht.sock"] + srv <- forkStreamServer (withSession session) [SockAddrUnix "dht.sock"] return ( do atomically $ readTVar signalQuit >>= check quitListening srv , readTVar signalQuit >>= check diff --git a/server/src/Connection/Tcp.hs b/server/src/Connection/Tcp.hs index 7d93e7de..72b51191 100644 --- a/server/src/Connection/Tcp.hs +++ b/server/src/Connection/Tcp.hs @@ -300,7 +300,7 @@ server allocate sessionConduits = do dput XMisc $ "Started listening on "++show port - sserv <- flip streamServer [port] ServerConfig + sserv <- flip forkStreamServer [port] ServerConfig { serverWarn = dput XMisc , serverSession = \sock _ h -> do (conkey,u) <- makeConnKey params sock 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 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RankNTypes #-} module Network.StreamServer - ( streamServer + ( forkStreamServer , ServerHandle , getAcceptLoopThreadId , ServerConfig(..) @@ -71,8 +71,9 @@ dummyServerHandle = do -} removeSocketFile :: SockAddr -> IO () -removeSocketFile (SockAddrUnix fname) = removeFile fname -removeSocketFile _ = return () +removeSocketFile (SockAddrUnix ('\0':_)) = return () +removeSocketFile (SockAddrUnix fname) = removeFile fname +removeSocketFile _ = return () -- | Terminate the server accept-loop. Call this to shut down the server. quitListening :: ServerHandle -> IO () @@ -106,15 +107,22 @@ data ServerConfig = ServerConfig withSession :: ((RestrictedSocket,(Local SockAddr,Remote SockAddr)) -> Int -> Handle -> IO ()) -> ServerConfig withSession session = ServerConfig warnStderr session --- | Launch a thread to listen at the given bind address and dispatch --- to session handler threads on every incoming connection. Supports --- IPv4 and IPv6, TCP and unix sockets. +-- | Launch a thread to listen at the given bind address and dispatch to +-- session handler threads on every incoming connection. Supports IPv4 and +-- IPv6, TCP and unix sockets. -- --- The returned handle can be used with 'quitListening' to terminate the --- thread and prevent any new sessions from starting. Currently active --- session threads will not be terminated or signaled in any way. -streamServer :: ServerConfig -> [SockAddr] -> IO ServerHandle -streamServer cfg addrs0 = do +-- Arguments: +-- +-- [cfg] Functions for handling incomming sessions and logging prints. +-- +-- [addrs] A list of bind addresses that will be tried one after another +-- until a successful listening socket is created. +-- +-- The returned handle can be used with 'quitListening' to terminate the thread +-- and prevent any new sessions from starting. Currently active session +-- threads will not be terminated or signaled in any way. +forkStreamServer :: ServerConfig -> [SockAddr] -> IO ServerHandle +forkStreamServer cfg addrs0 = do let warn = serverWarn cfg family = case addrs0 of SockAddrInet {}:_ -> AF_INET diff --git a/test/resourceExhausted.hs b/test/resourceExhausted.hs index 4cdef98e..c38784a5 100644 --- a/test/resourceExhausted.hs +++ b/test/resourceExhausted.hs @@ -15,7 +15,7 @@ sesh sock n h = do main = do setVerbose XMisc bind <- getBindAddress "8889" True - serv <- streamServer (withSession sesh) [bind] + serv <- forkStreamServer (withSession sesh) [bind] wtid <- getAcceptLoopThreadId serv mtid <- deRefWeak wtid -- cgit v1.2.3