WebSocket++  0.8.0-dev
C++ websocket client/server library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
endpoint_impl.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_ENDPOINT_IMPL_HPP
29 #define WEBSOCKETPP_ENDPOINT_IMPL_HPP
30 
31 #include <string>
32 
33 namespace websocketpp {
34 
35 template <typename connection, typename config>
38  m_alog->write(log::alevel::devel,"create_connection");
39  //scoped_lock_type lock(m_state_lock);
40 
41  /*if (m_state == STOPPING || m_state == STOPPED) {
42  return connection_ptr();
43  }*/
44 
45  //scoped_lock_type guard(m_mutex);
46  // Create a connection on the heap and manage it using a shared pointer
49 
51 
52  // Create a weak pointer on the heap using that shared_ptr.
53  // Cast that weak pointer to void* and manage it using another shared_ptr
54  // connection_hdl hdl(reinterpret_cast<void*>(new connection_weak_ptr(con)));
55 
56  con->set_handle(w);
57 
58  // Copy default handlers from the endpoint
69 
72  }
75  }
78  }
81  }
83 
84  lib::error_code ec;
85 
87  if (ec) {
89  return connection_ptr();
90  }
91 
92  return con;
93 }
94 
95 template <typename connection, typename config>
97 {
99  if (ec) {return;}
100 
101  m_alog->write(log::alevel::devel,"Interrupting connection");
102 
103  ec = con->interrupt();
104 }
105 
106 template <typename connection, typename config>
108  lib::error_code ec;
109  interrupt(hdl,ec);
110  if (ec) { throw exception(ec); }
111 }
112 
113 template <typename connection, typename config>
115 {
117  if (ec) {return;}
118 
119  ec = con->pause_reading();
120 }
121 
122 template <typename connection, typename config>
124  lib::error_code ec;
126  if (ec) { throw exception(ec); }
127 }
128 
129 template <typename connection, typename config>
131 {
133  if (ec) {return;}
134 
135  ec = con->resume_reading();
136 }
137 
138 template <typename connection, typename config>
140  lib::error_code ec;
142  if (ec) { throw exception(ec); }
143 }
144 
145 template <typename connection, typename config>
147  lib::error_code & ec)
148 {
150  if (ec) {return;}
152 }
153 
154 template <typename connection, typename config>
156  lib::error_code ec;
158  if (ec) { throw exception(ec); }
159 }
160 
161 template <typename connection, typename config>
164 {
166  if (ec) {return;}
167 
168  ec = con->send(payload,op);
169 }
170 
171 template <typename connection, typename config>
173  frame::opcode::value op)
174 {
175  lib::error_code ec;
176  send(hdl,payload,op,ec);
177  if (ec) { throw exception(ec); }
178 }
179 
180 template <typename connection, typename config>
183 {
185  if (ec) {return;}
186  ec = con->send(payload,len,op);
187 }
188 
189 template <typename connection, typename config>
192 {
193  lib::error_code ec;
194  send(hdl,payload,len,op,ec);
195  if (ec) { throw exception(ec); }
196 }
197 
198 template <typename connection, typename config>
200  lib::error_code & ec)
201 {
203  if (ec) {return;}
204  ec = con->send(msg);
205 }
206 
207 template <typename connection, typename config>
209  lib::error_code ec;
210  send(hdl,msg,ec);
211  if (ec) { throw exception(ec); }
212 }
213 
214 template <typename connection, typename config>
216  const code, std::string const & reason,
217  lib::error_code & ec)
218 {
220  if (ec) {return;}
221  con->close(code,reason,ec);
222 }
223 
224 template <typename connection, typename config>
226  const code, std::string const & reason)
227 {
228  lib::error_code ec;
230  if (ec) { throw exception(ec); }
231 }
232 
233 template <typename connection, typename config>
235  payload, lib::error_code & ec)
236 {
238  if (ec) {return;}
239  con->ping(payload,ec);
240 }
241 
242 template <typename connection, typename config>
244 {
245  lib::error_code ec;
246  ping(hdl,payload,ec);
247  if (ec) { throw exception(ec); }
248 }
249 
250 template <typename connection, typename config>
252  lib::error_code & ec)
253 {
255  if (ec) {return;}
256  con->pong(payload,ec);
257 }
258 
259 template <typename connection, typename config>
261 {
262  lib::error_code ec;
263  pong(hdl,payload,ec);
264  if (ec) { throw exception(ec); }
265 }
266 
267 } // namespace websocketpp
268 
269 #endif // WEBSOCKETPP_ENDPOINT_IMPL_HPP
void handle_accept(connection_ptr con, lib::error_code const &ec)
Handler callback for start_accept.