From c7ec97795a47f6e153e3a55ec295f20ad5d61365 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Sun, 2 Feb 2014 17:03:41 -0600 Subject: [PATCH] add C++11 nullptr support detection --- websocketpp/common/cpp11.hpp | 22 ++++++++++++++++++++++ websocketpp/transport/asio/connection.hpp | 7 ++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/websocketpp/common/cpp11.hpp b/websocketpp/common/cpp11.hpp index 2a638dce6a..c2da4b880f 100644 --- a/websocketpp/common/cpp11.hpp +++ b/websocketpp/common/cpp11.hpp @@ -53,6 +53,9 @@ #ifndef _WEBSOCKETPP_INITIALIZER_LISTS_ #define _WEBSOCKETPP_INITIALIZER_LISTS_ #endif + #ifndef _WEBSOCKETPP_NULLPTR_TOKEN_ + #define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr + #endif #else // Test for noexcept #ifndef _WEBSOCKETPP_NOEXCEPT_TOKEN_ @@ -90,6 +93,25 @@ #if __has_feature(cxx_generalized_initializers) && !defined(_WEBSOCKETPP_INITIALIZER_LISTS_) #define _WEBSOCKETPP_INITIALIZER_LISTS_ #endif + + // Test for nullptr + #ifndef _WEBSOCKETPP_NULLPTR_TOKEN_ + #ifdef _WEBSOCKETPP_NULLPTR_ + // build system says we have constexpr + #define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr + #else + #if __has_feature(cxx_nullptr) + // clang feature detect says we have constexpr + #define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr + #elif _MSC_VER >= 1600 + // Visual Studio version that has nullptr + #define _WEBSOCKETPP_NULLPTR_TOKEN_ nullptr + #else + // assume we don't have constexpr + #define _WEBSOCKETPP_NULLPTR_TOKEN_ 0 + #endif + #endif + #endif #endif #endif // WEBSOCKETPP_COMMON_CPP11_HPP diff --git a/websocketpp/transport/asio/connection.hpp b/websocketpp/transport/asio/connection.hpp index f88c7a75e0..d044c5932d 100644 --- a/websocketpp/transport/asio/connection.hpp +++ b/websocketpp/transport/asio/connection.hpp @@ -28,6 +28,7 @@ #ifndef WEBSOCKETPP_TRANSPORT_ASIO_CON_HPP #define WEBSOCKETPP_TRANSPORT_ASIO_CON_HPP +#include #include #include #include @@ -934,9 +935,9 @@ 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 = 0; - m_async_write_handler = 0; - m_init_handler = 0; + m_async_read_handler = _WEBSOCKETPP_NULLPTR_TOKEN_; + m_async_write_handler = _WEBSOCKETPP_NULLPTR_TOKEN_; + m_init_handler = _WEBSOCKETPP_NULLPTR_TOKEN_; timer_ptr shutdown_timer; shutdown_timer = set_timer(