#include <socket_handler.hxx>

Public Member Functions | |
| socket_type_value | get_type () |
| is this a tcp or unix socket connection | |
| bool | is_closed () |
| is the underlying socket connection still open? | |
| void | set_recv_buffer_size (unsigned int new_recv_buffer_size) |
| set a new size for the receive buffer. | |
| void | set_write_block_size (unsigned int new_write_block_size) |
| set new size for the data chunks when writeing. | |
| void | set_write_timeout (long long new_write_timeout) |
| set new timeout for writing a block | |
| unsigned int | get_recv_buffer_size () const |
| unsigned int | get_write_block_size () const |
| long long | get_write_timeout () const |
Protected Member Functions | |
| socket_handler (int _sock, socket_type_value _socket_type) | |
| void | set_socket_options (int sock) |
| set options like fast reuse and keepalive every socket should have | |
| virtual std::ostream * | get_logstream (log_level_values level) |
| void | socket_write (const std::string &data) |
| virtual void | close () |
| bool | fill_buffer (std::string &buffer, long long usec_timeout, long long *usec_timeout_remaining=NULL) |
| read data from the raw socket and copy it into the provided buffer | |
| bool | fill_buffer (std::string &buffer) |
| read data from the raw socket and copy it into the provided buffer. Returns instantly if no data is waiting. | |
Protected Attributes | |
| int | sock |
| unsigned int | recv_buffer_size |
| unsigned int | write_block_size |
| long long | write_timeout |
Private Member Functions | |
| bool | data_waiting (long long usec_timeout, long long *usec_timeout_remaining=NULL) |
| check if new data is waiting on the raw socket | |
| void | wait_ready_to_write (int socket, long long write_block_timeout) |
| wait until the socket is ready to write again | |
Private Attributes | |
| socket_type_value | socket_type |
Static Private Attributes | |
| static const unsigned int | default_recv_buffer_size = 2048 |
| static const unsigned int | default_write_block_size = 4096 |
| static const long long | default_write_timeout = 30000000 |
| libt2n::socket_handler::socket_handler | ( | int | _sock, | |
| socket_type_value | _socket_type | |||
| ) | [protected] |
| bool libt2n::socket_handler::data_waiting | ( | long long | usec_timeout, | |
| long long * | usec_timeout_remaining = NULL | |||
| ) | [private] |
check if new data is waiting on the raw socket
| [in,out] | usec_timeout | wait until new data is found, max timeout usecs. -1: wait endless 0: return instantly |
| [out] | usec_timeout_remaining | microseconds from the timeout that were not used |
References sock.
Referenced by fill_buffer().
| void libt2n::socket_handler::wait_ready_to_write | ( | int | socket, | |
| long long | write_block_timeout | |||
| ) | [private] |
wait until the socket is ready to write again
References libt2n::error, and EXCEPTIONSTREAM.
Referenced by socket_write().
| void libt2n::socket_handler::set_socket_options | ( | int | sock | ) | [protected] |
set options like fast reuse and keepalive every socket should have
References libt2n::error, and EXCEPTIONSTREAM.
Referenced by libt2n::socket_client_connection::connect_with_timeout(), libt2n::socket_server::new_connection(), and libt2n::socket_server::socket_server().
| virtual std::ostream* libt2n::socket_handler::get_logstream | ( | log_level_values | level | ) | [inline, protected, virtual] |
Reimplemented in libt2n::socket_client_connection, libt2n::socket_server, and libt2n::socket_server_connection.
| void libt2n::socket_handler::socket_write | ( | const std::string & | data | ) | [protected] |
writes raw data to the socket. Don't use directly, use the write() function provided by the connection because it encapsulates the data.
References libt2n::debug, libt2n::error, EXCEPTIONSTREAM, LOGSTREAM, sock, wait_ready_to_write(), write_block_size, and write_timeout.
Referenced by libt2n::socket_server_connection::real_write(), and libt2n::socket_client_connection::real_write().
| void libt2n::socket_handler::close | ( | ) | [protected, virtual] |
close the underlying socket connection. Don't call directly, use the version provided by the connection class you are using.
Reimplemented in libt2n::socket_client_connection, and libt2n::socket_server_connection.
References libt2n::debug, LOGSTREAM, and sock.
Referenced by libt2n::socket_server_connection::close(), libt2n::socket_client_connection::close(), fill_buffer(), and libt2n::socket_server::~socket_server().
| bool libt2n::socket_handler::fill_buffer | ( | std::string & | buffer, | |
| long long | usec_timeout, | |||
| long long * | usec_timeout_remaining = NULL | |||
| ) | [protected] |
read data from the raw socket and copy it into the provided buffer
| buffer | the buffer where to append the new data | |
| [in,out] | usec_timeout | wait until new data is found, max timeout usecs. -1: wait endless 0: return instantly |
| [out] | usec_timeout_remaining | microseconds from the timeout that were not used |
References data_waiting().
Referenced by libt2n::socket_server_connection::fill_buffer(), fill_buffer(), and libt2n::socket_client_connection::fill_buffer().
| bool libt2n::socket_handler::fill_buffer | ( | std::string & | buffer | ) | [protected] |
read data from the raw socket and copy it into the provided buffer. Returns instantly if no data is waiting.
| buffer | the buffer where to append the new data |
References close(), data_waiting(), libt2n::debug, libt2n::error, EXCEPTIONSTREAM, fill_buffer(), LOGSTREAM, recv_buffer_size, and sock.
| socket_type_value libt2n::socket_handler::get_type | ( | ) | [inline] |
is this a tcp or unix socket connection
References socket_type.
Referenced by libt2n::socket_server::new_connection(), libt2n::socket_client_connection::reconnect(), and libt2n::socket_server::~socket_server().
| bool libt2n::socket_handler::is_closed | ( | ) |
| void libt2n::socket_handler::set_recv_buffer_size | ( | unsigned int | new_recv_buffer_size | ) |
set a new size for the receive buffer.
| new_recv_buffer_size | the new size for the receive buffer. |
The value is normalized to be at least 512 bytes and at max 32K bytes.
References recv_buffer_size.
| void libt2n::socket_handler::set_write_block_size | ( | unsigned int | new_write_block_size | ) |
set new size for the data chunks when writeing.
| new_write_block_size | the new chunk size. |
The value is normalized to be at least 512 bytes and at max 32K bytes.
References write_block_size.
| void libt2n::socket_handler::set_write_timeout | ( | long long | new_write_timeout | ) |
set new timeout for writing a block
| new_write_timeout | the new timeout in usecs, -1: wait endless |
References write_block_size.
| unsigned int libt2n::socket_handler::get_recv_buffer_size | ( | ) | const [inline] |
References recv_buffer_size.
| unsigned int libt2n::socket_handler::get_write_block_size | ( | ) | const [inline] |
References write_block_size.
| long long libt2n::socket_handler::get_write_timeout | ( | ) | const [inline] |
References write_timeout.
const unsigned int libt2n::socket_handler::default_recv_buffer_size = 2048 [static, private] |
const unsigned int libt2n::socket_handler::default_write_block_size = 4096 [static, private] |
const long long libt2n::socket_handler::default_write_timeout = 30000000 [static, private] |
Referenced by get_type().
int libt2n::socket_handler::sock [protected] |
Referenced by libt2n::socket_server_connection::close(), close(), libt2n::socket_client_connection::connect_with_timeout(), data_waiting(), libt2n::socket_server::fill_buffer(), fill_buffer(), is_closed(), libt2n::socket_server::new_connection(), libt2n::socket_server::socket_server(), socket_write(), libt2n::socket_server::start_listening(), libt2n::socket_client_connection::tcp_connect(), and libt2n::socket_client_connection::unix_connect().
unsigned int libt2n::socket_handler::recv_buffer_size [protected] |
Referenced by fill_buffer(), get_recv_buffer_size(), and set_recv_buffer_size().
unsigned int libt2n::socket_handler::write_block_size [protected] |
Referenced by get_write_block_size(), set_write_block_size(), set_write_timeout(), and socket_write().
long long libt2n::socket_handler::write_timeout [protected] |
Referenced by get_write_timeout(), and socket_write().
1.5.6