Clarisse 4.0 SP5b SDK  4.0.0.0.5.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
SysSocketBase Class Reference

This class represents a socket. More...

Inheritance diagram for SysSocketBase:
CoreBaseObject CoreBaseType SysSocketClient SysSocketServer

Public Types

enum  Error {
  ERROR_NONE,
  ERROR_INVOP,
  ERROR_IOERR,
  ERROR_INVADDR,
  ERROR_INVSOCK,
  ERROR_NOHOST,
  ERROR_INVPORT,
  ERROR_WOULDBLOCK,
  ERROR_TIMEDOUT,
  ERROR_MEMERR,
  ERROR_COUNT
}
 

Public Member Functions

bool read (void *buffer, const size_t &nbytes)
 returns true if there's something to read on the given socket, false otherwise.
 
bool write (void *buffer, const size_t &nbytes)
 This function writes a buffer of nbytes bytes to the socket (wait mode)
 
bool close ()
 Tries to close the socket.
 
const CoreStringget_address () const
 
const unsigned int & get_port () const
 
bool is_error () const
 
const Error & get_last_error () const
 
const ssize_t & last_count () const
 
bool is_connected () const
 Return true if the connection is active.
 
bool is_no_delay () const
 
bool set_no_delay (const bool &no_delay)
 Activate or desactivate the TCP_NODELAY flag.
 
virtual SysIPV4Address get_peer () const
 Get peer information.
 
SysSocketId * get_socket_id () const
 
- Public Member Functions inherited from CoreBaseObject
bool is_kindof (const CoreBaseObject &object) const
 
virtual size_t get_memory_size () const
 
CoreString get_class_info_name () const
 
CoreString get_class_interface () const
 
const unsigned long & get_class_info_id () const
 
bool is_kindof (const CoreClassInfo &cinfo) const
 
virtual const CoreClassInfoget_class_info () const
 
bool operator== (const CoreBaseObject &obj) const
 
template<class T >
T * cast ()
 
template<class T >
const T * cast () const
 
- Public Member Functions inherited from CoreBaseType
bool is_kindof (const CoreClassInfo &cinfo) const
 
bool operator== (const CoreBaseType &obj) const
 

Static Public Member Functions

static const char * get_error_name (const Error &error)
 
static int get_hostname_from_ip (const CoreString &ip_address, CoreString &hostname)
 
static CoreString get_hostname ()
 Return local hostname.
 
- Static Public Member Functions inherited from CoreBaseObject
static const CoreClassInfoclass_info ()
 
static bool ___class_destructor__ (void *instance, const bool &is_array)
 
template<class T >
static T * cast (CoreBaseObject *object)
 
template<class T >
static const T * cast (const CoreBaseObject *object)
 
- Static Public Member Functions inherited from CoreBaseType
static bool ___class_destructor__ (void *instance, const bool &is_array)
 
static const CoreClassInfoclass_info ()
 

Protected Attributes

CoreString m_address
 
unsigned int m_port
 
Error m_last_error
 
bool m_is_closed
 
ssize_t m_last_count
 
bool m_is_no_delay
 
SysSocketId * m_socket
 

Friends

class SysSocketServer
 

Detailed Description

This class represents a socket.

This is the base class for all socket-related objects, and it defines all basic IO functionality.

Note
Currently works in blocking mode only.

Member Function Documentation

bool SysSocketBase::close ( )

Tries to close the socket.

Returns
true if the socket is closed
int SysSocketBase::get_hostname_from_ip ( const CoreString ip_address,
CoreString hostname 
)
static

Get the hostname for the given IP address.

Parameters
[in]ip_addressIP address
[out]hostnameHostname for the given IP address
Returns
0 if succeeded to get the hostname; 1 on failure
SysIPV4Address SysSocketBase::get_peer ( ) const
virtual

Get peer information.

Returns
a IPV4 object which contains peer information
bool SysSocketBase::read ( void *  buffer,
const size_t &  nbytes 
)

returns true if there's something to read on the given socket, false otherwise.

This function reads a buffer of nbytes bytes from the socket (wait mode)

Parameters
buffer: buffer to write read data into
nbytes: number of Bytes to read
Returns
true if no error occurred
bool SysSocketBase::set_no_delay ( const bool &  no_delay)

Activate or desactivate the TCP_NODELAY flag.

Parameters
no_delayif true activate TCP_NODELAY flag
Returns
True if successful
bool SysSocketBase::write ( void *  buffer,
const size_t &  nbytes 
)

This function writes a buffer of nbytes bytes to the socket (wait mode)

Parameters
buffer: buffer which contains data to write
nbytes: number of Bytes to write
Returns
true if no error occurred