From: Michael Vrable Date: Fri, 21 Jan 2011 01:55:31 +0000 (-0800) Subject: Enable range requests in the simple storage backend X-Git-Url: https://git.vrable.net/?a=commitdiff_plain;h=b9f7906b9eee10ea9e7eef3b4ff943319d5cf5d6;p=bluesky.git Enable range requests in the simple storage backend --- diff --git a/bluesky/store-simple.c b/bluesky/store-simple.c index 25eef53..a66053e 100644 --- a/bluesky/store-simple.c +++ b/bluesky/store-simple.c @@ -157,6 +157,7 @@ static void simplestore_task(gpointer a, gpointer b) async->data = bluesky_string_new(data, result); async->result = 0; + async->range_done = TRUE; break; } diff --git a/filestore/server.c b/filestore/server.c index 6bdc60f..0e2ed4b 100644 --- a/filestore/server.c +++ b/filestore/server.c @@ -136,12 +136,24 @@ void cmd_get(int fd, char *path, size_t start, ssize_t len) return; } - size_t filelen = statbuf.st_size; - sprintf(buf, "%zd\n", filelen); + size_t datalen = statbuf.st_size; + if (start > 0) { + if (start >= datalen) { + datalen = 0; + } else { + lseek(file, start, SEEK_SET); + datalen -= start; + } + } + if (len > 0 && len < datalen) { + datalen = len; + } + + sprintf(buf, "%zd\n", datalen); write_data(fd, buf, strlen(buf)); - while (filelen > 0) { - size_t needed = filelen > sizeof(buf) ? sizeof(buf) : filelen; + while (datalen > 0) { + size_t needed = datalen > sizeof(buf) ? sizeof(buf) : datalen; ssize_t bytes = read(file, buf, needed); if (bytes < 0 && errno == EINTR) continue; @@ -152,7 +164,7 @@ void cmd_get(int fd, char *path, size_t start, ssize_t len) bytes = needed; } write_data(fd, buf, bytes); - filelen -= bytes; + datalen -= bytes; } close(file);