Skip to content

libcURL.MultiHandle.PerformOnce

Andrew Lambert edited this page Sep 23, 2015 · 17 revisions

#libcURL.MultiHandle.PerformOnce

##Method Signature

 Function PerformOnce() As Boolean

##Return Value Returns True until all transfers have completed. Call PerformOnce again until it returns False.

##Remarks Calling MultiHandle.PerformOnce executes curl_multi_perform once and reads all messages emitted by libcURL during that operation. All EasyHandle and MultiHandle events will be raised on the thread which calls PerformOnce. PerformOnce will not return until all event handlers have returned.

Under no circumstances should PerformOnce be called from EasyHandle or MultiHandle events. Doing so will raise an IllegalLockingException.

The TransferComplete event will be raised for any completed easy handles.

Unlike MultiHandle.Perform, this method will run the transfers and raise events on the calling thread instead of always on the main thread.

##Example This example sets up a transfer using the EasyHandle class, and then adds it to an instance of MultiHandle. PerformOnce is called multiple times by a simple loop that yields between each call.

  Dim curl As New libcURL.EasyHandle
  curl.URL = "http://www.example.com/"
  Dim output As New MemoryBlock(0)
  Dim outstream As New BinaryStream(output)
  curl.DownloadStream = outstream

  Dim multi As New libcURL.MultiHandle  
  If Not multi.AddItem(curl) Then
    MsgBox("cURL error: " + libcURL.FormatMultiError(multi.LastError))
  End If
  
  Do Until Not multi.PerformOnce() ' do a little bit of the transfer
    App.YieldToNextThread
  Loop
  outstream.Close

  If curl.LastError <> 0 Then
    MsgBox("cURL error: " + libcURL.FormatError(curl.LastError))
  End If

##See also

Clone this wiki locally