pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/net/libfetch libfetch-2.37: Always run SSL_read first ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/60c5f12e6536
branches:  trunk
changeset: 354157:60c5f12e6536
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Thu Oct 20 21:25:57 2016 +0000

description:
libfetch-2.37: Always run SSL_read first for SSL connections. It will
signal whether more input (or output) is needed, update the poll mask
accordingly.

diffstat:

 net/libfetch/Makefile       |   5 ++---
 net/libfetch/files/common.c |  29 ++++++++++++++++++++++++-----
 net/libfetch/files/common.h |   3 ++-
 3 files changed, 28 insertions(+), 9 deletions(-)

diffs (97 lines):

diff -r 55af1375d267 -r 60c5f12e6536 net/libfetch/Makefile
--- a/net/libfetch/Makefile     Thu Oct 20 21:22:18 2016 +0000
+++ b/net/libfetch/Makefile     Thu Oct 20 21:25:57 2016 +0000
@@ -1,8 +1,7 @@
-# $NetBSD: Makefile,v 1.56 2016/03/05 11:27:52 jperkin Exp $
+# $NetBSD: Makefile,v 1.57 2016/10/20 21:25:57 joerg Exp $
 #
 
-DISTNAME=      libfetch-2.36
-PKGREVISION=   3
+DISTNAME=      libfetch-2.37
 CATEGORIES=    net
 MASTER_SITES=  # empty
 DISTFILES=     # empty
diff -r 55af1375d267 -r 60c5f12e6536 net/libfetch/files/common.c
--- a/net/libfetch/files/common.c       Thu Oct 20 21:22:18 2016 +0000
+++ b/net/libfetch/files/common.c       Thu Oct 20 21:25:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.c,v 1.30 2016/10/20 21:22:18 joerg Exp $        */
+/*     $NetBSD: common.c,v 1.31 2016/10/20 21:25:57 joerg Exp $        */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * Copyright (c) 2008, 2010 Joerg Sonnenberger <joerg%NetBSD.org@localhost>
@@ -240,6 +240,7 @@
        conn->next_buf = NULL;
        conn->next_len = 0;
        conn->sd = sd;
+       conn->buf_events = POLLIN;
        return (conn);
 }
 
@@ -456,6 +457,7 @@
                fprintf(stderr, "SSL context creation failed\n");
                return (-1);
        }
+       conn->buf_events = 0;
        SSL_set_fd(conn->ssl, conn->sd);
 #if OPENSSL_VERSION_NUMBER >= 0x0090806fL && !defined(OPENSSL_NO_TLSEXT)
        if (!SSL_set_tlsext_host_name(conn->ssl, (char *)(uintptr_t)URL->host)) {
@@ -537,9 +539,9 @@
        }
 
        pfd.fd = conn->sd;
-       pfd.events = POLLIN;
        for (;;) {
-               if (fetchTimeout) {
+               pfd.events = conn->buf_events;
+               if (fetchTimeout && pfd.events) {
                        do {
                                timeout_cur = compute_timeout(&timeout_end);
                                if (timeout_cur < 0) {
@@ -558,9 +560,26 @@
                        } while (pfd.revents == 0);
                }
 #ifdef WITH_SSL
-               if (conn->ssl != NULL)
+               if (conn->ssl != NULL) {
                        rlen = SSL_read(conn->ssl, buf, len);
-               else
+                       if (rlen == -1) {
+                               switch (SSL_get_error(conn->ssl, rlen)) {
+                               case SSL_ERROR_WANT_READ:
+                                       conn->buf_events = POLLIN;
+                                       break;
+                               case SSL_ERROR_WANT_WRITE:
+                                       conn->buf_events = POLLOUT;
+                                       break;
+                               default:
+                                       errno = EIO;
+                                       fetch_syserr();
+                                       return -1;
+                               }
+                       } else {
+                               /* Assume buffering on the SSL layer. */
+                               conn->buf_events = 0;
+                       }
+               } else
 #endif
                        rlen = read(conn->sd, buf, len);
                if (rlen >= 0)
diff -r 55af1375d267 -r 60c5f12e6536 net/libfetch/files/common.h
--- a/net/libfetch/files/common.h       Thu Oct 20 21:22:18 2016 +0000
+++ b/net/libfetch/files/common.h       Thu Oct 20 21:25:57 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: common.h,v 1.23 2014/01/08 20:25:34 joerg Exp $        */
+/*     $NetBSD: common.h,v 1.24 2016/10/20 21:25:57 joerg Exp $        */
 /*-
  * Copyright (c) 1998-2004 Dag-Erling Coïdan Smørgrav
  * All rights reserved.
@@ -66,6 +66,7 @@
        char            *buf;           /* buffer */
        size_t           bufsize;       /* buffer size */
        size_t           buflen;        /* length of buffer contents */
+       int              buf_events;    /* poll flags for the next cycle */
        char            *next_buf;      /* pending buffer, e.g. after getln */
        size_t           next_len;      /* size of pending buffer */
        int              err;           /* last protocol reply code */



Home | Main Index | Thread Index | Old Index