cgv
|
socket server allows to be connected to More...
#include <socket.h>
Public Member Functions | |
bool | bind_and_listen (int port, int max_nr_pending_connections) |
bind and listen to given port with a queue for pending connections of the given size | |
socket_ptr | wait_for_connection () |
if no connection is pending, block thread and wait for next incoming connection | |
socket_ptr | check_for_connection () |
check if a new connection is in the connection queue and return this or an empty connection pointer | |
![]() | |
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 | |
Protected Member Functions | |
socket_server () | |
hide from direct use | |
![]() | |
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 | |
Friends | |
CGV_API socket_server_ptr | create_socket_server () |
this is the only way to create a socket_server as a reference counted pointer | |
Additional Inherited Members | |
![]() | |
static void | enable_debug_output (bool enable=true) |
enables or disables (default) debug output for all socket commands | |
![]() | |
static bool | begin () |
static void | end () |
![]() | |
size_t | user_data |
store platform dependent reference to socket | |
std::string | last_error |
store the last error | |
![]() | |
static bool | show_debug_output = false |
static int | nr_of_sockets = 0 |
|
protected |
hide from direct use
Definition at line 304 of file socket.cxx.
bool cgv::os::socket_server::bind_and_listen | ( | int | port, |
int | max_nr_pending_connections | ||
) |
bind and listen to given port with a queue for pending connections of the given size
Definition at line 308 of file socket.cxx.
References cgv::os::socket::last_error, cgv::os::mutex::lock(), cgv::os::socket::set_last_error(), cgv::os::socket::socket(), cgv::os::mutex::unlock(), and cgv::os::socket::user_data.
socket_ptr cgv::os::socket_server::check_for_connection | ( | ) |
check if a new connection is in the connection queue and return this or an empty connection pointer
Definition at line 369 of file socket.cxx.
References cgv::os::socket::last_error, cgv::os::mutex::lock(), cgv::os::socket::set_last_error(), cgv::os::socket::socket(), cgv::os::mutex::unlock(), and cgv::os::socket::user_data.
socket_ptr cgv::os::socket_server::wait_for_connection | ( | ) |
if no connection is pending, block thread and wait for next incoming connection
Definition at line 340 of file socket.cxx.
References cgv::os::socket::last_error, cgv::os::mutex::lock(), cgv::os::socket::set_last_error(), cgv::os::socket::socket(), cgv::os::mutex::unlock(), and cgv::os::socket::user_data.
|
friend |
this is the only way to create a socket_server as a reference counted pointer
Definition at line 405 of file socket.cxx.