Electroneum
epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t > Struct Template Reference

#include <levin_protocol_handler_async.h>

Inheritance diagram for epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >:
Collaboration diagram for epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >:

Public Member Functions

 anvoke_handler (const callback_t &cb, uint64_t timeout, async_protocol_handler &con, int command)
 
virtual ~anvoke_handler ()
 
virtual bool handle (int res, const epee::span< const uint8_t > buff, typename async_protocol_handler::connection_context &context)
 
virtual bool is_timer_started () const
 
virtual void cancel ()
 
virtual bool cancel_timer ()
 
virtual void reset_timer ()
 

Public Attributes

callback_t m_cb
 
async_protocol_handlerm_con
 
boost::asio::deadline_timer m_timer
 
bool m_timer_started
 
bool m_cancel_timer_called
 
bool m_timer_cancelled
 
uint64_t m_timeout
 
int m_command
 

Detailed Description

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t>
struct epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >

Definition at line 162 of file levin_protocol_handler_async.h.

Constructor & Destructor Documentation

◆ anvoke_handler()

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::anvoke_handler ( const callback_t &  cb,
uint64_t  timeout,
async_protocol_handler con,
int  command 
)
inline

Definition at line 164 of file levin_protocol_handler_async.h.

165  :m_cb(cb), m_timeout(timeout), m_con(con), m_timer(con.m_pservice_endpoint->get_io_service()), m_timer_started(false),
166  m_cancel_timer_called(false), m_timer_cancelled(false), m_command(command)
167  {
168  if(m_con.start_outer_call())
169  {
170  MDEBUG(con.get_context_ref() << "anvoke_handler, timeout: " << timeout);
171  m_timer.expires_from_now(boost::posix_time::milliseconds(timeout));
172  m_timer.async_wait([&con, command, cb, timeout](const boost::system::error_code& ec)
173  {
174  if(ec == boost::asio::error::operation_aborted)
175  return;
176  MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout);
178  cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
179  con.close();
180  con.finish_outer_call();
181  });
182  m_timer_started = true;
183  }
184  }
#define LEVIN_ERROR_CONNECTION_TIMEDOUT
Definition: levin_base.h:97
#define MINFO(x)
Definition: misc_log_ex.h:75
Non-owning sequence of data. Does not deep copy.
Definition: span.h:56
#define MDEBUG(x)
Definition: misc_log_ex.h:76
Here is the call graph for this function:

◆ ~anvoke_handler()

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
virtual epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::~anvoke_handler ( )
inlinevirtual

Definition at line 185 of file levin_protocol_handler_async.h.

186  {}

Member Function Documentation

◆ cancel()

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
virtual void epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::cancel ( )
inlinevirtual

◆ cancel_timer()

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
virtual bool epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::cancel_timer ( )
inlinevirtual

Implements epee::levin::async_protocol_handler< t_connection_context >::invoke_response_handler_base.

Definition at line 216 of file levin_protocol_handler_async.h.

217  {
219  {
220  m_cancel_timer_called = true;
221  boost::system::error_code ignored_ec;
222  m_timer_cancelled = 1 == m_timer.cancel(ignored_ec);
223  }
224  return m_timer_cancelled;
225  }
Here is the caller graph for this function:

◆ handle()

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
virtual bool epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::handle ( int  res,
const epee::span< const uint8_t buff,
typename async_protocol_handler::connection_context context 
)
inlinevirtual

Implements epee::levin::async_protocol_handler< t_connection_context >::invoke_response_handler_base.

Definition at line 195 of file levin_protocol_handler_async.h.

196  {
197  if(!cancel_timer())
198  return false;
199  m_cb(res, buff, context);
201  return true;
202  }
const char * res
Definition: hmac_keccak.cpp:41
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
Here is the call graph for this function:

◆ is_timer_started()

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
virtual bool epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::is_timer_started ( ) const
inlinevirtual

◆ reset_timer()

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
virtual void epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::reset_timer ( )
inlinevirtual

Implements epee::levin::async_protocol_handler< t_connection_context >::invoke_response_handler_base.

Definition at line 226 of file levin_protocol_handler_async.h.

227  {
228  boost::system::error_code ignored_ec;
229  if (!m_cancel_timer_called && m_timer.cancel(ignored_ec) > 0)
230  {
231  callback_t& cb = m_cb;
232  uint64_t timeout = m_timeout;
234  int command = m_command;
235  m_timer.expires_from_now(boost::posix_time::milliseconds(m_timeout));
236  m_timer.async_wait([&con, cb, command, timeout](const boost::system::error_code& ec)
237  {
238  if(ec == boost::asio::error::operation_aborted)
239  return;
240  MINFO(con.get_context_ref() << "Timeout on invoke operation happened, command: " << command << " timeout: " << timeout);
242  cb(LEVIN_ERROR_CONNECTION_TIMEDOUT, fake, con.get_context_ref());
243  con.close();
244  con.finish_outer_call();
245  });
246  }
247  }
#define LEVIN_ERROR_CONNECTION_TIMEDOUT
Definition: levin_base.h:97
#define MINFO(x)
Definition: misc_log_ex.h:75
Non-owning sequence of data. Does not deep copy.
Definition: span.h:56
async_protocol_handler(net_utils::i_service_endpoint *psnd_hndlr, config_type &config, t_connection_context &conn_context)
unsigned __int64 uint64_t
Definition: stdint.h:136

Member Data Documentation

◆ m_cancel_timer_called

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
bool epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::m_cancel_timer_called

Definition at line 191 of file levin_protocol_handler_async.h.

◆ m_cb

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
callback_t epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::m_cb

Definition at line 187 of file levin_protocol_handler_async.h.

◆ m_command

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
int epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::m_command

Definition at line 194 of file levin_protocol_handler_async.h.

◆ m_con

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
async_protocol_handler& epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::m_con

Definition at line 188 of file levin_protocol_handler_async.h.

◆ m_timeout

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
uint64_t epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::m_timeout

Definition at line 193 of file levin_protocol_handler_async.h.

◆ m_timer

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
boost::asio::deadline_timer epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::m_timer

Definition at line 189 of file levin_protocol_handler_async.h.

◆ m_timer_cancelled

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
bool epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::m_timer_cancelled

Definition at line 192 of file levin_protocol_handler_async.h.

◆ m_timer_started

template<class t_connection_context = net_utils::connection_context_base>
template<class callback_t >
bool epee::levin::async_protocol_handler< t_connection_context >::anvoke_handler< callback_t >::m_timer_started

Definition at line 190 of file levin_protocol_handler_async.h.


The documentation for this struct was generated from the following file: