WebSocket++  0.7.0
C++ websocket client/server library
core.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_CORE_HPP
29 #define WEBSOCKETPP_CONFIG_CORE_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/basic.hpp>
38 
39 // Transport
40 #include <websocketpp/transport/iostream/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/basic.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 
63 namespace websocketpp {
64 namespace config {
65 
66 /// Server config with iostream transport
67 struct core {
68  typedef core type;
69 
70  // Concurrency policy
71  typedef websocketpp::concurrency::basic concurrency_type;
72 
73  // HTTP Parser Policies
74  typedef http::parser::request request_type;
75  typedef http::parser::response response_type;
76 
77  // Message Policies
78  typedef message_buffer::message<message_buffer::alloc::con_msg_manager>
79  message_type;
80  typedef message_buffer::alloc::con_msg_manager<message_type>
81  con_msg_manager_type;
82  typedef message_buffer::alloc::endpoint_msg_manager<con_msg_manager_type>
83  endpoint_msg_manager_type;
84 
85  /// Logging policies
88  typedef websocketpp::log::basic<concurrency_type,
89  websocketpp::log::alevel> alog_type;
90 
91  /// RNG policies
93 
94  /// Controls compile time enabling/disabling of thread syncronization
95  /// code Disabling can provide a minor performance improvement to single
96  /// threaded applications
97  static bool const enable_multithreading = true;
98 
100  typedef type::concurrency_type concurrency_type;
101  typedef type::elog_type elog_type;
102  typedef type::alog_type alog_type;
103  typedef type::request_type request_type;
104  typedef type::response_type response_type;
105 
106  /// Controls compile time enabling/disabling of thread syncronization
107  /// code Disabling can provide a minor performance improvement to single
108  /// threaded applications
109  static bool const enable_multithreading = true;
110 
111  /// Default timer values (in ms)
112 
113  /// Length of time to wait for socket pre-initialization
114  /**
115  * Exactly what this includes depends on the socket policy in use
116  */
117  static const long timeout_socket_pre_init = 5000;
118 
119  /// Length of time to wait before a proxy handshake is aborted
120  static const long timeout_proxy = 5000;
121 
122  /// Length of time to wait for socket post-initialization
123  /**
124  * Exactly what this includes depends on the socket policy in use.
125  * Often this means the TLS handshake
126  */
127  static const long timeout_socket_post_init = 5000;
128 
129  /// Length of time to wait for dns resolution
130  static const long timeout_dns_resolve = 5000;
131 
132  /// Length of time to wait for TCP connect
133  static const long timeout_connect = 5000;
134 
135  /// Length of time to wait for socket shutdown
136  static const long timeout_socket_shutdown = 5000;
137  };
138 
139  /// Transport Endpoint Component
142 
143  /// User overridable Endpoint base class
145  /// User overridable Connection base class
147 
148  /// Default timer values (in ms)
149 
150  /// Length of time before an opening handshake is aborted
151  static const long timeout_open_handshake = 5000;
152  /// Length of time before a closing handshake is aborted
153  static const long timeout_close_handshake = 5000;
154  /// Length of time to wait for a pong after a ping
155  static const long timeout_pong = 5000;
156 
157  /// WebSocket Protocol version to use as a client
158  /**
159  * What version of the WebSocket Protocol to use for outgoing client
160  * connections. Setting this to a value other than 13 (RFC6455) is not
161  * recommended.
162  */
163  static const int client_version = 13; // RFC6455
164 
165  /// Default static error logging channels
166  /**
167  * Which error logging channels to enable at compile time. Channels not
168  * enabled here will be unable to be selected by programs using the library.
169  * This option gives an optimizing compiler the ability to remove entirely
170  * code to test whether or not to print out log messages on a certain
171  * channel
172  *
173  * Default is all except for development/debug level errors
174  */
175  static const websocketpp::log::level elog_level =
177 
178  /// Default static access logging channels
179  /**
180  * Which access logging channels to enable at compile time. Channels not
181  * enabled here will be unable to be selected by programs using the library.
182  * This option gives an optimizing compiler the ability to remove entirely
183  * code to test whether or not to print out log messages on a certain
184  * channel
185  *
186  * Default is all except for development/debug level access messages
187  */
188  static const websocketpp::log::level alog_level =
190 
191  ///
192  static const size_t connection_read_buffer_size = 16384;
193 
194  /// Drop connections immediately on protocol error.
195  /**
196  * Drop connections on protocol error rather than sending a close frame.
197  * Off by default. This may result in legit messages near the error being
198  * dropped as well. It may free up resources otherwise spent dealing with
199  * misbehaving clients.
200  */
201  static const bool drop_on_protocol_error = false;
202 
203  /// Suppresses the return of detailed connection close information
204  /**
205  * Silence close suppresses the return of detailed connection close
206  * information during the closing handshake. This information is useful
207  * for debugging and presenting useful errors to end users but may be
208  * undesirable for security reasons in some production environments.
209  * Close reasons could be used by an attacker to confirm that the endpoint
210  * is out of resources or be used to identify the WebSocket implementation
211  * in use.
212  *
213  * Note: this will suppress *all* close codes, including those explicitly
214  * sent by local applications.
215  */
216  static const bool silent_close = false;
217 
218  /// Default maximum message size
219  /**
220  * Default value for the processor's maximum message size. Maximum message size
221  * determines the point at which the library will fail a connection with the
222  * message_too_big protocol error.
223  *
224  * The default is 32MB
225  *
226  * @since 0.3.0
227  */
228  static const size_t max_message_size = 32000000;
229 
230  /// Default maximum http body size
231  /**
232  * Default value for the http parser's maximum body size. Maximum body size
233  * determines the point at which the library will abort reading an HTTP
234  * connection with the 413/request entity too large error.
235  *
236  * The default is 32MB
237  *
238  * @since 0.5.0
239  */
240  static const size_t max_http_body_size = 32000000;
241 
242  /// Global flag for enabling/disabling extensions
243  static const bool enable_extensions = true;
244 
245  /// Extension specific settings:
246 
247  /// permessage_compress extension
249  typedef core::request_type request_type;
250 
251  /// If the remote endpoint requests that we reset the compression
252  /// context after each message should we honor the request?
253  static const bool allow_disabling_context_takeover = true;
254 
255  /// If the remote endpoint requests that we reduce the size of the
256  /// LZ77 sliding window size this is the lowest value that will be
257  /// allowed. Values range from 8 to 15. A value of 8 means we will
258  /// allow any possible window size. A value of 15 means do not allow
259  /// negotiation of the window size (ie require the default).
261  };
262 
263  typedef websocketpp::extensions::permessage_deflate::disabled
264  <permessage_deflate_config> permessage_deflate_type;
265 
266  /// Autonegotiate permessage-deflate
267  /**
268  * Automatically enables the permessage-deflate extension.
269  *
270  * For clients this results in a permessage-deflate extension request being
271  * sent with every request rather than requiring it to be requested manually
272  *
273  * For servers this results in accepting the first set of extension settings
274  * requested by the client that we understand being used. The alternative is
275  * requiring the extension to be manually negotiated in `validate`. With
276  * auto-negotiate on, you may still override the auto-negotiate manually if
277  * needed.
278  */
279  //static const bool autonegotiate_compression = false;
280 };
281 
282 } // namespace config
283 } // namespace websocketpp
284 
285 #endif // WEBSOCKETPP_CONFIG_CORE_HPP
static bool const enable_multithreading
Definition: core.hpp:97
static const size_t max_http_body_size
Default maximum http body size.
Definition: core.hpp:240
static const long timeout_pong
Length of time to wait for a pong after a ping.
Definition: core.hpp:155
static const bool enable_extensions
Global flag for enabling/disabling extensions.
Definition: core.hpp:243
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
Definition: core.hpp:92
static const long timeout_socket_pre_init
Default timer values (in ms)
Definition: core.hpp:117
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
Definition: core.hpp:153
websocketpp::connection_base connection_base
User overridable Connection base class.
Definition: core.hpp:146
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
Definition: core.hpp:120
websocketpp::log::basic< concurrency_type, websocketpp::log::elevel > elog_type
Logging policies.
Definition: core.hpp:87
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
Definition: core.hpp:127
websocketpp::transport::iostream::endpoint< transport_config > transport_type
Transport Endpoint Component.
Definition: core.hpp:141
static const long timeout_open_handshake
Default timer values (in ms)
Definition: core.hpp:151
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
Definition: core.hpp:201
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
Definition: core.hpp:130
void handle_accept(connection_ptr con, lib::error_code const &ec)
Handler callback for start_accept.
static const bool silent_close
Suppresses the return of detailed connection close information.
Definition: core.hpp:216
static const int client_version
WebSocket Protocol version to use as a client.
Definition: core.hpp:163
static const websocketpp::log::level elog_level
Default static error logging channels.
Definition: core.hpp:175
static const websocketpp::log::level alog_level
Default static access logging channels.
Definition: core.hpp:188
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
Definition: core.hpp:136
websocketpp::endpoint_base endpoint_base
User overridable Endpoint base class.
Definition: core.hpp:144
static const long timeout_connect
Length of time to wait for TCP connect.
Definition: core.hpp:133
Server config with iostream transport.
Definition: core.hpp:67
static const size_t max_message_size
Default maximum message size.
Definition: core.hpp:228