RESTinio

Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
restinio::impl::connection_t< Traits > Class Template Referencefinal

Context for handling http connections. More...

`#include <connection.hpp>`

Inheritance diagram for restinio::impl::connection_t< Traits >:

## Classes
struct | upgrade_internals_t
| Internals that are necessary for upgrade. More...

## Public Types
using | timer_manager_t = typename Traits::timer_manager_t
using | timer_guard_t = typename timer_manager_t::timer_guard_t
using | request_handler_t = request_handler_type_from_traits_t< Traits >
using | generic_request_t = generic_request_type_from_traits_t< Traits >
using | logger_t = typename Traits::logger_t
using | strand_t = typename Traits::strand_t
using | stream_socket_t = typename Traits::stream_socket_t
using | lifetime_monitor_t = typename connection_count_limit_types< Traits >::lifetime_monitor_t

## Public Member Functions
| connection_t (connection_id_t conn_id, stream_socket_t &&socket, connection_settings_handle_t< Traits > settings, endpoint_t remote_endpoint, lifetime_monitor_t lifetime_monitor)
| connection_t (const connection_t &)=delete
| connection_t (connection_t &&)=delete
connection_t & | operator= (const connection_t &)=delete
connection_t & | operator= (connection_t &&)=delete
| ~connection_t () override
void | init ()
void | wait_for_http_message ()
| Start reading next htttp-message. More...
upgrade_internals_t | move_upgrade_internals ()
| Move socket out of connection. More...
Public Member Functions inherited from restinio::impl::connection_base_t
| connection_base_t (connection_id_t id)
virtual void | write_response_parts (request_id_t request_id, response_output_flags_t response_output_flags, write_group_t wg)=0
| Write parts for specified request. More...
Public Member Functions inherited from restinio::tcp_connection_ctx_base_t
| tcp_connection_ctx_base_t (connection_id_t id)
virtual | ~tcp_connection_ctx_base_t ()=default
connection_id_t | connection_id () const noexcept
| Get connection id. More...
virtual void | check_timeout (std::shared_ptr< tcp_connection_ctx_base_t > &self)=0
| Check timeouts for all activities. More...
Public Member Functions inherited from restinio::impl::executor_wrapper_t< Traits::strand_t >
| executor_wrapper_t (Init_Executor &&init_executor)
virtual | ~executor_wrapper_t ()=default
Traits::strand_t & | get_executor () noexcept
| An executor for callbacks on async operations. More...

## Private Types
using | executor_wrapper_base_t = executor_wrapper_t< typename Traits::strand_t >
using | none_write_operation_t = write_group_output_ctx_t::none_write_operation_t
using | trivial_write_operation_t = write_group_output_ctx_t::trivial_write_operation_t
using | file_write_operation_t = write_group_output_ctx_t::file_write_operation_t

## Private Member Functions
void | consume_message ()
| Start (continue) a chain of read-parse-read-... operations. More...
void | after_read (const asio_ns::error_code &ec, std::size_t length) noexcept
| Handle read operation result. More...
void | consume_data (const char *data, std::size_t length)
| Parse some data. More...
void | on_request_message_complete ()
| Handle a given request message. More...
void | handle_upgrade_request ()
| Calls handler for upgrade request. More...
virtual void | write_response_parts (request_id_t request_id, response_output_flags_t response_output_flags, write_group_t wg) override
| Write parts for specified request. More...
void | write_response_parts_impl (request_id_t request_id, response_output_flags_t response_output_flags, write_group_t wg)
| Write parts for specified request. More...
void | init_write_if_necessary ()
void | init_write ()
| Initiate write operation. More...
void | handle_current_write_ctx () noexcept
| Start/continue/continue handling output data of current write group. More...
void | handle_trivial_write_operation (const trivial_write_operation_t &op)
| Run trivial buffers write operation. More...
void | handle_file_write_operation (file_write_operation_t &op)
| Run sendfile write operation. More...
void | finish_handling_current_write_ctx ()
| Do post write actions for current write group. More...
void | handle_nothing_to_write ()
void | after_write (const asio_ns::error_code &ec) noexcept
| Handle write response finished. More...
void | close () noexcept
| Close connection functions. More...
template<typename Message_Builder >
void | trigger_error_and_close (Message_Builder msg_builder) noexcept
| Trigger an error. More...

## Private Attributes
stream_socket_t | m_socket
| Connection. More...
connection_settings_handle_t< Traits > | m_settings
| Common paramaters of a connection. More...
const endpoint_t | m_remote_endpoint
| Remote endpoint for this connection. More...
connection_input_t | m_input
| Input routine. More...
write_group_output_ctx_t | m_write_output_ctx
| Write to socket operation context. More...
bool | m_init_read_after_this_write { false }
response_coordinator_t | m_response_coordinator
| Response coordinator. More...
request_handler_t & | m_request_handler
| Request handler. More...
logger_t & | m_logger
| Logger for operation. More...
lifetime_monitor_t | m_lifetime_monitor
| Monitor of the connection lifetime. More...
using | timout_cb_t = void(connection_t::*)(void)
| Callback type for timedout operations. More...
timout_cb_t | m_current_timeout_cb { nullptr }
| Callback to all if timeout happened. More...
std::chrono::steady_clock::time_point | m_current_timeout_after
| Timeout point of a current guarded operation. More...
timer_guard_t | m_timer_guard
| Timer guard. More...
tcp_connection_ctx_weak_handle_t | m_prepared_weak_ctx
| A prepared weak handle for passing it to timer guard. More...
virtual void | check_timeout (tcp_connection_ctx_handle_t &self) override
| Schedules real timedout operations check on the executer of a connection. More...
void | check_timeout_impl ()
| Check timed out operation. More...
void | init_next_timeout_checking ()
| Schedule next timeout checking. More...
void | cancel_timeout_checking () noexcept
| Stop timout guarding. More...
void | schedule_operation_timeout_callback (std::chrono::steady_clock::time_point timeout_after, timout_cb_t timout_cb)
| Helper function to work with timer guard. More...
void | schedule_operation_timeout_callback (std::chrono::steady_clock::duration timeout, timout_cb_t timout_cb)
void | handle_xxx_timeout (const char *operation_name)
void | handle_read_timeout ()
void | guard_read_operation ()
| Statr guard read operation if necessary. More...
void | handle_request_handling_timeout ()
void | guard_request_handling_operation ()
| Start guard request handling operation if necessary. More...
void | handle_write_response_timeout ()
void | guard_write_operation ()
| Start guard write operation if necessary. More...
void | handle_sendfile_timeout ()
void | guard_sendfile_operation (std::chrono::steady_clock::duration timelimit)
static connection_t & | cast_to_self (tcp_connection_ctx_base_t &base)
| Timer to controll operations. More...

## Additional Inherited Members
Protected Member Functions inherited from restinio::tcp_connection_ctx_base_t
template<typename Derived >
std::shared_ptr< Derived > | shared_from_concrete ()
| Cast self to derived class. More...

## Detailed Description

template<typename Traits>
class restinio::impl::connection_t< Traits >

Context for handling http connections.

Definition at line 303 of file connection.hpp.

## Member Typedef Documentation

## ◆ executor_wrapper_base_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::executor_wrapper_base_t = executor_wrapper_t< typename Traits::strand_t >
| private

Definition at line 307 of file connection.hpp.

## ◆ file_write_operation_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::file_write_operation_t = write_group_output_ctx_t::file_write_operation_t
| private

Definition at line 1061 of file connection.hpp.

## ◆ generic_request_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::generic_request_t = generic_request_type_from_traits_t< Traits >

Definition at line 313 of file connection.hpp.

## ◆ lifetime_monitor_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::lifetime_monitor_t = typename connection_count_limit_types<Traits>::lifetime_monitor_t

Definition at line 317 of file connection.hpp.

## ◆ logger_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::logger_t = typename Traits::logger_t

Definition at line 314 of file connection.hpp.

## ◆ none_write_operation_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::none_write_operation_t = write_group_output_ctx_t::none_write_operation_t
| private

Definition at line 1059 of file connection.hpp.

## ◆ request_handler_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::request_handler_t = request_handler_type_from_traits_t< Traits >

Definition at line 312 of file connection.hpp.

## ◆ strand_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::strand_t = typename Traits::strand_t

Definition at line 315 of file connection.hpp.

## ◆ stream_socket_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::stream_socket_t = typename Traits::stream_socket_t

Definition at line 316 of file connection.hpp.

## ◆ timer_guard_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::timer_guard_t = typename timer_manager_t::timer_guard_t

Definition at line 311 of file connection.hpp.

## ◆ timer_manager_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::timer_manager_t = typename Traits::timer_manager_t

Definition at line 310 of file connection.hpp.

## ◆ timout_cb_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::timout_cb_t = void (connection_t::* )( void )
| private

Callback type for timedout operations.

Definition at line 1541 of file connection.hpp.

## ◆ trivial_write_operation_t

template<typename Traits >

using restinio::impl::connection_t< Traits >::trivial_write_operation_t = write_group_output_ctx_t::trivial_write_operation_t
| private

Definition at line 1060 of file connection.hpp.

## Constructor & Destructor Documentation

## ◆ connection_t() [1/3]

template<typename Traits >

restinio::impl::connection_t< Traits >::connection_t | ( | connection_id_t | conn_id,
|  | stream_socket_t && | socket,
|  | connection_settings_handle_t< Traits > | settings,
|  | endpoint_t | remote_endpoint,
|  | lifetime_monitor_t | lifetime_monitor
| ) |  |
| inline

Parameters

  conn_id | Connection id.
  socket | Connection socket.
  settings | Settings that are common for connections.
  remote_endpoint | Remote endpoint for that connection.
  lifetime_monitor | Lifetime monitor to be used for handling connection count.

Definition at line 320 of file connection.hpp.

## ◆ connection_t() [2/3]

template<typename Traits >

restinio::impl::connection_t< Traits >::connection_t | ( | const connection_t< Traits > & |  | ) |
| delete

## ◆ connection_t() [3/3]

template<typename Traits >

restinio::impl::connection_t< Traits >::connection_t | ( | connection_t< Traits > && |  | ) |
| delete

## ◆ ~connection_t()

template<typename Traits >

restinio::impl::connection_t< Traits >::~connection_t | ( |  | ) |
| inline override

Definition at line 361 of file connection.hpp.

## Member Function Documentation

## ◆ after_read()

template<typename Traits >

void restinio::impl::connection_t< Traits >::after_read | ( | const asio_ns::error_code & | ec,
|  | std::size_t | length
| ) |  |
| inline private noexcept

Handle read operation result.

Definition at line 510 of file connection.hpp.

## ◆ after_write()

template<typename Traits >

void restinio::impl::connection_t< Traits >::after_write | ( | const asio_ns::error_code & | ec | ) |
| inline private noexcept

Handle write response finished.

Note
  Since v.0.6.0 this method is noexcept.

Definition at line 1357 of file connection.hpp.

## ◆ cancel_timeout_checking()

template<typename Traits >

void restinio::impl::connection_t< Traits >::cancel_timeout_checking | ( |  | ) |
| inline private noexcept

Stop timout guarding.

Definition at line 1577 of file connection.hpp.

## ◆ cast_to_self()

template<typename Traits >

static connection_t & restinio::impl::connection_t< Traits >::cast_to_self | ( | tcp_connection_ctx_base_t & | base | ) |
| inline static private

Timer to controll operations.

Check timeouts for all activities.

Definition at line 1506 of file connection.hpp.

## ◆ check_timeout()

template<typename Traits >

virtual void restinio::impl::connection_t< Traits >::check_timeout | ( | tcp_connection_ctx_handle_t & | self | ) |
| inline override private virtual

Schedules real timedout operations check on the executer of a connection.

Definition at line 1514 of file connection.hpp.

## ◆ check_timeout_impl()

template<typename Traits >

void restinio::impl::connection_t< Traits >::check_timeout_impl | ( |  | ) |
| inline private

Check timed out operation.

Definition at line 1555 of file connection.hpp.

## ◆ close()

template<typename Traits >

void restinio::impl::connection_t< Traits >::close | ( |  | ) |
| inline private noexcept

Close connection functions.

Standard close routine.

Definition at line 1398 of file connection.hpp.

## ◆ consume_data()

template<typename Traits >

void restinio::impl::connection_t< Traits >::consume_data | ( | const char * | data,
|  | std::size_t | length
| ) |  |
| inline private

Parse some data.

Definition at line 579 of file connection.hpp.

## ◆ consume_message()

template<typename Traits >

void restinio::impl::connection_t< Traits >::consume_message | ( |  | ) |
| inline private

Start (continue) a chain of read-parse-read-... operations.

Definition at line 474 of file connection.hpp.

## ◆ finish_handling_current_write_ctx()

template<typename Traits >

void restinio::impl::connection_t< Traits >::finish_handling_current_write_ctx | ( |  | ) |
| inline private

Do post write actions for current write group.

Definition at line 1252 of file connection.hpp.

## ◆ guard_read_operation()

template<typename Traits >

void restinio::impl::connection_t< Traits >::guard_read_operation | ( |  | ) |
| inline private

Statr guard read operation if necessary.

Definition at line 1624 of file connection.hpp.

## ◆ guard_request_handling_operation()

template<typename Traits >

void restinio::impl::connection_t< Traits >::guard_request_handling_operation | ( |  | ) |
| inline private

Start guard request handling operation if necessary.

Definition at line 1642 of file connection.hpp.

## ◆ guard_sendfile_operation()

template<typename Traits >

void restinio::impl::connection_t< Traits >::guard_sendfile_operation | ( | std::chrono::steady_clock::duration | timelimit | ) |
| inline private

Definition at line 1674 of file connection.hpp.

## ◆ guard_write_operation()

template<typename Traits >

void restinio::impl::connection_t< Traits >::guard_write_operation | ( |  | ) |
| inline private

Start guard write operation if necessary.

Definition at line 1660 of file connection.hpp.

## ◆ handle_current_write_ctx()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_current_write_ctx | ( |  | ) |
| inline private noexcept

Start/continue/continue handling output data of current write group.

This function is a starting point of a loop process of sending data from a given write group. It extracts the next bunch of trivial buffers or a sendfile-runner and starts an appropriate write operation. In data of a given write group finishes, finish_handling_current_write_ctx() is invoked thus breaking the loop.

Note
  Since v.0.6.0 this method is noexcept.

Definition at line 1076 of file connection.hpp.

## ◆ handle_file_write_operation()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_file_write_operation | ( | file_write_operation_t & | op | ) |
| inline private

Run sendfile write operation.

Definition at line 1172 of file connection.hpp.

## ◆ handle_nothing_to_write()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_nothing_to_write | ( |  | ) |
| inline private

Definition at line 1311 of file connection.hpp.

## ◆ handle_read_timeout()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_read_timeout | ( |  | ) |
| inline private

Definition at line 1617 of file connection.hpp.

## ◆ handle_request_handling_timeout()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_request_handling_timeout | ( |  | ) |
| inline private

Definition at line 1635 of file connection.hpp.

## ◆ handle_sendfile_timeout()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_sendfile_timeout | ( |  | ) |
| inline private

Definition at line 1668 of file connection.hpp.

## ◆ handle_trivial_write_operation()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_trivial_write_operation | ( | const trivial_write_operation_t & | op | ) |
| inline private

Run trivial buffers write operation.

Definition at line 1109 of file connection.hpp.

## ◆ handle_upgrade_request()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_upgrade_request | ( |  | ) |
| inline private

Calls handler for upgrade request.

Request data must be in input context (m_input).

Definition at line 757 of file connection.hpp.

## ◆ handle_write_response_timeout()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_write_response_timeout | ( |  | ) |
| inline private

Definition at line 1653 of file connection.hpp.

## ◆ handle_xxx_timeout()

template<typename Traits >

void restinio::impl::connection_t< Traits >::handle_xxx_timeout | ( | const char * | operation_name | ) |
| inline private

Definition at line 1604 of file connection.hpp.

## ◆ init()

template<typename Traits >

void restinio::impl::connection_t< Traits >::init | ( |  | ) |
| inline

Definition at line 372 of file connection.hpp.

## ◆ init_next_timeout_checking()

template<typename Traits >

void restinio::impl::connection_t< Traits >::init_next_timeout_checking | ( |  | ) |
| inline private

Schedule next timeout checking.

Definition at line 1570 of file connection.hpp.

## ◆ init_write()

template<typename Traits >

void restinio::impl::connection_t< Traits >::init_write | ( |  | ) |
| inline private

Initiate write operation.

Definition at line 990 of file connection.hpp.

## ◆ init_write_if_necessary()

template<typename Traits >

void restinio::impl::connection_t< Traits >::init_write_if_necessary | ( |  | ) |
| inline private

Definition at line 978 of file connection.hpp.

## ◆ move_upgrade_internals()

template<typename Traits >

upgrade_internals_t restinio::impl::connection_t< Traits >::move_upgrade_internals | ( |  | ) |
| inline

Move socket out of connection.

Definition at line 462 of file connection.hpp.

## ◆ on_request_message_complete()

template<typename Traits >

void restinio::impl::connection_t< Traits >::on_request_message_complete | ( |  | ) |
| inline private

Handle a given request message.

Definition at line 626 of file connection.hpp.

## ◆ operator=() [1/2]

template<typename Traits >

connection_t & restinio::impl::connection_t< Traits >::operator= | ( | connection_t< Traits > && |  | ) |
| delete

## ◆ operator=() [2/2]

template<typename Traits >

connection_t & restinio::impl::connection_t< Traits >::operator= | ( | const connection_t< Traits > & |  | ) |
| delete

## ◆ schedule_operation_timeout_callback() [1/2]

template<typename Traits >

void restinio::impl::connection_t< Traits >::schedule_operation_timeout_callback | ( | std::chrono::steady_clock::duration | timeout,
|  | timout_cb_t | timout_cb
| ) |  |
| inline private

Definition at line 1594 of file connection.hpp.

## ◆ schedule_operation_timeout_callback() [2/2]

template<typename Traits >

void restinio::impl::connection_t< Traits >::schedule_operation_timeout_callback | ( | std::chrono::steady_clock::time_point | timeout_after,
|  | timout_cb_t | timout_cb
| ) |  |
| inline private

Helper function to work with timer guard.

Definition at line 1585 of file connection.hpp.

## ◆ trigger_error_and_close()

template<typename Traits >
template<typename Message_Builder >

void restinio::impl::connection_t< Traits >::trigger_error_and_close | ( | Message_Builder | msg_builder | ) |
| inline private noexcept

Trigger an error.

Closes the connection and write to log an error message.

Definition at line 1469 of file connection.hpp.

## ◆ wait_for_http_message()

template<typename Traits >

void restinio::impl::connection_t< Traits >::wait_for_http_message | ( |  | ) |
| inline

Start reading next htttp-message.

Definition at line 409 of file connection.hpp.

## ◆ write_response_parts()

template<typename Traits >

virtual void restinio::impl::connection_t< Traits >::write_response_parts | ( | request_id_t | request_id,
|  | response_output_flags_t | response_output_flags,
|  | write_group_t | wg
| ) |  |
| inline override private virtual

Write parts for specified request.

Run write message on io_context loop if possible.

Parameters

  request_id | Request id.
  response_output_flags | Resp output flag.
  wg | Part of the response data.

Implements restinio::impl::connection_base_t.

Definition at line 846 of file connection.hpp.

## ◆ write_response_parts_impl()

template<typename Traits >

void restinio::impl::connection_t< Traits >::write_response_parts_impl | ( | request_id_t | request_id,
|  | response_output_flags_t | response_output_flags,
|  | write_group_t | wg
| ) |  |
| inline private

Write parts for specified request.

Parameters

  request_id | Request id.
  response_output_flags | Resp output flag.
  wg | Part of the response data.

Definition at line 886 of file connection.hpp.

## Member Data Documentation

## ◆ m_current_timeout_after

template<typename Traits >

std::chrono::steady_clock::time_point restinio::impl::connection_t< Traits >::m_current_timeout_after
| private

Timeout point of a current guarded operation.

Definition at line 1547 of file connection.hpp.

## ◆ m_current_timeout_cb

template<typename Traits >

timout_cb_t restinio::impl::connection_t< Traits >::m_current_timeout_cb { nullptr }
| private

Callback to all if timeout happened.

Definition at line 1544 of file connection.hpp.

## ◆ m_init_read_after_this_write

template<typename Traits >

bool restinio::impl::connection_t< Traits >::m_init_read_after_this_write { false }
| private

Definition at line 1496 of file connection.hpp.

## ◆ m_input

template<typename Traits >

connection_input_t restinio::impl::connection_t< Traits >::m_input
| private

Input routine.

Definition at line 1490 of file connection.hpp.

## ◆ m_lifetime_monitor

template<typename Traits >

lifetime_monitor_t restinio::impl::connection_t< Traits >::m_lifetime_monitor
| private

Monitor of the connection lifetime.

It's required for controlling the count of active parallel connections.

Since
  v.0.6.12

Definition at line 1699 of file connection.hpp.

## ◆ m_logger

template<typename Traits >

logger_t& restinio::impl::connection_t< Traits >::m_logger
| private

Logger for operation.

Definition at line 1689 of file connection.hpp.

## ◆ m_prepared_weak_ctx

template<typename Traits >

tcp_connection_ctx_weak_handle_t restinio::impl::connection_t< Traits >::m_prepared_weak_ctx
| private

A prepared weak handle for passing it to timer guard.

Definition at line 1551 of file connection.hpp.

## ◆ m_remote_endpoint

template<typename Traits >

const endpoint_t restinio::impl::connection_t< Traits >::m_remote_endpoint
| private

Remote endpoint for this connection.

Definition at line 1487 of file connection.hpp.

## ◆ m_request_handler

template<typename Traits >

request_handler_t& restinio::impl::connection_t< Traits >::m_request_handler
| private

Request handler.

Definition at line 1686 of file connection.hpp.

## ◆ m_response_coordinator

template<typename Traits >

response_coordinator_t restinio::impl::connection_t< Traits >::m_response_coordinator
| private

Response coordinator.

Definition at line 1499 of file connection.hpp.

## ◆ m_settings

template<typename Traits >

connection_settings_handle_t< Traits > restinio::impl::connection_t< Traits >::m_settings
| private

Common paramaters of a connection.

Definition at line 1484 of file connection.hpp.

## ◆ m_socket

template<typename Traits >

stream_socket_t restinio::impl::connection_t< Traits >::m_socket
| private

Connection.

Definition at line 1481 of file connection.hpp.

## ◆ m_timer_guard

template<typename Traits >

timer_guard_t restinio::impl::connection_t< Traits >::m_timer_guard
| private

Timer guard.

Definition at line 1549 of file connection.hpp.

## ◆ m_write_output_ctx

template<typename Traits >

write_group_output_ctx_t restinio::impl::connection_t< Traits >::m_write_output_ctx
| private

Write to socket operation context.

Definition at line 1493 of file connection.hpp.

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

- restinio/impl/connection.hpp