dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH/WIP 0/3] http state manglement
@ 2016-09-12 22:42 Eric Wong
  2016-09-12 22:42 ` [PATCH 1/3] http: warn on curl_multi_add_handle failures Eric Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2016-09-12 22:42 UTC (permalink / raw)
  To: spew

Eric Wong (3):
      http: warn on curl_multi_add_handle failures
      http: check curl_multi_remove_handle for errors
      http: always remove curl easy from multi session on release


 http.c | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] http: warn on curl_multi_add_handle failures
  2016-09-12 22:42 [PATCH/WIP 0/3] http state manglement Eric Wong
@ 2016-09-12 22:42 ` Eric Wong
  2016-09-12 22:42 ` [PATCH 2/3] http: check curl_multi_remove_handle for errors Eric Wong
  2016-09-12 22:42 ` [PATCH 3/3] http: always remove curl easy from multi session on release Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-09-12 22:42 UTC (permalink / raw)
  To: spew

This will be useful for tracking down curl usage errors.
---
 http.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/http.c b/http.c
index cd40b01..cac5db9 100644
--- a/http.c
+++ b/http.c
@@ -1022,6 +1022,8 @@ int start_active_slot(struct active_request_slot *slot)
 
 	if (curlm_result != CURLM_OK &&
 	    curlm_result != CURLM_CALL_MULTI_PERFORM) {
+		warning("curl_multi_add_handle failed: %s",
+			curl_multi_strerror(curlm_result));
 		active_requests--;
 		slot->in_use = 0;
 		return 0;
-- 
EW


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] http: check curl_multi_remove_handle for errors
  2016-09-12 22:42 [PATCH/WIP 0/3] http state manglement Eric Wong
  2016-09-12 22:42 ` [PATCH 1/3] http: warn on curl_multi_add_handle failures Eric Wong
@ 2016-09-12 22:42 ` Eric Wong
  2016-09-12 22:42 ` [PATCH 3/3] http: always remove curl easy from multi session on release Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-09-12 22:42 UTC (permalink / raw)
  To: spew

This should help us catch usage errors as well as consolidating
the number of #ifdefs in our code.
---
 http.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/http.c b/http.c
index cac5db9..f972ff3 100644
--- a/http.c
+++ b/http.c
@@ -201,6 +201,17 @@ static void finish_active_slot(struct active_request_slot *slot)
 		slot->callback_func(slot->callback_data);
 }
 
+static void xmulti_remove_handle(struct active_request_slot *slot)
+{
+#ifdef USE_CURL_MULTI
+	CURLMcode code = curl_multi_remove_handle(curlm, slot->curl);
+
+	if (code != CURLM_OK)
+		die("curl_multi_remove_handle failed: %s",
+			curl_multi_strerror(code));
+#endif
+}
+
 #ifdef USE_CURL_MULTI
 static void process_curl_messages(void)
 {
@@ -216,7 +227,7 @@ static void process_curl_messages(void)
 			       slot->curl != curl_message->easy_handle)
 				slot = slot->next;
 			if (slot != NULL) {
-				curl_multi_remove_handle(curlm, slot->curl);
+				xmulti_remove_handle(slot);
 				slot->curl_result = curl_result;
 				finish_active_slot(slot);
 			} else {
@@ -881,9 +892,7 @@ void http_cleanup(void)
 	while (slot != NULL) {
 		struct active_request_slot *next = slot->next;
 		if (slot->curl != NULL) {
-#ifdef USE_CURL_MULTI
-			curl_multi_remove_handle(curlm, slot->curl);
-#endif
+			xmulti_remove_handle(slot);
 			curl_easy_cleanup(slot->curl);
 		}
 		free(slot);
@@ -1164,9 +1173,7 @@ static void release_active_slot(struct active_request_slot *slot)
 {
 	closedown_active_slot(slot);
 	if (slot->curl && curl_session_count > min_curl_sessions) {
-#ifdef USE_CURL_MULTI
-		curl_multi_remove_handle(curlm, slot->curl);
-#endif
+		xmulti_remove_handle(slot);
 		curl_easy_cleanup(slot->curl);
 		slot->curl = NULL;
 		curl_session_count--;
-- 
EW


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] http: always remove curl easy from multi session on release
  2016-09-12 22:42 [PATCH/WIP 0/3] http state manglement Eric Wong
  2016-09-12 22:42 ` [PATCH 1/3] http: warn on curl_multi_add_handle failures Eric Wong
  2016-09-12 22:42 ` [PATCH 2/3] http: check curl_multi_remove_handle for errors Eric Wong
@ 2016-09-12 22:42 ` Eric Wong
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2016-09-12 22:42 UTC (permalink / raw)
  To: spew

We must call curl_multi_remove_handle when releasing the slot to
prevent subsequent calls to curl_multi_add_handle from failing
with CURLM_ADDED_ALREADY (in curl 7.32.1+; older versions
returned CURLM_BAD_EASY_HANDLE)
---
 http.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/http.c b/http.c
index f972ff3..cbf16c7 100644
--- a/http.c
+++ b/http.c
@@ -1172,11 +1172,13 @@ void run_active_slot(struct active_request_slot *slot)
 static void release_active_slot(struct active_request_slot *slot)
 {
 	closedown_active_slot(slot);
-	if (slot->curl && curl_session_count > min_curl_sessions) {
+	if (slot->curl) {
 		xmulti_remove_handle(slot);
-		curl_easy_cleanup(slot->curl);
-		slot->curl = NULL;
-		curl_session_count--;
+		if (curl_session_count > min_curl_sessions) {
+			curl_easy_cleanup(slot->curl);
+			slot->curl = NULL;
+			curl_session_count--;
+		}
 	}
 #ifdef USE_CURL_MULTI
 	fill_active_slots();
-- 
EW


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-09-12 22:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-12 22:42 [PATCH/WIP 0/3] http state manglement Eric Wong
2016-09-12 22:42 ` [PATCH 1/3] http: warn on curl_multi_add_handle failures Eric Wong
2016-09-12 22:42 ` [PATCH 2/3] http: check curl_multi_remove_handle for errors Eric Wong
2016-09-12 22:42 ` [PATCH 3/3] http: always remove curl easy from multi session on release Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).