13
13
14
14
namespace Aws
15
15
{
16
- namespace Http
17
- {
18
-
19
- /* *
20
- * Simple Connection pool manager for Curl. It maintains connections in a thread safe manner. You
21
- * can call into acquire a handle, then put it back when finished. It is assumed that reusing an already
22
- * initialized handle is preferable (especially for synchronous clients). The pool doubles in capacity as
23
- * needed up to the maximum amount of connections.
24
- */
25
- class CurlMultiHandleContainer
26
- {
27
- public:
28
- /* *
29
- * Initializes an empty stack of CURL handles. If you are only making synchronous calls via your http client
30
- * then a small size is best. For async support, a good value would be 6 * number of Processors. *
31
- */
32
- CurlMultiHandleContainer (unsigned maxSize = 50 , long httpRequestTimeout = 0 , long connectTimeout = 1000 , bool tcpKeepAlive = true ,
33
- unsigned long tcpKeepAliveIntervalMs = 30000 , long lowSpeedTime = 3000 , unsigned long lowSpeedLimit = 1 ,
34
- Version version = Version::HTTP_VERSION_2TLS);
35
- ~CurlMultiHandleContainer ();
16
+ namespace Http
17
+ {
18
+ namespace Curl
19
+ {
20
+ struct CurlEasyHandleContext ;
36
21
37
- /* *
38
- * Blocks until a curl handle from the pool is available for use.
39
- */
40
- CURL* AcquireCurlHandle ();
41
- /* *
42
- * Returns a handle to the pool for reuse. It is imperative that this is called
43
- * after you are finished with the handle.
44
- */
45
- void ReleaseCurlHandle (CURL* handle);
22
+ /* *
23
+ * Simple Connection pool manager for Curl. It maintains connections in a thread safe manner. You
24
+ * can call into acquire a handle, then put it back when finished. It is assumed that reusing an already
25
+ * initialized handle is preferable (especially for synchronous clients). The pool doubles in capacity as
26
+ * needed up to the maximum amount of connections.
27
+ */
28
+ class CurlMultiHandleContainer
29
+ {
30
+ public:
31
+ /* *
32
+ * Initializes an empty stack of CURL handles.
33
+ */
34
+ CurlMultiHandleContainer (unsigned maxSize = 50 ,
35
+ long httpRequestTimeout = 0 ,
36
+ long connectTimeout = 1000 ,
37
+ bool tcpKeepAlive = true ,
38
+ unsigned long tcpKeepAliveIntervalMs = 30000 ,
39
+ long lowSpeedTime = 3000 ,
40
+ unsigned long lowSpeedLimit = 1 ,
41
+ Version version = Version::HTTP_VERSION_2TLS);
42
+ ~CurlMultiHandleContainer ();
46
43
47
- /* *
48
- * When the handle has bad DNS entries, problematic live connections, we need to destroy the handle from pool.
49
- */
50
- void DestroyCurlHandle (CURL* handle);
44
+ /* *
45
+ * Blocks until a curl handle from the pool is available for use.
46
+ */
47
+ CurlEasyHandleContext* AcquireCurlHandle ();
48
+ /* *
49
+ * Returns a handle to the pool for reuse. It is imperative that this is called
50
+ * after you are finished with the handle.
51
+ */
52
+ void ReleaseCurlHandle (CurlEasyHandleContext* handleCtx);
51
53
52
- inline CURLM* AccessCurlMultiHandle ()
53
- {
54
- return m_curlMultiHandle;
55
- }
54
+ /* *
55
+ * When the handle has bad DNS entries, problematic live connections, we need to destroy the handle from pool.
56
+ */
57
+ void DestroyCurlHandle (CurlEasyHandleContext* handleCtx);
56
58
57
- private:
58
- CurlMultiHandleContainer (const CurlMultiHandleContainer&) = delete ;
59
- const CurlMultiHandleContainer& operator = (const CurlMultiHandleContainer&) = delete ;
60
- CurlMultiHandleContainer (const CurlMultiHandleContainer&&) = delete ;
61
- const CurlMultiHandleContainer& operator = (const CurlMultiHandleContainer&&) = delete ;
59
+ inline CURLM* AccessCurlMultiHandle ()
60
+ {
61
+ return m_curlMultiHandle;
62
+ }
62
63
63
- CURL* CreateCurlHandleInPool ();
64
- bool CheckAndGrowPool ();
65
- void SetDefaultOptionsOnHandle (CURL* handle);
66
- static long ConvertHttpVersion (Version version);
64
+ private:
65
+ CurlMultiHandleContainer (const CurlMultiHandleContainer&) = delete ;
66
+ const CurlMultiHandleContainer& operator = (const CurlMultiHandleContainer&) = delete ;
67
+ CurlMultiHandleContainer (const CurlMultiHandleContainer&&) = delete ;
68
+ const CurlMultiHandleContainer& operator = (const CurlMultiHandleContainer&&) = delete ;
67
69
68
- Aws::Utils::ExclusiveOwnershipResourceManager<CURL*> m_handleContainer;
69
- CURLM* m_curlMultiHandle = nullptr ;
70
+ CurlEasyHandleContext* CreateCurlHandleInPool ();
71
+ bool CheckAndGrowPool ();
72
+ void SetDefaultOptionsOnHandle (CurlEasyHandleContext& handleCtx);
73
+ static long ConvertHttpVersion (Version version);
70
74
71
- unsigned m_maxPoolSize;
72
- unsigned long m_httpRequestTimeout;
73
- unsigned long m_connectTimeout;
74
- bool m_enableTcpKeepAlive;
75
- unsigned long m_tcpKeepAliveIntervalMs;
76
- unsigned long m_lowSpeedTime;
77
- unsigned long m_lowSpeedLimit;
78
- unsigned m_poolSize;
79
- std::mutex m_containerLock;
80
- Version m_version;
81
- };
75
+ Aws::Utils::ExclusiveOwnershipResourceManager<CurlEasyHandleContext*> m_handleContainer;
76
+ CURLM* m_curlMultiHandle = nullptr ;
82
77
83
- } // namespace Http
84
- } // namespace Aws
78
+ unsigned m_maxPoolSize;
79
+ unsigned long m_httpRequestTimeout;
80
+ unsigned long m_connectTimeout;
81
+ bool m_enableTcpKeepAlive;
82
+ unsigned long m_tcpKeepAliveIntervalMs;
83
+ unsigned long m_lowSpeedTime;
84
+ unsigned long m_lowSpeedLimit;
85
+ unsigned m_poolSize;
86
+ std::mutex m_containerLock;
87
+ Version m_version;
88
+ };
85
89
90
+ } // namespace Curl
91
+ } // namespace Http
92
+ } // namespace Aws
0 commit comments