Skip to content

Commit 6867ad0

Browse files
committed
silenced warning about unused variable in TLS IP address validation, improved time-to-expiry calculation (credit toonetown), added CMake flag to compile tests and examples with ASIO standalone, fixed example and test compilation with ASIO standalone
1 parent 3d13472 commit 6867ad0

File tree

15 files changed

+82
-76
lines changed

15 files changed

+82
-76
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ include (CMakeHelpers)
7777
option (ENABLE_CPP11 "Build websocketpp with CPP11 features enabled." TRUE)
7878
option (BUILD_EXAMPLES "Build websocketpp examples." FALSE)
7979
option (BUILD_TESTS "Build websocketpp tests." FALSE)
80+
option (USE_ASIO_STANDALONE "Build websocketpp examples and tests using the standalone ASIO library." FALSE)
8081

8182
if (BUILD_TESTS OR BUILD_EXAMPLES)
8283

@@ -254,6 +255,10 @@ endif()
254255

255256
############ Add projects
256257

258+
if (USE_ASIO_STANDALONE)
259+
add_definitions("-DASIO_STANDALONE -DASIO_HAS_BOOST_DATE_TIME")
260+
endif ()
261+
257262
# Add main library
258263
add_subdirectory (websocketpp)
259264

examples/debug_client/debug_client.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ using websocketpp::lib::bind;
4343

4444
// pull out the type of messages sent by our config
4545
typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr;
46-
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
46+
typedef websocketpp::lib::shared_ptr<websocketpp::lib::asio::ssl::context> context_ptr;
4747
typedef client::connection_ptr connection_ptr;
4848

4949

@@ -93,13 +93,13 @@ class perftest {
9393

9494
context_ptr on_tls_init(websocketpp::connection_hdl) {
9595
m_tls_init = std::chrono::high_resolution_clock::now();
96-
context_ptr ctx = websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::tlsv1);
96+
context_ptr ctx = websocketpp::lib::make_shared<websocketpp::lib::asio::ssl::context>(websocketpp::lib::asio::ssl::context::tlsv1);
9797

9898
try {
99-
ctx->set_options(boost::asio::ssl::context::default_workarounds |
100-
boost::asio::ssl::context::no_sslv2 |
101-
boost::asio::ssl::context::no_sslv3 |
102-
boost::asio::ssl::context::single_dh_use);
99+
ctx->set_options(websocketpp::lib::asio::ssl::context::default_workarounds |
100+
websocketpp::lib::asio::ssl::context::no_sslv2 |
101+
websocketpp::lib::asio::ssl::context::no_sslv3 |
102+
websocketpp::lib::asio::ssl::context::single_dh_use);
103103
} catch (std::exception& e) {
104104
std::cout << e.what() << std::endl;
105105
}

examples/echo_server_both/echo_server_both.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using websocketpp::lib::bind;
1515
using websocketpp::lib::error_code;
1616

1717
// type of the ssl context pointer is long so alias it
18-
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
18+
typedef websocketpp::lib::shared_ptr<websocketpp::lib::asio::ssl::context> context_ptr;
1919

2020
// The shared on_message handler takes a template parameter so the function can
2121
// resolve any endpoint dependent types like message_ptr or connection_ptr
@@ -48,16 +48,16 @@ std::string get_password() {
4848

4949
context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
5050
std::cout << "on_tls_init called with hdl: " << hdl.lock().get() << std::endl;
51-
context_ptr ctx(new boost::asio::ssl::context(boost::asio::ssl::context::tlsv1));
51+
context_ptr ctx(new websocketpp::lib::asio::ssl::context(websocketpp::lib::asio::ssl::context::tlsv1));
5252

5353
try {
54-
ctx->set_options(boost::asio::ssl::context::default_workarounds |
55-
boost::asio::ssl::context::no_sslv2 |
56-
boost::asio::ssl::context::no_sslv3 |
57-
boost::asio::ssl::context::single_dh_use);
54+
ctx->set_options(websocketpp::lib::asio::ssl::context::default_workarounds |
55+
websocketpp::lib::asio::ssl::context::no_sslv2 |
56+
websocketpp::lib::asio::ssl::context::no_sslv3 |
57+
websocketpp::lib::asio::ssl::context::single_dh_use);
5858
ctx->set_password_callback(bind(&get_password));
5959
ctx->use_certificate_chain_file("server.pem");
60-
ctx->use_private_key_file("server.pem", boost::asio::ssl::context::pem);
60+
ctx->use_private_key_file("server.pem", websocketpp::lib::asio::ssl::context::pem);
6161
} catch (std::exception& e) {
6262
std::cout << e.what() << std::endl;
6363
}
@@ -67,7 +67,7 @@ context_ptr on_tls_init(websocketpp::connection_hdl hdl) {
6767
int main() {
6868
// set up an external io_context to run both endpoints on. This is not
6969
// strictly necessary, but simplifies thread management a bit.
70-
boost::asio::io_context ios;
70+
websocketpp::lib::asio::io_context ios;
7171

7272
// set up plain endpoint
7373
server_plain endpoint_plain;

examples/external_io_context/external_io_context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void on_end_accept(error_code lib_ec, error_code trans_ec) {
6666
}
6767

6868
int main() {
69-
asio::io_context context;
69+
websocketpp::lib::asio::io_context context;
7070

7171
// Add a TCP echo server on port 9003
7272
tcp_echo_server custom_http_server(context, 9003);

examples/external_io_context/tcp_echo_server.hpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,40 @@ using websocketpp::lib::placeholders::_1;
3939
using websocketpp::lib::placeholders::_2;
4040
using websocketpp::lib::bind;
4141

42-
namespace asio = websocketpp::lib::asio;
43-
4442
struct tcp_echo_session : websocketpp::lib::enable_shared_from_this<tcp_echo_session> {
4543
typedef websocketpp::lib::shared_ptr<tcp_echo_session> ptr;
4644

47-
tcp_echo_session(asio::io_context & context) : m_socket(context) {}
45+
tcp_echo_session(websocketpp::lib::asio::io_context & context) : m_socket(context) {}
4846

4947
void start() {
50-
m_socket.async_read_some(asio::buffer(m_buffer, sizeof(m_buffer)),
48+
m_socket.async_read_some(websocketpp::lib::asio::buffer(m_buffer, sizeof(m_buffer)),
5149
websocketpp::lib::bind(
5250
&tcp_echo_session::handle_read, shared_from_this(), _1, _2));
5351
}
5452

55-
void handle_read(const asio::error_code & ec, size_t transferred) {
53+
void handle_read(const websocketpp::lib::asio::error_code & ec, size_t transferred) {
5654
if (!ec) {
57-
asio::async_write(m_socket,
58-
asio::buffer(m_buffer, transferred),
55+
websocketpp::lib::asio::async_write(m_socket,
56+
websocketpp::lib::asio::buffer(m_buffer, transferred),
5957
bind(&tcp_echo_session::handle_write, shared_from_this(), _1));
6058
}
6159
}
6260

63-
void handle_write(const asio::error_code & ec) {
61+
void handle_write(const websocketpp::lib::asio::error_code & ec) {
6462
if (!ec) {
65-
m_socket.async_read_some(asio::buffer(m_buffer, sizeof(m_buffer)),
63+
m_socket.async_read_some(websocketpp::lib::asio::buffer(m_buffer, sizeof(m_buffer)),
6664
bind(&tcp_echo_session::handle_read, shared_from_this(), _1, _2));
6765
}
6866
}
6967

70-
asio::ip::tcp::socket m_socket;
68+
websocketpp::lib::asio::ip::tcp::socket m_socket;
7169
char m_buffer[1024];
7270
};
7371

7472
struct tcp_echo_server {
75-
tcp_echo_server(asio::io_context & context, short port)
73+
tcp_echo_server(websocketpp::lib::asio::io_context & context, short port)
7674
: m_context(context)
77-
, m_acceptor(context, asio::ip::tcp::endpoint(asio::ip::tcp::v6(), port))
75+
, m_acceptor(context, websocketpp::lib::asio::ip::tcp::endpoint(websocketpp::lib::asio::ip::tcp::v6(), port))
7876
{
7977
this->start_accept();
8078
}
@@ -85,13 +83,13 @@ struct tcp_echo_server {
8583
bind(&tcp_echo_server::handle_accept, this, new_session, _1));
8684
}
8785

88-
void handle_accept(tcp_echo_session::ptr new_session, const asio::error_code & ec) {
86+
void handle_accept(tcp_echo_session::ptr new_session, const websocketpp::lib::asio::error_code & ec) {
8987
if (!ec) {
9088
new_session->start();
9189
}
9290
start_accept();
9391
}
9492

95-
asio::io_context & m_context;
96-
asio::ip::tcp::acceptor m_acceptor;
93+
websocketpp::lib::asio::io_context & m_context;
94+
websocketpp::lib::asio::ip::tcp::acceptor m_acceptor;
9795
};

examples/print_client_tls/print_client_tls.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ bool verify_common_name(char const * hostname, X509 * cert) {
112112
* and
113113
* https://github.com/iSECPartners/ssl-conservatory
114114
*/
115-
bool verify_certificate(const char * hostname, bool preverified, boost::asio::ssl::verify_context& ctx) {
115+
bool verify_certificate(const char * hostname, bool preverified, websocketpp::lib::asio::ssl::verify_context& ctx) {
116116
// The verify callback can be used to check whether the certificate that is
117117
// being presented is valid for the peer. For example, RFC 2818 describes
118118
// the steps involved in doing this for HTTPS. Consult the OpenSSL
@@ -176,16 +176,16 @@ bool verify_certificate(const char * hostname, bool preverified, boost::asio::ss
176176
* (websocketpp.org, for example).
177177
*/
178178
context_ptr on_tls_init(const char * hostname, websocketpp::connection_hdl) {
179-
context_ptr ctx = websocketpp::lib::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);
179+
context_ptr ctx = websocketpp::lib::make_shared<websocketpp::lib::asio::ssl::context>(websocketpp::lib::asio::ssl::context::sslv23);
180180

181181
try {
182-
ctx->set_options(boost::asio::ssl::context::default_workarounds |
183-
boost::asio::ssl::context::no_sslv2 |
184-
boost::asio::ssl::context::no_sslv3 |
185-
boost::asio::ssl::context::single_dh_use);
182+
ctx->set_options(websocketpp::lib::asio::ssl::context::default_workarounds |
183+
websocketpp::lib::asio::ssl::context::no_sslv2 |
184+
websocketpp::lib::asio::ssl::context::no_sslv3 |
185+
websocketpp::lib::asio::ssl::context::single_dh_use);
186186

187187

188-
ctx->set_verify_mode(boost::asio::ssl::verify_peer);
188+
ctx->set_verify_mode(websocketpp::lib::asio::ssl::verify_peer);
189189
ctx->set_verify_callback(bind(&verify_certificate, hostname, ::_1, ::_2));
190190

191191
// Here we load the CA certificates of all CA's that this client trusts.

examples/testee_server/testee_server.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
8888
s->send(hdl, msg->get_payload(), msg->get_opcode());
8989
}
9090

91-
void on_socket_init(websocketpp::connection_hdl, boost::asio::ip::tcp::socket & s) {
92-
boost::asio::ip::tcp::no_delay option(true);
91+
void on_socket_init(websocketpp::connection_hdl, websocketpp::lib::asio::ip::tcp::socket & s) {
92+
websocketpp::lib::asio::ip::tcp::no_delay option(true);
9393
s.set_option(option);
9494
}
9595

test/endpoint/endpoint.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ BOOST_AUTO_TEST_CASE( initialize_server_asio ) {
5353

5454
BOOST_AUTO_TEST_CASE( initialize_server_asio_external ) {
5555
websocketpp::server<websocketpp::config::asio> s;
56-
boost::asio::io_context ios;
56+
websocketpp::lib::asio::io_context ios;
5757
s.init_asio(&ios);
5858
}
5959

@@ -141,8 +141,8 @@ BOOST_AUTO_TEST_CASE( listen_after_listen_failure ) {
141141
server1.init_asio();
142142
server2.init_asio();
143143

144-
boost::asio::ip::tcp::endpoint ep1(boost::asio::ip::make_address("127.0.0.1"), 12345);
145-
boost::asio::ip::tcp::endpoint ep2(boost::asio::ip::make_address("127.0.0.1"), 23456);
144+
websocketpp::lib::asio::ip::tcp::endpoint ep1(websocketpp::lib::asio::ip::make_address("127.0.0.1"), 12345);
145+
websocketpp::lib::asio::ip::tcp::endpoint ep2(websocketpp::lib::asio::ip::make_address("127.0.0.1"), 23456);
146146

147147
server1.listen(ep1, ec);
148148
BOOST_CHECK(!ec);

test/http/parser_perf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131

3232
class scoped_timer {
3333
public:
34-
scoped_timer(std::string i) : m_id(i),m_start(std::chrono::steady_clock::now()) {
34+
scoped_timer(std::string i) : m_id(i),m_start(timer_ptr::element_type::clock_type::now()) {
3535
std::cout << "Clock " << i << ": ";
3636
}
3737
~scoped_timer() {
38-
std::chrono::nanoseconds time_taken = std::chrono::steady_clock::now()-m_start;
38+
std::chrono::nanoseconds time_taken = timer_ptr::element_type::clock_type::now()-m_start;
3939

4040
//nanoseconds_per_test
4141

test/transport/asio/timers.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ struct config {
106106
};
107107

108108
// Mock context that does no validation
109-
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
109+
typedef websocketpp::lib::shared_ptr<websocketpp::lib::asio::ssl::context> context_ptr;
110110
context_ptr on_tls_init(websocketpp::connection_hdl) {
111-
return context_ptr(new boost::asio::ssl::context(boost::asio::ssl::context::sslv23));
111+
return context_ptr(new websocketpp::lib::asio::ssl::context(websocketpp::lib::asio::ssl::context::sslv23));
112112
}
113113

114114
// Mock connection

0 commit comments

Comments
 (0)