1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 #pragma once
6 
7 #include "pal_types.h"
8 
9 #include <curl/curl.h>
10 
11 enum PAL_CURLMcode : int32_t
12 {
13     PAL_CURLM_CALL_MULTI_PERFORM = -1,
14     PAL_CURLM_OK = 0,
15     PAL_CURLM_BAD_HANDLE = 1,
16     PAL_CURLM_BAD_EASY_HANDLE = 2,
17     PAL_CURLM_OUT_OF_MEMORY = 3,
18     PAL_CURLM_INTERNAL_ERROR = 4,
19     PAL_CURLM_BAD_SOCKET = 5,
20     PAL_CURLM_UNKNOWN_OPTION = 6,
21     PAL_CURLM_ADDED_ALREADY = 7, // Added in libcurl 7.32.1
22 };
23 
24 enum PAL_CURLMoption : int32_t
25 {
26     PAL_CURLMOPT_PIPELINING = 3,
27     PAL_CURLMOPT_MAX_HOST_CONNECTIONS = 7,
28 };
29 
30 enum PAL_CurlPipe : int32_t
31 {
32     PAL_CURLPIPE_MULTIPLEX = 2,
33 };
34 
35 enum PAL_CURLMSG : int32_t
36 {
37     PAL_CURLMSG_DONE = 1,
38 };
39 
40 /*
41 Creates a new CURLM instance.
42 
43 Returns the new CURLM instance or nullptr if something went wrong.
44 */
45 extern "C" CURLM* HttpNative_MultiCreate();
46 
47 /*
48 Cleans up and removes a whole multi stack.
49 
50 Returns CURLM_OK on success, otherwise an error code.
51 */
52 extern "C" int32_t HttpNative_MultiDestroy(CURLM* multiHandle);
53 
54 /*
55 Shims the curl_multi_add_handle function.
56 
57 Returns CURLM_OK on success, otherwise an error code.
58 */
59 extern "C" int32_t HttpNative_MultiAddHandle(CURLM* multiHandle, CURL* easyHandle);
60 
61 /*
62 Shims the curl_multi_remove_handle function.
63 
64 Returns CURLM_OK on success, otherwise an error code.
65 */
66 extern "C" int32_t HttpNative_MultiRemoveHandle(CURLM* multiHandle, CURL* easyHandle);
67 
68 /*
69 Shims the curl_multi_wait function.
70 
71 Returns CURLM_OK on success, otherwise an error code.
72 
73 isExtraFileDescriptorActive is set to a value indicating whether extraFileDescriptor has new data received.
74 isTimeout is set to a value indicating whether a timeout was encountered before any file descriptors had events occur.
75 */
76 extern "C" int32_t HttpNative_MultiWait(CURLM* multiHandle,
77                                         intptr_t extraFileDescriptor,
78                                         int32_t* isExtraFileDescriptorActive,
79                                         int32_t* isTimeout);
80 
81 /*
82 Reads/writes available data from each easy handle.
83 Shims the curl_multi_perform function.
84 
85 Returns CURLM_OK on success, otherwise an error code.
86 */
87 extern "C" int32_t HttpNative_MultiPerform(CURLM* multiHandle);
88 
89 /*
90 Ask the multi handle if there are any messages/informationals from the individual transfers.
91 Shims the curl_multi_info_read function.
92 
93 Returns 1 if a CURLMsg was retrieved and the out variables are set,
94 otherwise 0 when there are no more messages to retrieve.
95 */
96 extern "C" int32_t HttpNative_MultiInfoRead(CURLM* multiHandle, int32_t* message, CURL** easyHandle, int32_t* result);
97 
98 /*
99 Returns a string describing the CURLMcode error code.
100 */
101 extern "C" const char* HttpNative_MultiGetErrorString(PAL_CURLMcode code);
102 
103 /*
104 Shims the curl_multi_setopt function
105 */
106 extern "C" int32_t HttpNative_MultiSetOptionLong(CURLM* handle, PAL_CURLMoption option, int64_t value);
107