cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH 10/10] Curl_single_getsock: fix hold/pause sock handling.

From: Carlo Wood <carlo_at_alinoe.com>
Date: Sun, 2 Nov 2014 14:09:00 +0100

The original code tests (correctly)

if((data->req.keepon & KEEP_RECVBITS) == KEEP_RECV)

to decide if a read socket should be added.

The write socket should be added if either no
read socket was added (when the above condition is false)
or when they are they are different.

However, the old code tested (incorrectly)

if(data->req.keepon & KEEP_RECV)

to see if a read socket was added, which is different
from the first tests and therefore wrong.

The comment in the code was wrong too, stating:

/* only if they are not the same socket or we didn't have a
   readable one, we increase index */

but in fact the index should only be incremented when
we add both a read socket and a write socket. Note that
the code did something else than the comment, so the comment
was just wrong. I changed it to:

/* only if they are not the same socket and we have a
   readable one, we increase index */

Then, to test if we have a readable one, correct would be
test again '(data->req.keepon & KEEP_RECVBITS) == KEEP_RECV',
but I thought it to be easier and more to the point to just
check if bitmap is still GETSOCK_BLANK or not.

---
 lib/transfer.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/transfer.c b/lib/transfer.c
index dc817a6..02eb596 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -1202,10 +1202,10 @@ int Curl_single_getsock(const struct connectdata *conn,
   if((data->req.keepon & KEEP_SENDBITS) == KEEP_SEND) {
 
     if((conn->sockfd != conn->writesockfd) ||
-       !(data->req.keepon & KEEP_RECV)) {
-      /* only if they are not the same socket or we didn't have a readable
+       bitmap == GETSOCK_BLANK) {
+      /* only if they are not the same socket and we have a readable
          one, we increase index */
-      if(data->req.keepon & KEEP_RECV)
+      if(bitmap != GETSOCK_BLANK)
         sockindex++; /* increase index if we need two entries */
 
       DEBUGASSERT(conn->writesockfd != CURL_SOCKET_BAD);
-- 
2.1.1
--MP_/7brxTVcVc4EMkWuxsorxh/Y
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LS0tLS0tLS0tLQpMaXN0IGFkbWluOiBodHRwOi8vY29vbC5oYXh4LnNlL2xpc3QvbGlzdGluZm8v
Y3VybC1saWJyYXJ5CkV0aXF1ZXR0ZTogIGh0dHA6Ly9jdXJsLmhheHguc2UvbWFpbC9ldGlxdWV0
dGUuaHRtbA==
--MP_/7brxTVcVc4EMkWuxsorxh/Y--
Received on 2001-09-17