cgv
|
base class for all sockets More...
#include <socket.h>
Public Member Functions | |
virtual | ~socket () |
virtual destructor | |
std::string | get_last_error () const |
returns the last error | |
bool | is_data_pending () const |
return whether data has arrived | |
int | get_nr_of_arrived_bytes () const |
return the number of data bytes that have been arrived at the socket or -1 if socket is not connected | |
std::string | receive_line () |
receive data up to the next newline excluding the newline char | |
std::string | receive_data (unsigned int nr_of_bytes=0) |
receive all pending data or if nr_of_bytes is larger than 0, exactly nr_of_bytes | |
bool | send_line (const std::string &content) |
extends line by newline and send as data | |
bool | send_data (const std::string &) |
send the data in the string | |
bool | close () |
close the socket | |
![]() | |
int | get_ref_count () const |
read access to current count | |
Static Public Member Functions | |
static void | enable_debug_output (bool enable=true) |
enables or disables (default) debug output for all socket commands | |
Protected Member Functions | |
socket () | |
hides constructor from user | |
socket (size_t _id) | |
construct from existing socket identifier | |
bool | set_last_error (const char *location, const std::string &text="") const |
convenience function to set last error and print debug info. The method always returns false. | |
![]() | |
ref_counted () | |
constructor initializes the count to 0 | |
void | set_ref_count (int c) const |
write access is also const to allow ref counted pointers to const instances | |
Static Protected Member Functions | |
static bool | begin () |
static void | end () |
Protected Attributes | |
size_t | user_data |
store platform dependent reference to socket | |
std::string | last_error |
store the last error | |
Static Protected Attributes | |
static bool | show_debug_output = false |
static int | nr_of_sockets = 0 |
Friends | |
class | socket_server |
class | socket_select |
|
protected |
hides constructor from user
Definition at line 93 of file socket.cxx.
Referenced by cgv::os::socket_server::bind_and_listen(), cgv::os::socket_server::check_for_connection(), cgv::os::socket_client::connect(), and cgv::os::socket_server::wait_for_connection().
|
protected |
construct from existing socket identifier
Definition at line 98 of file socket.cxx.
|
virtual |
|
staticprotected |
Definition at line 53 of file socket.cxx.
bool cgv::os::socket::close | ( | ) |
close the socket
Definition at line 242 of file socket.cxx.
References last_error, cgv::os::mutex::lock(), set_last_error(), cgv::os::mutex::unlock(), and user_data.
Referenced by ~socket().
|
static |
enables or disables (default) debug output for all socket commands
Definition at line 47 of file socket.cxx.
|
staticprotected |
Definition at line 78 of file socket.cxx.
std::string cgv::os::socket::get_last_error | ( | ) | const |
int cgv::os::socket::get_nr_of_arrived_bytes | ( | ) | const |
return the number of data bytes that have been arrived at the socket or -1 if socket is not connected
return the number of data bytes that have been arrived at the socket
Definition at line 147 of file socket.cxx.
References last_error, set_last_error(), and user_data.
bool cgv::os::socket::is_data_pending | ( | ) | const |
return whether data has arrived
Definition at line 136 of file socket.cxx.
References user_data.
Referenced by receive_data().
std::string cgv::os::socket::receive_data | ( | unsigned int | nr_of_bytes = 0 | ) |
receive all pending data or if nr_of_bytes is larger than 0, exactly nr_of_bytes
Definition at line 167 of file socket.cxx.
References is_data_pending(), last_error, set_last_error(), and user_data.
std::string cgv::os::socket::receive_line | ( | ) |
receive data up to the next newline excluding the newline char
Definition at line 198 of file socket.cxx.
References last_error, cgv::os::mutex::lock(), set_last_error(), cgv::os::mutex::unlock(), and user_data.
bool cgv::os::socket::send_data | ( | const std::string & | s | ) |
send the data in the string
Definition at line 227 of file socket.cxx.
References last_error, set_last_error(), and user_data.
Referenced by send_line().
bool cgv::os::socket::send_line | ( | const std::string & | content | ) |
extends line by newline and send as data
Definition at line 222 of file socket.cxx.
References send_data().
|
protected |
convenience function to set last error and print debug info. The method always returns false.
Definition at line 102 of file socket.cxx.
References last_error, cgv::os::mutex::lock(), cgv::os::mutex::unlock(), and user_data.
Referenced by cgv::os::socket_server::bind_and_listen(), cgv::os::socket_server::check_for_connection(), close(), cgv::os::socket_client::connect(), get_nr_of_arrived_bytes(), receive_data(), receive_line(), send_data(), and cgv::os::socket_server::wait_for_connection().
|
friend |
|
mutableprotected |
store the last error
Definition at line 28 of file socket.h.
Referenced by cgv::os::socket_server::bind_and_listen(), cgv::os::socket_server::check_for_connection(), close(), get_last_error(), get_nr_of_arrived_bytes(), receive_data(), receive_line(), send_data(), set_last_error(), and cgv::os::socket_server::wait_for_connection().
|
staticprotected |
|
protected |
store platform dependent reference to socket
Definition at line 26 of file socket.h.
Referenced by cgv::os::socket_server::bind_and_listen(), cgv::os::socket_server::check_for_connection(), close(), cgv::os::socket_client::connect(), get_nr_of_arrived_bytes(), is_data_pending(), receive_data(), receive_line(), send_data(), set_last_error(), cgv::os::socket_server::wait_for_connection(), and ~socket().