OpenSDN source code
sandesh_session.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 //
7 // sandesh_session.cc
8 //
9 // Sandesh session
10 //
11 
12 #include <boost/bind/bind.hpp>
13 #include <boost/assign.hpp>
14 #include <boost/algorithm/string.hpp>
15 
16 #include <base/parse_object.h>
17 
18 #include <sandesh/common/vns_types.h>
19 #include <sandesh/common/vns_constants.h>
20 #include <sandesh/transport/TBufferTransports.h>
21 #include <sandesh/protocol/TXMLProtocol.h>
22 #include <sandesh/protocol/TJSONProtocol.h>
23 #include "sandesh/sandesh_types.h"
24 #include "sandesh/sandesh.h"
25 
26 #include "sandesh_connection.h"
27 #include "sandesh_session.h"
28 
29 
30 using namespace std;
31 using namespace contrail::sandesh::protocol;
32 using namespace contrail::sandesh::transport;
33 using namespace boost::placeholders;
34 
35 using boost::asio::mutable_buffer;
36 using boost::asio::buffer_cast;
37 
42 
43 //
44 // SandeshWriter
45 //
47  : session_(session),
48  ready_to_send_(true),
49  send_buf_(new uint8_t[kDefaultSendSize]),
50  send_buf_offset_(0) {
51 }
52 
54  delete [] send_buf_;
55 }
56 
57 void SandeshWriter::WriteReady(const boost::system::error_code &ec) {
58  if (ec) {
59  SANDESH_LOG(ERROR, "SandeshSession Write error value: " << ec.value()
60  << " category: " << ec.category().name()
61  << " message: " << ec.message());
63  return;
64  }
65 
66  {
67  std::scoped_lock lock(send_mutex_);
68  ready_to_send_ = true;
69  }
70 
71  // We may want to start the Runner for the send_queue
73 }
74 
76  SandeshHeader header;
77  std::stringstream ss;
78  uint8_t *buffer;
79  int32_t xfer = 0, ret;
80  uint32_t offset;
81  boost::shared_ptr<TMemoryBuffer> btrans(
83  boost::shared_ptr<TXMLProtocol> prot(
84  new TXMLProtocol(btrans));
85  // Populate the header
86  header.set_Namespace(sandesh->scope());
87  header.set_Timestamp(sandesh->timestamp());
88  header.set_Module(sandesh->module());
89  header.set_Source(sandesh->source());
90  header.set_Context(sandesh->context());
91  header.set_SequenceNum(sandesh->seqnum());
92  header.set_VersionSig(sandesh->versionsig());
93  header.set_Type(sandesh->type());
94  header.set_Hints(sandesh->hints());
95  header.set_Level(sandesh->level());
96  header.set_Category(sandesh->category());
97  header.set_NodeType(sandesh->node_type());
98  header.set_InstanceId(sandesh->instance_id());
99 
100  // Write the sandesh open envelope.
101  buffer = btrans->getWritePtr(sandesh_open_.length());
102  memcpy(buffer, sandesh_open_.c_str(), sandesh_open_.length());
103  btrans->wroteBytes(sandesh_open_.length());
104  // Write the sandesh header
105  if ((ret = header.write(prot)) < 0) {
106  SANDESH_LOG(ERROR, __func__ << ": Sandesh header write FAILED: " <<
107  sandesh->Name() << " : " << sandesh->source() << ":" <<
108  sandesh->module() << ":" << sandesh->instance_id() <<
109  " Sequence Number:" << sandesh->seqnum());
112  SandeshTxDropReason::HeaderWriteFailed);
113  sandesh->Release();
114  return;
115  }
116  xfer += ret;
117  // Write the sandesh
118  if ((ret = sandesh->Write(prot)) < 0) {
119  SANDESH_LOG(ERROR, __func__ << ": Sandesh write FAILED: "<<
120  sandesh->Name() << " : " << sandesh->source() << ":" <<
121  sandesh->module() << ":" << sandesh->instance_id() <<
122  " Sequence Number:" << sandesh->seqnum());
125  SandeshTxDropReason::WriteFailed);
126  sandesh->Release();
127  return;
128  }
129  xfer += ret;
130  // Write the sandesh close envelope
131  buffer = btrans->getWritePtr(sandesh_close_.length());
132  memcpy(buffer, sandesh_close_.c_str(), sandesh_close_.length());
133  btrans->wroteBytes(sandesh_close_.length());
134  // Get the buffer
135  btrans->getBuffer(&buffer, &offset);
136  // Sanity
137  assert(sandesh_open_.length() + xfer + sandesh_close_.length() ==
138  offset);
139  // Update the sandesh open envelope length;
140  char prev = ss.fill('0');
141  // Adjust for '">'
142  ss.width(sandesh_open_.length() - sandesh_open_attr_length_.length() - 2);
143  ss << offset;
144  ss.fill(prev);
145  memcpy(buffer + sandesh_open_attr_length_.length(), ss.str().c_str(),
146  ss.str().length());
147 
148  // Update sandesh stats
149  Sandesh::UpdateTxMsgStats(sandesh->Name(), offset);
151 
152  if (send_buf()) {
153  if (more) {
154  // There are more messages in the send_queue_.
155  // Try to package as many sandesh messages as possible
156  // (== kEncodeBufferSize) before transporting to the
157  // receiver.
158  SendMsgMore(btrans);
159  } else {
160  // send_queue_ is empty. Flush sandesh->send_buf_ and this message.
161  SendMsgAll(btrans);
162  }
163  } else {
164  // Send the message
165  SendInternal(btrans);
166  }
167  sandesh->Release();
168 }
169 
170 // Package as many sandesh messages as possible [not more than
171 // kEncodeBufferSize] before transporting it to the receiver.
172 //
173 // send_buf_ => unsent data (partial/complete message).
174 // buf => new message
175 // buf_len => buf's len
176 void SandeshWriter::SendMsgMore(boost::shared_ptr<TMemoryBuffer>
177  send_buffer) {
178  uint8_t *buf;
179  uint32_t buf_len;
180 
181  send_buffer->getBuffer(&buf, &buf_len);
182 
183  if (send_buf_offset()) {
184  // We have some unsent data.
185  size_t bulk_msg_len = send_buf_offset() + buf_len;
186  if (bulk_msg_len < kDefaultSendSize) {
187  // We still have space for more data. Don't send the message yet.
188  // Add the message to the existing data.
189  append_send_buf(buf, buf_len);
190  } else {
191  uint8_t *buffer;
192  // (send_buf_offset() + buf_len) >= kDefaultSendSize
193  boost::shared_ptr<TMemoryBuffer> bulk_msg(
195  buffer = bulk_msg->getWritePtr(send_buf_offset());
196  // Copy unsent data
197  memcpy(buffer, send_buf(), send_buf_offset());
198  bulk_msg->wroteBytes(send_buf_offset());
199  // Send it
200  SendInternal(bulk_msg);
201  // Cleanup send_buf
202  reset_send_buf();
203  // Next send the new message
204  SendInternal(send_buffer);
205  }
206  } else {
207  // We don't have any unsent data.
208  if (buf_len >= kDefaultSendSize) {
209  // We don't have room to accommodate anything more.
210  // Send the message now.
211  SendInternal(send_buffer);
212  } else {
213  // We have room to accommodate more data.
214  // Save this message.
215  // Note: The memcpy here can be avoided by passing send_buf_
216  // to TMemoryBuffer so that the message is encoded in
217  // send_buf_ itself.
218  set_send_buf(buf, buf_len);
219  }
220  }
221 }
222 
223 // sandesh->send_queue_ is empty.
224 // Flush unsent data (if any) and this message.
225 void SandeshWriter::SendMsgAll(boost::shared_ptr<TMemoryBuffer> send_buffer) {
226  uint8_t *buf;
227  uint32_t buf_len;
228 
229  send_buffer->getBuffer(&buf, &buf_len);
230 
231  if (send_buf_offset()) {
232  // We have some unsent data.
233  size_t bulk_msg_len = send_buf_offset() + buf_len;
234  if (bulk_msg_len <= kDefaultSendSize) {
235  uint8_t *buffer;
236  // We have enough room to send all the pending data in one message.
237  boost::shared_ptr<TMemoryBuffer> bulk_msg(new
238  TMemoryBuffer(bulk_msg_len));
239  buffer = bulk_msg->getWritePtr(bulk_msg_len);
240  memcpy(buffer, send_buf(), send_buf_offset());
241  memcpy(buffer + send_buf_offset(), buf, buf_len);
242  bulk_msg->wroteBytes(bulk_msg_len);
243  // send the message
244  SendInternal(bulk_msg);
245  // reset send_buf_
246  reset_send_buf();
247  } else {
248  uint8_t *buffer;
249  // We don't have enough space to accommodate all the
250  // pending data in one message.
251  boost::shared_ptr<TMemoryBuffer> old_buf(new
253  buffer = old_buf->getWritePtr(send_buf_offset());
254  memcpy(buffer, send_buf(),
255  send_buf_offset());
256  old_buf->wroteBytes(send_buf_offset());
257  // Take care of the unsent data in send_buf_ first.
258  // Note that we could have accomodated part of buf [last message]
259  // here. But, not doing so to avoid additional memcpy() :)
260  SendInternal(old_buf);
261  // Cleanup send_buf_
262  reset_send_buf();
263  // Well, send the last message now.
264  SendInternal(send_buffer);
265  }
266  } else {
267  // No unsent data. Send the message now.
268  SendInternal(send_buffer);
269  }
270 }
271 
272 void SandeshWriter::SendInternal(boost::shared_ptr<TMemoryBuffer> buf) {
273  uint8_t *buffer;
274  uint32_t len;
275  buf->getBuffer(&buffer, &len);
276  std::scoped_lock lock(send_mutex_);
277  ready_to_send_ = session_->Send((const uint8_t *)buffer, len, NULL);
278 }
279 
280 //
281 // SandeshSession
282 //
284  int task_instance, int writer_task_id, int reader_task_id) :
285  SslSession(client, socket),
286  instance_(task_instance),
287  writer_(new SandeshWriter(this)),
288  reader_(new SandeshReader(this)),
289  send_queue_(new Sandesh::SandeshQueue(writer_task_id,
290  task_instance,
291  boost::bind(&SandeshSession::SendMsg, this, _1),
292  kQueueSize)),
293  stats_client_(NULL),
294  connection_(NULL),
295  keepalive_idle_time_(kSessionKeepaliveIdleTime),
296  keepalive_interval_(kSessionKeepaliveInterval),
297  keepalive_probes_(kSessionKeepaliveProbes),
298  tcp_user_timeout_(kSessionTcpUserTimeout),
299  reader_task_id_(reader_task_id),
300  sending_level_(SandeshLevel::INVALID) {
302  send_buffer_queue_.reset(new Sandesh::SandeshBufferQueue(writer_task_id,
303  task_instance,
304  boost::bind(&SandeshSession::SendBuffer, this, _1)));
305  send_buffer_queue_->SetStartRunnerFunc(boost::bind(&SandeshSession::SessionSendReady, this));
306  }
307  send_queue_->SetStartRunnerFunc(boost::bind(&SandeshSession::SessionSendReady, this));
308 }
309 
311 }
312 
314  return (IsEstablished() && writer_->SendReady() &&
316 }
317 
320  WaterMarkInfo wm(boost::get<0>(swmi),
321  boost::bind(&SandeshSession::SetSendingLevel, this, _1,
322  boost::get<1>(swmi)));
323  if (boost::get<2>(swmi)) {
324  send_queue_->SetHighWaterMark(wm);
325  } else {
326  send_queue_->SetLowWaterMark(wm);
327  }
328 }
329 
331  send_queue_->ResetHighWaterMark();
332  send_queue_->ResetLowWaterMark();
333 }
334 
336  if (sending_level_ != level) {
337  sending_level_ = level;
338  }
339 }
340 
342  return sending_level_;
343 }
344 
347  send_buffer_queue_->Shutdown();
348  }
349  send_queue_->Shutdown();
350 }
351 
352 std::string SandeshSession::ToString() const {
353  std::stringstream out;
354  out << TcpSession::ToString() << "(" << instance_ << ")";
355  return out.str();
356 }
357 
358 boost::system::error_code SandeshSession::SetSocketOptions() {
359  boost::system::error_code ec = TcpSession::SetSocketOptions();
360  if (ec) {
361  return ec;
362  }
365 }
366 
368  reader_->OnRead(buffer);
369 }
370 
372  Sandesh *sandesh = element.snh_;
373  std::scoped_lock lock(send_mutex_);
374  if (!IsEstablished()) {
376  SANDESH_LOG(ERROR, __func__ << " Not Connected : Dropping Message: " <<
377  sandesh->ToString());
378  }
381  SandeshTxDropReason::SessionNotConnected);
382  sandesh->Release();
383  return true;
384  }
385  if (sandesh->IsLoggingAllowed()) {
386  sandesh->Log();
387  }
388  bool more = !send_queue_->IsQueueEmpty();
389  if (stats_client_ && sandesh->type() == SandeshType::UVE) {
391  }
392  writer_->SendMsg(sandesh, more);
393  return true;
394 }
395 
396 bool SandeshSession::SendBuffer(boost::shared_ptr<TMemoryBuffer> sbuffer) {
397  std::scoped_lock lock(send_mutex_);
398  if (!IsEstablished()) {
400  return true;
401  }
402  // No buffer packing supported currently
403  writer_->SendBuffer(sbuffer);
404  return true;
405 }
406 
407 bool SandeshSession::EnqueueBuffer(u_int8_t *buf, u_int32_t buf_len) {
408  boost::shared_ptr<TMemoryBuffer> sbuffer(new TMemoryBuffer(buf_len));
409  u_int8_t *write_buf = sbuffer->getWritePtr(buf_len);
410  memcpy(write_buf, buf, buf_len);
411  sbuffer->wroteBytes(buf_len);
412  return send_buffer_queue()->Enqueue(sbuffer);
413 }
414 
416  const SandeshHeader& header,
417  const string& sandesh_name, const uint32_t& header_offset) {
418  namespace sandesh_prot = contrail::sandesh::protocol;
419  namespace sandesh_trans = contrail::sandesh::transport;
420 
421  assert(header.get_Hints() & g_sandesh_constants.SANDESH_CONTROL_HINT);
422 
423  // Create and process the sandesh
425  if (sandesh == NULL) {
426  SANDESH_LOG(ERROR, __func__ << ": Unknown sandesh ctrl message: " << sandesh_name);
427  return NULL;
428  }
429  boost::shared_ptr<sandesh_trans::TMemoryBuffer> btrans =
430  boost::shared_ptr<sandesh_trans::TMemoryBuffer>(
431  new sandesh_trans::TMemoryBuffer((uint8_t *)msg.c_str() + header_offset,
432  msg.size() - header_offset));
433  boost::shared_ptr<sandesh_prot::TXMLProtocol> prot =
434  boost::shared_ptr<sandesh_prot::TXMLProtocol>(new sandesh_prot::TXMLProtocol(btrans));
435  int32_t xfer = sandesh->Read(prot);
436  if (xfer < 0) {
437  SANDESH_LOG(ERROR, __func__ << ": Decoding " << sandesh_name << " for ctrl FAILED");
438  sandesh->Release();
439  return NULL;
440  } else {
441  return sandesh;
442  }
443 }
444 
446  if (IsClosed()) {
447  return;
448  }
449  std::scoped_lock lock(conn_mutex_);
450  if (connection_) {
453  } else {
455  if (eobs) {
456  eobs(this, TcpSession::CLOSE);
457  }
458  }
459 }
460 
461 //
462 // SandeshReader
463 //
465  buf_(""),
466  offset_(0),
467  msg_length_(-1),
468  session_(session) {
469  buf_.reserve(kDefaultRecvSize);
470 }
471 
473 }
474 
475 int SandeshReader::ExtractMsgHeader(const std::string& msg,
476  SandeshHeader& header, std::string& msg_type, uint32_t& header_offset) {
477  int32_t xfer = 0, ret;
478  boost::shared_ptr<TMemoryBuffer> btrans =
479  boost::shared_ptr<TMemoryBuffer>(
480  new TMemoryBuffer((uint8_t *)msg.c_str(), msg.size()));
481  boost::shared_ptr<TXMLProtocol> prot =
482  boost::shared_ptr<TXMLProtocol>(new TXMLProtocol(btrans));
483  // Read the sandesh header and note the offset
484  if ((ret = header.read(prot)) <= 0) {
485  SANDESH_LOG(ERROR, __func__ << ": Sandesh header read FAILED: " << msg);
486  return EINVAL;
487  }
488  xfer += ret;
489  header_offset = xfer;
490  // Extract the message name
491  if ((ret = prot->readSandeshBegin(msg_type)) <= 0) {
492  SANDESH_LOG(ERROR, __func__ << ": Sandesh begin read FAILED: " << msg);
493  return EINVAL;
494  }
495  xfer += ret;
496  return 0;
497 }
498 
499 void SandeshReader::SetBuf(const std::string &str) {
500  if (buf_.empty()) {
501  ReplaceBuf(str);
502  } else {
503  buf_ += str;
504  }
505  // TODO handle buf_ > kMaxMessageSize
506 }
507 
508 void SandeshReader::ReplaceBuf(const std::string &str) {
509  buf_ = str;
511  offset_ = 0;
512 }
513 
515  if (buf_.empty()) {
516  return false;
517  }
518  return (buf_.size() != offset_);
519 }
520 
521 // Returns false if not able to extract the message length, true otherwise
522 bool SandeshReader::ExtractMsgLength(size_t &msg_length, int *result) {
523  // Have we read enough to extract the message length?
524  if (buf_.size() - offset_ < SandeshWriter::sandesh_open_.size()) {
525  return false;
526  }
527  // Some sanity check
528  if (!boost::algorithm::starts_with(buf_.c_str() + offset_,
530  *result = -1;
531  return false;
532  }
533 
534  std::string::const_iterator end = buf_.begin() + offset_ +
535  SandeshWriter::sandesh_open_.size() - 1;
536  if (*end != '>') {
537  *result = -2;
538  return false;
539  }
540 
541  std::string::const_iterator st = buf_.begin() + offset_ +
543  // Adjust for double quote
544  --end;
545  string length = string(st, end);
546 
547  stringToInteger(length.c_str(), msg_length);
548  if (msg_length == 0) {
549  *result = -3;
550  return false;
551  }
552  return true;
553 }
554 
555 // Returns false if not able to extract the full message, true otherwise
556 bool SandeshReader::ExtractMsg(Buffer buffer, int *result, bool NewBuf) {
557  if (NewBuf) {
558  const uint8_t *cp = TcpSession::BufferData(buffer);
559  // TODO Avoid this copy
560  std::string str(cp, cp + TcpSession::BufferSize(buffer));
561  SetBuf(str);
562  }
563  // Extract the message length
564  if (!MsgLengthKnown()) {
565  size_t msg_length = 0;
566  bool done = ExtractMsgLength(msg_length, result);
567  if (done == false) {
568  return false;
569  }
571  }
572  // Check if the entire message is read or not
573  if (buf_.size() < msg_length()) {
574  return false;
575  }
576  return true;
577 }
578 
580  std::scoped_lock lock(cb_mutex_);
581  // Check if session is being deleted, then drop the packet
582  if (cb_.empty()) {
583  SANDESH_LOG(ERROR, __func__ <<
584  " Session being deleted: Dropping Message");
586  session_->ReleaseBuffer(buffer);
587  return;
588  }
589  int result = 0;
590  bool done = ExtractMsg(buffer, &result, true);
591  do {
592  if (result < 0) {
593  // Generate error and close connection
594  SANDESH_LOG(ERROR, __func__ << " Message extract failed: " << result);
595  const uint8_t *cp = TcpSession::BufferData(buffer);
596  size_t cp_size = TcpSession::BufferSize(buffer);
597  SANDESH_LOG(ERROR, __func__ << " OnRead Buffer Size: " << cp_size);
598  SANDESH_LOG(ERROR, __func__ << " OnRead Buffer: ");
599  std::string debug((const char*)cp, cp_size);
600  SANDESH_LOG(ERROR, debug);
601  SANDESH_LOG(ERROR, __func__ << " Reader Size: " << buf_.size());
602  SANDESH_LOG(ERROR, __func__ << " Reader Offset: " << offset_);
603  SANDESH_LOG(ERROR, __func__ << " Reader Buffer: " << buf_);
604  buf_.clear();
605  offset_ = 0;
606  // Enqueue a close on the state machine
609  break;
610  }
611  if (done == true) {
612  // We got good match. Process the message after extracting out
613  // the sandesh open and close envelope
614  std::string::const_iterator st = buf_.begin() + offset_ +
616  std::string::const_iterator end = buf_.begin() + offset_ +
618  std::string xml(st, end);
619  offset_ += msg_length();
621  if (!cb_(xml, session_)) {
622  // Enqueue a close on the state machine
625  break;
626  }
627  } else {
628  // Read more data.
629  break;
630  }
631 
632  if (LeftOver()) {
633  ReplaceBuf(string(buf_, offset_, buf_.size() - offset_));
634  done = ExtractMsg(buffer, &result, false);
635  } else {
636  // No more data in the Buffer
637  buf_.clear();
638  offset_ = 0;
639  break;
640  }
641  } while (true);
642 
643  session_->ReleaseBuffer(buffer);
644  return;
645 }
646 
648  std::scoped_lock lock(cb_mutex_);
649  cb_ = cb;
650 }
static Sandesh * CreateInstance(std::string const &s)
Definition: cpp/sandesh.h:626
SandeshStateMachine * state_machine() const
void reset_msg_length()
virtual ~SandeshReader()
void SetReceiveMsgCb(SandeshReceiveMsgCb cb)
virtual void OnRead(Buffer buffer)
size_t msg_length()
SandeshReader(SandeshSession *session)
std::mutex cb_mutex_
void ReplaceBuf(const std::string &str)
SandeshReceiveMsgCb cb_
SandeshSession * session_
boost::asio::const_buffer Buffer
std::string buf_
void SetBuf(const std::string &str)
static const int kDefaultRecvSize
bool ExtractMsg(Buffer buffer, int *result, bool NewBuf)
bool LeftOver() const
bool ExtractMsgLength(size_t &msg_length, int *result)
void set_msg_length(size_t length)
static int ExtractMsgHeader(const std::string &msg, SandeshHeader &header, std::string &msg_type, uint32_t &header_offset)
bool SendMsg(SandeshElement element)
virtual void EnqueueClose()
virtual std::string ToString() const
virtual void OnRead(Buffer buffer)
virtual ~SandeshSession()
virtual boost::system::error_code SetSocketOptions()
void increment_send_buffer_fail()
SandeshSession(SslServer *client, SslSocket *socket, int task_instance, int writer_task_id, int reader_task_id)
void increment_write_ready_cb_error()
static Sandesh * DecodeCtrlSandesh(const std::string &msg, const SandeshHeader &header, const std::string &sandesh_name, const uint32_t &header_offset)
StatsClient * stats_client_
virtual void Shutdown()
boost::scoped_ptr< SandeshWriter > writer_
void SetSendQueueWaterMark(Sandesh::QueueWaterMarkInfo &wm_info)
boost::scoped_ptr< SandeshReader > reader_
Sandesh::SandeshBufferQueue * send_buffer_queue()
bool SendBuffer(boost::shared_ptr< TMemoryBuffer > sbuffer)
void increment_recv_fail()
void SetSendingLevel(size_t count, SandeshLevel::type level)
void increment_send_msg_fail()
SandeshLevel::type sending_level_
Sandesh::SandeshQueue * send_queue()
std::mutex conn_mutex_
std::mutex send_mutex_
virtual bool EnqueueBuffer(u_int8_t *buf, u_int32_t buf_len)
void increment_send_msg()
boost::scoped_ptr< Sandesh::SandeshQueue > send_queue_
SandeshLevel::type SendingLevel() const
boost::scoped_ptr< Sandesh::SandeshBufferQueue > send_buffer_queue_
void ResetSendQueueWaterMark()
SandeshConnection * connection_
void OnSessionEvent(TcpSession *session, TcpSession::Event event)
static const std::string sandesh_open_
void append_send_buf(uint8_t *buf, size_t len)
static const unsigned int kDefaultSendSize
void SendMsg(Sandesh *sandesh, bool more)
SandeshWriter(SandeshSession *session)
void WriteReady(const boost::system::error_code &ec)
void reset_send_buf()
void SendInternal(boost::shared_ptr< TMemoryBuffer >)
size_t send_buf_offset()
SandeshSession * session_
void set_send_buf(uint8_t *buf, size_t len)
static const uint32_t kEncodeBufferSize
static const std::string sandesh_close_
void SendMsgAll(boost::shared_ptr< TMemoryBuffer >)
void SendMsgMore(boost::shared_ptr< TMemoryBuffer >)
uint8_t * send_buf() const
uint8_t * send_buf_
std::mutex send_mutex_
static const std::string sandesh_open_attr_length_
static void UpdateTxMsgFailStats(const std::string &msg_name, uint64_t bytes, SandeshTxDropReason::type dreason)
Definition: sandesh.cc:892
static SandeshRole::type role()
Definition: cpp/sandesh.h:299
boost::tuple< size_t, SandeshLevel::type, bool, bool > QueueWaterMarkInfo
Definition: cpp/sandesh.h:150
static void UpdateTxMsgStats(const std::string &msg_name, uint64_t bytes)
Definition: sandesh.cc:886
static bool IsSendQueueEnabled()
Definition: cpp/sandesh.h:242
static bool IsLoggingDroppedAllowed(SandeshType::type)
Definition: sandesh.cc:846
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
Definition: ssl_session.h:21
virtual bool SendMsg(Sandesh *sandesh)=0
bool IsClosed() const
Definition: tcp_session.h:122
static const uint8_t * BufferData(const Buffer &buffer)
Definition: tcp_session.h:110
virtual std::string ToString() const
Definition: tcp_session.h:80
static size_t BufferSize(const Buffer &buffer)
Definition: tcp_session.h:113
virtual void ReleaseBuffer(Buffer buffer)
Definition: tcp_session.cc:145
boost::function< void(TcpSession *, Event)> EventObserver
Definition: tcp_session.h:60
boost::asio::const_buffer Buffer
Definition: tcp_session.h:61
bool IsEstablished() const
Definition: tcp_session.h:117
virtual boost::system::error_code SetSocketOptions()
Definition: tcp_session.cc:870
EventObserver observer()
Definition: tcp_session.h:211
boost::system::error_code SetSocketKeepaliveOptions(int keepalive_time, int keepalive_intvl, int keepalive_probes, int tcp_user_timeout_val=0)
Definition: tcp_session.cc:804
virtual bool Send(const uint8_t *data, size_t size, size_t *sent)
Definition: tcp_session.cc:430
bool Enqueue(QueueEntryT entry)
Definition: queue_task.h:249
void MayBeStartRunner()
Definition: queue_task.h:282
#define SANDESH_LOG(_Level, _Msg)
Definition: cpp/sandesh.h:477
@ INVALID
Definition: globals.h:150
uint8_t type
Definition: load_balance.h:2
boost::function< bool(const std::string &, SandeshSession *)> SandeshReceiveMsgCb
#define sXML_SANDESH_OPEN
#define sXML_SANDESH_CLOSE
#define sXML_SANDESH_OPEN_ATTR_LENGTH
bool stringToInteger(const std::string &str, NumberType &num)
Definition: string_util.h:72
Sandesh * snh_
Definition: cpp/sandesh.h:457