private void CheckMultiInfo() { IntPtr pMessage; while ((pMessage = CurlNative.Multi.InfoRead(_multiHandle, out int _)) != IntPtr.Zero) { var message = Marshal.PtrToStructure <CurlNative.Multi.CURLMsg>(pMessage); if (message.msg != CURLMSG.DONE) { throw new Exception($"Unexpected curl_multi_info_read result message: {message.msg}."); } var context = _easyPool[message.easy_handle]; /* Do not use message data after calling curl_multi_remove_handle() and * curl_easy_cleanup(). As per curl_multi_info_read() docs: * "WARNING: The data the returned pointer points to will not survive * calling curl_multi_cleanup, curl_multi_remove_handle or * curl_easy_cleanup." */ var action = _responseConsumer.OnComplete(context.Easy, context.CurrentRequest, message.data.result); if (action == HandleCompletedAction.ReuseHandleAndRetry) { CurlNative.Multi.RemoveHandle(_multiHandle, context.Easy); CurlNative.Multi.AddHandle(_multiHandle, context.Easy); } else if (action == HandleCompletedAction.ResetHandleAndNext) { CurlNative.Multi.RemoveHandle(_multiHandle, context.Easy); CurlNative.Easy.Reset(context.Easy); GC.KeepAlive(context.CurrentRequest); context.IsUsed = false; context.CurrentRequest = null; Refill(); } } }
private void CheckMultiInfo() { IntPtr pMessage; while ((pMessage = CurlNative.Multi.InfoRead(_multiHandle, out int _)) != IntPtr.Zero) { var message = Marshal.PtrToStructure <CurlNative.Multi.CURLMsg>(pMessage); if (message.msg != CURLMSG.DONE) { throw new Exception($"Unexpected curl_multi_info_read result message: {message.msg}."); } var easy = _easyPool.GetSafeHandleFromPtr(message.easy_handle); /* Do not use message data after calling curl_multi_remove_handle() and * curl_easy_cleanup(). As per curl_multi_info_read() docs: * "WARNING: The data the returned pointer points to will not survive * calling curl_multi_cleanup, curl_multi_remove_handle or * curl_easy_cleanup." */ _easyPool.GetAssignedContext(easy, out T requestContext); var action = _responseConsumer.OnComplete(easy, requestContext, message.data.result); if (action == HandleCompletedAction.ReuseHandleAndRetry) { CurlNative.Multi.RemoveHandle(_multiHandle, easy); CurlNative.Multi.AddHandle(_multiHandle, easy); } else if (action == HandleCompletedAction.ResetHandleAndNext) { CurlNative.Multi.RemoveHandle(_multiHandle, easy); CurlNative.Easy.Reset(easy); _easyPool.UnassignContext(easy); _easyPool.Free(easy); Refill(); } } }