|
Thrill
0.1
|
Dispatcher is a high level wrapper for asynchronous callback processing.
. One can register Connection objects for readability and writability checks, buffered reads and writes with completion callbacks, and also timer functions.
Definition at line 510 of file dispatcher.hpp.
Inheritance diagram for Dispatcher:#include <dispatcher.hpp>
Classes | |
| struct | Timer |
| struct for timer callbacks More... | |
Public Member Functions | |
| Dispatcher ()=default | |
| default constructor More... | |
| Dispatcher (const Dispatcher &)=delete | |
| non-copyable: delete copy-constructor More... | |
| virtual | ~Dispatcher () |
| virtual destructor More... | |
| Dispatcher & | operator= (const Dispatcher &)=delete |
| non-copyable: delete assignment operator More... | |
Timeout Callbacks | |
| void | AddTimer (const std::chrono::milliseconds &timeout, const TimerCallback &cb) |
| Register a relative timeout callback. More... | |
Connection Callbacks | |
| virtual void | AddRead (Connection &c, const AsyncCallback &read_cb)=0 |
| Register a buffered read callback and a default exception callback. More... | |
| virtual void | AddWrite (Connection &c, const AsyncCallback &write_cb)=0 |
| Register a buffered write callback and a default exception callback. More... | |
| virtual void | Cancel (Connection &c)=0 |
| Cancel all callbacks on a given connection. More... | |
Asynchronous Data Reader/Writer Callbacks | |
| virtual void | AsyncRead (Connection &c, uint32_t, size_t size, const AsyncReadBufferCallback &done_cb) |
| asynchronously read n bytes and deliver them to the callback More... | |
| virtual void | AsyncRead (Connection &c, uint32_t, size_t size, data::PinnedByteBlockPtr &&block, const AsyncReadByteBlockCallback &done_cb) |
| asynchronously read the full ByteBlock and deliver it to the callback More... | |
| virtual void | AsyncWrite (Connection &c, uint32_t, Buffer &&buffer, const AsyncWriteCallback &done_cb=AsyncWriteCallback()) |
| virtual void | AsyncWrite (Connection &c, uint32_t, data::PinnedBlock &&block, const AsyncWriteCallback &done_cb=AsyncWriteCallback()) |
| void | AsyncWriteCopy (Connection &c, uint32_t seq, const void *buffer, size_t size, const AsyncWriteCallback &done_cb=AsyncWriteCallback()) |
| void | AsyncWriteCopy (Connection &c, uint32_t seq, const std::string &str, const AsyncWriteCallback &done_cb=AsyncWriteCallback()) |
Dispatch | |
| void | Dispatch () |
| Dispatch one or more events. More... | |
| void | Loop () |
| Loop over Dispatch() until terminate_ flag is set. More... | |
| virtual void | Interrupt ()=0 |
| Interrupt current dispatch. More... | |
| void | Terminate () |
| bool | HasAsyncWrites () const |
| Check whether there are still AsyncWrite()s in the queue. More... | |
Protected Types | |
| using | TimerPQ = std::priority_queue< Timer, std::vector< Timer, mem::GPoolAllocator< Timer > > > |
| priority queue of timer callbacks More... | |
Protected Member Functions | |
| virtual void | DispatchOne (const std::chrono::milliseconds &timeout)=0 |
Static Protected Member Functions | |
| static bool | ExceptionCallback (Connection &c) |
| Default exception handler. More... | |
Protected Attributes | |
| std::deque< AsyncReadBuffer, mem::GPoolAllocator< AsyncReadBuffer > > | async_read_ |
| deque of asynchronous readers More... | |
| std::deque< AsyncReadByteBlock, mem::GPoolAllocator< AsyncReadByteBlock > > | async_read_block_ |
| deque of asynchronous readers More... | |
| std::deque< AsyncWriteBuffer, mem::GPoolAllocator< AsyncWriteBuffer > > | async_write_ |
| deque of asynchronous writers More... | |
| std::deque< AsyncWriteBlock, mem::GPoolAllocator< AsyncWriteBlock > > | async_write_block_ |
| deque of asynchronous writers More... | |
| std::atomic< bool > | terminate_ { false } |
| true if dispatcher needs to stop More... | |
| TimerPQ | timer_pq_ |
Private Types | |
| using | milliseconds = std::chrono::milliseconds |
| import into class namespace More... | |
| using | steady_clock = std::chrono::steady_clock |
| import into class namespace More... | |
Static Private Attributes | |
| static constexpr bool | debug = false |
|
private |
import into class namespace
Definition at line 519 of file dispatcher.hpp.
|
private |
import into class namespace
Definition at line 516 of file dispatcher.hpp.
|
protected |
priority queue of timer callbacks
Definition at line 784 of file dispatcher.hpp.
|
default |
default constructor
|
delete |
non-copyable: delete copy-constructor
|
inlinevirtual |
virtual destructor
Reimplemented in Dispatcher, and Dispatcher.
Definition at line 534 of file dispatcher.hpp.
|
pure virtual |
Register a buffered read callback and a default exception callback.
Implemented in Dispatcher, SelectDispatcher, and Dispatcher.
|
inline |
Register a relative timeout callback.
Definition at line 540 of file dispatcher.hpp.
|
pure virtual |
Register a buffered write callback and a default exception callback.
Implemented in Dispatcher, SelectDispatcher, and Dispatcher.
|
inlinevirtual |
asynchronously read n bytes and deliver them to the callback
Reimplemented in Dispatcher.
Definition at line 567 of file dispatcher.hpp.
References Connection::IsValid(), and LOG.
|
inlinevirtual |
asynchronously read the full ByteBlock and deliver it to the callback
Reimplemented in Dispatcher.
Definition at line 587 of file dispatcher.hpp.
References Connection::IsValid(), and LOG.
|
inlinevirtual |
asynchronously write buffer and callback when delivered. The buffer is MOVED into the async writer.
Reimplemented in Dispatcher.
Definition at line 609 of file dispatcher.hpp.
References AsyncReadBuffer::buffer(), Connection::IsValid(), and Buffer::size().
|
inlinevirtual |
asynchronously write buffer and callback when delivered. The buffer is MOVED into the async writer.
Reimplemented in Dispatcher.
Definition at line 630 of file dispatcher.hpp.
References Connection::IsValid().
|
inline |
asynchronously write buffer and callback when delivered. COPIES the data into a Buffer!
Definition at line 651 of file dispatcher.hpp.
|
inline |
asynchronously write buffer and callback when delivered. COPIES the data into a Buffer!
Definition at line 659 of file dispatcher.hpp.
|
pure virtual |
Cancel all callbacks on a given connection.
Implemented in Dispatcher, SelectDispatcher, and Dispatcher.
|
inline |
Dispatch one or more events.
Definition at line 671 of file dispatcher.hpp.
References Dispatcher::Timer::cb, LOG, Dispatcher::Timer::next_timeout, sLOG, and Dispatcher::Timer::timeout.
|
protectedpure virtual |
Implemented in Dispatcher, Dispatcher, and SelectDispatcher.
|
inlinestaticprotected |
Default exception handler.
Definition at line 749 of file dispatcher.hpp.
References Connection::ToString().
|
inline |
Check whether there are still AsyncWrite()s in the queue.
Definition at line 739 of file dispatcher.hpp.
|
pure virtual |
Interrupt current dispatch.
Implemented in Dispatcher, Dispatcher, and SelectDispatcher.
|
inline |
Loop over Dispatch() until terminate_ flag is set.
Definition at line 722 of file dispatcher.hpp.
|
delete |
non-copyable: delete assignment operator
|
inline |
Causes the dispatcher to break out after the next timeout occurred Does not interrupt the currently running read/write operation, but breaks after the operation finished or timed out.
Definition at line 734 of file dispatcher.hpp.
|
protected |
deque of asynchronous readers
Definition at line 794 of file dispatcher.hpp.
|
protected |
deque of asynchronous readers
Definition at line 802 of file dispatcher.hpp.
|
protected |
deque of asynchronous writers
Definition at line 798 of file dispatcher.hpp.
|
protected |
deque of asynchronous writers
Definition at line 806 of file dispatcher.hpp.
|
staticprivate |
Definition at line 512 of file dispatcher.hpp.
|
protected |
true if dispatcher needs to stop
Definition at line 757 of file dispatcher.hpp.
|
protected |
priority queue of timer callbacks, obviously kept in timeout order. Currently not addressable.
Definition at line 788 of file dispatcher.hpp.