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:
parent
466ad228b0
commit
44bf18d4df
|
@ -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);
|
||||
|
|
50
ircd/fs.cc
50
ircd/fs.cc
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue