websocketpp  0.3.0
C++/Boost Asio based websocket client/server library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
base.hpp
1 /*
2  * Copyright (c) 2013, 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_TRANSPORT_ASIO_SOCKET_BASE_HPP
29 #define WEBSOCKETPP_TRANSPORT_ASIO_SOCKET_BASE_HPP
30 
31 #include <websocketpp/common/memory.hpp>
32 #include <websocketpp/common/functional.hpp>
33 #include <websocketpp/common/system_error.hpp>
34 #include <websocketpp/common/cpp11.hpp>
35 #include <websocketpp/common/connection_hdl.hpp>
36 
37 #include <boost/asio.hpp>
38 
39 #include <iostream>
40 #include <string>
41 
42 // Interface that sockets/security policies must implement
43 
44 /*
45  * Endpoint Interface
46  *
47  * bool is_secure() const;
48  * @return Whether or not the endpoint creates secure connections
49  *
50  * lib::error_code init(socket_con_ptr scon);
51  * Called by the transport after a new connection is created to initialize
52  * the socket component of the connection.
53  * @param scon Pointer to the socket component of the connection
54  * @return Error code (empty on success)
55  */
56 
57 
58 // Connection
59 // TODO
60 // pre_init(init_handler);
61 // post_init(init_handler);
62 
63 namespace websocketpp {
64 namespace transport {
65 namespace asio {
66 namespace socket {
67 
73 namespace error {
75  enum value {
78  security = 1,
79 
83 
86 
90 
93 
96 
99 
102  };
103 } // namespace error
104 
106 class socket_category : public lib::error_category {
107 public:
108  const char *name() const _WEBSOCKETPP_NOEXCEPT_TOKEN_ {
109  return "websocketpp.transport.asio.socket";
110  }
111 
112  std::string message(int value) const {
113  switch(value) {
114  case error::security:
115  return "Security policy error";
116  case error::socket:
117  return "Socket component error";
119  return "Invalid state";
121  return "Invalid or empty TLS context supplied";
123  return "TLS handshake timed out";
124  case error::pass_through:
125  return "Pass through from socket policy";
127  return "Required tls_init handler not present.";
129  return "TLS handshake failed";
130  default:
131  return "Unknown";
132  }
133  }
134 };
135 
136 inline const lib::error_category& get_socket_category() {
137  static socket_category instance;
138  return instance;
139 }
140 
141 inline lib::error_code make_error_code(error::value e) {
142  return lib::error_code(static_cast<int>(e), get_socket_category());
143 }
144 
146 typedef lib::function<void(const lib::error_code&)> init_handler;
147 
148 } // namespace socket
149 } // namespace asio
150 } // namespace transport
151 } // namespace websocketpp
152 
153 #endif // WEBSOCKETPP_TRANSPORT_ASIO_SOCKET_BASE_HPP
uint16_t value
The type of a close code value.
Definition: close.hpp:49
Error category related to asio transport socket policies.
Definition: base.hpp:106
pass_through from underlying library
Definition: base.hpp:95
A function was called in a state that it was illegal to do so.
Definition: base.hpp:85
Namespace for the WebSocket++ project.
Definition: base64.hpp:41
lib::function< void(lib::error_code const &)> init_handler
The type and signature of the callback passed to the init hook.
Definition: connection.hpp:116