join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::Reactor Class Reference

Reactor class. More...

#include <reactor.hpp>

Public Types

using InvokeHandler = Function<void (), 64>
 function invoked on the reactor thread.
 

Public Member Functions

 Reactor ()
 default constructor.
 
 Reactor (const Reactor &other)=delete
 copy constructor.
 
Reactoroperator= (const Reactor &other)=delete
 copy assignment operator.
 
 Reactor (Reactor &&other)=delete
 move constructor.
 
Reactoroperator= (Reactor &&other)=delete
 move assignment operator.
 
 ~Reactor () noexcept
 destroy instance.
 
int addHandler (int fd, EventHandler *handler, bool wantRead=true, bool wantWrite=false, bool sync=true) noexcept
 add handler to reactor.
 
int delHandler (int fd, bool sync=true) noexcept
 delete handler from reactor.
 
int invoke (InvokeHandler *fn, bool sync=true) noexcept
 invoke a function from the reactor thread.
 
void run ()
 run the event loop (blocking).
 
void stop (bool sync=true) noexcept
 stop the event loop, ignored if no event loop is running.
 
void waitStopped () const noexcept
 wait for the event loop thread to terminate.
 
int mlock () const noexcept
 lock command queue memory in RAM.
 
bool isRunning () const noexcept
 check if the event loop is running.
 
bool isReactorThread () const noexcept
 check if the calling thread is the reactor thread.
 

Detailed Description

Reactor class.

Member Typedef Documentation

◆ InvokeHandler

using join::Reactor::InvokeHandler = Function<void (), 64>

function invoked on the reactor thread.

Constructor & Destructor Documentation

◆ Reactor() [1/3]

Reactor::Reactor ( )

default constructor.

◆ Reactor() [2/3]

join::Reactor::Reactor ( const Reactor & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ Reactor() [3/3]

join::Reactor::Reactor ( Reactor && other)
delete

move constructor.

Parameters
otherother object to move.

◆ ~Reactor()

Reactor::~Reactor ( )
noexcept

destroy instance.

Member Function Documentation

◆ addHandler()

int Reactor::addHandler ( int fd,
EventHandler * handler,
bool wantRead = true,
bool wantWrite = false,
bool sync = true )
noexcept

add handler to reactor.

Parameters
fdfile descriptor.
handlerhandler pointer.
wantReadsubscribe to read events.
wantWritesubscribe to write events.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ delHandler()

int Reactor::delHandler ( int fd,
bool sync = true )
noexcept

delete handler from reactor.

Parameters
fdfile descriptor.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ invoke()

int Reactor::invoke ( InvokeHandler * fn,
bool sync = true )
noexcept

invoke a function from the reactor thread.

Parameters
fnfunction to invoke, shall remain valid until invoked.
syncwait for operation completion if true.
Returns
0 on success, -1 on failure.

◆ isReactorThread()

bool Reactor::isReactorThread ( ) const
noexcept

check if the calling thread is the reactor thread.

Returns
true if called from the reactor thread.

◆ isRunning()

bool Reactor::isRunning ( ) const
noexcept

check if the event loop is running.

Returns
true if the event loop is running.

◆ mlock()

int Reactor::mlock ( ) const
noexcept

lock command queue memory in RAM.

Returns
0 on success, -1 on failure.

◆ operator=() [1/2]

Reactor & join::Reactor::operator= ( const Reactor & other)
delete

copy assignment operator.

Parameters
otherother object to copy.
Returns
current object.

◆ operator=() [2/2]

Reactor & join::Reactor::operator= ( Reactor && other)
delete

move assignment operator.

Parameters
otherother object to move.
Returns
current object.

◆ run()

void Reactor::run ( )

run the event loop (blocking).

◆ stop()

void Reactor::stop ( bool sync = true)
noexcept

stop the event loop, ignored if no event loop is running.

Parameters
syncwait for the event loop thread to terminate.

◆ waitStopped()

void Reactor::waitStopped ( ) const
noexcept

wait for the event loop thread to terminate.


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