#include <server.hxx>
Public Member Functions | |
virtual | ~server () |
void | set_default_timeout (int _default_timeout) |
set the default timeout for new client connections | |
int | get_default_timeout (void) |
get the current default timeout for client connections | |
void | set_logging (std::ostream *_logstream, log_level_values _log_level) |
activate logging to the given stream. everything above the given level is logged. | |
server_connection * | get_connection (unsigned int conn_id) |
Gets a connection by id. | |
void | add_callback (callback_event_type event, const boost::function< void(unsigned int)> &func) |
add a callback | |
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 | |
void | close () |
void | cleanup () |
check for timeouts, remove closed connections. don't forget to call this from time to time. | |
bool | get_packet (std::string &data) |
get a complete data packet from any client. The packet is removed from the connection buffer. | |
bool | get_packet (std::string &data, unsigned int &conn_id) |
get a complete data packet from any client. The packet is removed from the connection buffer. | |
std::ostream * | get_logstream (log_level_values level) |
get pointer to logging stream, returns NULL if no logging needed | |
Protected Member Functions | |
server () | |
virtual bool | fill_connection_buffers (void)=0 |
unsigned int | add_connection (server_connection *newconn) |
add a new connection to the server | |
void | do_callbacks (callback_event_type event, unsigned int conn_id) |
an event occured, call all server-side callbacks | |
Protected Attributes | |
std::map< unsigned int, server_connection * > | connections |
Private Attributes | |
int | default_timeout |
log_level_values | log_level |
std::ostream * | logstream |
std::vector< std::list < boost::function< void(unsigned int)> > > | callbacks |
vector initialized for all callback-types, all elements in each list will be called | |
unsigned int | next_id |
server base class
constitutes a server. is abstract, use derived classes like socket_server.
libt2n::server::server | ( | ) | [protected] |
References next_id, libt2n::none, set_default_timeout(), and set_logging().
libt2n::server::~server | ( | ) | [virtual] |
References connections.
void libt2n::server::add_callback | ( | callback_event_type | event, | |
const boost::function< void(unsigned int)> & | func | |||
) |
add a callback
event | event the function will be called at | |
func | functor (see boost::function) that will be called |
References callbacks, connections, and libt2n::new_connection.
Referenced by libt2n::command_server::command_server().
unsigned int libt2n::server::add_connection | ( | server_connection * | newconn | ) | [protected] |
add a new connection to the server
References libt2n::__events_end, libt2n::server_connection::add_callback(), callbacks, libt2n::connection_closed, connections, libt2n::debug, do_callbacks(), LOGSTREAM, libt2n::new_connection, next_id, libt2n::server_connection::set_id(), and libt2n::server_connection::set_server().
Referenced by libt2n::socket_server::new_connection().
void libt2n::server::cleanup | ( | ) |
check for timeouts, remove closed connections. don't forget to call this from time to time.
References connections, libt2n::debug, and LOGSTREAM.
Referenced by libt2n::command_server::handle().
void libt2n::server::close | ( | ) |
Close all open connections
References connections.
Referenced by libt2n::socket_server::~socket_server().
void libt2n::server::do_callbacks | ( | callback_event_type | event, | |
unsigned int | conn_id | |||
) | [protected] |
an event occured, call all server-side callbacks
event | event that occured | |
conn_id | connection-id parameter that will be given to the callback-function |
References callbacks.
Referenced by add_connection().
virtual bool libt2n::server::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_server.
Referenced by libt2n::command_server::handle().
virtual bool libt2n::server::fill_connection_buffers | ( | void | ) | [protected, pure virtual] |
Implemented in libt2n::socket_server.
server_connection * libt2n::server::get_connection | ( | unsigned int | conn_id | ) |
Gets a connection by id.
conn_id | Connection ID |
Pointer | to connection object |
References connections.
Referenced by libt2n::command_server::handle(), and libt2n::command_server::send_hello().
int libt2n::server::get_default_timeout | ( | void | ) | [inline] |
get the current default timeout for client connections
References default_timeout.
Referenced by libt2n::socket_server::new_connection().
std::ostream * libt2n::server::get_logstream | ( | log_level_values | level | ) |
get pointer to logging stream, returns NULL if no logging needed
Reimplemented in libt2n::socket_server.
References log_level, and logstream.
Referenced by libt2n::server_connection::get_logstream(), libt2n::command_server::get_logstream(), and libt2n::command_server::handle_packet().
bool libt2n::server::get_packet | ( | std::string & | data, | |
unsigned int & | conn_id | |||
) |
get a complete data packet from any client. The packet is removed from the connection buffer.
[out] | data | the data package |
[out] | conn_id | the connection id we got this packet from |
true | if packet found |
References connections, libt2n::debug, and LOGSTREAM.
bool libt2n::server::get_packet | ( | std::string & | data | ) | [inline] |
get a complete data packet from any client. The packet is removed from the connection buffer.
[out] | data | the data package |
true | if packet found |
References get_packet().
Referenced by get_packet(), and libt2n::command_server::handle().
void libt2n::server::set_default_timeout | ( | int | _default_timeout | ) | [inline] |
set the default timeout for new client connections
References default_timeout.
Referenced by server().
void libt2n::server::set_logging | ( | std::ostream * | _logstream, | |
log_level_values | _log_level | |||
) |
std::vector<std::list<boost::function<void (unsigned int)> > > libt2n::server::callbacks [private] |
vector initialized for all callback-types, all elements in each list will be called
Referenced by add_callback(), add_connection(), and do_callbacks().
std::map<unsigned int, server_connection*> libt2n::server::connections [protected] |
int libt2n::server::default_timeout [private] |
Referenced by get_default_timeout(), and set_default_timeout().
log_level_values libt2n::server::log_level [private] |
Referenced by get_logstream(), and set_logging().
std::ostream* libt2n::server::logstream [private] |
Referenced by get_logstream(), and set_logging().
unsigned int libt2n::server::next_id [private] |
Referenced by add_connection(), and server().