MPD: NfsFileReader Class Reference

MPD 0.20.15

Public Member Functions | Protected Member Functions
NfsFileReader Class Referenceabstract

A helper class which helps with reading from a file. More...

`#include <FileReader.hxx>`

Inheritance diagram for NfsFileReader:
[legend]
Collaboration diagram for NfsFileReader:
[legend]

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

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ NfsFileReader()

NfsFileReader::NfsFileReader | ( |  | ) |

## ◆ ~NfsFileReader()

NfsFileReader::~NfsFileReader | ( |  | ) |

## Member Function Documentation

## ◆ CancelRead()

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.

## ◆ Close()

void NfsFileReader::Close | ( |  | ) |

## ◆ DeferClose()

void NfsFileReader::DeferClose | ( |  | ) |

## ◆ IsIdle()

bool NfsFileReader::IsIdle | ( |  | ) | const
| inline

Definition at line 100 of file FileReader.hxx.

## ◆ OnNfsFileError()

virtual void NfsFileReader::OnNfsFileError | ( | std::exception_ptr && | e | ) |
| protectedpure virtual

An error has occurred, which can be either while waiting for OnNfsFileOpen(), or while waiting for OnNfsFileRead(), or if disconnected while idle.

## ◆ OnNfsFileOpen()

virtual void NfsFileReader::OnNfsFileOpen | ( | uint64_t | size | ) |
| 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.

## ◆ OnNfsFileRead()

virtual void NfsFileReader::OnNfsFileRead | ( | const void * | data,
|  | size_t | size
| ) |  |
| protectedpure virtual

A Read() has completed successfully.

This method will be called from within the I/O thread.

## ◆ Open()

void NfsFileReader::Open | ( | const char * | uri | ) |

Open the file.

This method is thread-safe.

Throws std::runtime_error on error.

## ◆ Read()

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.

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

- lib/nfs/FileReader.hxx