Safe Haskell | Safe-Infered |
---|
Ganeti-specific implementation of the Curl multi interface (http://curl.haxx.se/libcurl/c/libcurl-multi.html).
TODO: Evaluate implementing and switching to curl_multi_socket_action(3) interface, which is deemed to be more performant for high-numbers of connections (but this is not the case for Ganeti).
- data CurlM_
- type CurlMH = Ptr CurlM_
- type HandleMap = Map CurlH (IORef CurlCode)
- curl_multi_init :: IO CurlMH
- curl_multi_cleanup :: CurlMH -> IO CInt
- curl_multi_add_handle :: CurlMH -> CurlH -> IO CInt
- curl_multi_remove_handle :: CurlMH -> CurlH -> IO CInt
- curl_multi_perform :: CurlMH -> Ptr CInt -> IO CInt
- curl_multi_info_read :: CurlMH -> Ptr CInt -> IO (Ptr CurlMsg)
- curlMultiAddHandle :: CurlMH -> Curl -> IO ()
- curlMultiInfoRead :: CurlMH -> IO (Maybe CurlMsg, CInt)
- curlMultiPerform :: CurlMH -> IO (CurlMCode, CInt)
- pollDelayInterval :: Int
- writeHandle :: IORef [String] -> Ptr CChar -> CInt -> CInt -> Ptr () -> IO CInt
- readMessages :: CurlMH -> HandleMap -> IO ()
- performMulti :: CurlMH -> HandleMap -> CInt -> IO ()
- errorBuffer :: String
- mallocErrorBuffer :: IO CString
- makeEasyHandle :: (IORef [String], Ptr CChar, ([CurlOption], URLString)) -> IO Curl
- execMultiCall :: [([CurlOption], String)] -> IO [(CurlCode, String)]
Data types
Empty data type denoting a Curl multi handle. Naming is similar to Network.Curl types.
type HandleMap = Map CurlH (IORef CurlCode)Source
Our type alias for maps indexing CurlH
handles to the IORef
for the Curl code.
FFI declarations
curl_multi_init :: IO CurlMHSource
curl_multi_cleanup :: CurlMH -> IO CIntSource
curl_multi_add_handle :: CurlMH -> CurlH -> IO CIntSource
curl_multi_remove_handle :: CurlMH -> CurlH -> IO CIntSource
curl_multi_perform :: CurlMH -> Ptr CInt -> IO CIntSource
curl_multi_info_read :: CurlMH -> Ptr CInt -> IO (Ptr CurlMsg)Source
Wrappers over FFI functions
curlMultiAddHandle :: CurlMH -> Curl -> IO ()Source
Adds an easy handle to a multi handle. This is a nicer wrapper
over curl_multi_add_handle
that fails for wrong codes.
curlMultiInfoRead :: CurlMH -> IO (Maybe CurlMsg, CInt)Source
Nice wrapper over curl_multi_info_read
that massages the
results into Haskell types.
curlMultiPerform :: CurlMH -> IO (CurlMCode, CInt)Source
Nice wrapper over curl_multi_perform
.
Helper functions
pollDelayInterval :: IntSource
Magical constant for the polling delay. This needs to be chosen such that:
- we don't poll too often; a slower poll allows the RTS to schedule other threads, and let them work
- we don't want to pool too slow, so that Curl gets to act on the handles that need it
writeHandle :: IORef [String] -> Ptr CChar -> CInt -> CInt -> Ptr () -> IO CIntSource
Writes incoming curl data to a list of strings, stored in an IORef
.
readMessages :: CurlMH -> HandleMap -> IO ()Source
Loops and extracts all pending messages from a Curl multi handle.
performMulti :: CurlMH -> HandleMap -> CInt -> IO ()Source
Loops and polls curl until there are no more remaining handles.
errorBuffer :: StringSource
Template for the Curl error buffer.
mallocErrorBuffer :: IO CStringSource
Allocate a NULL-initialised error buffer.
makeEasyHandle :: (IORef [String], Ptr CChar, ([CurlOption], URLString)) -> IO CurlSource
Initialise a curl handle. This is just a wrapper over the
Network.Curl function initialize
, plus adding our options.
Main multi-call work function
execMultiCall :: [([CurlOption], String)] -> IO [(CurlCode, String)]Source
Perform a multi-call against a list of nodes.