uvw 3.1.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
uvw::file_req Class Referencefinal

The file request. More...

#include <fs.h>

Inheritance diagram for uvw::file_req:
Inheritance graph
[legend]
Collaboration diagram for uvw::file_req:
Collaboration graph
[legend]

Public Member Functions

void close ()
 Async close.
 
bool close_sync ()
 Sync close.
 
void open (const std::string &path, file_open_flags flags, int mode)
 Async open.
 
bool open_sync (const std::string &path, file_open_flags 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 > > read_sync (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 > write_sync (std::unique_ptr< char[]> buf, unsigned int len, int64_t offset)
 Sync write.
 
void stat ()
 Async fstat.
 
std::pair< bool, file_infostat_sync ()
 Sync fstat.
 
void sync ()
 Async fsync.
 
bool sync_sync ()
 Sync fsync.
 
void datasync ()
 Async fdatasync.
 
bool datasync_sync ()
 Sync fdatasync.
 
void truncate (int64_t offset)
 Async ftruncate.
 
bool truncate_sync (int64_t offset)
 Sync ftruncate.
 
void sendfile (file_handle out, int64_t offset, std::size_t length)
 Async sendfile.
 
std::pair< bool, std::size_t > sendfile_sync (file_handle out, int64_t offset, std::size_t length)
 Sync sendfile.
 
void chmod (int mode)
 Async fchmod.
 
bool chmod_sync (int mode)
 Sync fchmod.
 
void futime (time atime, time mtime)
 Async futime.
 
bool futime_sync (time atime, time mtime)
 Sync futime.
 
void chown (uid_type uid, gid_type gid)
 Async fchown.
 
bool chown_sync (uid_type uid, gid_type gid)
 Sync fchown.
 
 operator file_handle () const noexcept
 Cast operator to file_handle.
 
- Public Member Functions inherited from uvw::request< T, U, E >
int 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< T, U, E... >
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::uv_type< U >
virtual int init ()
 Initializes the handle.
 
loopparent () const noexcept
 Gets the loop from which the resource was originated.
 
const U * raw () const noexcept
 Gets the underlying raw data structure.
 
U * raw () noexcept
 Gets the underlying raw data structure.
 
- Public Member Functions inherited from uvw::emitter< T, E... >
void on (listener_t< U > f)
 Registers a long-lived listener with the event emitter.
 
void reset () noexcept
 Disconnects the listener for the given event type.
 
void reset () noexcept
 Disconnects all listeners.
 
bool has () const noexcept
 Checks if there is a listener registered for the specific event.
 

Detailed Description

The file request.

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

To create a file_req through a loop, no arguments are required.

See the official documentation for further details.

Definition at line 254 of file fs.h.

Member Function Documentation

◆ chmod()

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

Async fchmod.

Emit a fs_event event when completed.

Parameters
modeMode, as described in the official documentation.

◆ chmod_sync()

bool uvw::file_req::chmod_sync ( int  mode)

Sync fchmod.

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

◆ chown()

void uvw::file_req::chown ( uid_type  uid,
gid_type  gid 
)

Async fchown.

Emit a fs_event event when completed.

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

◆ chown_sync()

bool uvw::file_req::chown_sync ( uid_type  uid,
gid_type  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::file_req::close ( )

Async close.

Emit a fs_event event when completed.

◆ close_sync()

bool uvw::file_req::close_sync ( )

Sync close.

Returns
True in case of success, false otherwise.

◆ datasync()

void uvw::file_req::datasync ( )

Async fdatasync.

Emit a fs_event event when completed.

◆ datasync_sync()

bool uvw::file_req::datasync_sync ( )

Sync fdatasync.

Returns
True in case of success, false otherwise.

◆ futime()

void uvw::file_req::futime ( time  atime,
time  mtime 
)

Async futime.

Emit a fs_event event when completed.

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.

◆ futime_sync()

bool uvw::file_req::futime_sync ( 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::file_req::open ( const std::string &  path,
file_open_flags  flags,
int  mode 
)

Async open.

Emit a fs_event event when completed.

Available flags are:

  • file_req::file_open_flags::APPEND
  • file_req::file_open_flags::CREAT
  • file_req::file_open_flags::DIRECT
  • file_req::file_open_flags::DIRECTORY
  • file_req::file_open_flags::DSYNC
  • file_req::file_open_flags::EXCL
  • file_req::file_open_flags::EXLOCK
  • file_req::file_open_flags::FILEMAP
  • file_req::file_open_flags::NOATIME
  • file_req::file_open_flags::NOCTTY
  • file_req::file_open_flags::NOFOLLOW
  • file_req::file_open_flags::NONBLOCK
  • file_req::file_open_flags::RANDOM
  • file_req::file_open_flags::RDONLY
  • file_req::file_open_flags::RDWR
  • file_req::file_open_flags::SEQUENTIAL
  • file_req::file_open_flags::SHORT_LIVED
  • file_req::file_open_flags::SYMLINK
  • file_req::file_open_flags::SYNC
  • file_req::file_open_flags::TEMPORARY
  • file_req::file_open_flags::TRUNC
  • file_req::file_open_flags::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.

◆ open_sync()

bool uvw::file_req::open_sync ( const std::string &  path,
file_open_flags  flags,
int  mode 
)

Sync open.

Available flags are:

  • file_req::file_open_flags::APPEND
  • file_req::file_open_flags::CREAT
  • file_req::file_open_flags::DIRECT
  • file_req::file_open_flags::DIRECTORY
  • file_req::file_open_flags::DSYNC
  • file_req::file_open_flags::EXCL
  • file_req::file_open_flags::EXLOCK
  • file_req::file_open_flags::FILEMAP
  • file_req::file_open_flags::NOATIME
  • file_req::file_open_flags::NOCTTY
  • file_req::file_open_flags::NOFOLLOW
  • file_req::file_open_flags::NONBLOCK
  • file_req::file_open_flags::RANDOM
  • file_req::file_open_flags::RDONLY
  • file_req::file_open_flags::RDWR
  • file_req::file_open_flags::SEQUENTIAL
  • file_req::file_open_flags::SHORT_LIVED
  • file_req::file_open_flags::SYMLINK
  • file_req::file_open_flags::SYNC
  • file_req::file_open_flags::TEMPORARY
  • file_req::file_open_flags::TRUNC
  • file_req::file_open_flags::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 file_handle()

uvw::file_req::operator file_handle ( ) const
noexcept

Cast operator to file_handle.

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

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

◆ read()

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

Async read.

Emit a fs_event event when completed.

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

◆ read_sync()

std::pair< bool, std::pair< std::unique_ptr< const char[]>, std::size_t > > uvw::file_req::read_sync ( 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::file_req::sendfile ( file_handle  out,
int64_t  offset,
std::size_t  length 
)

Async sendfile.

Emit a fs_event event when completed.

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

◆ sendfile_sync()

std::pair< bool, std::size_t > uvw::file_req::sendfile_sync ( file_handle  out,
int64_t  offset,
std::size_t  length 
)

Sync sendfile.

Parameters
outA valid instance of file_handle.
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::file_req::stat ( )

Async fstat.

Emit a fs_event event when completed.

◆ stat_sync()

std::pair< bool, file_info > uvw::file_req::stat_sync ( )

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 file_info.

◆ sync()

void uvw::file_req::sync ( )

Async fsync.

Emit a fs_event event when completed.

◆ sync_sync()

bool uvw::file_req::sync_sync ( )

Sync fsync.

Returns
True in case of success, false otherwise.

◆ truncate()

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

Async ftruncate.

Emit a fs_event event when completed.

Parameters
offsetOffset, as described in the official documentation.

◆ truncate_sync()

bool uvw::file_req::truncate_sync ( 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::file_req::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 fs_event event when completed.

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

◆ write() [2/2]

void uvw::file_req::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 fs_event event when completed.

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

◆ write_sync()

std::pair< bool, std::size_t > uvw::file_req::write_sync ( 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: