matador::acceptor Class Reference

#include <acceptor.hpp>

Inherits matador::handler, and handler_creator.

Public Types

typedef std::function< std::shared_ptr< handler >(tcp::socket sock, tcp::peer endpoint, acceptor *accptr)> t_accept_handler
 

Public Member Functions

 acceptor ()
 
 acceptor (tcp::peer endpoint)
 
 acceptor (tcp::peer endpoint, t_accept_handler on_new_connection)
 
 ~acceptor () override
 
void accecpt (t_accept_handler on_new_connection)
 
void accecpt (const tcp::peer &endpoint, t_accept_handler on_new_connection)
 
void open () override
 
socket_type handle () const override
 
void on_input () override
 
void on_output () override
 
void on_except () override
 
void on_timeout () override
 
void on_close () override
 
void close () override
 
bool is_ready_write () const override
 
bool is_ready_read () const override
 
void notify_close (handler *hndlr) override
 
std::string name () const override
 
const tcp::peerendpoint () const
 
- Public Member Functions inherited from matador::handler
virtual ~handler ()=default
 
time_t next_timeout () const
 
time_t interval () const
 

Additional Inherited Members

- Protected Member Functions inherited from matador::handler
reactorget_reactor () const
 

Detailed Description

The acceptor class is used to accept new connection within the reactor dispatcher.

Once a new connection was accepted by the acceptor a new handler is created and registered within the reactor to handle the established connection

Member Typedef Documentation

◆ t_accept_handler

typedef std::function<std::shared_ptr<handler>(tcp::socket sock, tcp::peer endpoint, acceptor *accptr)> matador::acceptor::t_accept_handler

Shortcut to a function creating a handler on successfully accepted a new connection

Constructor & Destructor Documentation

◆ acceptor() [1/3]

matador::acceptor::acceptor ( )

Default constructor

◆ acceptor() [2/3]

matador::acceptor::acceptor ( tcp::peer  endpoint)
explicit

Creates an acceptor with the given endpoint. The endpoint represents the address on which the acceptor listens for new connections

Parameters
endpointEndpoint to listen for new connections

◆ acceptor() [3/3]

matador::acceptor::acceptor ( tcp::peer  endpoint,
t_accept_handler  on_new_connection 
)

Creates an acceptor with the given endpoint. The endpoint represents the address on which the acceptor listens for new connections. The given function is called when a new connection was accepted and returns a new handler for the new connection.

Parameters
endpointEndpoint to listen for new connections
on_new_connectionFunction creating a new handler for each accepted new connection

◆ ~acceptor()

matador::acceptor::~acceptor ( )
override

Destructor

Member Function Documentation

◆ accecpt() [1/2]

void matador::acceptor::accecpt ( const tcp::peer endpoint,
t_accept_handler  on_new_connection 
)

Accepts new connection at the given endpoint. When a new connection is accepted the given function is called to create a new handler for the connection.

Parameters
endpointEndpoint to listen for new connections
on_new_connectionFunction creating a new handler for the new connection

◆ accecpt() [2/2]

void matador::acceptor::accecpt ( t_accept_handler  on_new_connection)

When a new connection is accepted the given function is called to create a new handler for the connection

Parameters
on_new_connectionFunction creating a new handler for the new connection

◆ close()

void matador::acceptor::close ( )
overridevirtual

Closes the listen fd of the acceptor

Implements matador::handler.

◆ endpoint()

const tcp::peer & matador::acceptor::endpoint ( ) const

Returns the current endpoint accepting new connection.

Returns
Current listening endpoint

◆ handle()

socket_type matador::acceptor::handle ( ) const
overridevirtual

Returns the current listening socket fd

Returns
Listening socket fd

Implements matador::handler.

◆ is_ready_read()

bool matador::acceptor::is_ready_read ( ) const
overridevirtual

Returns true if the acceptor was opened and a listen fd was created.

Returns
True If a listen socket was created

Implements matador::handler.

◆ is_ready_write()

bool matador::acceptor::is_ready_write ( ) const
overridevirtual

Returns always false because new connections are indicated as read events.

Returns
Always false

Implements matador::handler.

◆ name()

std::string matador::acceptor::name ( ) const
overridevirtual

Get the name of the handler. The name don't need to be unique. It has only an informational purpose.

Returns
The name of the handler

Implements matador::handler.

◆ notify_close()

void matador::acceptor::notify_close ( handler hndlr)
override

Notifies the acceptor that this handler was closed.

Parameters
hndlrClosed handler.

◆ on_close()

void matador::acceptor::on_close ( )
inlineoverridevirtual

Does actually nothing

Implements matador::handler.

◆ on_except()

void matador::acceptor::on_except ( )
inlineoverridevirtual

Does actually nothing

Implements matador::handler.

◆ on_input()

void matador::acceptor::on_input ( )
overridevirtual

Is called when a new connection wants to execute to the endpoint. Once the connection was accepted a new connection handler is created and the socket is passed to the handler. The handler is then registered to the reactor to disptach its read and write events.

Implements matador::handler.

◆ on_output()

void matador::acceptor::on_output ( )
inlineoverridevirtual

Does actually nothing

Implements matador::handler.

◆ on_timeout()

void matador::acceptor::on_timeout ( )
inlineoverridevirtual

Does actually nothing

Implements matador::handler.

◆ open()

void matador::acceptor::open ( )
overridevirtual

Opens the acceptor means the socket address of the endpoint is bound to the created listing socket Then the socket is used for listening for new connections.

Implements matador::handler.


The documentation for this class was generated from the following file:
  • matador/net/acceptor.hpp