a connection between client and server. abstact. More...
#include <connection.hxx>
Public Member Functions | |
virtual | ~connection () |
bool | is_closed () |
is this connection closed or not | |
virtual void | close () |
close this connection | |
virtual bool | fill_buffer (long long usec_timeout=-1, long long *usec_timeout_remaining=NULL)=0 |
look for new data and store it in the local buffer | |
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 | |
connection () | |
packet_size_indicator | bytes_available () |
get the number of bytes being available as next complete packet | |
virtual void | real_write (const std::string &data)=0 |
virtual std::ostream * | get_logstream (log_level_values level)=0 |
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 Attributes | |
bool | closed |
std::vector< std::list < boost::function< void()> > > | callbacks |
vector initialized for all callback-types, all elements in each list will be called |
a connection between client and server. abstact.
typedef uint32_t libt2n::connection::packet_size_indicator [protected] |
libt2n::connection::connection | ( | ) | [inline, protected] |
libt2n::connection::~connection | ( | ) | [virtual] |
References closed, libt2n::connection_closed, libt2n::connection_deleted, do_callbacks(), and is_closed().
void libt2n::connection::add_callback | ( | callback_event_type | event, | |
const boost::function< void()> & | func | |||
) |
add a callback
event | event the function will be called at | |
func | functor (see boost function) that will be called |
Reimplemented in libt2n::server_connection.
References callbacks.
Referenced by libt2n::command_client::command_client(), and libt2n::command_client::replace_connection().
connection::packet_size_indicator libt2n::connection::bytes_available | ( | ) | [protected] |
get the number of bytes being available as next complete packet
References buffer.
Referenced by get_packet(), and packet_available().
void libt2n::connection::close | ( | ) | [virtual] |
close this connection
Reimplemented in libt2n::socket_client_connection, and libt2n::socket_server_connection.
References closed, libt2n::connection_closed, do_callbacks(), and is_closed().
Referenced by libt2n::server_connection::check_timeout(), libt2n::command_client::command_client(), libt2n::dummy_client_connection::dummy_client_connection(), and libt2n::command_server::handle().
void libt2n::connection::do_callbacks | ( | callback_event_type | event | ) | [protected] |
an event has occured, execute the callbacks that are registered for this event
event | event type that has occured |
References callbacks.
Referenced by close(), reopen(), libt2n::socket_client_connection::socket_client_connection(), and ~connection().
virtual bool libt2n::connection::fill_buffer | ( | long long | usec_timeout = -1 , |
|
long long * | usec_timeout_remaining = NULL | |||
) | [pure virtual] |
look for new data and store it in the local buffer
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 |
true | if new data was found (does not mean that the received data is a complete packet though) |
Implemented in libt2n::socket_client_connection, libt2n::socket_server_connection, and libt2n::dummy_client_connection.
Referenced by libt2n::command_client::read_hello(), and libt2n::command_client::read_packet().
std::list< boost::function< void()> > libt2n::connection::get_callback_list | ( | callback_event_type | event | ) |
get the callbacks in place for one event
event | event the callbacks should be registered for |
References callbacks.
Referenced by libt2n::command_client::replace_connection().
virtual std::ostream* libt2n::connection::get_logstream | ( | log_level_values | level | ) | [protected, pure virtual] |
bool libt2n::connection::get_packet | ( | std::string & | data | ) |
read a complete data packet from the buffer. The packet is removed from the connection buffer.
[out] | data | the data package |
true | if packet found |
References buffer, and bytes_available().
Referenced by libt2n::command_client::read_hello(), and libt2n::command_client::read_packet().
bool libt2n::connection::is_closed | ( | ) | [inline] |
is this connection closed or not
References closed.
Referenced by libt2n::socket_server_connection::close(), libt2n::socket_client_connection::close(), close(), libt2n::ReconnectIgnoreFailureSocketWrapper::get_connection(), libt2n::command_client::is_connection_closed(), libt2n::command_client::read_hello(), libt2n::command_client::read_packet(), libt2n::socket_client_connection::reconnect(), reopen(), libt2n::socket_client_connection::socket_client_connection(), and ~connection().
bool libt2n::connection::packet_available | ( | ) | [inline] |
returns true if a complete data packet is in the buffer. retrieve it with get_packet().
References bytes_available().
unsigned int libt2n::connection::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.
[out] | data | the data package |
full | size of the packet when it will be complete |
References buffer.
Referenced by libt2n::command_client::read_hello().
virtual void libt2n::connection::real_write | ( | const std::string & | data | ) | [protected, pure virtual] |
Implemented in libt2n::socket_client_connection, libt2n::socket_server_connection, and libt2n::dummy_client_connection.
Referenced by write().
void libt2n::connection::remove_incomplete_packets | ( | ) | [protected] |
void libt2n::connection::reopen | ( | void | ) | [protected] |
reopen a already closed connection, removes incomplete packets from the buffer
References closed, do_callbacks(), is_closed(), libt2n::new_connection, and remove_incomplete_packets().
Referenced by libt2n::socket_client_connection::reconnect().
void libt2n::connection::write | ( | const std::string & | data | ) |
send a blob to the peer
References real_write().
Referenced by libt2n::command_server::handle_packet(), libt2n::command_client::send_command(), and libt2n::command_server::send_hello().
std::string libt2n::connection::buffer [protected] |
std::vector<std::list<boost::function<void ()> > > libt2n::connection::callbacks [private] |
vector initialized for all callback-types, all elements in each list will be called
Referenced by add_callback(), do_callbacks(), and get_callback_list().
bool libt2n::connection::closed [private] |
Referenced by close(), is_closed(), reopen(), and ~connection().