10 #include <boost/bind/bind.hpp>
11 #include <boost/assign.hpp>
12 #include <sandesh/transport/TBufferTransports.h>
13 #include <sandesh/protocol/TJSONProtocol.h>
16 using namespace boost::placeholders;
18 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
19 void StatsClientLocal::Initialize() {
20 boost::system::error_code ec;
21 stats_socket_->connect(stats_server_ep_, ec);
23 SANDESH_LOG(ERROR,
"LOCAL could not connect to socket: " << ec.message());
24 is_connected_ =
false;
30 size_t StatsClientLocal::SendBuf(uint8_t *data,
size_t size) {
34 boost::system::error_code ec;
35 size_t ret = stats_socket_->send(boost::asio::buffer(data, size), 0, ec);
37 SANDESH_LOG(ERROR,
"LOCAL could not send to socket: " << ec.message());
38 is_connected_ =
false;
44 std::scoped_lock lock(send_mutex_);
46 int32_t xfer = 0, ret = 0;
50 boost::shared_ptr<sandesh_trans::TMemoryBuffer> btrans(
52 boost::shared_ptr<sandesh_prot::TJSONProtocol> prot(
53 new sandesh_prot::TJSONProtocol(btrans));
54 if ((ret =
sandesh->Write(prot)) < 0) {
55 SANDESH_LOG(ERROR, __func__ <<
": Sandesh write FAILED: "<<
58 " Sequence Number:" <<
sandesh->seqnum());
60 SandeshTxDropReason::WriteFailed);
64 btrans->getBuffer(&buffer, &offset);
65 SendBuf(buffer, offset);
71 boost::system::error_code ec;
72 stats_socket_->open(boost::asio::ip::udp::v4(), ec);
74 SANDESH_LOG(ERROR,
"REMOTE could not open socket: " << ec.message());
75 is_connected_ =
false;
78 stats_socket_->connect(stats_server_ep_, ec);
80 SANDESH_LOG(ERROR,
"REMOTE could not connect address: " << ec.message());
81 is_connected_ =
false;
82 stats_socket_->close();
92 boost::system::error_code ec;
93 size_t ret = stats_socket_->send(boost::asio::buffer(data, size), 0, ec);
95 SANDESH_LOG(ERROR,
"REMOTE could not send to socket: " << ec.message());
96 is_connected_ =
false;
102 std::scoped_lock lock(send_mutex_);
104 int32_t xfer = 0, ret = 0;
108 boost::shared_ptr<sandesh_trans::TMemoryBuffer> btrans(
110 boost::shared_ptr<sandesh_prot::TJSONProtocol> prot(
111 new sandesh_prot::TJSONProtocol(btrans));
112 if ((ret =
sandesh->Write(prot)) < 0) {
113 SANDESH_LOG(ERROR, __func__ <<
": Sandesh write FAILED: "<<
116 " Sequence Number:" <<
sandesh->seqnum());
118 SandeshTxDropReason::WriteFailed);
122 btrans->getBuffer(&buffer, &offset);
123 SendBuf(buffer, offset);
static void UpdateTxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshTxDropReason::type dreason)
virtual bool SendMsg(Sandesh *sandesh)
virtual size_t SendBuf(uint8_t *data, size_t size)
virtual void Initialize()
#define SANDESH_LOG(_Level, _Msg)
static int kEncodeBufferSize