PionNetworkLibrary
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pion::tcp::stream_buffer Class Reference

#include <stream.hpp>

Inheritance diagram for pion::tcp::stream_buffer:
Collaboration diagram for pion::tcp::stream_buffer:

Public Types

enum  { PUT_BACK_MAX = 10, WRITE_BUFFER_SIZE = 8192 }
 
typedef char char_type
 
typedef std::char_traits< char >
::int_type 
int_type
 
typedef std::char_traits< char >
::off_type 
off_type
 
typedef std::char_traits< char >
::pos_type 
pos_type
 
typedef std::char_traits< char > traits_type
 

Public Member Functions

 stream_buffer (const tcp::connection_ptr &conn_ptr)
 
 stream_buffer (boost::asio::io_service &io_service, const bool ssl_flag=false)
 
 stream_buffer (boost::asio::io_service &io_service, connection::ssl_context_type &ssl_context)
 
virtual ~stream_buffer ()
 virtual destructor flushes the write buffer More...
 
connectionget_connection (void)
 returns a reference to the current TCP connection More...
 
const connectionget_connection (void) const
 returns a const reference to the current TCP connection More...
 

Protected Member Functions

void setup_buffers (void)
 sets up the read and write buffers for input and output More...
 
int_type flush_output (void)
 
virtual int_type underflow (void)
 
virtual int_type overflow (int_type c)
 
virtual std::streamsize xsputn (const char_type *s, std::streamsize n)
 
virtual std::streamsize xsgetn (char_type *s, std::streamsize n)
 
virtual int_type sync (void)
 

Detailed Description

stream_buffer: std::basic_streambuf wrapper for TCP network connections. Based in part on section 13.13.3 of "The Standard C++ Library" by Nicolai M. Josuttis, published in 1999 by Addison-Wesley

Member Typedef Documentation

typedef std::char_traits<char>::int_type pion::tcp::stream_buffer::int_type
typedef std::char_traits<char>::off_type pion::tcp::stream_buffer::off_type
typedef std::char_traits<char>::pos_type pion::tcp::stream_buffer::pos_type
typedef std::char_traits<char> pion::tcp::stream_buffer::traits_type

Member Enumeration Documentation

anonymous enum
Enumerator
PUT_BACK_MAX 
WRITE_BUFFER_SIZE 

Constructor & Destructor Documentation

pion::tcp::stream_buffer::stream_buffer ( const tcp::connection_ptr conn_ptr)
inlineexplicit

constructs a TCP stream buffer object for an existing TCP connection

Parameters
conn_ptrpointer to the TCP connection to use for reading & writing

References setup_buffers().

pion::tcp::stream_buffer::stream_buffer ( boost::asio::io_service &  io_service,
const bool  ssl_flag = false 
)
inlineexplicit

constructs a TCP stream buffer object for a new TCP connection

Parameters
io_serviceasio service associated with the connection
ssl_flagif true then the connection will be encrypted using SSL

References setup_buffers().

pion::tcp::stream_buffer::stream_buffer ( boost::asio::io_service &  io_service,
connection::ssl_context_type ssl_context 
)
inline

constructs a TCP stream buffer object for a new SSL/TCP connection

Parameters
io_serviceasio service associated with the connection
ssl_contextasio ssl context associated with the connection

References setup_buffers().

virtual pion::tcp::stream_buffer::~stream_buffer ( )
inlinevirtual

virtual destructor flushes the write buffer

References sync().

Member Function Documentation

int_type pion::tcp::stream_buffer::flush_output ( void  )
inlineprotected

writes data in the output buffer to the TCP connection

Returns
int_type the number of bytes sent, or eof() if there was an error

Referenced by overflow(), sync(), and xsputn().

connection& pion::tcp::stream_buffer::get_connection ( void  )
inline
const connection& pion::tcp::stream_buffer::get_connection ( void  ) const
inline

returns a const reference to the current TCP connection

virtual int_type pion::tcp::stream_buffer::overflow ( int_type  c)
inlineprotectedvirtual

this function is called when the write buffer for the stream is full

Parameters
ccharacter that has not been written yet, or eof() if we are flushing
Returns
int_type the last character written, or eof() if there was an error

References flush_output().

void pion::tcp::stream_buffer::setup_buffers ( void  )
inlineprotected

sets up the read and write buffers for input and output

References PUT_BACK_MAX, and WRITE_BUFFER_SIZE.

Referenced by stream_buffer().

virtual int_type pion::tcp::stream_buffer::sync ( void  )
inlineprotectedvirtual

synchronize buffers with the TCP connection

Returns
0 if successful, -1 if there was an error

References flush_output().

Referenced by ~stream_buffer().

virtual int_type pion::tcp::stream_buffer::underflow ( void  )
inlineprotectedvirtual

this function is called when the read buffer has no more characters available

Returns
int_type the next character available for reading, or eof() if there was an error

References PUT_BACK_MAX, and pion::tcp::connection::READ_BUFFER_SIZE.

Referenced by xsgetn().

virtual std::streamsize pion::tcp::stream_buffer::xsgetn ( char_type s,
std::streamsize  n 
)
inlineprotectedvirtual

reads a sequence of characters

Parameters
spointer to where the sequence of characters will be stored
nnumber of characters in the sequence to read
Returns
std::streamsize number of character read

References underflow().

virtual std::streamsize pion::tcp::stream_buffer::xsputn ( const char_type s,
std::streamsize  n 
)
inlineprotectedvirtual

writes a sequence of characters

Parameters
spointer to a sequence of characters
nnumber of characters in the sequence to write
Returns
std::streamsize number of character written

References flush_output(), and WRITE_BUFFER_SIZE.


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