RESTinio
Loading...
Searching...
No Matches
common_types.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
5/*!
6 Restinio common types.
7*/
8
9#pragma once
10
11#include <cstdint>
12
13#include <restinio/asio_include.hpp>
14
15namespace restinio
16{
17
18//! Request handling status.
19/*!
20 If handler handles request it must return accepted.
21
22 If handler refuses to handle request
23 it must return rejected.
24*/
26{
27 //! Request accepted for handling.
29
30 //! Request wasn't accepted for handling.
32
33 //! The request wasn't handled. If there is another handler to
34 //! be tried it should be tried. Otherwise the request has to
35 //! be rejected.
36 //!
37 //! @since v.0.6.13.
39};
40
41//! @name Helper funcs for working with request_handling_status_t
42//! \see request_handling_status_t.
43///@{
44[[nodiscard]]
50
51[[nodiscard]]
57
58/*!
59 * @since v.0.6.13
60 */
61[[nodiscard]]
67///@}
68
69//! Request id in scope of single connection.
70using request_id_t = unsigned int;
71
72//! Attribute for parts.
74{
75 //! Intermediate parts (more parts of response to follow).
77 //! Final parts (response ands with these parts).
79};
80
81inline std::ostream &
82operator << ( std::ostream & o, response_parts_attr_t attr )
83{
85 o << "not_final_parts";
86 else
87 o << "final_parts";
88
89 return o;
90}
91
92//! Attribute for parts.
94{
95 //! This response says to keep connection.
97 //! This response says to close connection.
99};
100
101inline std::ostream &
102operator << ( std::ostream & o, response_connection_attr_t attr )
103{
105 o << "connection_keepalive";
106 else
107 o << "connection_close";
108
109 return o;
110}
111
113response_connection_attr( bool should_keep_alive )
114{
115 if( should_keep_alive )
117
119}
120
121//! Response output flags for buffers commited to response-coordinator
134
135inline std::ostream &
136operator << ( std::ostream & o, const response_output_flags_t & flags )
137{
138 return o << "{ " << flags.m_response_parts << ", "
139 << flags.m_response_connection << " }";
140}
141
142//
143// nullable_pointer_t
144//
145/*!
146 * @brief Type for pointer that can be nullptr.
147 *
148 * This type is used in methods which return raw pointers. It indicates
149 * that returned value should be checked for nullptr.
150 *
151 * @since v.0.4.9
152 */
153template< typename T >
155
156//
157// not_null_pointer_t
158//
159/*!
160 * @brief Type for pointer that is not null by design.
161 *
162 * @note
163 * There is no any compile-time or run-time checks for a value of the pointer.
164 * It is just a flag that we don't expect a nullptr here by design.
165 *
166 * @since v.0.4.9
167 */
168template< typename T >
170
171/*!
172 * @brief Type for ID of connection.
173 */
175
176//! An alias for endpoint type from Asio.
177using endpoint_t = asio_ns::ip::tcp::endpoint;
178
179} /* namespace restinio */
asio_ns::ip::tcp::endpoint endpoint_t
An alias for endpoint type from Asio.
unsigned int request_id_t
Request id in scope of single connection.
T * not_null_pointer_t
Type for pointer that is not null by design.
constexpr request_handling_status_t request_not_handled() noexcept
response_connection_attr_t response_connection_attr(bool should_keep_alive)
T * nullable_pointer_t
Type for pointer that can be nullptr.
constexpr request_handling_status_t request_accepted() noexcept
request_handling_status_t
Request handling status.
@ accepted
Request accepted for handling.
@ not_handled
The request wasn't handled. If there is another handler to be tried it should be tried....
@ rejected
Request wasn't accepted for handling.
constexpr request_handling_status_t request_rejected() noexcept
std::uint64_t connection_id_t
Type for ID of connection.
response_connection_attr_t
Attribute for parts.
@ connection_close
This response says to close connection.
@ connection_keepalive
This response says to keep connection.
response_parts_attr_t
Attribute for parts.
@ final_parts
Final parts (response ands with these parts).
@ not_final_parts
Intermediate parts (more parts of response to follow).
Response output flags for buffers commited to response-coordinator.
response_connection_attr_t m_response_connection
response_parts_attr_t m_response_parts
response_output_flags_t(response_parts_attr_t response_parts, response_connection_attr_t response_connection) noexcept