Add an abstract type to keep monitor server state

This commit is contained in:
Johan Tibell 2011-12-28 19:44:14 -08:00
parent bc42acf53c
commit cc6301df2b

View file

@ -23,7 +23,9 @@ module System.Remote.Monitoring
-- * JSON API -- * JSON API
-- $api -- $api
forkServer Server
, serverThreadId
, forkServer
) where ) where
import Control.Applicative ((<$>), (<|>)) import Control.Applicative ((<$>), (<|>))
@ -116,6 +118,16 @@ import System.FilePath ((</>))
-- a maximally sequential run and approaches the number of threads -- a maximally sequential run and approaches the number of threads
-- (set by the RTS flag @-N@) for a maximally parallel run. -- (set by the RTS flag @-N@) for a maximally parallel run.
-- | A handle that can be used to control the monitor server.
data Server = Server {
threadId :: {-# UNPACK #-} !ThreadId
}
-- | The thread ID of the server. You can kill the server by killing
-- this thread (i.e. by throwing it an asynchronous exception.)
serverThreadId :: Server -> ThreadId
serverThreadId = threadId
-- | Start an HTTP server in a new thread. The server replies to GET -- | Start an HTTP server in a new thread. The server replies to GET
-- requests to the given host and port. The host argument can be -- requests to the given host and port. The host argument can be
-- either a numeric network address (dotted quad for IPv4, -- either a numeric network address (dotted quad for IPv4,
@ -123,13 +135,12 @@ import System.FilePath ((</>))
-- The client can set the desired response format (i.e. Content-Type) -- The client can set the desired response format (i.e. Content-Type)
-- by setting the Accept header. At the moment two response formats -- by setting the Accept header. At the moment two response formats
-- are available: \"application\/json\" and \"text\/html\". -- are available: \"application\/json\" and \"text\/html\".
--
-- You can kill the server by killing the thread (i.e. by throwing it
-- an asynchronous exception.)
forkServer :: S.ByteString -- ^ Host to listen on (e.g. \"localhost\") forkServer :: S.ByteString -- ^ Host to listen on (e.g. \"localhost\")
-> Int -- ^ Port to listen on (e.g. 8000) -> Int -- ^ Port to listen on (e.g. 8000)
-> IO ThreadId -> IO Server
forkServer host port = forkIO $ httpServe conf monitor forkServer host port = do
tid <- forkIO $ httpServe conf monitor
return $! Server tid
where conf = Config.setErrorLog Config.ConfigNoLog $ where conf = Config.setErrorLog Config.ConfigNoLog $
Config.setAccessLog Config.ConfigNoLog $ Config.setAccessLog Config.ConfigNoLog $
Config.setPort port $ Config.setPort port $