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

base class for all sockets More...

#include <socket.h>

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

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
 
- Public Member Functions inherited from cgv::data::ref_counted
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.
 
- 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
 

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
 

Detailed Description

base class for all sockets

Definition at line 12 of file socket.h.

Constructor & Destructor Documentation

◆ socket() [1/2]

cgv::os::socket::socket ( )
protected

◆ socket() [2/2]

cgv::os::socket::socket ( size_t  _id)
protected

construct from existing socket identifier

Definition at line 98 of file socket.cxx.

◆ ~socket()

cgv::os::socket::~socket ( )
virtual

virtual destructor

Definition at line 123 of file socket.cxx.

References close(), and user_data.

Member Function Documentation

◆ begin()

bool cgv::os::socket::begin ( )
staticprotected

Definition at line 53 of file socket.cxx.

◆ close()

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().

◆ enable_debug_output()

void cgv::os::socket::enable_debug_output ( bool  enable = true)
static

enables or disables (default) debug output for all socket commands

Definition at line 47 of file socket.cxx.

◆ end()

void cgv::os::socket::end ( )
staticprotected

Definition at line 78 of file socket.cxx.

◆ get_last_error()

std::string cgv::os::socket::get_last_error ( ) const

returns the last error

Definition at line 130 of file socket.cxx.

References last_error.

◆ get_nr_of_arrived_bytes()

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.

◆ is_data_pending()

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().

◆ 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.

◆ receive_line()

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.

◆ send_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().

◆ 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().

◆ set_last_error()

bool cgv::os::socket::set_last_error ( const char *  location,
const std::string &  text = "" 
) const
protected

Friends And Related Symbol Documentation

◆ socket_select

friend class socket_select
friend

Definition at line 20 of file socket.h.

◆ socket_server

friend class socket_server
friend

Definition at line 19 of file socket.h.

Member Data Documentation

◆ last_error

◆ nr_of_sockets

int cgv::os::socket::nr_of_sockets = 0
staticprotected

Definition at line 16 of file socket.h.

◆ show_debug_output

bool cgv::os::socket::show_debug_output = false
staticprotected

Definition at line 15 of file socket.h.

◆ user_data


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