0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::fs: Integrate read(iov) suite.

This commit is contained in:
Jason Volk 2018-11-28 17:26:25 -08:00
parent 466ad228b0
commit 44bf18d4df
2 changed files with 42 additions and 12 deletions

View file

@ -15,6 +15,10 @@ namespace ircd::fs
{
struct read_opts extern const read_opts_default;
// Yields ircd::ctx for read into buffers; returns bytes read
size_t read(const fd &, const mutable_buffers &, const read_opts & = read_opts_default);
size_t read(const string_view &path, const mutable_buffers &, const read_opts & = read_opts_default);
// Yields ircd::ctx for read into buffer; returns view of read portion.
const_buffer read(const fd &, const mutable_buffer &, const read_opts & = read_opts_default);
const_buffer read(const string_view &path, const mutable_buffer &, const read_opts & = read_opts_default);

View file

@ -549,6 +549,38 @@ ircd::const_buffer
ircd::fs::read(const string_view &path,
const mutable_buffer &buf,
const read_opts &opts)
{
const mutable_buffers bufs
{
&buf, 1
};
return mutable_buffer
{
data(buf), read(path, bufs, opts)
};
}
ircd::const_buffer
ircd::fs::read(const fd &fd,
const mutable_buffer &buf,
const read_opts &opts)
{
const mutable_buffers bufs
{
&buf, 1
};
return mutable_buffer
{
data(buf), read(fd, bufs, opts)
};
}
size_t
ircd::fs::read(const string_view &path,
const mutable_buffers &bufs,
const read_opts &opts)
try
{
const fd fd
@ -556,7 +588,7 @@ try
path
};
return read(fd, buf, opts);
return read(fd, bufs, opts);
}
catch(const error &e)
{
@ -574,25 +606,19 @@ catch(const std::exception &e)
};
}
ircd::const_buffer
size_t
ircd::fs::read(const fd &fd,
const mutable_buffer &buf,
const mutable_buffers &bufs,
const read_opts &opts)
try
{
#ifdef IRCD_USE_AIO
if(likely(aio::context))
return
{
data(buf), aio::read(fd, {&buf, 1}, opts)
};
return aio::read(fd, bufs, opts);
#endif
return
{
data(buf),
size_t(syscall(::pread, fd, data(buf), size(buf), opts.offset))
};
const auto iov(make_iov(bufs));
return size_t(syscall(::preadv, fd, iov.data(), iov.size(), opts.offset));
}
catch(const error &e)
{