]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl_multi_fdset: include the shutdown connections in the set
authorDaniel Stenberg <daniel@haxx.se>
Sun, 19 Jan 2025 10:16:56 +0000 (11:16 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 22 Jan 2025 06:55:31 +0000 (07:55 +0100)
They were previously missing.

Follow-up from c9b95c0bb30f88bf00e1ac7e706c

Fixes #15156
Reported-by: Christopher Dannemiller
Closes #16049

lib/conncache.c
lib/conncache.h
lib/multi.c
lib/select.c
lib/select.h

index 0aa2dabb16c60dc2ca459abf4b88dc22b23fda2f..85435bfac001987092f74bb0534382b3e6e4155c 100644 (file)
@@ -953,8 +953,9 @@ CURLcode Curl_cpool_add_pollfds(struct cpool *cpool,
   return result;
 }
 
+/* return information about the shutdown connections */
 unsigned int Curl_cpool_add_waitfds(struct cpool *cpool,
-                                    struct curl_waitfds *cwfds)
+                                    struct Curl_waitfds *cwfds)
 {
   unsigned int need = 0;
 
@@ -979,6 +980,46 @@ unsigned int Curl_cpool_add_waitfds(struct cpool *cpool,
   return need;
 }
 
+/* return fd_set info about the shutdown connections */
+void Curl_cpool_setfds(struct cpool *cpool,
+                       fd_set *read_fd_set, fd_set *write_fd_set,
+                       int *maxfd)
+{
+  CPOOL_LOCK(cpool);
+  if(Curl_llist_head(&cpool->shutdowns)) {
+    struct Curl_llist_node *e;
+
+    for(e = Curl_llist_head(&cpool->shutdowns); e;
+        e = Curl_node_next(e)) {
+      struct easy_pollset ps;
+      unsigned int i;
+      struct connectdata *conn = Curl_node_elem(e);
+      memset(&ps, 0, sizeof(ps));
+      Curl_attach_connection(cpool->idata, conn);
+      Curl_conn_adjust_pollset(cpool->idata, &ps);
+      Curl_detach_connection(cpool->idata);
+
+      for(i = 0; i < ps.num; i++) {
+#if defined(__DJGPP__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warith-conversion"
+#endif
+        if(ps.actions[i] & CURL_POLL_IN)
+          FD_SET(ps.sockets[i], read_fd_set);
+        if(ps.actions[i] & CURL_POLL_OUT)
+          FD_SET(ps.sockets[i], write_fd_set);
+#if defined(__DJGPP__)
+#pragma GCC diagnostic pop
+#endif
+        if((ps.actions[i] & (CURL_POLL_OUT | CURL_POLL_IN)) &&
+           ((int)ps.sockets[i] > *maxfd))
+          *maxfd = (int)ps.sockets[i];
+      }
+    }
+  }
+  CPOOL_UNLOCK(cpool);
+}
+
 static void cpool_perform(struct cpool *cpool)
 {
   struct Curl_easy *data = cpool->idata;
index 5a1bf10959ffb859718170369696ec377b1ef653..5f239bc0b0a810dc72db79f102932c1443ff1dec 100644 (file)
@@ -31,7 +31,7 @@
 struct connectdata;
 struct Curl_easy;
 struct curl_pollfds;
-struct curl_waitfds;
+struct Curl_waitfds;
 struct Curl_multi;
 struct Curl_share;
 
@@ -184,7 +184,11 @@ void Curl_cpool_do_locked(struct Curl_easy *data,
 CURLcode Curl_cpool_add_pollfds(struct cpool *connc,
                                 struct curl_pollfds *cpfds);
 unsigned int Curl_cpool_add_waitfds(struct cpool *connc,
-                                    struct curl_waitfds *cwfds);
+                                    struct Curl_waitfds *cwfds);
+
+void Curl_cpool_setfds(struct cpool *cpool,
+                       fd_set *read_fd_set, fd_set *write_fd_set,
+                       int *maxfd);
 
 /**
  * Perform maintenance on connections in the pool. Specifically,
index bb9ccd03f9915792f3114916b721b4441caf411e..c877b6baca244f216e42ace6fcc64333cd3f9aee 100644 (file)
@@ -1168,6 +1168,7 @@ CURLMcode curl_multi_fdset(CURLM *m,
   int this_max_fd = -1;
   struct Curl_llist_node *e;
   struct Curl_multi *multi = m;
+  unsigned int i;
   (void)exc_fd_set; /* not used */
 
   if(!GOOD_MULTI_HANDLE(multi))
@@ -1178,7 +1179,6 @@ CURLMcode curl_multi_fdset(CURLM *m,
 
   for(e = Curl_llist_head(&multi->process); e; e = Curl_node_next(e)) {
     struct Curl_easy *data = Curl_node_elem(e);
-    unsigned int i;
 
     multi_getsock(data, &data->last_poll);
 
@@ -1202,6 +1202,8 @@ CURLMcode curl_multi_fdset(CURLM *m,
     }
   }
 
+  Curl_cpool_setfds(&multi->cpool, read_fd_set, write_fd_set, &this_max_fd);
+
   *max_fd = this_max_fd;
 
   return CURLM_OK;
@@ -1212,7 +1214,7 @@ CURLMcode curl_multi_waitfds(CURLM *m,
                              unsigned int size,
                              unsigned int *fd_count)
 {
-  struct curl_waitfds cwfds;
+  struct Curl_waitfds cwfds;
   CURLMcode result = CURLM_OK;
   struct Curl_llist_node *e;
   struct Curl_multi *multi = m;
index a14696d114b71365c1dfff6def196338e514cd3d..ef8d554f1cee9c01d939a168e49a4c7c3358a879 100644 (file)
@@ -488,7 +488,7 @@ CURLcode Curl_pollfds_add_ps(struct curl_pollfds *cpfds,
   return CURLE_OK;
 }
 
-void Curl_waitfds_init(struct curl_waitfds *cwfds,
+void Curl_waitfds_init(struct Curl_waitfds *cwfds,
                        struct curl_waitfd *static_wfds,
                        unsigned int static_count)
 {
@@ -499,7 +499,7 @@ void Curl_waitfds_init(struct curl_waitfds *cwfds,
   cwfds->count = static_count;
 }
 
-static unsigned int cwfds_add_sock(struct curl_waitfds *cwfds,
+static unsigned int cwfds_add_sock(struct Curl_waitfds *cwfds,
                                    curl_socket_t sock, short events)
 {
   int i;
@@ -524,7 +524,7 @@ static unsigned int cwfds_add_sock(struct curl_waitfds *cwfds,
   return 1;
 }
 
-unsigned int Curl_waitfds_add_ps(struct curl_waitfds *cwfds,
+unsigned int Curl_waitfds_add_ps(struct Curl_waitfds *cwfds,
                                  struct easy_pollset *ps)
 {
   size_t i;
index 9d2d7bd21b95340b1756e4f184bac4aa40e66168..608395ff34b9003bb2cf250f07c7b185c0efb4d7 100644 (file)
@@ -130,17 +130,17 @@ CURLcode Curl_pollfds_add_ps(struct curl_pollfds *cpfds,
 CURLcode Curl_pollfds_add_sock(struct curl_pollfds *cpfds,
                                curl_socket_t sock, short events);
 
-struct curl_waitfds {
+struct Curl_waitfds {
   struct curl_waitfd *wfds;
   unsigned int n;
   unsigned int count;
 };
 
-void Curl_waitfds_init(struct curl_waitfds *cwfds,
+void Curl_waitfds_init(struct Curl_waitfds *cwfds,
                        struct curl_waitfd *static_wfds,
                        unsigned int static_count);
 
-unsigned int Curl_waitfds_add_ps(struct curl_waitfds *cwfds,
+unsigned int Curl_waitfds_add_ps(struct Curl_waitfds *cwfds,
                                  struct easy_pollset *ps);
 
 #endif /* HEADER_CURL_SELECT_H */