10 #include <boost/bind.hpp>
11 #include <boost/assign.hpp>
12 #include <sandesh/transport/TBufferTransports.h>
13 #include <sandesh/protocol/TJSONProtocol.h>
16 #if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
17 void StatsClientLocal::Initialize() {
18 boost::system::error_code ec;
19 stats_socket_->connect(stats_server_ep_, ec);
21 SANDESH_LOG(ERROR,
"LOCAL could not connect to socket: " << ec.message());
22 is_connected_ =
false;
28 size_t StatsClientLocal::SendBuf(uint8_t *data,
size_t size) {
32 boost::system::error_code ec;
33 size_t ret = stats_socket_->send(boost::asio::buffer(data, size), 0, ec);
35 SANDESH_LOG(ERROR,
"LOCAL could not send to socket: " << ec.message());
36 is_connected_ =
false;
41 bool StatsClientLocal::SendMsg(
Sandesh *sandesh) {
42 tbb::mutex::scoped_lock lock(send_mutex_);
44 int32_t xfer = 0, ret = 0;
46 namespace sandesh_prot = contrail::sandesh::protocol;
47 namespace sandesh_trans = contrail::sandesh::transport;
48 boost::shared_ptr<sandesh_trans::TMemoryBuffer> btrans(
50 boost::shared_ptr<sandesh_prot::TJSONProtocol> prot(
51 new sandesh_prot::TJSONProtocol(btrans));
52 if ((ret = sandesh->
Write(prot)) < 0) {
53 SANDESH_LOG(ERROR, __func__ <<
": Sandesh write FAILED: "<<
54 sandesh->
Name() <<
" : " << sandesh->
source() <<
":" <<
56 " Sequence Number:" << sandesh->
seqnum());
58 SandeshTxDropReason::WriteFailed);
62 btrans->getBuffer(&buffer, &offset);
63 SendBuf(buffer, offset);
69 boost::system::error_code ec;
72 SANDESH_LOG(ERROR,
"REMOTE could not open socket: " << ec.message());
78 SANDESH_LOG(ERROR,
"REMOTE could not connect address: " << ec.message());
90 boost::system::error_code ec;
91 size_t ret =
stats_socket_->send(boost::asio::buffer(data, size), 0, ec);
93 SANDESH_LOG(ERROR,
"REMOTE could not send to socket: " << ec.message());
102 int32_t xfer = 0, ret = 0;
104 namespace sandesh_prot = contrail::sandesh::protocol;
105 namespace sandesh_trans = contrail::sandesh::transport;
106 boost::shared_ptr<sandesh_trans::TMemoryBuffer> btrans(
108 boost::shared_ptr<sandesh_prot::TJSONProtocol> prot(
109 new sandesh_prot::TJSONProtocol(btrans));
110 if ((ret = sandesh->
Write(prot)) < 0) {
111 SANDESH_LOG(ERROR, __func__ <<
": Sandesh write FAILED: "<<
112 sandesh->
Name() <<
" : " << sandesh->
source() <<
":" <<
114 " Sequence Number:" << sandesh->
seqnum());
116 SandeshTxDropReason::WriteFailed);
120 btrans->getBuffer(&buffer, &offset);
virtual void Initialize()
virtual bool SendMsg(Sandesh *sandesh)
virtual const char * Name() const
#define SANDESH_LOG(_Level, _Msg)
static void UpdateTxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshTxDropReason::type dreason)
static std::string module()
boost::scoped_ptr< UdpServer::Socket > stats_socket_
virtual const uint32_t seqnum()
static const uint32_t kEncodeBufferSize
virtual int32_t Write(boost::shared_ptr< contrail::sandesh::protocol::TProtocol > oprot) const =0
static std::string source()
static int kEncodeBufferSize
virtual size_t SendBuf(uint8_t *data, size_t size)
static std::string instance_id()
UdpServer::Endpoint stats_server_ep_