From b46c0fb142772df108256259bddb3a6e8248aa17 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Mon, 3 Nov 2014 08:53:49 -0500 Subject: [PATCH] adds std/boost::ref as needed for non-const references passed to make_shared required for boost::make_shared to work without rvalue references. --- websocketpp/common/functional.hpp | 13 +++++++++++++ websocketpp/impl/connection_impl.hpp | 6 +++--- websocketpp/impl/endpoint_impl.hpp | 2 +- websocketpp/transport/asio/connection.hpp | 5 +++-- websocketpp/transport/asio/endpoint.hpp | 19 ++++++++++++------- websocketpp/transport/asio/security/none.hpp | 3 ++- websocketpp/transport/asio/security/tls.hpp | 3 ++- 7 files changed, 36 insertions(+), 15 deletions(-) diff --git a/websocketpp/common/functional.hpp b/websocketpp/common/functional.hpp index 2855d3fc18..ae5f041afd 100644 --- a/websocketpp/common/functional.hpp +++ b/websocketpp/common/functional.hpp @@ -39,8 +39,11 @@ #else #include #include + #include #endif + + namespace websocketpp { namespace lib { @@ -50,6 +53,13 @@ namespace lib { using std::ref; namespace placeholders = std::placeholders; + // There are some cases where a C++11 compiler balks at using std::ref + // but a C++03 compiler using boost function requires boost::ref. As such + // lib::ref is not useful in these cases. Instead this macro allows the use + // of boost::ref in the case of a boost compile or no reference wrapper at + // all in the case of a C++11 compile + #define _WEBSOCKETPP_REF(x) x + template void clear_function(T & x) { x = nullptr; @@ -64,6 +74,9 @@ namespace lib { using ::_2; } + // See above definition for more details on what this is and why it exists + #define _WEBSOCKETPP_REF(x) boost::ref(x) + template void clear_function(T & x) { x.clear(); diff --git a/websocketpp/impl/connection_impl.hpp b/websocketpp/impl/connection_impl.hpp index 3df934032f..1f29f4effc 100644 --- a/websocketpp/impl/connection_impl.hpp +++ b/websocketpp/impl/connection_impl.hpp @@ -1980,7 +1980,7 @@ connection::get_processor(int version) const { transport_con_type::is_secure(), m_is_server, m_msg_manager, - m_rng + lib::ref(m_rng) ); break; case 8: @@ -1988,7 +1988,7 @@ connection::get_processor(int version) const { transport_con_type::is_secure(), m_is_server, m_msg_manager, - m_rng + lib::ref(m_rng) ); break; case 13: @@ -1996,7 +1996,7 @@ connection::get_processor(int version) const { transport_con_type::is_secure(), m_is_server, m_msg_manager, - m_rng + lib::ref(m_rng) ); break; default: diff --git a/websocketpp/impl/endpoint_impl.hpp b/websocketpp/impl/endpoint_impl.hpp index 2c53914b91..a91d8376bd 100644 --- a/websocketpp/impl/endpoint_impl.hpp +++ b/websocketpp/impl/endpoint_impl.hpp @@ -43,7 +43,7 @@ endpoint::create_connection() { //scoped_lock_type guard(m_mutex); // Create a connection on the heap and manage it using a shared pointer connection_ptr con = lib::make_shared(m_is_server, - m_user_agent, m_alog, m_elog, m_rng); + m_user_agent, lib::ref(m_alog), lib::ref(m_elog), lib::ref(m_rng)); connection_weak_ptr w(con); diff --git a/websocketpp/transport/asio/connection.hpp b/websocketpp/transport/asio/connection.hpp index 7969226c3e..f4341019fc 100644 --- a/websocketpp/transport/asio/connection.hpp +++ b/websocketpp/transport/asio/connection.hpp @@ -291,7 +291,7 @@ public: */ timer_ptr set_timer(long duration, timer_handler callback) { timer_ptr new_timer = lib::make_shared( - *m_io_service, + lib::ref(*m_io_service), boost::posix_time::milliseconds(duration) ); @@ -417,7 +417,8 @@ protected: m_io_service = io_service; if (config::enable_multithreading) { - m_strand = lib::make_shared(*io_service); + m_strand = lib::make_shared( + lib::ref(*io_service)); m_async_read_handler = m_strand->wrap(lib::bind( &type::handle_async_read, get_shared(),lib::placeholders::_1, diff --git a/websocketpp/transport/asio/endpoint.hpp b/websocketpp/transport/asio/endpoint.hpp index 06dd52d291..9464ced357 100644 --- a/websocketpp/transport/asio/endpoint.hpp +++ b/websocketpp/transport/asio/endpoint.hpp @@ -176,7 +176,9 @@ public: m_io_service = ptr; m_external_io_service = true; - m_acceptor = lib::make_shared(*m_io_service); + m_acceptor = lib::make_shared( + lib::ref(*m_io_service)); + m_state = READY; ec = lib::error_code(); } @@ -287,11 +289,11 @@ public: m_listen_backlog = backlog; } - /// Sets whether or not to use the SO_REUSEADDR flag when opening a listening socket + /// Sets whether to use the SO_REUSEADDR flag when opening listening sockets /** - * Specifies whether or not to use the SO_REUSEADDR TCP socket option. What this flag - * does depends on your operating system. Please consult operating system - * documentation for more details. + * Specifies whether or not to use the SO_REUSEADDR TCP socket option. What + * this flag does depends on your operating system. Please consult operating + * system documentation for more details. * * New values affect future calls to listen only. * @@ -597,7 +599,9 @@ public: * @since 0.3.0 */ void start_perpetual() { - m_work = lib::make_shared(*m_io_service); + m_work = lib::make_shared( + lib::ref(*m_io_service) + ); } /// Clears the endpoint's perpetual flag, allowing it to exit when empty @@ -761,7 +765,8 @@ protected: // Create a resolver if (!m_resolver) { - m_resolver = lib::make_shared(*m_io_service); + m_resolver = lib::make_shared( + lib::ref(*m_io_service)); } std::string proxy = tcon->get_proxy(); diff --git a/websocketpp/transport/asio/security/none.hpp b/websocketpp/transport/asio/security/none.hpp index 33fbedab59..17ddbf6fe6 100644 --- a/websocketpp/transport/asio/security/none.hpp +++ b/websocketpp/transport/asio/security/none.hpp @@ -164,7 +164,8 @@ protected: return socket::make_error_code(socket::error::invalid_state); } - m_socket = lib::make_shared(*service); + m_socket = lib::make_shared( + lib::ref(*service)); m_state = READY; diff --git a/websocketpp/transport/asio/security/tls.hpp b/websocketpp/transport/asio/security/tls.hpp index 419a10b3b2..68f4198ebe 100644 --- a/websocketpp/transport/asio/security/tls.hpp +++ b/websocketpp/transport/asio/security/tls.hpp @@ -193,7 +193,8 @@ protected: if (!m_context) { return socket::make_error_code(socket::error::invalid_tls_context); } - m_socket = lib::make_shared(*service,*m_context); + m_socket = lib::make_shared( + _WEBSOCKETPP_REF(*service),lib::ref(*m_context)); m_io_service = service; m_strand = strand;