uvw 2.12.1
Loading...
Searching...
No Matches
uvw::FileReq Class Referencefinal

The FileReq request. More...

#include <fs.h>

Inheritance diagram for uvw::FileReq:
Collaboration diagram for uvw::FileReq:

Public Member Functions

void close ()
 Async close.
 
bool closeSync ()
 Sync close.
 
void open (const std::string &path, Flags< FileOpen > flags, int mode)
 Async open.
 
bool openSync (const std::string &path, Flags< FileOpen > flags, int mode)
 Sync open.
 
void read (int64_t offset, unsigned int len)
 Async read.
 
std::pair< bool, std::pair< std::unique_ptr< const char[]>, std::size_t > > readSync (int64_t offset, unsigned int len)
 Sync read.
 
void write (std::unique_ptr< char[]> buf, unsigned int len, int64_t offset)
 Async write.
 
void write (char *buf, unsigned int len, int64_t offset)
 Async write.
 
std::pair< bool, std::size_t > writeSync (std::unique_ptr< char[]> buf, unsigned int len, int64_t offset)
 Sync write.
 
void stat ()
 Async fstat.
 
std::pair< bool, StatstatSync ()
 Sync fstat.
 
void sync ()
 Async fsync.
 
bool syncSync ()
 Sync fsync.
 
void datasync ()
 Async fdatasync.
 
bool datasyncSync ()
 Sync fdatasync.
 
void truncate (int64_t offset)
 Async ftruncate.
 
bool truncateSync (int64_t offset)
 Sync ftruncate.
 
void sendfile (FileHandle out, int64_t offset, std::size_t length)
 Async sendfile.
 
std::pair< bool, std::size_t > sendfileSync (FileHandle out, int64_t offset, std::size_t length)
 Sync sendfile.
 
void chmod (int mode)
 Async fchmod.
 
bool chmodSync (int mode)
 Sync fchmod.
 
void futime (Time atime, Time mtime)
 Async futime.
 
bool futimeSync (Time atime, Time mtime)
 Sync futime.
 
void chown (Uid uid, Gid gid)
 Async fchown.
 
bool chownSync (Uid uid, Gid gid)
 Sync fchown.
 
 operator FileHandle () const noexcept
 Cast operator to FileHandle.
 
- Public Member Functions inherited from uvw::Request< FileReq, uv_fs_t >
bool cancel ()
 Cancels a pending request.
 
std::size_t size () const noexcept
 Returns the size of the underlying request type.
 
- Public Member Functions inherited from uvw::Resource< FileReq, uv_fs_t >
std::shared_ptr< R > data () const
 Gets user-defined data. uvw won't use this field in any case.
 
void data (std::shared_ptr< void > uData)
 Sets arbitrary data. uvw won't use this field in any case.
 
- Public Member Functions inherited from uvw::UnderlyingType< FileReq, uv_fs_t >
Looploop () const noexcept
 Gets the loop from which the resource was originated.
 
const uv_fs_t * raw () const noexcept
 Gets the underlying raw data structure.
 
uv_fs_t * raw () noexcept
 Gets the underlying raw data structure.
 
- Public Member Functions inherited from uvw::Emitter< FileReq >
Connection< E > on (Listener< E > f)
 Registers a long-lived listener with the event emitter.
 
Connection< E > once (Listener< E > f)
 Registers a short-lived listener with the event emitter.
 
void erase (Connection< E > conn) noexcept
 Disconnects a listener from the event emitter.
 
void clear () noexcept
 Disconnects all the listeners for the given event type.
 
void clear () noexcept
 Disconnects all the listeners.
 
bool empty () const noexcept
 Checks if there are listeners registered for the specific event.
 
bool empty () const noexcept
 Checks if there are listeners registered with the event emitter.
 

Additional Inherited Members

- Public Types inherited from uvw::FsRequest< FileReq >
- Public Types inherited from uvw::Emitter< FileReq >
- Static Public Member Functions inherited from uvw::UnderlyingType< FileReq, uv_fs_t >
static std::shared_ptr< FileReqcreate (Args &&...args)
 Creates a new resource of the given type.
 
- Protected Types inherited from uvw::Resource< FileReq, uv_fs_t >
- Protected Member Functions inherited from uvw::FsRequest< FileReq >
- Protected Member Functions inherited from uvw::Request< FileReq, uv_fs_t >
- Protected Member Functions inherited from uvw::Resource< FileReq, uv_fs_t >
- Protected Member Functions inherited from uvw::UnderlyingType< FileReq, uv_fs_t >
- Protected Member Functions inherited from uvw::Emitter< FileReq >
- Static Protected Member Functions inherited from uvw::FsRequest< FileReq >
- Static Protected Member Functions inherited from uvw::Request< FileReq, uv_fs_t >

Detailed Description

The FileReq request.

Cross-platform sync and async filesystem operations.
All file operations are run on the threadpool.

To create a FileReq through a Loop, no arguments are required.

See the official documentation for further details.

Definition at line 411 of file fs.h.

Member Function Documentation

◆ chmod()

void uvw::FileReq::chmod ( int mode)

Async fchmod.

Emit a FsEvent<FileReq::Type::FCHMOD> event when completed.
Emit an ErrorEvent event in case of errors.

Parameters
modeMode, as described in the official documentation.

◆ chmodSync()

bool uvw::FileReq::chmodSync ( int mode)

Sync fchmod.

Parameters
modeMode, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ chown()

void uvw::FileReq::chown ( Uid uid,
Gid gid )

Async fchown.

Emit a FsEvent<FileReq::Type::FCHOWN> event when completed.
Emit an ErrorEvent event in case of errors.

Parameters
uidUID, as described in the official documentation.
gidGID, as described in the official documentation.

◆ chownSync()

bool uvw::FileReq::chownSync ( Uid uid,
Gid gid )

Sync fchown.

Parameters
uidUID, as described in the official documentation.
gidGID, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ close()

void uvw::FileReq::close ( )

Async close.

Emit a FsEvent<FileReq::Type::CLOSE> event when completed.
Emit an ErrorEvent event in case of errors.

◆ closeSync()

bool uvw::FileReq::closeSync ( )

Sync close.

Returns
True in case of success, false otherwise.

◆ datasync()

void uvw::FileReq::datasync ( )

Async fdatasync.

Emit a FsEvent<FileReq::Type::FDATASYNC> event when completed.
Emit an ErrorEvent event in case of errors.

◆ datasyncSync()

bool uvw::FileReq::datasyncSync ( )

Sync fdatasync.

Returns
True in case of success, false otherwise.

◆ futime()

void uvw::FileReq::futime ( Time atime,
Time mtime )

Async futime.

Emit a FsEvent<FileReq::Type::FUTIME> event when completed.
Emit an ErrorEvent event in case of errors.

Parameters
atimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
mtimestd::chrono::duration<double>, having the same meaning as described in the official documentation.

◆ futimeSync()

bool uvw::FileReq::futimeSync ( Time atime,
Time mtime )

Sync futime.

Parameters
atimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
mtimestd::chrono::duration<double>, having the same meaning as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ open()

void uvw::FileReq::open ( const std::string & path,
Flags< FileOpen > flags,
int mode )

Async open.

Emit a FsEvent<FileReq::Type::OPEN> event when completed.
Emit an ErrorEvent event in case of errors.

Available flags are:

  • FileReq::FileOpen::APPEND
  • FileReq::FileOpen::CREAT
  • FileReq::FileOpen::DIRECT
  • FileReq::FileOpen::DIRECTORY
  • FileReq::FileOpen::DSYNC
  • FileReq::FileOpen::EXCL
  • FileReq::FileOpen::EXLOCK
  • FileReq::FileOpen::FILEMAP
  • FileReq::FileOpen::NOATIME
  • FileReq::FileOpen::NOCTTY
  • FileReq::FileOpen::NOFOLLOW
  • FileReq::FileOpen::NONBLOCK
  • FileReq::FileOpen::RANDOM
  • FileReq::FileOpen::RDONLY
  • FileReq::FileOpen::RDWR
  • FileReq::FileOpen::SEQUENTIAL
  • FileReq::FileOpen::SHORT_LIVED
  • FileReq::FileOpen::SYMLINK
  • FileReq::FileOpen::SYNC
  • FileReq::FileOpen::TEMPORARY
  • FileReq::FileOpen::TRUNC
  • FileReq::FileOpen::WRONLY

See the official documentation for further details.

Parameters
pathA valid path name for a file.
flagsFlags made out of underlying constants.
modeMode, as described in the official documentation.

◆ openSync()

bool uvw::FileReq::openSync ( const std::string & path,
Flags< FileOpen > flags,
int mode )

Sync open.

Available flags are:

  • FileReq::FileOpen::APPEND
  • FileReq::FileOpen::CREAT
  • FileReq::FileOpen::DIRECT
  • FileReq::FileOpen::DIRECTORY
  • FileReq::FileOpen::DSYNC
  • FileReq::FileOpen::EXCL
  • FileReq::FileOpen::EXLOCK
  • FileReq::FileOpen::FILEMAP
  • FileReq::FileOpen::NOATIME
  • FileReq::FileOpen::NOCTTY
  • FileReq::FileOpen::NOFOLLOW
  • FileReq::FileOpen::NONBLOCK
  • FileReq::FileOpen::RANDOM
  • FileReq::FileOpen::RDONLY
  • FileReq::FileOpen::RDWR
  • FileReq::FileOpen::SEQUENTIAL
  • FileReq::FileOpen::SHORT_LIVED
  • FileReq::FileOpen::SYMLINK
  • FileReq::FileOpen::SYNC
  • FileReq::FileOpen::TEMPORARY
  • FileReq::FileOpen::TRUNC
  • FileReq::FileOpen::WRONLY

See the official documentation for further details.

Parameters
pathA valid path name for a file.
flagsFlags made out of underlying constants.
modeMode, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ operator FileHandle()

uvw::FileReq::operator FileHandle ( ) const
noexcept

Cast operator to FileHandle.

Cast operator to an internal representation of the underlying file handle.

Returns
A valid instance of FileHandle (the descriptor can be invalid).

◆ read()

void uvw::FileReq::read ( int64_t offset,
unsigned int len )

Async read.

Emit a FsEvent<FileReq::Type::READ> event when completed.
Emit an ErrorEvent event in case of errors.

Parameters
offsetOffset, as described in the official documentation.
lenLength, as described in the official documentation.

◆ readSync()

std::pair< bool, std::pair< std::unique_ptr< const char[]>, std::size_t > > uvw::FileReq::readSync ( int64_t offset,
unsigned int len )

Sync read.

Parameters
offsetOffset, as described in the official documentation.
lenLength, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • A std::pair composed as it follows:
    • A bunch of data read from the given path.
    • The amount of data read from the given path.

◆ sendfile()

void uvw::FileReq::sendfile ( FileHandle out,
int64_t offset,
std::size_t length )

Async sendfile.

Emit a FsEvent<FileReq::Type::SENDFILE> event when completed.
Emit an ErrorEvent event in case of errors.

Parameters
outA valid instance of FileHandle.
offsetOffset, as described in the official documentation.
lengthLength, as described in the official documentation.

◆ sendfileSync()

std::pair< bool, std::size_t > uvw::FileReq::sendfileSync ( FileHandle out,
int64_t offset,
std::size_t length )

Sync sendfile.

Parameters
outA valid instance of FileHandle.
offsetOffset, as described in the official documentation.
lengthLength, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • The amount of data transferred.

◆ stat()

void uvw::FileReq::stat ( )

Async fstat.

Emit a FsEvent<FileReq::Type::FSTAT> event when completed.
Emit an ErrorEvent event in case of errors.

◆ statSync()

std::pair< bool, Stat > uvw::FileReq::statSync ( )

Sync fstat.

Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • An initialized instance of Stat.

◆ sync()

void uvw::FileReq::sync ( )

Async fsync.

Emit a FsEvent<FileReq::Type::FSYNC> event when completed.
Emit an ErrorEvent event in case of errors.

◆ syncSync()

bool uvw::FileReq::syncSync ( )

Sync fsync.

Returns
True in case of success, false otherwise.

◆ truncate()

void uvw::FileReq::truncate ( int64_t offset)

Async ftruncate.

Emit a FsEvent<FileReq::Type::FTRUNCATE> event when completed.
Emit an ErrorEvent event in case of errors.

Parameters
offsetOffset, as described in the official documentation.

◆ truncateSync()

bool uvw::FileReq::truncateSync ( int64_t offset)

Sync ftruncate.

Parameters
offsetOffset, as described in the official documentation.
Returns
True in case of success, false otherwise.

◆ write() [1/2]

void uvw::FileReq::write ( char * buf,
unsigned int len,
int64_t offset )

Async write.

The request doesn't take the ownership of the data. Be sure that their lifetime overcome the one of the request.

Emit a FsEvent<FileReq::Type::WRITE> event when completed.
Emit an ErrorEvent event in case of errors.

Parameters
bufThe data to be written.
lenThe lenght of the submitted data.
offsetOffset, as described in the official documentation.

◆ write() [2/2]

void uvw::FileReq::write ( std::unique_ptr< char[]> buf,
unsigned int len,
int64_t offset )

Async write.

The request takes the ownership of the data and it is in charge of delete them.

Emit a FsEvent<FileReq::Type::WRITE> event when completed.
Emit an ErrorEvent event in case of errors.

Parameters
bufThe data to be written.
lenThe lenght of the submitted data.
offsetOffset, as described in the official documentation.

◆ writeSync()

std::pair< bool, std::size_t > uvw::FileReq::writeSync ( std::unique_ptr< char[]> buf,
unsigned int len,
int64_t offset )

Sync write.

Parameters
bufThe data to be written.
lenThe lenght of the submitted data.
offsetOffset, as described in the official documentation.
Returns
A std::pair composed as it follows:
  • A boolean value that is true in case of success, false otherwise.
  • The amount of data written to the given path.

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