On Thu, 18 Jul 2013, Evgeny Turnaev wrote:
Another fix in attachment.
Okay, I had a proper look now then and I have a much larger fix to suggest,
see my attachment. I don't have any test case for this so I haven't actually
verified that this is working properly.
Changes:
- Use a different index lookup that I think look easier and I think it is
correct
- It only copies if any socket had activity
- It translates between the internal bitfields and the external ones as
there's no guarantee they actually match!
I'm very interested in feedback, especially if someone can test it against
some real code/application...
--
/ daniel.haxx.se
From 33cca631c018c4534ca3cec02eb6379f67b856e8 Mon Sep 17 00:00:00 2001
From: Daniel Stenberg <[email protected]>
Date: Thu, 18 Jul 2013 23:36:59 +0200
Subject: [PATCH] curl_multi_wait: fix revents
Commit 6d30f8ebed34e7276 didn't work properly. First, it used the wrong
array index, but this fix also:
1 - only does the copying if indeed there was any activity
2 - makes sure to properly translate between internal and external
bitfields, which are not guaranteed to match
Reported-by: Evgeny Turnaev
---
lib/multi.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/lib/multi.c b/lib/multi.c
index dee2356..e173fd6 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -808,7 +808,7 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
struct Curl_one_easy *easy;
curl_socket_t sockbunch[MAX_SOCKSPEREASYHANDLE];
int bitmap;
- unsigned int i, j;
+ unsigned int i;
unsigned int nfds = 0;
unsigned int curlfds;
struct pollfd *ufds = NULL;
@@ -904,15 +904,33 @@ CURLMcode curl_multi_wait(CURLM *multi_handle,
++nfds;
}
- if(nfds)
+ if(nfds) {
/* wait... */
i = Curl_poll(ufds, nfds, timeout_ms);
+
+ if(i) {
+ unsigned int j;
+ /* copy revents results from the poll to the curl_multi_wait poll
+ struct, the bit values of the actual underlying poll() implementation
+ may not be the same as the ones in the public libcurl API! */
+ for(j = 0; j < extra_nfds; j++) {
+ unsigned short mask = 0;
+ unsigned r = ufds[curlfds + j].revents;
+
+ if(r & POLLIN)
+ mask |= CURL_WAIT_POLLIN;
+ if(r & POLLOUT)
+ mask |= CURL_WAIT_POLLOUT;
+ if(r & POLLPRI)
+ mask |= CURL_WAIT_POLLPRI;
+
+ extra_fds[j].revents = mask;
+ }
+ }
+ }
else
i = 0;
- for(j = nfds - extra_nfds; j < nfds; j++)
- extra_fds[j].revents = ufds[j].revents;
-
Curl_safefree(ufds);
if(ret)
*ret = i;
--
1.8.3.2
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html