Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
Recipient Class Reference

#include <recipient.hh>

Public Member Functions

 Recipient (boost::asio::io_service &service, const boost::asio::ip::tcp::endpoint &endpoint, size_t circbuff_size)
 
void sock_reset ()
 
bool sendIfPossible (const Frame &data)
 
 ~Recipient ()
 

Private Member Functions

void connect ()
 
void stop ()
 
bool send (const Frame &data)
 Send data.
 

Private Attributes

boost::asio::ip::tcp::socket m_sock
 
boost::asio::ip::tcp::endpoint m_endpoint
 
CircularBuffer m_cbuffer
 
bool m_connected
 

Friends

class RecipientsHandler
 

Detailed Description

Definition at line 15 of file recipient.hh.

Constructor & Destructor Documentation

◆ Recipient()

Recipient::Recipient ( boost::asio::io_service & service,
const boost::asio::ip::tcp::endpoint & endpoint,
size_t circbuff_size )
inline

Definition at line 24 of file recipient.hh.

27 :
28 m_sock(service),
29 m_endpoint(endpoint),
30 m_cbuffer(circbuff_size),
31 m_connected(false)
32 {
33 LOG_NOTICE << "Trying to connect to " << m_endpoint;
34 connect();
35 if (!m_connected) {
36 LOG_ERROR << "Connection to " << m_endpoint << " failed";
37 }
38 }
boost::asio::ip::tcp::endpoint m_endpoint
Definition recipient.hh:18
void connect()
Definition recipient.hh:88
CircularBuffer m_cbuffer
Definition recipient.hh:19
boost::asio::ip::tcp::socket m_sock
Definition recipient.hh:17
bool m_connected
Definition recipient.hh:20
#define LOG_ERROR
Definition log.hh:111
#define LOG_NOTICE
Definition log.hh:112

◆ ~Recipient()

Recipient::~Recipient ( )
inline

Definition at line 79 of file recipient.hh.

80 {
81 stop();
82 }
void stop()
Definition recipient.hh:107

Member Function Documentation

◆ sock_reset()

void Recipient::sock_reset ( )
inline

Definition at line 40 of file recipient.hh.

41 {
42 stop();
43 connect();
44 }

◆ sendIfPossible()

bool Recipient::sendIfPossible ( const Frame & data)
inline

Definition at line 46 of file recipient.hh.

47 {
48
49 if (! m_connected)
50 {
51 sock_reset();
52
53 if (! m_connected)
54 {
55 m_cbuffer.push_back(data);
56 return false;
57 }
58 }
59
60 while (m_cbuffer.size())
61 {
62 if (send(m_cbuffer.front()))
63 {
64 m_cbuffer.pop_front();
65 }
66 else
67 {
68 break;
69 }
70 }
71 if (! send(data))
72 {
73 m_cbuffer.push_back(data);
74 }
75
76 return m_connected;
77 }
bool send(const Frame &data)
Send data.
Definition recipient.hh:119
void sock_reset()
Definition recipient.hh:40

◆ connect()

void Recipient::connect ( )
inlineprivate

Definition at line 88 of file recipient.hh.

89 {
90 boost::system::error_code ec;
91 m_sock.connect(m_endpoint, ec);
92 m_connected = !ec;
93
94 if (m_connected) {
95#if __APPLE__
96 boost::asio::socket_base::send_buffer_size option(6108864);
97#else
98 boost::asio::socket_base::send_buffer_size option(67108864);
99#endif
100 m_sock.set_option(option);
101 LOG_NOTICE << "Connection to " << m_endpoint << " succeeded";
102 boost::system::error_code ec;
103 m_sock.shutdown(boost::asio::ip::tcp::socket::shutdown_receive, ec);
104 }
105 }

◆ stop()

void Recipient::stop ( )
inlineprivate

Definition at line 107 of file recipient.hh.

108 {
109 boost::system::error_code ec;
110 m_sock.shutdown(boost::asio::ip::tcp::socket::shutdown_send, ec);
111 m_sock.close(ec);
112 }

◆ send()

bool Recipient::send ( const Frame & data)
inlineprivate

Send data.

Parameters
datathe Frame to send.
Returns
true if OK; else false

Definition at line 119 of file recipient.hh.

120 {
121 boost::system::error_code ec;
122 boost::asio::write(m_sock, boost::asio::buffer(data.data(), data.getFrameLength()), ec);
123 m_connected = !ec;
124
125 if (ec) {
126 LOG_ERROR << "Error transmitting data to " << m_endpoint << ": " << ec;
127 }
128 return m_connected;
129 }

Friends And Related Symbol Documentation

◆ RecipientsHandler

friend class RecipientsHandler
friend

Definition at line 84 of file recipient.hh.

Member Data Documentation

◆ m_sock

boost::asio::ip::tcp::socket Recipient::m_sock
private

Definition at line 17 of file recipient.hh.

◆ m_endpoint

boost::asio::ip::tcp::endpoint Recipient::m_endpoint
private

Definition at line 18 of file recipient.hh.

◆ m_cbuffer

CircularBuffer Recipient::m_cbuffer
private

Definition at line 19 of file recipient.hh.

◆ m_connected

bool Recipient::m_connected
private

Definition at line 20 of file recipient.hh.


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