Oipo commented on a change in pull request #274:
URL: https://github.com/apache/celix/pull/274#discussion_r470755157
##########
File path: libs/etcdlib/src/etcd.c
##########
@@ -647,40 +666,58 @@ static size_t WriteHeaderCallback(void *contents, size_t size, size_t
nmemb, voi
-static int performRequest(char* url, request_t request, void* reqData, void* repData) {
- CURL *curl = NULL;
+static int performRequest(CURL **curl, pthread_mutex_t *mutex, char* url, request_t request,
void* reqData, void* repData) {
CURLcode res = 0;
- curl = curl_easy_init();
- curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, DEFAULT_CURL_TIMEOUT);
- curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, DEFAULT_CURL_CONNECT_TIMEOUT);
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, repData);
+ if(mutex != NULL) {
+ pthread_mutex_lock(mutex);
+ }
+ if(*curl == NULL) {
+ *curl = curl_easy_init();
+ curl_easy_setopt(*curl, CURLOPT_NOSIGNAL, 1);
+ curl_easy_setopt(*curl, CURLOPT_TIMEOUT, DEFAULT_CURL_TIMEOUT);
+ curl_easy_setopt(*curl, CURLOPT_CONNECTTIMEOUT, DEFAULT_CURL_CONNECT_TIMEOUT);
+ curl_easy_setopt(*curl, CURLOPT_FOLLOWLOCATION, 1L);
+ curl_easy_setopt(*curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
+ //curl_easy_setopt(*curl, CURLOPT_VERBOSE, 1L);
+ }
+
+ curl_easy_setopt(*curl, CURLOPT_URL, url);
+ curl_easy_setopt(*curl, CURLOPT_WRITEDATA, repData);
if (((struct MemoryStruct*)repData)->header) {
- curl_easy_setopt(curl, CURLOPT_HEADERDATA, repData);
- curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, WriteHeaderCallback);
+ curl_easy_setopt(*curl, CURLOPT_HEADERDATA, repData);
+ curl_easy_setopt(*curl, CURLOPT_HEADERFUNCTION, WriteHeaderCallback);
+ } else {
+ curl_easy_setopt(*curl, CURLOPT_HEADERDATA, NULL);
+ curl_easy_setopt(*curl, CURLOPT_HEADERFUNCTION, NULL);
}
- if (request == PUT) {
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_easy_setopt(curl, CURLOPT_POST, 1L);
- curl_easy_setopt(curl, CURLOPT_POSTFIELDS, reqData);
- } else if (request == DELETE) {
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
- } else if (request == GET) {
- curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
- }
+ if (request == PUT) {
+ curl_easy_setopt(*curl, CURLOPT_CUSTOMREQUEST, "PUT");
+ curl_easy_setopt(*curl, CURLOPT_POST, 1L);
+ curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, reqData);
+ } else if (request == DELETE) {
+ curl_easy_setopt(*curl, CURLOPT_CUSTOMREQUEST, "DELETE");
+ curl_easy_setopt(*curl, CURLOPT_POST, 0);
Review comment:
Exactly. If a previous request sets them, they stay set. So you have to explicitly
clear them (or suffer some really weird behaviour)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
|