cgv
Loading...
Searching...
No Matches
cgv::os::socket_server Class Reference

socket server allows to be connected to More...

#include <socket.h>

Inheritance diagram for cgv::os::socket_server:
cgv::os::socket cgv::data::ref_counted

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
 
- Public Member Functions inherited from cgv::os::socket
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
 
- Public Member Functions inherited from cgv::data::ref_counted
int get_ref_count () const
 read access to current count
 

Protected Member Functions

 socket_server ()
 hide from direct use
 
- Protected Member Functions inherited from cgv::os::socket
 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.
 
- Protected Member Functions inherited from cgv::data::ref_counted
 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 Public Member Functions inherited from cgv::os::socket
static void enable_debug_output (bool enable=true)
 enables or disables (default) debug output for all socket commands
 
- Static Protected Member Functions inherited from cgv::os::socket
static bool begin ()
 
static void end ()
 
- Protected Attributes inherited from cgv::os::socket
size_t user_data
 store platform dependent reference to socket
 
std::string last_error
 store the last error
 
- Static Protected Attributes inherited from cgv::os::socket
static bool show_debug_output = false
 
static int nr_of_sockets = 0
 

Detailed Description

socket server allows to be connected to

Definition at line 84 of file socket.h.

Constructor & Destructor Documentation

◆ socket_server()

cgv::os::socket_server::socket_server ( )
protected

hide from direct use

Definition at line 304 of file socket.cxx.

Member Function Documentation

◆ bind_and_listen()

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.

◆ check_for_connection()

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.

◆ wait_for_connection()

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.

Friends And Related Symbol Documentation

◆ create_socket_server

CGV_API socket_server_ptr create_socket_server ( )
friend

this is the only way to create a socket_server as a reference counted pointer

Definition at line 405 of file socket.cxx.


The documentation for this class was generated from the following files: