diff options
author | joerg <joerg@pkgsrc.org> | 2016-10-20 21:25:57 +0000 |
---|---|---|
committer | joerg <joerg@pkgsrc.org> | 2016-10-20 21:25:57 +0000 |
commit | 2977e2321c86e9e57d23234c2bbafe2581625ba9 (patch) | |
tree | 5e0656125edcd247277f865ecb323b11b322c489 /net/libfetch | |
parent | 1c34e9e34cdeb947e6578109800483a34fdf9c70 (diff) | |
download | pkgsrc-2977e2321c86e9e57d23234c2bbafe2581625ba9.tar.gz |
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 (limited to 'net/libfetch')
-rw-r--r-- | net/libfetch/Makefile | 5 | ||||
-rw-r--r-- | net/libfetch/files/common.c | 29 | ||||
-rw-r--r-- | net/libfetch/files/common.h | 3 |
3 files changed, 28 insertions, 9 deletions
diff --git a/net/libfetch/Makefile b/net/libfetch/Makefile index 7be4d954372..6d61c1521fe 100644 --- a/net/libfetch/Makefile +++ b/net/libfetch/Makefile @@ -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 --git a/net/libfetch/files/common.c b/net/libfetch/files/common.c index 90fe09fb05e..c1e15871163 100644 --- a/net/libfetch/files/common.c +++ b/net/libfetch/files/common.c @@ -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> @@ -240,6 +240,7 @@ fetch_reopen(int sd) conn->next_buf = NULL; conn->next_len = 0; conn->sd = sd; + conn->buf_events = POLLIN; return (conn); } @@ -456,6 +457,7 @@ fetch_ssl(conn_t *conn, const struct url *URL, int verbose) 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 @@ fetch_read(conn_t *conn, char *buf, size_t len) } 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 @@ fetch_read(conn_t *conn, char *buf, size_t len) } 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 --git a/net/libfetch/files/common.h b/net/libfetch/files/common.h index 63170907a01..9a07e3560c8 100644 --- a/net/libfetch/files/common.h +++ b/net/libfetch/files/common.h @@ -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 @@ struct fetchconn { 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 */ |