OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TcpSession Class Referenceabstract

#include <tcp_session.h>

Inheritance diagram for TcpSession:
Collaboration diagram for TcpSession:

Classes

class  Reader
 

Public Types

enum  Event {
  EVENT_NONE, ACCEPT, CONNECT_COMPLETE, CONNECT_FAILED,
  CLOSE
}
 
enum  Direction { ACTIVE, PASSIVE }
 
typedef
boost::asio::ip::tcp::socket 
Socket
 
typedef
boost::asio::ip::tcp::socket::native_handle_type 
NativeSocketType
 
typedef
boost::asio::ip::tcp::endpoint 
Endpoint
 
typedef boost::function< void(TcpSession
*, Event)> 
EventObserver
 
typedef boost::asio::const_buffer Buffer
 

Public Member Functions

 TcpSession (TcpServer *server, Socket *socket, bool async_read_ready=true, size_t buffer_send_size=TcpSession::kDefaultWriteBufferSize)
 
virtual bool Send (const uint8_t *data, size_t size, size_t *sent)
 
virtual bool Connected (Endpoint remote)
 
virtual void Accepted ()
 
void ConnectFailed ()
 
void Close ()
 
virtual std::string ToString () const
 
virtual Socketsocket () const
 
NativeSocketType sock_descriptor ()
 
TcpServerserver ()
 
int32_t local_port () const
 
int32_t remote_port () const
 
void set_observer (EventObserver observer)
 
virtual void ReleaseBuffer (Buffer buffer)
 
virtual int GetSessionInstance () const
 
bool IsEstablished () const
 
bool IsClosed () const
 
bool IsServerSession ()
 
Endpoint remote_endpoint () const
 
const std::string & remote_addr_string () const
 
Endpoint local_endpoint () const
 
const boost::system::error_code & close_reason () const
 
virtual boost::system::error_code SetSocketOptions ()
 
void set_read_on_connect (bool read)
 
void SessionEstablished (Endpoint remote, Direction direction)
 
virtual void AsyncReadStart ()
 
virtual void SetDeferReader (bool defer_reader)
 
virtual bool IsReaderDeferred () const
 
const io::SocketStatsGetSocketStats () const
 
void GetRxSocketStats (SocketIOStats *socket_stats) const
 
void GetTxSocketStats (SocketIOStats *socket_stats) const
 
void GetRxSocketStats (SocketIOStats &socket_stats) const
 
void GetTxSocketStats (SocketIOStats &socket_stats) const
 
int SetMd5SocketOption (uint32_t peer_ip, const std::string &md5_password)
 
int ClearMd5SocketOption (uint32_t peer_ip)
 
int SetDscpSocketOption (uint8_t value)
 
uint8_t GetDscpValue () const
 
const std::string & ToUVEKey () const
 
boost::system::error_code SetTcpNoDelay ()
 
boost::system::error_code SetTcpSendBufSize (uint32_t size)
 
boost::system::error_code SetTcpRecvBufSize (uint32_t size)
 

Static Public Member Functions

static const uint8_t * BufferData (const Buffer &buffer)
 
static size_t BufferSize (const Buffer &buffer)
 
static bool IsSocketErrorHard (const boost::system::error_code &ec)
 

Static Public Attributes

static const int kDefaultBufferSize = 16 * 1024
 
static const int kDefaultWriteBufferSize = 32 * 1024
 

Protected Types

typedef boost::intrusive_ptr
< TcpSession
TcpSessionPtr
 
typedef boost::asio::strand
< boost::asio::io_context::executor_type > 
Strand
 

Protected Member Functions

void AsyncReadStartInternal (TcpSessionPtr session)
 
virtual TaskCreateReaderTask (boost::asio::mutable_buffer, size_t)
 
virtual ~TcpSession ()
 
virtual void OnRead (Buffer buffer)=0
 
virtual void WriteReady (const boost::system::error_code &error)
 
void AsyncWriteInternal (TcpSessionPtr session)
 
virtual void AsyncReadSome ()
 
virtual size_t GetReadBufferSize () const
 
virtual size_t ReadSome (boost::asio::mutable_buffer buffer, boost::system::error_code *error)
 
virtual void AsyncWrite (const uint8_t *data, std::size_t size)
 
virtual int reader_task_id () const
 
bool established () const
 
EventObserver observer ()
 
boost::system::error_code SetSocketKeepaliveOptions (int keepalive_time, int keepalive_intvl, int keepalive_probes, int tcp_user_timeout_val=0)
 
void CloseInternal (const boost::system::error_code &ec, bool call_observer, bool notify_server=true)
 
void TriggerAsyncReadHandler ()
 

Static Protected Member Functions

static void AsyncReadHandler (TcpSessionPtr session)
 
static void AsyncWriteHandler (TcpSessionPtr session, const boost::system::error_code &error, std::size_t bytes_transferred)
 

Protected Attributes

tbb::mutex mutex_
 
io::SocketStats stats_
 
boost::scoped_ptr< Strandio_strand_
 

Private Types

typedef std::list
< boost::asio::mutable_buffer > 
BufferQueue
 

Private Member Functions

void ReleaseBufferLocked (Buffer buffer)
 
void SetEstablished (Endpoint remote, Direction dir)
 
bool IsClosedLocked () const
 
bool IsEstablishedLocked () const
 
void SetName ()
 
boost::asio::mutable_buffer AllocateBuffer (size_t buffer_size)
 
void DeleteBuffer (boost::asio::mutable_buffer buffer)
 
 DISALLOW_COPY_AND_ASSIGN (TcpSession)
 

Static Private Member Functions

static void WriteReadyInternal (TcpSessionPtr session, const boost::system::error_code &error, uint64_t block_start_time)
 

Private Attributes

TcpServerPtr server_
 
boost::scoped_ptr< Socketsocket_
 
bool read_on_connect_
 
bool established_
 
bool closed_
 
Endpoint remote_
 
std::string remote_addr_str_
 
Direction direction_
 
BufferQueue buffer_queue_
 
boost::system::error_code close_reason_
 
tbb::mutex obs_mutex_
 
EventObserver observer_
 
boost::scoped_ptr
< TcpMessageWriter
writer_
 
tbb::atomic< int > refcount_
 
std::string name_
 
tbb::atomic< bool > defer_reader_
 
std::string uve_key_str_
 
tbb::atomic< bool > write_blocked_
 
tbb::atomic< bool > tcp_close_in_progress_
 

Static Private Attributes

static int reader_task_id_ = -1
 

Friends

class TcpServer
 
class TcpMessageWriter
 
void intrusive_ptr_add_ref (TcpSession *session)
 
void intrusive_ptr_release (TcpSession *session)
 

Detailed Description

Definition at line 42 of file tcp_session.h.

Member Typedef Documentation

typedef boost::asio::const_buffer TcpSession::Buffer

Definition at line 64 of file tcp_session.h.

typedef std::list<boost::asio::mutable_buffer> TcpSession::BufferQueue
private

Definition at line 238 of file tcp_session.h.

typedef boost::asio::ip::tcp::endpoint TcpSession::Endpoint

Definition at line 62 of file tcp_session.h.

typedef boost::function<void(TcpSession *, Event)> TcpSession::EventObserver

Definition at line 63 of file tcp_session.h.

typedef boost::asio::ip::tcp::socket::native_handle_type TcpSession::NativeSocketType

Definition at line 61 of file tcp_session.h.

typedef boost::asio::ip::tcp::socket TcpSession::Socket

Definition at line 60 of file tcp_session.h.

typedef boost::asio::strand<boost::asio::io_context::executor_type> TcpSession::Strand
protected

Definition at line 229 of file tcp_session.h.

typedef boost::intrusive_ptr<TcpSession> TcpSession::TcpSessionPtr
protected

Definition at line 184 of file tcp_session.h.

Member Enumeration Documentation

Enumerator
ACTIVE 
PASSIVE 

Definition at line 55 of file tcp_session.h.

Enumerator
EVENT_NONE 
ACCEPT 
CONNECT_COMPLETE 
CONNECT_FAILED 
CLOSE 

Definition at line 47 of file tcp_session.h.

Constructor & Destructor Documentation

TcpSession::TcpSession ( TcpServer server,
Socket socket,
bool  async_read_ready = true,
size_t  buffer_send_size = TcpSession::kDefaultWriteBufferSize 
)

Definition at line 86 of file tcp_session.cc.

Here is the call graph for this function:

TcpSession::~TcpSession ( )
protectedvirtual

Definition at line 110 of file tcp_session.cc.

Here is the call graph for this function:

Member Function Documentation

void TcpSession::Accepted ( )
virtual

Definition at line 254 of file tcp_session.cc.

Here is the call graph for this function:

mutable_buffer TcpSession::AllocateBuffer ( size_t  buffer_size)
private

Definition at line 119 of file tcp_session.cc.

void TcpSession::AsyncReadHandler ( TcpSessionPtr  session)
staticprotected

Definition at line 483 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::AsyncReadSome ( )
protectedvirtual

Reimplemented in SslSession.

Definition at line 192 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::AsyncReadStart ( )
virtual

Definition at line 174 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::AsyncReadStartInternal ( TcpSessionPtr  session)
protected

Definition at line 160 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::AsyncWrite ( const uint8_t *  data,
std::size_t  size 
)
protectedvirtual

Reimplemented in SslSession.

Definition at line 199 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::AsyncWriteHandler ( TcpSessionPtr  session,
const boost::system::error_code &  error,
std::size_t  bytes_transferred 
)
staticprotected

Definition at line 378 of file tcp_session.cc.

void TcpSession::AsyncWriteInternal ( TcpSessionPtr  session)
protected

Definition at line 417 of file tcp_session.cc.

static const uint8_t* TcpSession::BufferData ( const Buffer buffer)
inlinestatic

Definition at line 113 of file tcp_session.h.

static size_t TcpSession::BufferSize ( const Buffer buffer)
inlinestatic

Definition at line 116 of file tcp_session.h.

int TcpSession::ClearMd5SocketOption ( uint32_t  peer_ip)

Definition at line 565 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::Close ( )

Definition at line 354 of file tcp_session.cc.

Here is the call graph for this function:

const boost::system::error_code& TcpSession::close_reason ( ) const
inline

Definition at line 145 of file tcp_session.h.

void TcpSession::CloseInternal ( const boost::system::error_code &  ec,
bool  call_observer,
bool  notify_server = true 
)
protected

Definition at line 305 of file tcp_session.cc.

Here is the call graph for this function:

bool TcpSession::Connected ( Endpoint  remote)
virtual

Definition at line 269 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::ConnectFailed ( )

Definition at line 297 of file tcp_session.cc.

Task * TcpSession::CreateReaderTask ( boost::asio::mutable_buffer  ,
size_t   
)
protectedvirtual

Reimplemented in SslSession.

Definition at line 460 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::DeleteBuffer ( boost::asio::mutable_buffer  buffer)
private

Definition at line 126 of file tcp_session.cc.

TcpSession::DISALLOW_COPY_AND_ASSIGN ( TcpSession  )
private
bool TcpSession::established ( ) const
inlineprotected

Definition at line 212 of file tcp_session.h.

uint8_t TcpSession::GetDscpValue ( ) const

Definition at line 573 of file tcp_session.cc.

Here is the call graph for this function:

size_t TcpSession::GetReadBufferSize ( ) const
protectedvirtual

Reimplemented in SslSession.

Definition at line 475 of file tcp_session.cc.

void TcpSession::GetRxSocketStats ( SocketIOStats *  socket_stats) const

Definition at line 912 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::GetRxSocketStats ( SocketIOStats &  socket_stats) const
inline

Definition at line 166 of file tcp_session.h.

Here is the call graph for this function:

int TcpSession::GetSessionInstance ( ) const
virtual
const io::SocketStats& TcpSession::GetSocketStats ( ) const
inline

Definition at line 162 of file tcp_session.h.

void TcpSession::GetTxSocketStats ( SocketIOStats *  socket_stats) const

Definition at line 916 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::GetTxSocketStats ( SocketIOStats &  socket_stats) const
inline

Definition at line 170 of file tcp_session.h.

Here is the call graph for this function:

bool TcpSession::IsClosed ( ) const
inline

Definition at line 125 of file tcp_session.h.

bool TcpSession::IsClosedLocked ( ) const
inlineprivate

Definition at line 246 of file tcp_session.h.

bool TcpSession::IsEstablished ( ) const
inline

Definition at line 120 of file tcp_session.h.

bool TcpSession::IsEstablishedLocked ( ) const
inlineprivate

Definition at line 250 of file tcp_session.h.

virtual bool TcpSession::IsReaderDeferred ( ) const
inlinevirtual

Definition at line 158 of file tcp_session.h.

bool TcpSession::IsServerSession ( )
inline

Definition at line 130 of file tcp_session.h.

bool TcpSession::IsSocketErrorHard ( const boost::system::error_code &  ec)
static

Definition at line 742 of file tcp_session.cc.

TcpSession::Endpoint TcpSession::local_endpoint ( ) const

Definition at line 205 of file tcp_session.cc.

Here is the call graph for this function:

int32_t TcpSession::local_port ( ) const

Definition at line 535 of file tcp_session.cc.

Here is the call graph for this function:

EventObserver TcpSession::observer ( )
inlineprotected

Definition at line 214 of file tcp_session.h.

virtual void TcpSession::OnRead ( Buffer  buffer)
protectedpure virtual
virtual int TcpSession::reader_task_id ( ) const
inlineprotectedvirtual

Reimplemented in SandeshSession, OVSDB::OvsdbClientTcpSession, and OVSDB::OvsdbClientSslSession.

Definition at line 208 of file tcp_session.h.

size_t TcpSession::ReadSome ( boost::asio::mutable_buffer  buffer,
boost::system::error_code *  error 
)
protectedvirtual

Reimplemented in SslSession.

Definition at line 468 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::ReleaseBuffer ( Buffer  buffer)
virtual

Definition at line 143 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::ReleaseBufferLocked ( Buffer  buffer)
private

Definition at line 148 of file tcp_session.cc.

Here is the call graph for this function:

const std::string& TcpSession::remote_addr_string ( ) const
inline

Definition at line 139 of file tcp_session.h.

Endpoint TcpSession::remote_endpoint ( ) const
inline

Definition at line 135 of file tcp_session.h.

int32_t TcpSession::remote_port ( ) const

Definition at line 547 of file tcp_session.cc.

Here is the call graph for this function:

bool TcpSession::Send ( const uint8_t *  data,
size_t  size,
size_t *  sent 
)
virtual

Definition at line 428 of file tcp_session.cc.

Here is the call graph for this function:

TcpServer* TcpSession::server ( )
inline

Definition at line 88 of file tcp_session.h.

void TcpSession::SessionEstablished ( Endpoint  remote,
Direction  direction 
)

Definition at line 245 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::set_observer ( EventObserver  observer)

Definition at line 218 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::set_read_on_connect ( bool  read)
inline

Definition at line 151 of file tcp_session.h.

void TcpSession::SetDeferReader ( bool  defer_reader)
virtual

Definition at line 182 of file tcp_session.cc.

Here is the call graph for this function:

int TcpSession::SetDscpSocketOption ( uint8_t  value)

Definition at line 569 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::SetEstablished ( Endpoint  remote,
Direction  dir 
)
private
int TcpSession::SetMd5SocketOption ( uint32_t  peer_ip,
const std::string &  md5_password 
)

Definition at line 559 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::SetName ( )
private

Definition at line 223 of file tcp_session.cc.

Here is the call graph for this function:

error_code TcpSession::SetSocketKeepaliveOptions ( int  keepalive_time,
int  keepalive_intvl,
int  keepalive_probes,
int  tcp_user_timeout_val = 0 
)
protected

Definition at line 802 of file tcp_session.cc.

Here is the call graph for this function:

error_code TcpSession::SetSocketOptions ( )
virtual

Reimplemented in SandeshSession.

Definition at line 868 of file tcp_session.cc.

Here is the call graph for this function:

error_code TcpSession::SetTcpNoDelay ( )

Definition at line 765 of file tcp_session.cc.

Here is the call graph for this function:

error_code TcpSession::SetTcpRecvBufSize ( uint32_t  size)

Definition at line 789 of file tcp_session.cc.

Here is the call graph for this function:

error_code TcpSession::SetTcpSendBufSize ( uint32_t  size)

Definition at line 776 of file tcp_session.cc.

Here is the call graph for this function:

NativeSocketType TcpSession::sock_descriptor ( )
inline

Definition at line 87 of file tcp_session.h.

virtual Socket* TcpSession::socket ( ) const
inlinevirtual

Reimplemented in SslSession.

Definition at line 86 of file tcp_session.h.

virtual std::string TcpSession::ToString ( ) const
inlinevirtual

Reimplemented in SandeshSession.

Definition at line 83 of file tcp_session.h.

const std::string& TcpSession::ToUVEKey ( ) const
inline

Definition at line 178 of file tcp_session.h.

void TcpSession::TriggerAsyncReadHandler ( )
protected

Definition at line 346 of file tcp_session.cc.

Here is the call graph for this function:

void TcpSession::WriteReady ( const boost::system::error_code &  error)
protectedvirtual

Reimplemented in SandeshSession, BgpSession, and XmppSession.

Definition at line 375 of file tcp_session.cc.

static void TcpSession::WriteReadyInternal ( TcpSessionPtr  session,
const boost::system::error_code &  error,
uint64_t  block_start_time 
)
staticprivate

Friends And Related Function Documentation

void intrusive_ptr_add_ref ( TcpSession session)
friend

Definition at line 292 of file tcp_session.h.

void intrusive_ptr_release ( TcpSession session)
friend

Definition at line 296 of file tcp_session.h.

friend class TcpMessageWriter
friend

Definition at line 235 of file tcp_session.h.

friend class TcpServer
friend

Definition at line 233 of file tcp_session.h.

Member Data Documentation

BufferQueue TcpSession::buffer_queue_
private

Definition at line 271 of file tcp_session.h.

boost::system::error_code TcpSession::close_reason_
private

Definition at line 272 of file tcp_session.h.

bool TcpSession::closed_
private

Definition at line 267 of file tcp_session.h.

tbb::atomic<bool> TcpSession::defer_reader_
private

Definition at line 284 of file tcp_session.h.

Direction TcpSession::direction_
private

Definition at line 270 of file tcp_session.h.

bool TcpSession::established_
private

Definition at line 266 of file tcp_session.h.

boost::scoped_ptr<Strand> TcpSession::io_strand_
protected

Definition at line 230 of file tcp_session.h.

const int TcpSession::kDefaultBufferSize = 16 * 1024
static

Definition at line 44 of file tcp_session.h.

const int TcpSession::kDefaultWriteBufferSize = 32 * 1024
static

Definition at line 45 of file tcp_session.h.

tbb::mutex TcpSession::mutex_
mutableprotected

Definition at line 225 of file tcp_session.h.

std::string TcpSession::name_
private

Definition at line 283 of file tcp_session.h.

tbb::mutex TcpSession::obs_mutex_
private

Definition at line 277 of file tcp_session.h.

EventObserver TcpSession::observer_
private

Definition at line 278 of file tcp_session.h.

bool TcpSession::read_on_connect_
private

Definition at line 263 of file tcp_session.h.

int TcpSession::reader_task_id_ = -1
staticprivate

Definition at line 259 of file tcp_session.h.

tbb::atomic<int> TcpSession::refcount_
private

Definition at line 282 of file tcp_session.h.

Endpoint TcpSession::remote_
private

Definition at line 268 of file tcp_session.h.

std::string TcpSession::remote_addr_str_
private

Definition at line 269 of file tcp_session.h.

TcpServerPtr TcpSession::server_
private

Definition at line 261 of file tcp_session.h.

boost::scoped_ptr<Socket> TcpSession::socket_
private

Definition at line 262 of file tcp_session.h.

io::SocketStats TcpSession::stats_
protected

Definition at line 226 of file tcp_session.h.

tbb::atomic<bool> TcpSession::tcp_close_in_progress_
private

Definition at line 287 of file tcp_session.h.

std::string TcpSession::uve_key_str_
private

Definition at line 285 of file tcp_session.h.

tbb::atomic<bool> TcpSession::write_blocked_
private

Definition at line 286 of file tcp_session.h.

boost::scoped_ptr<TcpMessageWriter> TcpSession::writer_
private

Definition at line 280 of file tcp_session.h.


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