websocketpp  0.4.0
C++/Boost Asio based websocket client/server library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
connection.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_TRANSPORT_STUB_CON_HPP
29 #define WEBSOCKETPP_TRANSPORT_STUB_CON_HPP
30 
31 #include <websocketpp/common/connection_hdl.hpp>
32 #include <websocketpp/common/memory.hpp>
33 #include <websocketpp/common/platforms.hpp>
34 #include <websocketpp/logger/levels.hpp>
35 
36 #include <websocketpp/transport/base/connection.hpp>
37 #include <websocketpp/transport/stub/base.hpp>
38 
39 namespace websocketpp {
40 namespace transport {
41 namespace stub {
42 
45 struct timer {
46  void cancel() {}
47 };
48 
49 template <typename config>
50 class connection : public lib::enable_shared_from_this< connection<config> > {
51 public:
55  typedef lib::shared_ptr<type> ptr;
56 
58  typedef typename config::concurrency_type concurrency_type;
60  typedef typename config::alog_type alog_type;
62  typedef typename config::elog_type elog_type;
63 
64  // Concurrency policy types
65  typedef typename concurrency_type::scoped_lock_type scoped_lock_type;
66  typedef typename concurrency_type::mutex_type mutex_type;
67 
68  typedef lib::shared_ptr<timer> timer_ptr;
69 
70  explicit connection(bool is_server, alog_type & alog, elog_type & elog)
71  {
72  m_alog.write(log::alevel::devel,"stub con transport constructor");
73  }
74 
76  ptr get_shared() {
77  return type::shared_from_this();
78  }
79 
81 
88  void set_secure(bool value) {}
89 
91 
96  bool is_secure() const {
97  return false;
98  }
99 
101 
114  void set_remote_endpoint(std::string value) {}
115 
117 
125  std::string get_remote_endpoint() const {
126  return "unknown (stub transport)";
127  }
128 
130 
134  return connection_hdl();
135  }
136 
138 
147  timer_ptr set_timer(long duration, timer_handler handler) {
148  return timer_ptr();
149  }
150 protected:
152 
157  void init(init_handler handler) {
158  m_alog.write(log::alevel::devel,"stub connection init");
159  handler(make_error_code(error::not_implimented));
160  }
161 
163 
186  void async_read_at_least(size_t num_bytes, char *buf, size_t len,
187  read_handler handler)
188  {
189  m_alog.write(log::alevel::devel, "stub_con async_read_at_least");
190  handler(make_error_code(error::not_implimented));
191  }
192 
194 
205  void async_write(char const * buf, size_t len, write_handler handler) {
206  m_alog.write(log::alevel::devel,"stub_con async_write");
207  handler(make_error_code(error::not_implimented));
208  }
209 
211 
221  void async_write(std::vector<buffer> const & bufs, write_handler handler) {
222  m_alog.write(log::alevel::devel,"stub_con async_write buffer list");
223  handler(make_error_code(error::not_implimented));
224  }
225 
227 
231 
233 
243  lib::error_code dispatch(dispatch_handler handler) {
244  handler();
245  return lib::error_code();
246  }
247 
249 
253  handler(lib::error_code());
254  }
255 private:
256  // member variables!
257 };
258 
259 
260 } // namespace stub
261 } // namespace transport
262 } // namespace websocketpp
263 
264 #endif // WEBSOCKETPP_TRANSPORT_STUB_CON_HPP
config::concurrency_type concurrency_type
transport concurrency policy
Definition: connection.hpp:58
uint16_t value
The type of a close code value.
Definition: close.hpp:49
connection_hdl get_handle() const
Get the connection handle.
Definition: connection.hpp:133
void async_write(std::vector< buffer > const &bufs, write_handler handler)
Asyncronous Transport Write (scatter-gather)
Definition: connection.hpp:221
void async_read_at_least(size_t num_bytes, char *buf, size_t len, read_handler handler)
Initiate an async_read for at least num_bytes bytes into buf.
Definition: connection.hpp:186
lib::error_code dispatch(dispatch_handler handler)
Call given handler back within the transport's event system (if present)
Definition: connection.hpp:243
bool is_secure() const
Tests whether or not the underlying transport is secure.
Definition: connection.hpp:96
lib::function< void(lib::error_code const &)> write_handler
The type and signature of the callback passed to the write method.
Definition: connection.hpp:122
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
lib::function< void(lib::error_code const &, size_t)> read_handler
The type and signature of the callback passed to the read method.
Definition: connection.hpp:119
void set_secure(bool value)
Set whether or not this connection is secure.
Definition: connection.hpp:88
static level const devel
Development messages (warning: very chatty)
Definition: levels.hpp:141
void set_handle(connection_hdl hdl)
Set Connection Handle.
Definition: connection.hpp:230
void async_write(char const *buf, size_t len, write_handler handler)
Asyncronous Transport Write.
Definition: connection.hpp:205
void set_remote_endpoint(std::string value)
Set human readable remote endpoint address.
Definition: connection.hpp:114
lib::function< void()> dispatch_handler
The type and signature of the callback passed to the dispatch method.
Definition: connection.hpp:134
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
Definition: connection.hpp:55
lib::function< void(lib::error_code const &)> timer_handler
The type and signature of the callback passed to the read method.
Definition: connection.hpp:125
lib::function< void(lib::error_code const &)> shutdown_handler
The type and signature of the callback passed to the shutdown method.
Definition: connection.hpp:128
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
ptr get_shared()
Get a shared pointer to this component.
Definition: connection.hpp:76
connection< config > type
Type of this connection transport component.
Definition: connection.hpp:53
void init(init_handler handler)
Initialize the connection transport.
Definition: connection.hpp:157
timer_ptr set_timer(long duration, timer_handler handler)
Call back a function after a period of time.
Definition: connection.hpp:147
config::elog_type elog_type
Type of this transport's error logging policy.
Definition: connection.hpp:62
config::alog_type alog_type
Type of this transport's access logging policy.
Definition: connection.hpp:60
std::string get_remote_endpoint() const
Get human readable remote endpoint address.
Definition: connection.hpp:125
void async_shutdown(shutdown_handler handler)
Perform cleanup on socket shutdown_handler.
Definition: connection.hpp:252