MPD
0.20.15
|
A helper class which helps with reading from a file. More...
#include <FileReader.hxx>
Public Member Functions | |
NfsFileReader () | |
~NfsFileReader () | |
void | Close () |
void | DeferClose () |
void | Open (const char *uri) |
Open the file. More... | |
void | Read (uint64_t offset, size_t size) |
Attempt to read from the file. More... | |
void | CancelRead () |
Cancel the most recent Read() call. More... | |
bool | IsIdle () const |
Protected Member Functions | |
virtual void | OnNfsFileOpen (uint64_t size)=0 |
The file has been opened successfully. More... | |
virtual void | OnNfsFileRead (const void *data, size_t size)=0 |
A Read() has completed successfully. More... | |
virtual void | OnNfsFileError (std::exception_ptr &&e)=0 |
An error has occurred, which can be either while waiting for OnNfsFileOpen(), or while waiting for OnNfsFileRead(), or if disconnected while idle. More... | |
A helper class which helps with reading from a file.
It obtains a connection lease (NfsLease), opens the given file, "stats" the file, and finally allos you to read its contents.
To get started, derive your class from it and implement the pure virtual methods, construct an instance, and call Open().
Definition at line 46 of file FileReader.hxx.
NfsFileReader::NfsFileReader | ( | ) |
NfsFileReader::~NfsFileReader | ( | ) |
void NfsFileReader::CancelRead | ( | ) |
Cancel the most recent Read() call.
This method is not thread-safe and must be called from within the I/O thread.
void NfsFileReader::Close | ( | ) |
void NfsFileReader::DeferClose | ( | ) |
|
inline |
Definition at line 100 of file FileReader.hxx.
|
protectedpure virtual |
An error has occurred, which can be either while waiting for OnNfsFileOpen(), or while waiting for OnNfsFileRead(), or if disconnected while idle.
|
protectedpure virtual |
The file has been opened successfully.
It is a regular file, and its size is known. It is ready to be read from using Read().
This method will be called from within the I/O thread.
|
protectedpure virtual |
A Read() has completed successfully.
This method will be called from within the I/O thread.
void NfsFileReader::Open | ( | const char * | uri | ) |
Open the file.
This method is thread-safe.
Throws std::runtime_error on error.
void NfsFileReader::Read | ( | uint64_t | offset, |
size_t | size | ||
) |
Attempt to read from the file.
This may only be done after OnNfsFileOpen() has been called. Only one read operation may be performed at a time.
This method is not thread-safe and must be called from within the I/O thread.
Throws std::runtime_error on error.