Thrill  0.1
Dispatcher Class Referencefinal

Detailed Description

A virtual Dispatcher which waits for messages to arrive in the mock network.

It is implemented as a ConcurrentBoundedQueue, into which Connections lay notification events.

Definition at line 171 of file group.hpp.

+ Inheritance diagram for Dispatcher:
+ Collaboration diagram for Dispatcher:

#include <group.hpp>

Public Types

using Callback = AsyncCallback
 type for file descriptor readiness callbacks More...
 

Public Member Functions

 Dispatcher ()
 
 ~Dispatcher ()
 virtual destructor More...
 
Implementation of Virtual Methods
void AddRead (net::Connection &_c, const Callback &read_cb) final
 Register a buffered read callback and a default exception callback. More...
 
void AddWrite (net::Connection &_c, const Callback &write_cb) final
 Register a buffered write callback and a default exception callback. More...
 
void Cancel (net::Connection &) final
 Cancel all callbacks on a given connection. More...
 
void Notify (Connection *c)
 
void Interrupt () final
 Interrupt current dispatch. More...
 
void DispatchOne (const std::chrono::milliseconds &timeout) final
 
- Public Member Functions inherited from Dispatcher
 Dispatcher ()=default
 default constructor More...
 
 Dispatcher (const Dispatcher &)=delete
 non-copyable: delete copy-constructor More...
 
Dispatcheroperator= (const Dispatcher &)=delete
 non-copyable: delete assignment operator More...
 
void AddTimer (const std::chrono::milliseconds &timeout, const TimerCallback &cb)
 Register a relative timeout callback. More...
 
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())
 
void Dispatch ()
 Dispatch one or more events. More...
 
void Loop ()
 Loop over Dispatch() until terminate_ flag is set. More...
 
void Terminate ()
 
bool HasAsyncWrites () const
 Check whether there are still AsyncWrite()s in the queue. More...
 

Private Member Functions

Watch & GetWatch (Connection *c)
 lookup method More...
 

Private Attributes

std::unique_ptr< Data > d_
 pimpl data struct with complex components More...
 

Static Private Attributes

static constexpr bool debug = false
 

Additional Inherited Members

- Protected Types inherited from Dispatcher
using TimerPQ = std::priority_queue< Timer, std::vector< Timer, mem::GPoolAllocator< Timer > > >
 priority queue of timer callbacks More...
 
- Static Protected Member Functions inherited from Dispatcher
static bool ExceptionCallback (Connection &c)
 Default exception handler. More...
 
- Protected Attributes inherited from Dispatcher
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_
 

Member Typedef Documentation

◆ Callback

type for file descriptor readiness callbacks

Definition at line 177 of file group.hpp.

Constructor & Destructor Documentation

◆ Dispatcher()

Definition at line 227 of file group.cpp.

◆ ~Dispatcher()

~Dispatcher ( )
virtual

virtual destructor

Reimplemented from Dispatcher.

Definition at line 232 of file group.cpp.

Member Function Documentation

◆ AddRead()

void AddRead ( net::Connection _c,
const Callback read_cb 
)
finalvirtual

Register a buffered read callback and a default exception callback.

Implements Dispatcher.

Definition at line 236 of file group.cpp.

References Connection::d_, Dispatcher::d_, Dispatcher::GetWatch(), and Dispatcher::Notify().

◆ AddWrite()

void AddWrite ( net::Connection c,
const Callback write_cb 
)
finalvirtual

Register a buffered write callback and a default exception callback.

Implements Dispatcher.

Definition at line 253 of file group.cpp.

References Connection::d_, Dispatcher::d_, Dispatcher::GetWatch(), and Dispatcher::Notify().

◆ Cancel()

void Cancel ( net::Connection c)
finalvirtual

Cancel all callbacks on a given connection.

Implements Dispatcher.

Definition at line 269 of file group.cpp.

◆ DispatchOne()

void DispatchOne ( const std::chrono::milliseconds &  timeout)
finalvirtual

Implements Dispatcher.

Definition at line 288 of file group.cpp.

References Connection::d_, Dispatcher::d_, LOG1, and sLOG.

◆ GetWatch()

Dispatcher::Watch & GetWatch ( Connection c)
private

lookup method

Definition at line 281 of file group.cpp.

References Dispatcher::d_.

Referenced by Dispatcher::AddRead(), and Dispatcher::AddWrite().

◆ Interrupt()

void Interrupt ( )
finalvirtual

Interrupt current dispatch.

Implements Dispatcher.

Definition at line 277 of file group.cpp.

References Dispatcher::Notify().

◆ Notify()

void Notify ( Connection c)

Member Data Documentation

◆ d_

std::unique_ptr<Data> d_
private

pimpl data struct with complex components

Definition at line 201 of file group.hpp.

Referenced by Dispatcher::AddRead(), Dispatcher::AddWrite(), Dispatcher::DispatchOne(), Dispatcher::GetWatch(), and Dispatcher::Notify().

◆ debug

constexpr bool debug = false
staticprivate

Definition at line 173 of file group.hpp.


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