api_connection.hpp: Properly lock connection object for callbacks
This commit is contained in:
parent
458b601774
commit
3cd9ed4386
1 changed files with 14 additions and 9 deletions
|
|
@ -22,15 +22,15 @@ namespace fc {
|
|||
public:
|
||||
typedef typename std::function<Signature>::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<typename... Args>
|
||||
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<typename R, typename Arg0, typename ... Args>
|
||||
|
|
@ -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<std::string> get_method_names()const
|
||||
{
|
||||
|
|
@ -391,7 +396,7 @@ namespace fc {
|
|||
template<typename... Args>
|
||||
typename callback_functor<Signature>::result_type callback_functor<Signature>::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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue