Safe Haskell | None |
---|
Implementation of the Ganeti Unix Domain Socket JSON server interface.
- withTimeout :: Int -> String -> IO a -> IO a
- data RecvResult
- = RecvConnClosed
- | RecvError String
- | RecvOk String
- eOM :: Word8
- bEOM :: ByteString
- data MsgKeys
- strOfKey :: MsgKeys -> String
- data ConnectConfig = ConnectConfig {
- connDaemon :: GanetiDaemon
- recvTmo :: Int
- sendTmo :: Int
- data Client = Client {
- socket :: Handle
- rbuf :: IORef ByteString
- clientConfig :: ConnectConfig
- data Server = Server {
- sSocket :: Socket
- sPath :: FilePath
- serverConfig :: ConnectConfig
- openClientSocket :: Int -> FilePath -> IO Handle
- closeClientSocket :: Handle -> IO ()
- openServerSocket :: FilePath -> IO Socket
- closeServerSocket :: Socket -> FilePath -> IO ()
- acceptSocket :: Socket -> IO Handle
- connectClient :: ConnectConfig -> Int -> FilePath -> IO Client
- connectServer :: ConnectConfig -> Bool -> FilePath -> IO Server
- closeServer :: Server -> IO ()
- acceptClient :: Server -> IO Client
- closeClient :: Client -> IO ()
- sendMsg :: Client -> String -> IO ()
- recvUpdate :: ConnectConfig -> Handle -> ByteString -> IO (ByteString, ByteString)
- recvMsg :: Client -> IO String
- recvMsgExt :: Client -> IO RecvResult
- parseCall :: (JSON mth, JSON args) => String -> Result (mth, args)
- buildResponse :: Bool -> JSValue -> String
- logMsg :: (Show e, JSON e, MonadLog m) => Handler i o -> i -> GenericResult e JSValue -> m ()
- prepareMsg :: JSON e => GenericResult e JSValue -> (Bool, JSValue)
- type HandlerResult o = IO (Bool, GenericResult GanetiException o)
- data Handler i o = Handler {
- hParse :: JSValue -> JSValue -> Result i
- hInputLogShort :: i -> String
- hInputLogLong :: i -> String
- hExec :: i -> HandlerResult o
- handleJsonMessage :: JSON o => Handler i o -> i -> HandlerResult JSValue
- handleRawMessage :: JSON o => Handler i o -> String -> IO (Bool, String)
- handleClient :: JSON o => Handler i o -> Client -> IO Bool
- clientLoop :: JSON o => Handler i o -> Client -> IO ()
- listener :: JSON o => Handler i o -> Server -> IO ()
Utility functions
withTimeout :: Int -> String -> IO a -> IO aSource
Generic protocol functionality
data RecvResult Source
Result of receiving a message from the socket.
RecvConnClosed | Connection closed |
RecvError String | Any other error |
RecvOk String | Successfull receive |
Eq RecvResult | |
Show RecvResult |
data ConnectConfig Source
ConnectConfig | |
|
A client encapsulation.
Client | |
|
A server encapsulation.
Server | |
|
Unix sockets
:: Int | connection timeout |
-> FilePath | socket path |
-> IO Handle |
Creates a Unix socket and connects it to the specified path
,
where timeout
specifies the connection timeout.
closeClientSocket :: Handle -> IO ()Source
openServerSocket :: FilePath -> IO SocketSource
Creates a Unix socket and binds it to the specified path
.
closeServerSocket :: Socket -> FilePath -> IO ()Source
acceptSocket :: Socket -> IO HandleSource
Client and server
:: ConnectConfig | configuration for the client |
-> Int | connection timeout |
-> FilePath | socket path |
-> IO Client |
Connects to the master daemon and returns a Client.
connectServer :: ConnectConfig -> Bool -> FilePath -> IO ServerSource
Creates and returns a server endpoint.
closeServer :: Server -> IO ()Source
Closes a server endpoint.
acceptClient :: Server -> IO ClientSource
Accepts a client
closeClient :: Client -> IO ()Source
Closes the client socket.
recvUpdate :: ConnectConfig -> Handle -> ByteString -> IO (ByteString, ByteString)Source
recvMsgExt :: Client -> IO RecvResultSource
Extended wrapper over recvMsg.
parseCall :: (JSON mth, JSON args) => String -> Result (mth, args)Source
Parse the required keys out of a call.
:: Bool | Success |
-> JSValue | The arguments |
-> String | The serialized form |
Serialize the response to String.
logMsg :: (Show e, JSON e, MonadLog m) => Handler i o -> i -> GenericResult e JSValue -> m ()Source
prepareMsg :: JSON e => GenericResult e JSValue -> (Bool, JSValue)Source
Processing client requests
type HandlerResult o = IO (Bool, GenericResult GanetiException o)Source
Handler | |
|
handleJsonMessage :: JSON o => Handler i o -> i -> HandlerResult JSValueSource
handleRawMessage :: JSON o => Handler i o -> String -> IO (Bool, String)Source
handleClient :: JSON o => Handler i o -> Client -> IO BoolSource
clientLoop :: JSON o => Handler i o -> Client -> IO ()Source