summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/http.c
diff options
context:
space:
mode:
authorkaiw <kaiw@FreeBSD.org>2014-01-28 19:12:31 +0000
committerkaiw <kaiw@FreeBSD.org>2014-01-28 19:12:31 +0000
commit9c3c6fdae0b43f1bbd5486754c20e403fc83c3b6 (patch)
treec000f1bf7a21df619e5cc1ac52b3edc991b884d0 /lib/libfetch/http.c
parent0fb1cfad9518e33fe20de1d9d694d0d5c2044fa2 (diff)
parent17e24564634134c9b7145fcf8d1c7d51b93c3182 (diff)
downloadFreeBSD-src-9c3c6fdae0b43f1bbd5486754c20e403fc83c3b6.zip
FreeBSD-src-9c3c6fdae0b43f1bbd5486754c20e403fc83c3b6.tar.gz
MFH@261240.
Diffstat (limited to 'lib/libfetch/http.c')
-rw-r--r--lib/libfetch/http.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c
index 87535f0..fc43a97 100644
--- a/lib/libfetch/http.c
+++ b/lib/libfetch/http.c
@@ -208,6 +208,7 @@ static int
http_fillbuf(struct httpio *io, size_t len)
{
ssize_t nbytes;
+ char ch;
if (io->error)
return (-1);
@@ -249,10 +250,8 @@ http_fillbuf(struct httpio *io, size_t len)
io->chunksize -= io->buflen;
if (io->chunksize == 0) {
- char endl[2];
-
- if (fetch_read(io->conn, endl, 2) != 2 ||
- endl[0] != '\r' || endl[1] != '\n')
+ if (fetch_read(io->conn, &ch, 1) != 1 || ch != '\r' ||
+ fetch_read(io->conn, &ch, 1) != 1 || ch != '\n')
return (-1);
}
@@ -268,31 +267,28 @@ static int
http_readfn(void *v, char *buf, int len)
{
struct httpio *io = (struct httpio *)v;
- int l, pos;
+ int rlen;
if (io->error)
return (-1);
if (io->eof)
return (0);
- for (pos = 0; len > 0; pos += l, len -= l) {
- /* empty buffer */
- if (!io->buf || io->bufpos == io->buflen)
- if (http_fillbuf(io, len) < 1)
- break;
- l = io->buflen - io->bufpos;
- if (len < l)
- l = len;
- memcpy(buf + pos, io->buf + io->bufpos, l);
- io->bufpos += l;
+ /* empty buffer */
+ if (!io->buf || io->bufpos == io->buflen) {
+ if (http_fillbuf(io, len) < 1) {
+ if (io->error == EINTR)
+ io->error = 0;
+ return (-1);
+ }
}
- if (!pos && io->error) {
- if (io->error == EINTR)
- io->error = 0;
- return (-1);
- }
- return (pos);
+ rlen = io->buflen - io->bufpos;
+ if (len < rlen)
+ rlen = len;
+ memcpy(buf, io->buf + io->bufpos, rlen);
+ io->bufpos += rlen;
+ return (rlen);
}
/*
OpenPOWER on IntegriCloud