switch to alternate method of clearing function objects

may help with null_ptr related issues when using boost with c++11
compilers
This commit is contained in:
Peter Thorson
2014-10-19 08:56:07 -04:00
parent f06b623767
commit 4309749dd9
3 changed files with 19 additions and 11 deletions

View File

@@ -49,7 +49,11 @@ namespace lib {
using std::bind;
using std::ref;
namespace placeholders = std::placeholders;
#define _WEBSOCKETPP_NULL_FUNCTION_ nullptr
template <typename T>
void clear_function(T & x) {
x = nullptr;
}
#else
using boost::function;
using boost::bind;
@@ -59,7 +63,11 @@ namespace lib {
using ::_1;
using ::_2;
}
#define _WEBSOCKETPP_NULL_FUNCTION_ 0
template <typename T>
void clear_function(T & x) {
x.clear();
}
#endif
} // namespace lib

View File

@@ -42,8 +42,8 @@ endpoint<connection,config>::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<connection_type>(m_is_server,m_user_agent,m_alog,
m_elog, m_rng);
connection_ptr con = lib::make_shared<connection_type>(m_is_server,
m_user_agent, m_alog, m_elog, m_rng);
connection_weak_ptr w(con);

View File

@@ -440,8 +440,8 @@ protected:
if (ec) {
// reset the handlers to break the circular reference:
// this->handler->this
m_async_read_handler = _WEBSOCKETPP_NULL_FUNCTION_;
m_async_write_handler = _WEBSOCKETPP_NULL_FUNCTION_;
lib::clear_function(m_async_read_handler);
lib::clear_function(m_async_write_handler);
}
return ec;
@@ -994,12 +994,12 @@ protected:
// Reset cached handlers now that we won't be reading or writing anymore
// These cached handlers store shared pointers to this connection and
// will leak the connection if not destroyed.
m_async_read_handler = _WEBSOCKETPP_NULL_FUNCTION_;
m_async_write_handler = _WEBSOCKETPP_NULL_FUNCTION_;
m_init_handler = _WEBSOCKETPP_NULL_FUNCTION_;
lib::clear_function(m_async_read_handler);
lib::clear_function(m_async_write_handler);
lib::clear_function(m_init_handler);
m_read_handler = _WEBSOCKETPP_NULL_FUNCTION_;
m_write_handler = _WEBSOCKETPP_NULL_FUNCTION_;
lib::clear_function(m_read_handler);
lib::clear_function(m_write_handler);
timer_ptr shutdown_timer;
shutdown_timer = set_timer(