Intra2net AG

libt2n::dummy_client_connection Class Reference

a placeholder-client_connection which is closed all the time More...

#include <socket_wrapper.hxx>

Inheritance diagram for libt2n::dummy_client_connection:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 dummy_client_connection ()
bool fill_buffer (long long usec_timeout=-1, long long *usec_timeout_remaining=NULL)
 look for new data and store it in the local buffer
void set_logging (std::ostream *_logstream, log_level_values _log_level)
 activate logging to the given stream. everything above the given level is logged.
std::ostream * get_logstream (log_level_values level)
 get pointer to logging stream, returns NULL if no logging needed
bool is_closed ()
 is this connection closed or not
virtual void close ()
 close this connection
bool get_packet (std::string &data)
 read a complete data packet from the buffer. The packet is removed from the connection buffer.
unsigned int peek_packet (std::string &data)
 get (maybe incomplete) data of the next packet from the buffer. Does not remove the data from the connection buffer.
bool packet_available ()
 returns true if a complete data packet is in the buffer. retrieve it with get_packet().
void write (const std::string &data)
 send a blob to the peer
void add_callback (callback_event_type event, const boost::function< void()> &func)
 add a callback
std::list< boost::function
< void()> > 
get_callback_list (callback_event_type event)
 get the callbacks in place for one event

Protected Types

typedef uint32_t packet_size_indicator

Protected Member Functions

packet_size_indicator bytes_available ()
 get the number of bytes being available as next complete packet
void do_callbacks (callback_event_type event)
 an event has occured, execute the callbacks that are registered for this event
void reopen (void)
 reopen a already closed connection, removes incomplete packets from the buffer
void remove_incomplete_packets ()
 remove all data from buffer that is not a complete packet

Protected Attributes

std::string buffer

Private Member Functions

void real_write (const std::string &data)

Detailed Description

a placeholder-client_connection which is closed all the time


Member Typedef Documentation

typedef uint32_t libt2n::connection::packet_size_indicator [protected, inherited]

Constructor & Destructor Documentation

libt2n::dummy_client_connection::dummy_client_connection (  )  [inline]

Member Function Documentation

void libt2n::connection::add_callback ( callback_event_type  event,
const boost::function< void()> &  func 
) [inherited]

add a callback

Parameters:
event event the function will be called at
func functor (see boost function) that will be called
Note:
use boost::bind to bind to member functions and parameters like this: 17 is a fixed parameter that is always added to the call c.add_callback(connection_closed,bind(&my_class::func_to_call_back, boost::ref(*this), 17));

Reimplemented in libt2n::server_connection.

References libt2n::connection::callbacks.

Referenced by libt2n::command_client::command_client(), and libt2n::command_client::replace_connection().

connection::packet_size_indicator libt2n::connection::bytes_available (  )  [protected, inherited]

get the number of bytes being available as next complete packet

References libt2n::connection::buffer.

Referenced by libt2n::connection::get_packet(), and libt2n::connection::packet_available().

void libt2n::connection::close (  )  [virtual, inherited]
void libt2n::connection::do_callbacks ( callback_event_type  event  )  [protected, inherited]

an event has occured, execute the callbacks that are registered for this event

Parameters:
event event type that has occured

References libt2n::connection::callbacks.

Referenced by libt2n::connection::close(), libt2n::connection::reopen(), libt2n::socket_client_connection::socket_client_connection(), and libt2n::connection::~connection().

bool libt2n::dummy_client_connection::fill_buffer ( long long  usec_timeout = -1,
long long *  usec_timeout_remaining = NULL 
) [inline, virtual]

look for new data and store it in the local buffer

Parameters:
usec_timeout wait until new data is found, max timeout usecs. -1: wait endless 0: return instantly
usec_timeout_remaining if non-NULL the function will write the not used time to the given target
Return values:
true if new data was found (does not mean that the received data is a complete packet though)

Implements libt2n::connection.

std::list< boost::function< void()> > libt2n::connection::get_callback_list ( callback_event_type  event  )  [inherited]

get the callbacks in place for one event

Parameters:
event event the callbacks should be registered for
Returns:
std::list of functors (boost::function) with the callbacks
Note:
if you want to get the callbacks for all events, loop from 0 to __events_end

References libt2n::connection::callbacks.

Referenced by libt2n::command_client::replace_connection().

std::ostream * libt2n::client_connection::get_logstream ( log_level_values  level  )  [virtual, inherited]

get pointer to logging stream, returns NULL if no logging needed

Implements libt2n::connection.

Reimplemented in libt2n::socket_client_connection.

References libt2n::client_connection::log_level, and libt2n::client_connection::logstream.

Referenced by libt2n::command_client::send_command().

bool libt2n::connection::get_packet ( std::string &  data  )  [inherited]

read a complete data packet from the buffer. The packet is removed from the connection buffer.

Parameters:
[out] data the data package
Return values:
true if packet found

References libt2n::connection::buffer, and libt2n::connection::bytes_available().

Referenced by libt2n::command_client::read_hello(), and libt2n::command_client::read_packet().

bool libt2n::connection::is_closed (  )  [inline, inherited]
bool libt2n::connection::packet_available (  )  [inline, inherited]

returns true if a complete data packet is in the buffer. retrieve it with get_packet().

References libt2n::connection::bytes_available().

unsigned int libt2n::connection::peek_packet ( std::string &  data  )  [inherited]

get (maybe incomplete) data of the next packet from the buffer. Does not remove the data from the connection buffer.

Parameters:
[out] data the data package
Return values:
full size of the packet when it will be complete

References libt2n::connection::buffer.

Referenced by libt2n::command_client::read_hello().

void libt2n::dummy_client_connection::real_write ( const std::string &  data  )  [inline, private, virtual]

Implements libt2n::connection.

void libt2n::connection::remove_incomplete_packets (  )  [protected, inherited]

remove all data from buffer that is not a complete packet

References libt2n::connection::buffer.

Referenced by libt2n::connection::reopen().

void libt2n::connection::reopen ( void   )  [protected, inherited]

reopen a already closed connection, removes incomplete packets from the buffer

Note:
Only call when the connection is closed.
Justs cares about the data of connection, reconnecting has to be done in a derived class.

References libt2n::connection::closed, libt2n::connection::do_callbacks(), libt2n::connection::is_closed(), libt2n::new_connection, and libt2n::connection::remove_incomplete_packets().

Referenced by libt2n::socket_client_connection::reconnect().

void libt2n::client_connection::set_logging ( std::ostream *  _logstream,
log_level_values  _log_level 
) [inherited]
void libt2n::connection::write ( const std::string &  data  )  [inherited]

Member Data Documentation

std::string libt2n::connection::buffer [protected, inherited]

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

Generated on 13 May 2015 by  doxygen 1.6.1
© Intra2net AG 2024 | Legal | Contact