diff options
-rw-r--r-- | src/main.c | 9 | ||||
-rw-r--r-- | src/stream.c | 62 | ||||
-rw-r--r-- | src/stream.h | 5 |
3 files changed, 71 insertions, 5 deletions
@@ -78,7 +78,8 @@ int main(int argc, char **argv) try_s((ret = cache_transfer(&file_tmp, &file_out)), out); } } else { /* uncached */ - /* TODO */ + bench(&file_in, &file_tmp); + file_transfer(&file_tmp, &file_out); } stream_close(&file_in); @@ -235,7 +236,11 @@ static int load_io_functions(struct settings const * const s, struct stream * co } } } else { - ret = ENOSYS; + if (s->format == array) { + in->get = file_get_array; + in->put = file_put_array; + in->copy = stream_copy_range; + } } return ret; diff --git a/src/stream.c b/src/stream.c index b7bc39e..da8d9c8 100644 --- a/src/stream.c +++ b/src/stream.c @@ -99,6 +99,56 @@ err: return ret; } +struct entry_l *file_get_array(struct stream * const in, struct entry_l * const store) +{ + struct entry ent; + struct entry_l *ret = NULL; + ssize_t bytes_read; + + if (in->index < in->n) { + do { + try(0 > (bytes_read = pread(in->fd, &ent, sizeof(ent), in->index * in->settings->stride)), err, NULL, "Writing to stream failed with %i", errno); + } while (bytes_read != sizeof(ent)); + + ++in->index; + store->val = ent.val; + ret = store; + } + +err: + return ret; +} + +int file_put_array(struct stream * const in, const struct entry_l * const data) +{ + int ret = 0; + ssize_t bytes_written; + + if (in->index < in->n) { + do { + try(0 > (bytes_written = pwrite(in->fd, data, sizeof(data->val), in->index * in->settings->stride)), err, errno, "Writing to stream failed with %i", ret); + } while (bytes_written != sizeof(data->val)); + ++in->index; + } + +err: + return ret; +} + +int file_transfer(struct stream * const src, struct stream * const dest) +{ + int ret = 0; + int tmp; + + /* just a simple switcheroo of file descriptors */ + + tmp = src->fd; + src->fd = dest->fd; + dest->fd = tmp; + + return ret; +} + /* generic, naïve and slow copy routine when an optimized one cannot be used */ int stream_copy_range(struct stream * const restrict src, struct stream * const restrict dest) { @@ -138,9 +188,15 @@ int stream_shallow_copy(struct stream const * const restrict src, struct stream dest->put = src->put; dest->copy = src->copy; - dest->type = src->settings->access == cached ? stream_cache : stream_lite; - - try_s((ret = cache_create(dest)), err); + if (src->settings->access == cached) { + dest->fd = -1; + dest->type = stream_lite; + try_s((ret = cache_create(dest)), err); + } else { + dest->name = src->name; + dest->type = stream_lite; + try_s((ret = stream_open_lite(dest)), err); + } err: return ret; diff --git a/src/stream.h b/src/stream.h index 6288d32..3617930 100644 --- a/src/stream.h +++ b/src/stream.h @@ -10,9 +10,14 @@ int stream_open(struct stream * const in); int stream_close(struct stream * const in); +/* uncached GET */ +struct entry_l *file_get_array(struct stream * const in, struct entry_l * const store); +/* uncached PUT */ +int file_put_array(struct stream * const in, const struct entry_l * const data); /* uncached blockmanip */ +int file_transfer(struct stream * const src, struct stream * const dest); int stream_copy_range(struct stream * const restrict src, struct stream * const restrict dest); /* misc */ |