summaryrefslogtreecommitdiff
path: root/src/url.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2020-01-10 11:02:48 +0200
committerTimo Teräs <timo.teras@iki.fi>2020-01-11 03:44:23 +0200
commit7ca0d146ecaf2f99781653d1203bd3db7afc85ba (patch)
tree0b167bd627a174be8e0d24f2af0f3697904ad5de /src/url.c
parent9dda2d3c21d1116077257caafa065b659ffe419b (diff)
downloadapk-tools-7ca0d146ecaf2f99781653d1203bd3db7afc85ba.tar.gz
apk-tools-7ca0d146ecaf2f99781653d1203bd3db7afc85ba.tar.bz2
apk-tools-7ca0d146ecaf2f99781653d1203bd3db7afc85ba.tar.xz
apk-tools-7ca0d146ecaf2f99781653d1203bd3db7afc85ba.zip
istream: add buffering capability
Convert all implementations to do buffering. This is in preparation to remove bstream interface as redundant. istream_read() will return full reads unless end-of-file. The backends can return short reads to optimize buffering or due to other reasons like boundary change for gz.
Diffstat (limited to 'src/url.c')
-rw-r--r--src/url.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/url.c b/src/url.c
index cacca81..d233e06 100644
--- a/src/url.c
+++ b/src/url.c
@@ -80,18 +80,11 @@ static void fetch_get_meta(struct apk_istream *is, struct apk_file_meta *meta)
static ssize_t fetch_read(struct apk_istream *is, void *ptr, size_t size)
{
struct apk_fetch_istream *fis = container_of(is, struct apk_fetch_istream, is);
- ssize_t i = 0, r;
+ ssize_t r;
- if (ptr == NULL) return apk_istream_skip(&fis->is, size);
-
- while (i < size) {
- r = fetchIO_read(fis->fetchIO, ptr + i, size - i);
- if (r < 0) return -EIO;
- if (r == 0) break;
- i += r;
- }
-
- return i;
+ r = fetchIO_read(fis->fetchIO, ptr, size);
+ if (r < 0) return -EIO;
+ return r;
}
static void fetch_close(struct apk_istream *is)
@@ -120,7 +113,7 @@ static struct apk_istream *apk_istream_fetch(const char *url, time_t since)
rc = -EAPKBADURL;
goto err;
}
- fis = malloc(sizeof(*fis));
+ fis = malloc(sizeof *fis + apk_io_bufsize);
if (!fis) {
rc = -ENOMEM;
goto err;
@@ -135,6 +128,8 @@ static struct apk_istream *apk_istream_fetch(const char *url, time_t since)
*fis = (struct apk_fetch_istream) {
.is.ops = &fetch_istream_ops,
+ .is.buf = (uint8_t*)(fis+1),
+ .is.buf_size = apk_io_bufsize,
.fetchIO = io,
.urlstat = fis->urlstat,
};