c10k 0.4.1 → 0.5.0
raw patch · 2 files changed
+24/−26 lines, 2 filesdep −haskell98dep ~networkPVP ok
version bump matches the API change (PVP)
Dependencies removed: haskell98
Dependency ranges changed: network
API changes (from Hackage documentation)
Files
- Network/C10kServer.hs +20/−22
- c10k.cabal +4/−4
Network/C10kServer.hs view
@@ -7,12 +7,8 @@ server can handle 'preforkProcessNumber' * 'threadNumberPerProcess' connections. - Programs complied by GHC 6.10 or earlier with the -threaded option- kill the IO thread when forkProcess is used. So, don't specify- the -threaded option to use this library.-- Even if GHC 6.14 supports kqueue or epoll(), it is difficult for RTS- to balance over multi-cores. So, this library can be used to+ GHC 7 supports kqueue or epoll() but it is difficult+ to balance over multi-core. So, this library can be used to make a process for each core and to set limitation of the number to accept connections. @@ -29,13 +25,14 @@ import Control.Concurrent import Control.Exception import Control.Monad-import System.IO+import Data.IORef import Network.BSD import Network.Socket-import Prelude hiding (catch)-import Network.TCPInfo hiding (accept) import qualified Network.TCPInfo as T (accept)+import Network.TCPInfo hiding (accept)+import Prelude hiding (catch) import System.Exit+import System.IO import System.Posix.Process import System.Posix.Signals import System.Posix.Types@@ -150,7 +147,7 @@ handleSignal cids = do ignoreSigChild mapM_ (terminator cids) [sigTERM,sigINT]- pause = awaitSignal Nothing >> yield+ pause = blockSignals reservedSignals >> awaitSignal Nothing >> yield initHandler func sig = installHandler sig func Nothing ignoreSigChild = initHandler Ignore sigCHLD terminator cids = initHandler (Catch (terminateChildren cids))@@ -194,20 +191,20 @@ runServer :: Dispatch -> C10kConfig -> IO () runServer dispatch cnf = do startedHook cnf- mvar <- newMVar 0- dispatchOrSleep mvar dispatch cnf+ ref <- newIORef 0 :: IO (IORef Int)+ dispatchOrSleep ref dispatch cnf -dispatchOrSleep :: MVar Int -> Dispatch -> C10kConfig -> IO ()-dispatchOrSleep mvar dispatch cnf = do+dispatchOrSleep :: IORef Int -> Dispatch -> C10kConfig -> IO ()+dispatchOrSleep ref dispatch cnf = do n <- howMany if n > threadNumberPerProcess cnf then sleep (sleepTimer cnf * microseconds) else dispatch increase decrease- dispatchOrSleep mvar dispatch cnf+ dispatchOrSleep ref dispatch cnf where- howMany = readMVar mvar- increase = modifyMVar_ mvar (return . succ)- decrease = modifyMVar_ mvar (return . pred)+ howMany = readIORef ref+ increase = atomicModifyIORef ref (\n -> (n+1,()))+ decrease = atomicModifyIORef ref (\n -> (n-1,())) sleep = threadDelay ----------------------------------------------------------------@@ -248,10 +245,11 @@ , addrSocketType = Stream , addrProtocol = proto }- ais <- getAddrInfo (Just hints) maddr (Just serv)- let ai = head ais- sock <- socket (addrFamily ai) (addrSocketType ai) (addrProtocol ai)+ addrs <- getAddrInfo (Just hints) maddr (Just serv)+ let addrs' = filter (\x -> addrFamily x == AF_INET6) addrs+ addr = if null addrs' then head addrs else head addrs'+ sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) setSocketOption sock ReuseAddr 1- bindSocket sock (addrAddress ai)+ bindSocket sock (addrAddress addr) listen sock maxListenQueue return sock
c10k.cabal view
@@ -1,5 +1,5 @@ Name: c10k-Version: 0.4.1+Version: 0.5.0 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3@@ -20,12 +20,12 @@ Build-Type: Simple Library if impl(ghc >= 6.12)- GHC-Options: -Wall -O2 -fno-warn-unused-do-bind+ GHC-Options: -Wall -fno-warn-unused-do-bind else- GHC-Options: -Wall -O2+ GHC-Options: -Wall Exposed-Modules: Network.C10kServer Network.TCPInfo- Build-Depends: base >= 4 && < 5, haskell98, network, unix+ Build-Depends: base >= 4 && < 5, network, unix Source-Repository head Type: git Location: git://github.com/kazu-yamamoto/c10k.git