NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
endpoint.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, 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 //#define BOOST_TEST_DYN_LINK
28 #define BOOST_TEST_MODULE endpoint
29 #include <boost/test/unit_test.hpp>
30 
31 #include <iostream>
32 #include <sstream>
33 
35 #include <websocketpp/server.hpp>
36 
37 BOOST_AUTO_TEST_CASE( construct_server_iostream ) {
39 }
40 
41 BOOST_AUTO_TEST_CASE( construct_server_asio_plain ) {
43 }
44 
45 BOOST_AUTO_TEST_CASE( construct_server_asio_tls ) {
47 }
48 
49 BOOST_AUTO_TEST_CASE( initialize_server_asio ) {
51  s.init_asio();
52 }
53 
54 BOOST_AUTO_TEST_CASE( initialize_server_asio_external ) {
56  boost::asio::io_service ios;
57  s.init_asio(&ios);
58 }
59 
60 #ifdef _WEBSOCKETPP_MOVE_SEMANTICS_
61 BOOST_AUTO_TEST_CASE( move_construct_server_core ) {
63 
65 }
66 
67 /*
68 // temporary disable because library doesn't pass
69 BOOST_AUTO_TEST_CASE( emplace ) {
70  std::stringstream out1;
71  std::stringstream out2;
72 
73  std::vector<websocketpp::server<websocketpp::config::asio_tls>> v;
74 
75  v.emplace_back();
76  v.emplace_back();
77 
78  v[0].get_alog().set_ostream(&out1);
79  v[0].get_alog().set_ostream(&out2);
80 
81  v[0].get_alog().write(websocketpp::log::alevel::app,"devel0");
82  v[1].get_alog().write(websocketpp::log::alevel::app,"devel1");
83  BOOST_CHECK( out1.str().size() > 0 );
84  BOOST_CHECK( out2.str().size() > 0 );
85 }*/
86 
87 #endif // _WEBSOCKETPP_MOVE_SEMANTICS_
88 
91 
93  return extension_value;
94  }
95 
96  bool is_server() const {
97  return false;
98  }
99 
101 };
102 
103 struct stub_config : public websocketpp::config::core {
104  typedef core::concurrency_type concurrency_type;
105 
106  typedef core::request_type request_type;
107  typedef core::response_type response_type;
108 
109  typedef core::message_type message_type;
111  typedef core::endpoint_msg_manager_type endpoint_msg_manager_type;
112 
113  typedef core::alog_type alog_type;
114  typedef core::elog_type elog_type;
115 
116  typedef core::rng_type rng_type;
117 
118  typedef core::transport_type transport_type;
119 
121 };
122 
123 BOOST_AUTO_TEST_CASE( endpoint_extensions ) {
125 
126  BOOST_CHECK_EQUAL( s.extension_value, 5 );
127  BOOST_CHECK_EQUAL( s.extension_method(), 5 );
128 
129  BOOST_CHECK( s.is_server() );
130 }
131 
132 BOOST_AUTO_TEST_CASE( listen_after_listen_failure ) {
135 
138 
139  websocketpp::lib::error_code ec;
140 
141  server1.init_asio();
142  server2.init_asio();
143 
144  boost::asio::ip::tcp::endpoint ep1(boost::asio::ip::address::from_string("127.0.0.1"), 12345);
145  boost::asio::ip::tcp::endpoint ep2(boost::asio::ip::address::from_string("127.0.0.1"), 23456);
146 
147  server1.listen(ep1, ec);
148  BOOST_CHECK(!ec);
149 
150  server2.listen(ep1, ec);
151  BOOST_REQUIRE_EQUAL(ec, make_error_code(pass_through));
152 
153  server2.listen(ep2, ec);
154  BOOST_CHECK(!ec);
155 }
lib::error_code make_error_code(error::value e)
Definition: error.hpp:235
bool is_server() const
Returns whether or not this endpoint is a server.
Definition: endpoint.hpp:205
core::con_msg_manager_type con_msg_manager_type
Definition: endpoint.cpp:110
lib::error_code make_error_code(error::value e)
Create an error code with the given value and the asio transport category.
Definition: base.hpp:217
core::message_type message_type
Definition: endpoint.cpp:109
int extension_method()
Definition: endpoint.cpp:92
core::rng_type rng_type
Definition: endpoint.cpp:116
core::transport_type transport_type
Definition: endpoint.cpp:118
stub_config::con_msg_manager_type con_msg_manager_type
Definition: hybi13.cpp:89
core::elog_type elog_type
Definition: endpoint.cpp:114
void init_asio(io_service_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_service (exception free)
Definition: endpoint.hpp:181
core::endpoint_msg_manager_type endpoint_msg_manager_type
Definition: endpoint.cpp:111
bool is_server() const
Definition: endpoint.cpp:96
BOOST_AUTO_TEST_CASE(construct_server_iostream)
Definition: endpoint.cpp:37
Server endpoint role based on the given config.
there was an error in the underlying transport library
Definition: base.hpp:171
core::alog_type alog_type
Definition: endpoint.cpp:113
core::concurrency_type concurrency_type
Definition: endpoint.cpp:104
core::request_type request_type
Definition: endpoint.cpp:106
endpoint_extension endpoint_base
Definition: endpoint.cpp:120
core::response_type response_type
Definition: endpoint.cpp:107
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free)
Definition: endpoint.hpp:391
Server config with iostream transport.
Definition: core.hpp:67