Skip to content

libcURL.MultiHandle

Andrew Lambert edited this page Jan 16, 2023 · 29 revisions

libcURL.MultiHandle

Class Declaration

 Protected Class MultiHandle
 Inherits libcURL.cURLHandle

Remarks

This class wraps the curl_multi API. A curl_multi "stack" can manage one or more EasyHandles, with each EasyHandle corresponding to a single transfer. Once all desired transfers have been added, you may call MultiHandle.Perform (instead of EasyHandle.Perform) to begin the transfer(s).

Calling MultiHandle.Perform asynchronously performs all of the transfers in the multistack until they complete, error out, or are explicitly removed. Calling MultiHandle.PerformOnce synchronously performs a portion of the transfers on the calling thread. In both cases transfers are automatically removed when they finish or error out.

EasyHandles may be added and removed at any point during a transfer. Once added, the MultiHandle will maintain a (RB) reference to the EasyHandle until it is removed (either explicitly or automatically).

An EasyHandle added to a multistack will behave exactly as it would had it not been added, including raising events in response to libcURL callback functions, but without blocking the thread.

Using a multistack allows single-threaded apps (like RB apps) to use libcURL in a non-blocking manner.

Event Definitions

Methods

Properties

Example

This example creates two instances of EasyHandle and then adds both of them to a MultiHandle:

  Dim multi As New libcURL.MultiHandle
  Dim easy1 As New libcURL.EasyHandle
  Dim easy2 As New libcURL.EasyHandle

  easy1.URL = "www.example.com/file.html"
  easy2.URL = "www.example.com/image.png"
  
  Dim mb1 As New MemoryBlock(0)
  Dim b1 As New BinaryStream(mb1)
  easy1.DownloadStream = b1
  
  Dim mb2 As New MemoryBlock(0)
  Dim b2 As New BinaryStream(mb2)
  easy2.DownloadStream = b2
  
  multi.AddTransfer(easy1)
  multi.AddTransfer(easy2)
  
  Do Until Not multi.PerformOnce()
    App.YieldToNextThread
  Loop
  
  b1.Close
  b2.Close

See also

Clone this wiki locally