![]() |
libfilezilla
|
Base class for all readers. More...
#include <reader.hpp>
Public Member Functions | |
reader_base (reader_base const &)=delete | |
reader_base & | operator= (reader_base const &)=delete |
void | close () |
virtual bool | seekable () const |
bool | seek (uint64_t offset, uint64_t size=nosize) |
If seek fails, the reader is in an undefined state and must be closed. | |
bool | rewind () |
Only seekable readers can be rewound. | |
std::wstring const & | name () const |
virtual uint64_t | size () const |
Size of the reader. If the size is indetermined, nosize is returned. | |
virtual datetime | mtime () const |
Last modification time, might be indetermined. | |
std::pair< aio_result, buffer_lease > | get_buffer (event_handler &h) |
Gets the next buffer with data from the reader. | |
bool | error () const |
![]() | |
![]() | |
void | remove_waiter (event_handler &h) |
![]() | |
event_handler (event_loop &loop) | |
event_handler (event_handler const &h) | |
event_handler & | operator= (event_handler const &)=delete |
void | remove_handler () |
Deactivates handler, removes all pending events and stops all timers for this handler. | |
template<typename T , typename... Args> | |
void | send_event (Args &&... args) |
Sends the passed event asynchronously to the handler. | |
template<typename T > | |
void | send_event (T *evt) |
template<typename T > | |
void | send_persistent_event (T *evt) |
Be careful with lifetime. | |
timer_id | add_timer (monotonic_clock const &deadline, duration const &interval={}) |
Adds a timer, returns the timer id. | |
timer_id | add_timer (duration const &interval, bool one_shot) |
Adds a timer, returns the timer id. | |
void | stop_timer (timer_id id) |
timer_id | stop_add_timer (timer_id id, monotonic_clock const &deadline, duration const &interval={}) |
timer_id | stop_add_timer (timer_id id, duration const &interval, bool one_shot) |
void | filter_events (std::function< bool(event_base &ev)> const &filter) |
void | resend_current_event () |
Protected Member Functions | |
reader_base (std::wstring &&name, aio_buffer_pool &pool, size_t max_buffers) noexcept | |
Constructs a reader. | |
reader_base (std::wstring_view name, aio_buffer_pool &pool, size_t max_buffers) noexcept | |
virtual std::pair< aio_result, buffer_lease > | do_get_buffer (scoped_lock &l)=0 |
virtual bool | do_seek (scoped_lock &) |
virtual void | do_close (scoped_lock &) |
virtual void | operator() (event_base const &) override |
Called by the event loop in the worker thread with the event to process. | |
void | on_buffer_availability (aio_waitable const *w) |
virtual void | do_on_buffer_availability (fz::scoped_lock &l, aio_waitable const *w)=0 |
![]() | |
void | remove_waiters () |
Call in destructor of most-derived class. | |
void | add_waiter (event_handler &h) |
void | signal_availibility () |
Protected Attributes | |
mutex | mtx_ |
aio_buffer_pool & | buffer_pool_ |
logger_interface & | logger_ |
std::wstring const | name_ |
size_t const | max_buffers_ {} |
std::list< buffer_lease > | buffers_ |
uint64_t | size_ {nosize} |
uint64_t | max_size_ {nosize} |
uint64_t | start_offset_ {nosize} |
uint64_t | remaining_ {nosize} |
bool | get_buffer_called_ {} |
bool | error_ {} |
bool | eof_ {} |
bool | waiting_ {} |
Additional Inherited Members | |
![]() | |
using | size_type = uint64_t |
![]() | |
event_loop & | event_loop_ |
![]() | |
static constexpr auto | nosize = static_cast<size_type>(-1) |
Base class for all readers.
All readers have a name describing them for logging purposes.
The initial state of a freshly opened reader is readable, get_buffer() can be called.
See the aio demo program for example usage.
|
inlineprotectednoexcept |
Constructs a reader.
The passed aio_buffer_pool
must live longer than the reader.
max_buffers
controls the amount of buffers the reader is prepared to use at any given time.
|
inlineprotectedvirtual |
When this gets called, buffers_ has already been cleared and the waiters have been removed. start_offset_, size_ and remaining_ have already been set.
std::pair< aio_result, buffer_lease > get_buffer | ( | event_handler & | h | ) |
Gets the next buffer with data from the reader.
If it returns aio_result::ok, a buffer may be returned as well for the caller to consume. If no buffer is returned on aio_result::ok, the reader has reached eof.
If aio_result::error is returned, the reader has failed and can only be closed.
After getting aio_result::wait, do not call get_buffer again until after the passed waiter got on_buffer_availability() invoked.
|
overrideprotectedvirtual |
Called by the event loop in the worker thread with the event to process.
Override in your derived class.
Consider using dispatch inside your function.
Implements event_handler.