c10k 0.1.0 → 0.2.0
raw patch · 3 files changed
+16/−55 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Network.TCPInfo: TCPInfo :: HostName -> ServiceName -> HostName -> ServiceName -> TCPInfo
- Network.TCPInfo: accept :: Socket -> IO (Handle, TCPInfo)
- Network.TCPInfo: data TCPInfo
- Network.TCPInfo: instance Eq TCPInfo
- Network.TCPInfo: instance Show TCPInfo
- Network.TCPInfo: myAddr :: TCPInfo -> HostName
- Network.TCPInfo: myPort :: TCPInfo -> ServiceName
- Network.TCPInfo: peerAddr :: TCPInfo -> HostName
- Network.TCPInfo: peerPort :: TCPInfo -> ServiceName
- Network.C10kServer: type C10kServer = Handle -> TCPInfo -> IO ()
+ Network.C10kServer: type C10kServer = Socket -> IO ()
Files
- Network/C10kServer.hs +13/−8
- Network/TCPInfo.hs +0/−44
- c10k.cabal +3/−3
Network/C10kServer.hs view
@@ -5,8 +5,15 @@ barrier. Each process handles 'threadNumberPerProcess' connections. 'preforkProcessNumber' child server processes are preforked. So, this server can handle 'preforkProcessNumber' * 'threadNumberPerProcess'- connections. To stop all server, send SIGTERM to the parent- process. (e.g. @kill `cat PIDFILE`@ where the PID file name is+ connections.++ Even if GHC supports kqueue or epoll(), it is difficult for RTS+ to balance over multi-cores. So, this library can be used to+ make a process for each core and to set limitation of the number+ to accept connections.++ To stop all server, send SIGTERM to the parent process.+ (e.g. @kill `cat PIDFILE`@ where the PID file name is specified by 'pidFile') -} module Network.C10kServer (C10kServer, C10kConfig(..),@@ -15,10 +22,8 @@ import Control.Concurrent import Control.Exception import Control.Monad-import IO hiding (catch, try) import Network hiding (accept)-import Network.Socket hiding (accept)-import Network.TCPInfo+import Network.Socket import Prelude hiding (catch) import System.Posix.Process import System.Posix.Signals@@ -30,7 +35,7 @@ {-| The type of the first argument of 'runC10kServer'. -}-type C10kServer = Handle -> TCPInfo -> IO ()+type C10kServer = Socket -> IO () {-| The type of configuration given to 'runC10kServer' as the second@@ -143,9 +148,9 @@ dispatchOrSleep mvar s srv cnf where dispatch = do- (hdl,tcpi) <- accept s+ (sock,_) <- accept s increase- forkIO $ srv hdl tcpi `finally` (decrease >> hClose hdl)+ forkIO $ srv sock `finally` (decrease >> (sClose sock `catch` ignore)) return () howMany = readMVar mvar increase = modifyMVar_ mvar (return . succ)
− Network/TCPInfo.hs
@@ -1,44 +0,0 @@-{-|- Yet another accept() to tell TCP information.--}-module Network.TCPInfo where--import Data.List-import Network.Socket-import System.IO--{-|- A Type to carry TCP information.--}-data TCPInfo = TCPInfo {- -- | Local IP address- myAddr :: HostName- -- | Local port number- , myPort :: ServiceName- -- | Remote IP address- , peerAddr :: HostName- -- | Remote port number- , peerPort :: ServiceName- } deriving (Eq,Show)--------------------------------------------------------------------{-|- Yet another accept() to return both 'Handle' and 'TCPInfo'.--}-accept :: Socket -> IO (Handle, TCPInfo)-accept sock = do- (sock', sockaddr) <- Network.Socket.accept sock- let getInfo = getNameInfo [NI_NUMERICHOST, NI_NUMERICSERV] True True- (Just vMyAddr, Just vMyPort) <- getSocketName sock' >>= getInfo- (Just vPeerAddr, Just vPeerPort) <- getInfo sockaddr- hdl <- socketToHandle sock' ReadWriteMode- let info = TCPInfo { myAddr = strip vMyAddr- , myPort = vMyPort- , peerAddr = strip vPeerAddr- , peerPort = vPeerPort}- return (hdl, info)- where- strip x- | "::ffff:" `isPrefixOf` x = drop 7 x- | otherwise = x
c10k.cabal view
@@ -1,10 +1,10 @@ Name: c10k-Version: 0.1.0+Version: 0.2.0 Author: Kazu Yamamoto <kazu@iij.ad.jp> Maintainer: Kazu Yamamoto <kazu@iij.ad.jp> License: BSD3 License-File: LICENSE-Synopsis: C10k server+Synopsis: C10k server library Description: Network server library to handle over 10,000 connections. Since GHC 6.10.4 or earlier uses select(), it cannot handle@@ -20,7 +20,7 @@ Build-Type: Simple Library GHC-Options: -Wall -O2- Exposed-Modules: Network.C10kServer, Network.TCPInfo+ Exposed-Modules: Network.C10kServer Build-Depends: base >= 4 && < 10, haskell98, network, unix, hdaemonize Source-Repository head Type: git