matador::stream_handler Class Reference

#include <stream_handler.hpp>

Inherits matador::handler, and matador::io_stream.

Public Types

typedef std::function< void(tcp::peer, io_stream &)> t_init_handler
 
- Public Types inherited from matador::io_stream
typedef std::function< void(int ec, long nread)> t_read_handler
 
typedef std::function< void(int ec, long nwrite)> t_write_handler
 

Public Member Functions

 stream_handler (tcp::socket sock, tcp::peer endpoint, handler_creator *creator, t_init_handler init_handler)
 
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 read (buffer_view buf, t_read_handler read_handler) override
 
void write (std::list< buffer_view > buffers, t_write_handler write_handler) override
 
void close_stream () override
 
tcp::socketstream () override
 
std::string name () const override
 
- 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 stream_handler class implements the handler and io_stream interface and is used with the io_service to handle socket connections more easily in comparison with the plain reactor boilerplate.

Instances of the class are used internally within the io_service hiding the read and write wiring. The user just use the interface provided by the io_service to setup a server.

Member Typedef Documentation

◆ t_init_handler

Shortcut to the initialize function

Constructor & Destructor Documentation

◆ stream_handler()

matador::stream_handler::stream_handler ( tcp::socket  sock,
tcp::peer  endpoint,
handler_creator *  creator,
t_init_handler  init_handler 
)

Creates a new stream_handler for the given socket. The acceptor is the link to the creation source where the given init function is called when the handler is initialized

Parameters
sockSocket to read and write on
endpointEndpoint of the connection
creatorPointer to the creating handler class
init_handlerInitialize function

Member Function Documentation

◆ close()

void matador::stream_handler::close ( )
overridevirtual

Interface implementation should close the handle gracefully

Implements matador::handler.

◆ close_stream()

void matador::stream_handler::close_stream ( )
overridevirtual

Closes the stream

Implements matador::io_stream.

◆ handle()

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

Interface to returns the socket handle of the concrete handler implementation.

Returns
The socket fd

Implements matador::handler.

◆ is_ready_read()

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

Interface should return true if there is incoming data

Returns
True if there is incoming data

Implements matador::handler.

◆ is_ready_write()

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

Interface should return true if there is outgoing data

Returns
True if there is outgoing data

Implements matador::handler.

◆ name()

std::string matador::stream_handler::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.

◆ on_close()

void matador::stream_handler::on_close ( )
overridevirtual

Interface called when the handler is closed

Implements matador::handler.

◆ on_except()

void matador::stream_handler::on_except ( )
inlineoverridevirtual

Interface handling exceptional data

Implements matador::handler.

◆ on_input()

void matador::stream_handler::on_input ( )
overridevirtual

Interface handling incoming data

Implements matador::handler.

◆ on_output()

void matador::stream_handler::on_output ( )
overridevirtual

Interface handling outgoing data

Implements matador::handler.

◆ on_timeout()

void matador::stream_handler::on_timeout ( )
inlineoverridevirtual

Interface handling timout data

Implements matador::handler.

◆ open()

void matador::stream_handler::open ( )
overridevirtual

Interface to open a handler. This is called when a handler is registered within the reactor

Implements matador::handler.

◆ read()

void matador::stream_handler::read ( buffer_view  buf,
t_read_handler  read_handler 
)
overridevirtual

This interface is called when data should be read from a socket. Once the date was read the given read handler is called.

Parameters
bufBuffer to read the data in
read_handlerHandler to be called when data was read

Implements matador::io_stream.

◆ stream()

tcp::socket & matador::stream_handler::stream ( )
overridevirtual

Returns the underlying stream socket

Returns

Implements matador::io_stream.

◆ write()

void matador::stream_handler::write ( std::list< buffer_view buffers,
t_write_handler  write_handler 
)
overridevirtual

This interface is called when data should be written to a socket. Once the data was written the given write handler is called.

Parameters
buffersList of buffers containing the data to write
write_handlerHandler to be called when the data was written

Implements matador::io_stream.


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