URING++
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
uringpp::file Class Reference

An opened file. More...

#include <uringpp/file.h>

Inheritance diagram for uringpp::file:
Inheritance graph
[legend]
Collaboration diagram for uringpp::file:
Collaboration graph
[legend]

Public Member Functions

int fd () const
 Get the file descriptor of the file. More...
 
 file (file &&other) noexcept
 Move construct a new file object. More...
 
 file (std::shared_ptr< event_loop > loop, int fd)
 Construct a new file object using the given event loop and file descriptor. The fd will be closed when the file object is destroyed. More...
 
task< void > close ()
 Close the file. More...
 
 ~file ()
 Destroy the file object. If the fd is still open, it will be closed. More...
 
sqe_awaitable read (void *buf, size_t count, off_t offset=0)
 Read data from the file. More...
 
sqe_awaitable write (void const *buf, size_t count, off_t offset=0)
 Write data to the file. More...
 
sqe_awaitable readv (struct iovec const *iov, int iovcnt, off_t offset=0)
 Vectorized read from the file. More...
 
sqe_awaitable writev (struct iovec const *iov, int iovcnt, off_t offset=0)
 Vectorized write to the file. More...
 
sqe_awaitable read_fixed (void *buf, size_t count, off_t offset, int buf_index)
 Read data to a preregistered buffer from the file. More...
 
sqe_awaitable write_fixed (void const *buf, size_t count, off_t offset, int buf_index)
 Write data from a preregistered buffer to the file. More...
 
sqe_awaitable fsync (int flags)
 Asynchronously flush the file. More...
 
sqe_awaitable sync_file_range (off_t offset, off_t nbytes, unsigned sync_range_flags)
 Asynchronously flush a range of the file. More...
 
sqe_awaitable tee (file const &out, size_t count, unsigned int flags)
 Tee data from the file to another file. More...
 
sqe_awaitable tee (socket const &out, size_t count, unsigned int flags)
 Tee data from the file to a socket. More...
 
sqe_awaitable splice_to (loff_t off_in, size_t nbytes, pipe const &out, unsigned flags)
 Splice data from the file to a pipe. More...
 
sqe_awaitable splice_from (pipe const &in, loff_t off_out, size_t nbytes, unsigned flags)
 Splice data from a pipe to the file. More...
 
- Public Member Functions inherited from uringpp::noncopyable
 noncopyable (noncopyable &&)=default
 
 noncopyable (noncopyable const &)=delete
 
noncopyableoperator= (noncopyable const &)=delete
 
noncopyableoperator= (noncopyable &&)=default
 

Static Public Member Functions

static task< fileopen (std::shared_ptr< event_loop > loop, char const *path, int flags, mode_t mode)
 Opens a file in the current working directory. More...
 
static task< fileopenat (std::shared_ptr< event_loop > loop, dir const &dir, char const *path, int flags, mode_t mode)
 Open a file in the given directory. More...
 
static task< fileopenat2 (std::shared_ptr< event_loop > loop, dir const &dir, char const *path, struct open_how *how)
 Open a file in the given directory. More...
 

Protected Attributes

std::shared_ptr< event_looploop_
 
int fd_
 

Detailed Description

An opened file.

Constructor & Destructor Documentation

◆ file() [1/2]

uringpp::file::file ( file &&  other)
inlinenoexcept

Move construct a new file object.

Parameters
otherThe file object to move from.

◆ file() [2/2]

uringpp::file::file ( std::shared_ptr< event_loop loop,
int  fd 
)
inline

Construct a new file object using the given event loop and file descriptor. The fd will be closed when the file object is destroyed.

Parameters
loopThe event loop.
fdThe file descriptor.

◆ ~file()

uringpp::file::~file ( )
inline

Destroy the file object. If the fd is still open, it will be closed.

Member Function Documentation

◆ close()

task< void > uringpp::file::close ( )
inline

Close the file.

Returns
task<void>

◆ fd()

int uringpp::file::fd ( ) const
inline

Get the file descriptor of the file.

Returns
int The file descriptor of the file.

◆ fsync()

sqe_awaitable uringpp::file::fsync ( int  flags)
inline

Asynchronously flush the file.

Parameters
flagsThe flags to use when flushing the file.
Returns
sqe_awaitable

◆ open()

static task< file > uringpp::file::open ( std::shared_ptr< event_loop loop,
char const *  path,
int  flags,
mode_t  mode 
)
inlinestatic

Opens a file in the current working directory.

Parameters
loopThe event loop.
pathThe path to the file.
flagsThe flags to use when opening the file.
modeThe mode to use when opening the file.
Returns
task<file> The file object.
Examples
helloworld.cc.

◆ openat()

static task< file > uringpp::file::openat ( std::shared_ptr< event_loop loop,
dir const &  dir,
char const *  path,
int  flags,
mode_t  mode 
)
inlinestatic

Open a file in the given directory.

Parameters
loopThe event loop.
dirThe directory to open the file in.
pathThe path to the file.
flagsThe flags to use when opening the file.
modeThe mode to use when opening the file.
Returns
task<file> The file object.

◆ openat2()

static task< file > uringpp::file::openat2 ( std::shared_ptr< event_loop loop,
dir const &  dir,
char const *  path,
struct open_how *  how 
)
inlinestatic

Open a file in the given directory.

Parameters
loopThe event loop.
dirThe directory to open the file in.
pathThe path to the file.
howThe open_how struct to use when opening the file.
Returns
task<file>

◆ read()

sqe_awaitable uringpp::file::read ( void *  buf,
size_t  count,
off_t  offset = 0 
)
inline

Read data from the file.

Parameters
bufThe buffer to read into.
countThe number of bytes to read.
offsetThe offset to start reading from.
Returns
sqe_awaitable

◆ read_fixed()

sqe_awaitable uringpp::file::read_fixed ( void *  buf,
size_t  count,
off_t  offset,
int  buf_index 
)
inline

Read data to a preregistered buffer from the file.

Parameters
bufThe preregistered buffer to read into.
countThe number of bytes to read.
offsetThe offset to start reading from.
buf_indexThe index of the preregistered buffer to read into.
Returns
sqe_awaitable

◆ readv()

sqe_awaitable uringpp::file::readv ( struct iovec const *  iov,
int  iovcnt,
off_t  offset = 0 
)
inline

Vectorized read from the file.

Parameters
iovThe iovec to read into.
iovcntThe number of iovecs to read.
offsetThe offset to start reading from.
Returns
sqe_awaitable

◆ splice_from()

sqe_awaitable uringpp::file::splice_from ( pipe const &  in,
loff_t  off_out,
size_t  nbytes,
unsigned  flags 
)
inline

Splice data from a pipe to the file.

Parameters
off_outThe offset to start splicing to.
inThe pipe to splice data from.
nbytesThe number of bytes to splice.
flagsThe flags to use when splicing the data.
Returns
sqe_awaitable

◆ splice_to()

sqe_awaitable uringpp::file::splice_to ( loff_t  off_in,
size_t  nbytes,
pipe const &  out,
unsigned  flags 
)
inline

Splice data from the file to a pipe.

Parameters
off_inThe offset to start splicing from.
nbytesThe number of bytes to splice.
outThe pipe to splice data to.
flagsThe flags to use when splicing the data.
Returns
sqe_awaitable

◆ sync_file_range()

sqe_awaitable uringpp::file::sync_file_range ( off_t  offset,
off_t  nbytes,
unsigned  sync_range_flags 
)
inline

Asynchronously flush a range of the file.

Parameters
offsetThe offset to start flushing from.
nbytesThe number of bytes to flush.
sync_range_flagsThe flags to use when flushing the file.
Returns
sqe_awaitable

◆ tee() [1/2]

sqe_awaitable uringpp::file::tee ( file const &  out,
size_t  count,
unsigned int  flags 
)
inline

Tee data from the file to another file.

Parameters
outThe file to tee data to.
countThe number of bytes to tee.
flagsThe flags to use when teeing the data.
Returns
sqe_awaitable

◆ tee() [2/2]

sqe_awaitable uringpp::file::tee ( socket const &  out,
size_t  count,
unsigned int  flags 
)
inline

Tee data from the file to a socket.

Parameters
outThe socket to tee data to.
countThe number of bytes to tee.
flagsThe flags to use when teeing the data.
Returns
sqe_awaitable

◆ write()

sqe_awaitable uringpp::file::write ( void const *  buf,
size_t  count,
off_t  offset = 0 
)
inline

Write data to the file.

Parameters
bufThe buffer to write from.
countThe number of bytes to write.
offsetThe offset to start writing from.
Returns
sqe_awaitable

◆ write_fixed()

sqe_awaitable uringpp::file::write_fixed ( void const *  buf,
size_t  count,
off_t  offset,
int  buf_index 
)
inline

Write data from a preregistered buffer to the file.

Parameters
bufThe preregistered buffer to write from.
countThe number of bytes to write.
offsetThe offset to start writing from.
buf_indexThe index of the preregistered buffer to write from.
Returns
sqe_awaitable

◆ writev()

sqe_awaitable uringpp::file::writev ( struct iovec const *  iov,
int  iovcnt,
off_t  offset = 0 
)
inline

Vectorized write to the file.

Parameters
iovThe iovec to write from.
iovcntThe number of iovecs to write.
offsetThe offset to start writing from.
Returns
sqe_awaitable

The documentation for this class was generated from the following file: