WebSocket++ 0.8.2
C++ websocket client/server library
minimal_server.hpp
1/*
2 * Copyright (c) 2014, Peter Thorson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28#ifndef WEBSOCKETPP_CONFIG_MINIMAL_HPP
29#define WEBSOCKETPP_CONFIG_MINIMAL_HPP
30
31// Non-Policy common stuff
32#include <websocketpp/common/platforms.hpp>
33#include <websocketpp/common/cpp11.hpp>
34#include <websocketpp/common/stdint.hpp>
35
36// Concurrency
37#include <websocketpp/concurrency/none.hpp>
38
39// Transport
40#include <websocketpp/transport/stub/endpoint.hpp>
41
42// HTTP
43#include <websocketpp/http/request.hpp>
44#include <websocketpp/http/response.hpp>
45
46// Messages
47#include <websocketpp/message_buffer/message.hpp>
48#include <websocketpp/message_buffer/alloc.hpp>
49
50// Loggers
51#include <websocketpp/logger/stub.hpp>
52
53// RNG
54#include <websocketpp/random/none.hpp>
55
56// User stub base classes
57#include <websocketpp/endpoint_base.hpp>
58#include <websocketpp/connection_base.hpp>
59
60// Extensions
61#include <websocketpp/extensions/permessage_deflate/disabled.hpp>
62
63namespace websocketpp {
64namespace config {
65
66/// Server config with minimal dependencies
67/**
68 * This config strips out as many dependencies as possible. It is suitable for
69 * use as a base class for custom configs that want to implement or choose their
70 * own policies for components that even the core config includes.
71 *
72 * NOTE: this config stubs out enough that it cannot be used directly. You must
73 * supply at least a transport policy for a config based on `minimal_server` to
74 * do anything useful.
75 *
76 * Present dependency list for minimal_server config:
77 *
78 * C++98 STL:
79 * <algorithm>
80 * <map>
81 * <sstream>
82 * <string>
83 * <vector>
84 *
85 * C++11 STL or Boost
86 * <memory>
87 * <functional>
88 * <system_error>
89 *
90 * Operating System:
91 * <stdint.h> or <boost/cstdint.hpp>
92 * <netinet/in.h> or <winsock2.h> (for ntohl.. could potentially bundle this)
93 *
94 * @since 0.4.0-dev
95 */
96struct minimal_server {
97 typedef minimal_server type;
98
99 // Concurrency policy
100 typedef websocketpp::concurrency::none concurrency_type;
101
102 // HTTP Parser Policies
103 typedef http::parser::request request_type;
104 typedef http::parser::response response_type;
105
106 // Message Policies
107 typedef message_buffer::message<message_buffer::alloc::con_msg_manager>
108 message_type;
109 typedef message_buffer::alloc::con_msg_manager<message_type>
110 con_msg_manager_type;
111 typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type>
112 endpoint_msg_manager_type;
113
114 /// Logging policies
115 typedef websocketpp::log::stub elog_type;
116 typedef websocketpp::log::stub alog_type;
117
118 /// RNG policies
119 typedef websocketpp::random::none::int_generator<uint32_t> rng_type;
120
121 /// Controls compile time enabling/disabling of thread syncronization
122 /// code Disabling can provide a minor performance improvement to single
123 /// threaded applications
124 static bool const enable_multithreading = true;
125
126 struct transport_config {
127 typedef type::concurrency_type concurrency_type;
128 typedef type::elog_type elog_type;
129 typedef type::alog_type alog_type;
130 typedef type::request_type request_type;
131 typedef type::response_type response_type;
132
133 /// Controls compile time enabling/disabling of thread syncronization
134 /// code Disabling can provide a minor performance improvement to single
135 /// threaded applications
136 static bool const enable_multithreading = true;
137
138 /// Default timer values (in ms)
139
140 /// Length of time to wait for socket pre-initialization
141 /**
142 * Exactly what this includes depends on the socket policy in use
143 */
144 static const long timeout_socket_pre_init = 5000;
145
146 /// Length of time to wait before a proxy handshake is aborted
147 static const long timeout_proxy = 5000;
148
149 /// Length of time to wait for socket post-initialization
150 /**
151 * Exactly what this includes depends on the socket policy in use.
152 * Often this means the TLS handshake
153 */
154 static const long timeout_socket_post_init = 5000;
155
156 /// Length of time to wait for dns resolution
157 static const long timeout_dns_resolve = 5000;
158
159 /// Length of time to wait for TCP connect
160 static const long timeout_connect = 5000;
161
162 /// Length of time to wait for socket shutdown
163 static const long timeout_socket_shutdown = 5000;
164 };
165
166 /// Transport Endpoint Component
169
170 /// User overridable Endpoint base class
171 typedef websocketpp::endpoint_base endpoint_base;
172 /// User overridable Connection base class
173 typedef websocketpp::connection_base connection_base;
174
175 /// Default timer values (in ms)
176
177 /// Length of time before an opening handshake is aborted
178 static const long timeout_open_handshake = 5000;
179 /// Length of time before a closing handshake is aborted
180 static const long timeout_close_handshake = 5000;
181 /// Length of time to wait for a pong after a ping
182 static const long timeout_pong = 5000;
183
184 /// WebSocket Protocol version to use as a client
185 /**
186 * What version of the WebSocket Protocol to use for outgoing client
187 * connections. Setting this to a value other than 13 (RFC6455) is not
188 * recommended.
189 */
190 static const int client_version = 13; // RFC6455
191
192 /// Default static error logging channels
193 /**
194 * Which error logging channels to enable at compile time. Channels not
195 * enabled here will be unable to be selected by programs using the library.
196 * This option gives an optimizing compiler the ability to remove entirely
197 * code to test whether or not to print out log messages on a certain
198 * channel
199 *
200 * Default is all except for development/debug level errors
201 */
202 static const websocketpp::log::level elog_level =
204
205 /// Default static access logging channels
206 /**
207 * Which access logging channels to enable at compile time. Channels not
208 * enabled here will be unable to be selected by programs using the library.
209 * This option gives an optimizing compiler the ability to remove entirely
210 * code to test whether or not to print out log messages on a certain
211 * channel
212 *
213 * Default is all except for development/debug level access messages
214 */
215 static const websocketpp::log::level alog_level =
217
218 ///
219 static const size_t connection_read_buffer_size = 16384;
220
221 /// Drop connections immediately on protocol error.
222 /**
223 * Drop connections on protocol error rather than sending a close frame.
224 * Off by default. This may result in legit messages near the error being
225 * dropped as well. It may free up resources otherwise spent dealing with
226 * misbehaving clients.
227 */
228 static const bool drop_on_protocol_error = false;
229
230 /// Suppresses the return of detailed connection close information
231 /**
232 * Silence close suppresses the return of detailed connection close
233 * information during the closing handshake. This information is useful
234 * for debugging and presenting useful errors to end users but may be
235 * undesirable for security reasons in some production environments.
236 * Close reasons could be used by an attacker to confirm that the endpoint
237 * is out of resources or be used to identify the WebSocket implementation
238 * in use.
239 *
240 * Note: this will suppress *all* close codes, including those explicitly
241 * sent by local applications.
242 */
243 static const bool silent_close = false;
244
245 /// Default maximum message size
246 /**
247 * Default value for the processor's maximum message size. Maximum message size
248 * determines the point at which the library will fail a connection with the
249 * message_too_big protocol error.
250 *
251 * The default is 32MB
252 *
253 * @since 0.4.0-alpha1
254 */
255 static const size_t max_message_size = 32000000;
256
257 /// Default maximum http body size
258 /**
259 * Default value for the http parser's maximum body size. Maximum body size
260 * determines the point at which the library will abort reading an HTTP
261 * connection with the 413/request entity too large error.
262 *
263 * The default is 32MB
264 *
265 * @since 0.5.0
266 */
267 static const size_t max_http_body_size = 32000000;
268
269 /// Global flag for enabling/disabling extensions
270 static const bool enable_extensions = true;
271
272 /// Extension specific settings:
273
274 /// permessage_compress extension
276 typedef core::request_type request_type;
277
278 /// If the remote endpoint requests that we reset the compression
279 /// context after each message should we honor the request?
280 static const bool allow_disabling_context_takeover = true;
281
282 /// If the remote endpoint requests that we reduce the size of the
283 /// LZ77 sliding window size this is the lowest value that will be
284 /// allowed. Values range from 8 to 15. A value of 8 means we will
285 /// allow any possible window size. A value of 15 means do not allow
286 /// negotiation of the window size (ie require the default).
287 static const uint8_t minimum_outgoing_window_bits = 8;
288 };
289
291 <permessage_deflate_config> permessage_deflate_type;
292
293 /// Autonegotiate permessage-deflate
294 /**
295 * Automatically enables the permessage-deflate extension.
296 *
297 * For clients this results in a permessage-deflate extension request being
298 * sent with every request rather than requiring it to be requested manually
299 *
300 * For servers this results in accepting the first set of extension settings
301 * requested by the client that we understand being used. The alternative is
302 * requiring the extension to be manually negotiated in `validate`. With
303 * auto-negotiate on, you may still override the auto-negotiate manually if
304 * needed.
305 */
306 //static const bool autonegotiate_compression = false;
307};
308
309} // namespace config
310} // namespace websocketpp
311
312#endif // WEBSOCKETPP_CONFIG_MINIMAL_HPP
Stub concurrency policy that implements the interface using no-ops.
Definition: none.hpp:60
Stub for user supplied base class.
Stub for user supplied base class.
Stub class for use when disabling permessage_deflate extension.
Definition: disabled.hpp:53
Stores, parses, and manipulates HTTP requests.
Definition: request.hpp:50
Stores, parses, and manipulates HTTP responses.
Definition: response.hpp:57
Stub logger that ignores all input.
Definition: stub.hpp:41
Thread safe stub "random" integer generator.
Definition: none.hpp:46
Concurrency handling support.
Definition: basic.hpp:34
Implementation of RFC 7692, the permessage-deflate WebSocket extension.
Definition: disabled.hpp:44
HTTP handling support.
Definition: request.hpp:37
Stub RNG policy that always returns 0.
Definition: none.hpp:35
Random number generation policies.
Stub transport policy that has no input or output.
Definition: base.hpp:39
Transport policies provide network connectivity and timers.
Definition: endpoint.hpp:45
Namespace for the WebSocket++ project.
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
static const long timeout_socket_pre_init
Default timer values (in ms)
static const long timeout_connect
Length of time to wait for TCP connect.
Server config with minimal dependencies.
static const int client_version
WebSocket Protocol version to use as a client.
static const bool silent_close
Suppresses the return of detailed connection close information.
static const websocketpp::log::level elog_level
Default static error logging channels.
static const size_t max_http_body_size
Default maximum http body size.
static const long timeout_open_handshake
Default timer values (in ms)
websocketpp::transport::stub::endpoint< transport_config > transport_type
Transport Endpoint Component.
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
websocketpp::log::stub elog_type
Logging policies.
static const long timeout_pong
Length of time to wait for a pong after a ping.
static const size_t max_message_size
Default maximum message size.
static const bool enable_extensions
Global flag for enabling/disabling extensions.
static const websocketpp::log::level alog_level
Default static access logging channels.
Package of log levels for logging access events.
Definition: levels.hpp:112
static level const none
Special aggregate value representing "no levels".
Definition: levels.hpp:114
Package of log levels for logging errors.
Definition: levels.hpp:59
static level const none
Special aggregate value representing "no levels".
Definition: levels.hpp:61