celix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [celix] abroekhuis commented on a change in pull request #274: Reuse etcd connection to prevent storm of new sockets
Date Fri, 14 Aug 2020 17:17:16 GMT

abroekhuis commented on a change in pull request #274:
URL: https://github.com/apache/celix/pull/274#discussion_r470752378



##########
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:
       Just curious, are these explicitly unset since they might be retained by the reused
handle?

##########
File path: libs/etcdlib/test/etcdlib_test.c
##########
@@ -98,6 +97,7 @@ int waitforchangetest() {
 	sleep(1);
 	etcdlib_set(etcdlib, "hier/ar/chi/cal", "testvalue3", 5, false);
 	void *resVal = NULL;
+	printf("joining\n");

Review comment:
       Can be removed I think?




----------------------------------------------------------------
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



Mime
View raw message