Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data RpcServer
- data RpcConversation :: * = RpcConversation {}
- forkRpcServer :: FilePath -> [String] -> Maybe FilePath -> Maybe [(String, String)] -> IO RpcServer
- connectToRpcServer :: FilePath -> FilePath -> FilePath -> (RpcServer -> IO a) -> IO a
- rpc :: (Typeable req, Typeable resp, Binary req, Binary resp) => RpcServer -> req -> IO resp
- rpcConversation :: RpcServer -> (RpcConversation -> IO a) -> IO a
- shutdown :: RpcServer -> IO ()
- forceShutdown :: RpcServer -> IO ()
- data ExternalException :: * = ExternalException {}
- illscopedConversationException :: IOException
- serverKilledException :: Maybe IOException -> ExternalException
- getRpcExitCode :: RpcServer -> IO (Maybe ExitCode)
- findProgram :: LogFunc -> ProgramSearchPath -> FilePath -> IO (Maybe FilePath)
Documentation
data RpcConversation :: *
:: FilePath | Filename of the executable |
-> [String] | Arguments |
-> Maybe FilePath | Working directory |
-> Maybe [(String, String)] | Environment |
-> IO RpcServer |
Fork an RPC server as a separate process
forkRpcServer exec args
starts executable exec
with arguments
args ++ args'
where args'
are internal arguments generated by
forkRpcServer
. These internal arguments should be passed as arguments
to rpcServer
.
As a typical example, you might pass ["--server"]
as args
, and the
main
function of exec
might look like
main = do args <- getArgs case args of "--server" : args' -> rpcServer args' <<your request handler>> _ -> <<deal with other cases>>
:: FilePath | stdin named pipe |
-> FilePath | stdout named pipe |
-> FilePath | logfile for storing exceptions |
-> (RpcServer -> IO a) | |
-> IO a |
Connect to an existing RPC server
It is the responsibility of the caller to make sure that each triplet of named pipes is only used for RPC connection.
rpc :: (Typeable req, Typeable resp, Binary req, Binary resp) => RpcServer -> req -> IO resp Source
Specialized form of rpcConversation
to do single request and wait for
a single response.
rpcConversation :: RpcServer -> (RpcConversation -> IO a) -> IO a Source
Run an RPC conversation. If the handler throws an exception during the conversation the server is terminated.
shutdown :: RpcServer -> IO () Source
Shut down the RPC server
This simply kills the remote process. If you want to shut down the remote
process cleanly you must implement your own termination protocol before
calling shutdown
.
forceShutdown :: RpcServer -> IO () Source
Force shutdown.
In order to faciliate a force shutdown while another thread may be
communicating with the RPC server, we _try_ to update the MVar underlying
the RPC server, but if we fail, we terminate the server anyway. This means
that this may leave the RpcServer
in an invalid state -- so you shouldn't
be using it anymore after calling forceShutdown!
data ExternalException :: *
Exceptions thrown by the remote server
ExternalException | |
|
serverKilledException :: Maybe IOException -> ExternalException
Generic exception thrown if the server gets killed for unknown reason
getRpcExitCode :: RpcServer -> IO (Maybe ExitCode) Source
Get the exit code of the RPC server, unless still running.
Thross an exception for connections to existing RPC servers.
findProgram :: LogFunc -> ProgramSearchPath -> FilePath -> IO (Maybe FilePath) Source