/// <summary> /// Run the sub-connections of the current cURL handle. /// </summary> public static int curl_multi_exec(Context ctx, CURLMultiResource mh, out int still_running) { int runningCount = 0; foreach (var handle in mh.Handles) { if (handle.ResponseTask != null) { if (handle.ResponseTask.IsCompleted) { EndRequestExecution(ctx, handle); mh.AddResultMessage(handle); } else { runningCount++; } } else if (handle.Result == null) { StartRequestExecution(ctx, handle); runningCount++; } } still_running = runningCount; return(CURLConstants.CURLM_OK); }
/// <summary> /// Remove a multi handle from a set of cURL handles /// </summary> /// <remarks> /// Removes a given <paramref name="ch"/> handle from the given <paramref name="mh"/> handle. /// When the <paramref name="ch"/> handle has been removed, it is again perfectly legal to run /// <see cref="curl_exec(Context, CURLResource)"/> on this handle. Removing the <paramref name="ch"/> /// handle while being used, will effectively halt the transfer in progress involving that handle. /// </remarks> public static int curl_multi_remove_handle(CURLMultiResource mh, CURLResource ch) { if (mh.Handles.Remove(ch) && ch.ResponseTask != null) { // We will simply remove the only reference to the ongoing request and let the framework either // finish it or cancel it ch.ResponseTask = null; } return(CURLConstants.CURLM_OK); }
public static PhpArray curl_multi_info_read(CURLMultiResource mh, out int msgs_in_queue) { if (mh.MessageQueue.Count == 0) { msgs_in_queue = 0; return(null); } else { var msg = mh.MessageQueue.Dequeue(); msgs_in_queue = mh.MessageQueue.Count; return(msg); } }
/// <summary> /// Wait for activity on any curl_multi connection. /// </summary> public static int curl_multi_select(CURLMultiResource mh, float timeout = 1.0f) { var tasks = mh.Handles .Select(h => h.ResponseTask) .Where(t => t != null) .ToArray(); if (tasks.Length == 0) { return(0); } // Already completed and not yet processed by curl_multi_exec -> no waiting int finished = tasks.Count(t => t.IsCompleted); if (finished > 0 || timeout == 0.0f) { return(finished); } Task.WaitAny(tasks, TimeSpan.FromSeconds(timeout)); return(tasks.Count(t => t.IsCompleted)); }
/// <summary> /// Set an option for the cURL multi handle. /// </summary> public static bool curl_multi_setopt(CURLMultiResource mh, int option, PhpValue value) { // We keep the responsibility of multiple request handling completely on .NET framework PhpException.FunctionNotSupported(nameof(curl_multi_setopt)); return(false); }
/// <summary> /// Return the last multi curl error number. /// </summary> public static int curl_multi_errno(CURLMultiResource mh) => (int)mh.LastError;
public static PhpArray curl_multi_info_read(CURLMultiResource mh) => curl_multi_info_read(mh, out _);
/// <summary> /// Add a normal cURL handle to a cURL multi handle. /// </summary> public static int curl_multi_add_handle(CURLMultiResource mh, CURLResource ch) => (int)mh.TryAddHandle(ch);
/// <summary> /// Close a set of cURL handles. /// </summary> public static void curl_multi_close(CURLMultiResource mh) => mh?.Dispose();