]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
multi: make multi_perform ignore/unignore signals less often
authorDaniel Stenberg <daniel@haxx.se>
Sun, 12 Mar 2023 22:55:09 +0000 (23:55 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 13 Mar 2023 22:01:02 +0000 (23:01 +0100)
For improved performance

Reported-by: Jerome St-Louis
Ref: #10743
Closes #10750

lib/multi.c
lib/sigpipe.h

index 3bf72ce65583e3940f736e8e5b2895339ff6c23c..6e272cb665a845b5a46f522f6ae8d9d8f0f2bf26 100644 (file)
@@ -2706,18 +2706,25 @@ CURLMcode curl_multi_perform(struct Curl_multi *multi, int *running_handles)
     return CURLM_RECURSIVE_API_CALL;
 
   data = multi->easyp;
-  while(data) {
+  if(data) {
     CURLMcode result;
+    bool nosig = data->set.no_signal;
     SIGPIPE_VARIABLE(pipe_st);
-
     sigpipe_ignore(data, &pipe_st);
-    result = multi_runsingle(multi, &now, data);
+    /* Do the loop and only alter the signal ignore state if the next handle
+       has a different NO_SIGNAL state than the previous */
+    do {
+      if(data->set.no_signal != nosig) {
+        sigpipe_restore(&pipe_st);
+        sigpipe_ignore(data, &pipe_st);
+        nosig = data->set.no_signal;
+      }
+      result = multi_runsingle(multi, &now, data);
+      if(result)
+        returncode = result;
+      data = data->next; /* operate on next handle */
+    } while(data);
     sigpipe_restore(&pipe_st);
-
-    if(result)
-      returncode = result;
-
-    data = data->next; /* operate on next handle */
   }
 
   /*
index 14ab25b67cecdcebcbbd3c11bdd3cacbd377df50..48761ad0fde40f9e2edcceb3a5bf2a80efa2ab10 100644 (file)
@@ -50,7 +50,6 @@ static void sigpipe_ignore(struct Curl_easy *data,
   if(!data->set.no_signal) {
     struct sigaction action;
     /* first, extract the existing situation */
-    memset(&ig->old_pipe_act, 0, sizeof(struct sigaction));
     sigaction(SIGPIPE, NULL, &ig->old_pipe_act);
     action = ig->old_pipe_act;
     /* ignore this signal */