ganeti

Safe HaskellSafe-Infered

Ganeti.Curl.Multi

Contents

Description

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).

Synopsis

Data types

data CurlM_ Source

Empty data type denoting a Curl multi handle. Naming is similar to Network.Curl types.

type CurlMH = Ptr CurlM_Source

Type alias for a pointer to a Curl multi handle.

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_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.