29
29
#include " curl_interface.h"
30
30
#include " curl_pair.h"
31
31
32
+ #define CURLCPP_DEFINE_OPTION (opt, value_type )\
33
+ template <> struct shoption_t <opt> {\
34
+ using type = value_type;\
35
+ }
36
+
32
37
namespace curl {
38
+ namespace detail {
39
+ template <CURLSHoption>
40
+ struct shoption_t ;
41
+
42
+ template <CURLSHoption opt>
43
+ using SHOption_type = typename shoption_t <opt>::type;
44
+
45
+ /*
46
+ * The parameter must be a pointer to a function matching the following prototype:
47
+ * void lock_function(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr);
48
+ * data defines what data libcurl wants to lock, and you must make sure that only one lock is given
49
+ * at any time for each kind of data. access defines what access type libcurl wants, shared or single.
50
+ * userptr is the pointer you set with CURLSHOPT_USERDATA.
51
+ */
52
+ CURLCPP_DEFINE_OPTION (CURLSHOPT_LOCKFUNC,
53
+ void (*)(CURL *handle, curl_lock_data data, curl_lock_access access, void *userptr));
54
+ /*
55
+ * The parameter must be a pointer to a function matching the following prototype:
56
+ * void unlock_function(CURL *handle, curl_lock_data data, void *userptr);
57
+ * data defines what data libcurl wants to unlock, and you must make sure that only one lock is given
58
+ * at any time for each kind of data.
59
+ * userptr is the pointer you set with CURLSHOPT_USERDATA.
60
+ */
61
+ CURLCPP_DEFINE_OPTION (CURLSHOPT_UNLOCKFUNC, void (*)(CURL *handle, curl_lock_data data, void *userptr));
62
+
63
+ /*
64
+ * The parameter specifies a type of data that should be shared. This may be set to one of the values described below.
65
+ * CURL_LOCK_DATA_COOKIE: Cookie data will be shared across the easy handles using this shared object.
66
+ * CURL_LOCK_DATA_DNS: Cached DNS hosts will be shared across the easy handles using this shared object.
67
+ * Note that when you use the multi interface, all easy handles added to the same multi handle will share
68
+ * DNS cache by default without this having to be used!
69
+ * CURL_LOCK_DATA_SSL_SESSION: SSL session IDs will be shared across the easy handles using this shared
70
+ * object. This will reduce the time spent in the SSL handshake when reconnecting to the same server.
71
+ * Note SSL session IDs are reused within the same easy handle by default. Note this symbol was added
72
+ * in 7.10.3 but was not implemented until 7.23.0.
73
+ */
74
+ CURLCPP_DEFINE_OPTION (CURLSHOPT_SHARE, int );
75
+
76
+ /*
77
+ * This option does the opposite of CURLSHOPT_SHARE. It specifies that the specified parameter will no longer
78
+ * be shared. Valid values are the same as those for CURLSHOPT_SHARE.
79
+ */
80
+ CURLCPP_DEFINE_OPTION (CURLSHOPT_UNSHARE, int );
81
+
82
+ /*
83
+ * The parameter allows you to specify a pointer to data that will be passed to the lock_function and
84
+ * unlock_function each time it is called.
85
+ */
86
+ CURLCPP_DEFINE_OPTION (CURLSHOPT_USERDATA, void *);
87
+ }
88
+
33
89
/* *
34
90
* Definition of share interface. The purpose of this interface is to
35
91
* enable data sharing between curl handlers.
@@ -64,7 +120,7 @@ namespace curl {
64
120
/* *
65
121
* Add method used to add options to the share handle.
66
122
*/
67
- template < typename T > void add (const curl_pair<CURLSHoption,T> & );
123
+ template <CURLSHoption Opt > void add (const detail::SHOption_type<Opt> );
68
124
/* *
69
125
* Allows users to specify a list of options for the current
70
126
* easy handler. In this way, you can specify any iterable data
@@ -87,10 +143,10 @@ namespace curl {
87
143
}
88
144
89
145
// Implementation of add method
90
- template <typename T > void curl_share::add (const curl_pair<CURLSHoption,T> &pair ) {
91
- const CURLSHcode code = curl_share_setopt (this ->curl ,pair. first (),pair. second () );
146
+ template <CURLSHoption Opt > void curl_share::add (const detail::SHOption_type<Opt> val ) {
147
+ const auto code = curl_share_setopt (this ->curl , Opt, val );
92
148
if (code != CURLSHE_OK) {
93
- throw curl_share_exception (code,__FUNCTION__);
149
+ throw curl_share_exception (code, __FUNCTION__);
94
150
}
95
151
}
96
152
0 commit comments