Commit Graph

6 Commits

Author SHA1 Message Date
Raphael S. Carvalho
971a3bb0b9 fstream: add file output stream support 2015-03-10 18:44:22 -03:00
Nadav Har'El
8b4117cc66 fstream: use temporary_buffer<char>::aligned
In fstream.cc, use the convenient new temporary_buffer<char>::aligned()
function for creating an aligned temporary buffer - instead of repeating
its implementation.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-10 17:25:42 +02:00
Nadav Har'El
7a04d1f662 fstream: refactor file input stream interface
The file_input_stream interface was messy: it was not fiber safe (e.g., code
doing seek() in the middle of an ongoing read_exactly()), and went against
the PIMPL philosophy.

So this patch removes the file_input_stream class, and replaces it with a
completely different design:

We now have in fstream.hh a global function:

input_stream<char>
make_file_input_stream(
        lw_shared_ptr<file> file, uint64_t offset = 0,
	uint64_t buffer_size = 8192);

In other words, instead of "seeking" in an input stream, we just open a new
input stream object at a particular offset of the given file. Multiple input
streams might be concurrently active on the same file.

Note how make_file_input_stream now returns a regular "input_stream", not a
subtype, and it can be used just like any normal input_stream to read the stream
starting at the given position.

This patch makes "input_stream" a "final" type: we no longer subclass it in our
code, and we shouldn't in the future because it goes against the PIMPL design
(the subclass should be of the inner workings, like the data_source_impl, not
of input_stream).

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
2015-03-10 15:39:17 +02:00
Avi Kivity
7f8d88371a Add LICENSE, NOTICE, and copyright headers to all source files.
The two files imported from the OSv project retain their original licenses.
2015-02-19 16:52:34 +02:00
Glauber Costa
861d2625b2 file_stream: proper seek support.
Our file_stream interface supports seek, but when we try to seek to arbitrary
locations that are smaller than an aio-boundary (say, for instance, f->seek(4)),
we will end up not being able to perform the read.

We need to guarantee the reads are aligned, and will then present to the caller
the buffer properly offset.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-02-18 22:56:07 +02:00
Avi Kivity
af0bf06836 core: add file_data_source, file_input_stream
Implement a character stream backed by a file.
2015-02-11 15:38:51 +02:00