diff --git a/include/fc/rpc/api_connection.hpp b/include/fc/rpc/api_connection.hpp index 4f632c8..c7c752f 100644 --- a/include/fc/rpc/api_connection.hpp +++ b/include/fc/rpc/api_connection.hpp @@ -22,15 +22,15 @@ namespace fc { public: typedef typename std::function::result_type result_type; - callback_functor( fc::api_connection& con, uint64_t id ) + callback_functor( std::shared_ptr< fc::api_connection > con, uint64_t id ) :_callback_id(id),_api_connection(con){} template result_type operator()( Args... args )const; private: - uint64_t _callback_id; - fc::api_connection& _api_connection; + uint64_t _callback_id; + std::shared_ptr< fc::api_connection > _api_connection; }; template @@ -91,7 +91,12 @@ namespace fc { return _methods[method_id](args); } - fc::api_connection& get_connection(){ auto tmp = _api_connection.lock(); FC_ASSERT( tmp, "connection closed"); return *tmp; } + std::shared_ptr< fc::api_connection > get_connection() + { + std::shared_ptr< fc::api_connection > locked = _api_connection.lock(); + FC_ASSERT( locked, "connection closed" ); + return locked; + } std::vector get_method_names()const { @@ -391,7 +396,7 @@ namespace fc { template typename callback_functor::result_type callback_functor::operator()( Args... args )const { - _api_connection.send_callback( _callback_id, fc::variants{ args... } ).template as< result_type >(); + _api_connection->send_callback( _callback_id, fc::variants{ args... } ).template as< result_type >(); } @@ -401,17 +406,17 @@ namespace fc { public: typedef void result_type; - callback_functor( fc::api_connection& con, uint64_t id ) + callback_functor( std::shared_ptr< fc::api_connection > con, uint64_t id ) :_callback_id(id),_api_connection(con){} void operator()( Args... args )const { - _api_connection.send_notice( _callback_id, fc::variants{ args... } ); + _api_connection->send_notice( _callback_id, fc::variants{ args... } ); } private: - uint64_t _callback_id; - fc::api_connection& _api_connection; + uint64_t _callback_id; + std::shared_ptr< fc::api_connection > _api_connection; }; } // namespace detail