RESTinio

common_types.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
9#pragma once
10
11#include <cstdint>
12
13#include <restinio/asio_include.hpp>
14
15 namespace restinio
16{
17
19
25 enum class request_handling_status_t : std::uint8_t
26{
28 accepted,
29
31 rejected,
32
38 not_handled
39};
40
44 RESTINIO_NODISCARD
45 constexpr request_handling_status_t
46 request_accepted() noexcept
47{
48 return request_handling_status_t::accepted;
49}
50
51 RESTINIO_NODISCARD
52 constexpr request_handling_status_t
53 request_rejected() noexcept
54{
55 return request_handling_status_t::rejected;
56}
57
61 RESTINIO_NODISCARD
62 constexpr request_handling_status_t
63 request_not_handled() noexcept
64{
65 return request_handling_status_t::not_handled;
66}
68
70 using request_id_t = unsigned int;
71
73 enum class response_parts_attr_t : std::uint8_t
74{
76 not_final_parts,
78 final_parts
79};
80
81 inline std::ostream &
82 operator << ( std::ostream & o, response_parts_attr_t attr )
83{
84 if( response_parts_attr_t::not_final_parts == attr )
85 o << "not_final_parts";
86 else
87 o << "final_parts";
88
89 return o;
90}
91
93 enum class response_connection_attr_t : std::uint8_t
94{
96 connection_keepalive,
98 connection_close
99};
100
101 inline std::ostream &
102 operator << ( std::ostream & o, response_connection_attr_t attr )
103{
104 if( response_connection_attr_t::connection_keepalive == attr )
105 o << "connection_keepalive";
106 else
107 o << "connection_close";
108
109 return o;
110}
111
112 inline response_connection_attr_t
113 response_connection_attr( bool should_keep_alive )
114{
115 if( should_keep_alive )
116 return response_connection_attr_t::connection_keepalive;
117
118 return response_connection_attr_t::connection_close;
119}
120
122 struct response_output_flags_t
123{
124 response_output_flags_t(
125 response_parts_attr_t response_parts,
126 response_connection_attr_t response_connection ) noexcept
127 : m_response_parts{ response_parts }
128 , m_response_connection{ response_connection }
129 {}
130
131 response_parts_attr_t m_response_parts;
132 response_connection_attr_t m_response_connection;
133};
134
135 inline std::ostream &
136 operator << ( 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//
153 template< typename T >
154 using nullable_pointer_t = T*;
155
156//
157// not_null_pointer_t
158//
168 template< typename T >
169 using not_null_pointer_t = T*;
170
174 using connection_id_t = std::uint64_t;
175
177 using endpoint_t = asio_ns::ip::tcp::endpoint;
178
179} /* namespace restinio */
180
asio_include.hpp
RESTINIO_NODISCARD
#define RESTINIO_NODISCARD
Definition: compiler_features.hpp:33
restinio
Definition: asio_include.hpp:21
restinio::request_not_handled
RESTINIO_NODISCARD constexpr request_handling_status_t request_not_handled() noexcept
Definition: common_types.hpp:63
restinio::nullable_pointer_t
T * nullable_pointer_t
Type for pointer that can be nullptr.
Definition: common_types.hpp:154
restinio::request_rejected
RESTINIO_NODISCARD constexpr request_handling_status_t request_rejected() noexcept
Definition: common_types.hpp:53
restinio::not_null_pointer_t
T * not_null_pointer_t
Type for pointer that is not null by design.
Definition: common_types.hpp:169
restinio::operator<<
std::ostream & operator<<(std::ostream &o, response_parts_attr_t attr)
Definition: common_types.hpp:82
restinio::request_id_t
unsigned int request_id_t
Request id in scope of single connection.
Definition: common_types.hpp:70
restinio::response_connection_attr
response_connection_attr_t response_connection_attr(bool should_keep_alive)
Definition: common_types.hpp:113
restinio::request_handling_status_t
request_handling_status_t
Request handling status.
Definition: common_types.hpp:26
restinio::request_handling_status_t::accepted
@ accepted
Request accepted for handling.
restinio::request_handling_status_t::not_handled
@ not_handled
The request wasn't handled. If there is another handler to be tried it should be tried....
restinio::request_handling_status_t::rejected
@ rejected
Request wasn't accepted for handling.
restinio::endpoint_t
asio_ns::ip::tcp::endpoint endpoint_t
An alias for endpoint type from Asio.
Definition: common_types.hpp:177
restinio::response_connection_attr_t
response_connection_attr_t
Attribute for parts.
Definition: common_types.hpp:94
restinio::response_connection_attr_t::connection_close
@ connection_close
This response says to close connection.
restinio::response_connection_attr_t::connection_keepalive
@ connection_keepalive
This response says to keep connection.
restinio::request_accepted
RESTINIO_NODISCARD constexpr request_handling_status_t request_accepted() noexcept
Definition: common_types.hpp:46
restinio::response_parts_attr_t
response_parts_attr_t
Attribute for parts.
Definition: common_types.hpp:74
restinio::response_parts_attr_t::final_parts
@ final_parts
Final parts (response ands with these parts).
restinio::response_parts_attr_t::not_final_parts
@ not_final_parts
Intermediate parts (more parts of response to follow).
restinio::connection_id_t
std::uint64_t connection_id_t
Type for ID of connection.
Definition: common_types.hpp:174
restinio::response_output_flags_t
Response output flags for buffers commited to response-coordinator.
Definition: common_types.hpp:123
restinio::response_output_flags_t::m_response_connection
response_connection_attr_t m_response_connection
Definition: common_types.hpp:132
restinio::response_output_flags_t::m_response_parts
response_parts_attr_t m_response_parts
Definition: common_types.hpp:131
restinio::response_output_flags_t::response_output_flags_t
response_output_flags_t(response_parts_attr_t response_parts, response_connection_attr_t response_connection) noexcept
Definition: common_types.hpp:124