Electroneum
epee::net_utils::async_blocked_mode_client Class Reference

#include <net_helper.h>

Inheritance diagram for epee::net_utils::async_blocked_mode_client:
Collaboration diagram for epee::net_utils::async_blocked_mode_client:

Public Member Functions

 async_blocked_mode_client ()
 
 ~async_blocked_mode_client ()
 
bool shutdown ()
 
bool send (const void *data, size_t sz)
 
- Public Member Functions inherited from epee::net_utils::blocked_mode_client
 blocked_mode_client ()
 
 ~blocked_mode_client ()
 
void set_ssl (ssl_options_t ssl_options)
 
bool connect (const std::string &addr, int port, std::chrono::milliseconds timeout)
 
try_connect_result_t try_connect (const std::string &addr, const std::string &port, std::chrono::milliseconds timeout, epee::net_utils::ssl_support_t ssl_support)
 
bool connect (const std::string &addr, const std::string &port, std::chrono::milliseconds timeout)
 
void set_connector (std::function< connect_func > connector)
 Change the connection routine (proxy, etc.) More...
 
bool disconnect ()
 
bool send (const std::string &buff, std::chrono::milliseconds timeout)
 
bool send (const void *data, size_t sz)
 
bool is_connected (bool *ssl=NULL)
 
bool recv (std::string &buff, std::chrono::milliseconds timeout)
 
bool recv_n (std::string &buff, int64_t sz, std::chrono::milliseconds timeout)
 
bool shutdown ()
 
boost::asio::io_service & get_io_service ()
 
boost::asio::ip::tcp::socket & get_socket ()
 
uint64_t get_bytes_sent () const
 
uint64_t get_bytes_received () const
 

Additional Inherited Members

- Public Types inherited from epee::net_utils::blocked_mode_client
using connect_func = boost::unique_future< boost::asio::ip::tcp::socket >(const std::string &, const std::string &, boost::asio::steady_timer &)
 
- Protected Member Functions inherited from epee::net_utils::blocked_mode_client
bool write (const void *data, size_t sz, boost::system::error_code &ec)
 
void async_write (const void *data, size_t sz, boost::system::error_code &ec)
 
void async_read (char *buff, size_t sz, boost::asio::detail::transfer_at_least_t transfer_at_least, handler_obj &hndlr)
 
- Protected Attributes inherited from epee::net_utils::blocked_mode_client
boost::asio::io_service m_io_service
 
boost::asio::ssl::context m_ctx
 
std::shared_ptr< boost::asio::ssl::stream< boost::asio::ip::tcp::socket > > m_ssl_socket
 
std::function< connect_funcm_connector
 
ssl_options_t m_ssl_options
 
bool m_initialized
 
bool m_connected
 
boost::asio::steady_timer m_deadline
 
volatile uint32_t m_shutdowned
 
std::atomic< uint64_tm_bytes_sent
 
std::atomic< uint64_tm_bytes_received
 

Detailed Description

Definition at line 694 of file net_helper.h.

Constructor & Destructor Documentation

◆ async_blocked_mode_client()

epee::net_utils::async_blocked_mode_client::async_blocked_mode_client ( )
inline

Definition at line 697 of file net_helper.h.

697  :m_send_deadline(blocked_mode_client::m_io_service)
698  {
699 
700  // No deadline is required until the first socket operation is started. We
701  // set the deadline to positive infinity so that the actor takes no action
702  // until a specific deadline is set.
703  m_send_deadline.expires_at(boost::posix_time::pos_infin);
704 
705  // Start the persistent actor that checks for deadline expiry.
706  check_send_deadline();
707  }
boost::asio::io_service m_io_service
Definition: net_helper.h:677

◆ ~async_blocked_mode_client()

epee::net_utils::async_blocked_mode_client::~async_blocked_mode_client ( )
inline

Definition at line 708 of file net_helper.h.

709  {
710  m_send_deadline.cancel();
711  }

Member Function Documentation

◆ send()

bool epee::net_utils::async_blocked_mode_client::send ( const void *  data,
size_t  sz 
)
inline

Definition at line 721 of file net_helper.h.

722  {
723  try
724  {
725  /*
726  m_send_deadline.expires_from_now(boost::posix_time::milliseconds(m_reciev_timeout));
727 
728  // Set up the variable that receives the result of the asynchronous
729  // operation. The error code is set to would_block to signal that the
730  // operation is incomplete. Asio guarantees that its asynchronous
731  // operations will never fail with would_block, so any other value in
732  // ec indicates completion.
733  boost::system::error_code ec = boost::asio::error::would_block;
734 
735  // Start the asynchronous operation itself. The boost::lambda function
736  // object is used as a callback and will update the ec variable when the
737  // operation completes. The blocking_udp_client.cpp example shows how you
738  // can use boost::bind rather than boost::lambda.
739  boost::asio::async_write(m_socket, boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
740 
741  // Block until the asynchronous operation has completed.
742  while(ec == boost::asio::error::would_block)
743  {
744  m_io_service.run_one();
745  }*/
746 
747  boost::system::error_code ec;
748 
749  size_t writen = write(data, sz, ec);
750 
751  if (!writen || ec)
752  {
753  LOG_PRINT_L3("Problems at write: " << ec.message());
754  return false;
755  }else
756  {
757  m_send_deadline.expires_at(boost::posix_time::pos_infin);
758  }
759  }
760 
761  catch(const boost::system::system_error& er)
762  {
763  LOG_ERROR("Some problems at connect, message: " << er.what());
764  return false;
765  }
766  catch(...)
767  {
768  LOG_ERROR("Some fatal problems.");
769  return false;
770  }
771 
772  return true;
773  }
bool write(const void *data, size_t sz, boost::system::error_code &ec)
Definition: net_helper.h:649
#define LOG_PRINT_L3(x)
Definition: misc_log_ex.h:102
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
Here is the call graph for this function:

◆ shutdown()

bool epee::net_utils::async_blocked_mode_client::shutdown ( )
inline

Definition at line 713 of file net_helper.h.

714  {
716  m_send_deadline.cancel();
717  return true;
718  }
Here is the call graph for this function:

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