Socket Class Reference

The base class for all sockets. More...

Inheritance diagram for Socket:

InetSocket UnixSocket

List of all members.

Public Member Functions

void close ()
 Closes connection.
int getHandler () const
 Returns system connection handler.
bool opened () const
 Returns non-zero if connection was opened.
ssize_t read (std::string &s) const
 Reads data and saves it in string object.
ssize_t read (void *buf, size_t s) const
 Reads data from the socket.
 Socket (int fd)
 The constructor with file descriptor specification.
 Socket ()
 The default constructor.
ssize_t write (const void *buf, size_t s) const
 Writes data to socket.
virtual ~Socket ()
 The destructor.

Protected Attributes

bool m_opened
int m_sock


Detailed Description

This class is the ancestor of all socket objects. In all socket operations only server role is implemented. Considering the VoiceMan daemon does not need any client functions. This class contains general I/O operations and respond for automatic socket closing on object destruction.

See also:
UnixSocket InetSocket

Constructor & Destructor Documentation

Socket::Socket ( int  fd  )  [inline]

Parameters:
[in] fd The file descriptor new socket object must be associated with

virtual Socket::~Socket (  )  [inline, virtual]

This destructor closes socket if it was opened and not closed.


Member Function Documentation

void Socket::close (  ) 

This method will be called automatically on socket object deletion if it was not closed explicitly. You can call this method in any situation, there is checking, not opened object will not be closed.

int Socket::getHandler (  )  const

This method just returned file descriptor associated with current connection, but it may not be called for not opened sockets.

Returns:
The associated file descriptor

bool Socket::opened (  )  const

This method checks internal variables and let you know is this object is ready for I/O operations or not.

Returns:
Non-zero if connection is opened or zero otherwise

ssize_t Socket::read ( std::string &  s  )  const

This method tries to read 2048 bytes and saves available data in string object. The number of read bytes does not have any meaning are there more bytes to read or not. You should explicitly use select() function or ioctrl(FIONREAD) calls to determine this.

Parameters:
[out] s The string object to receive data
Returns:
Number of read bytes or -1 if there was an error (use errno to get error code)

ssize_t Socket::read ( void *  buf,
size_t  s 
) const

This method performs one read() call with appropriate parameters. The value returned by this function is the native value from read() system call.

Parameters:
[out] buf The buffer to receive data
[in] s The size of a buffer to receive data
Returns:
The number of read bytes or -1 if there was an error (use errno for error code)

ssize_t Socket::write ( const void *  buf,
size_t  s 
) const

This method performs one write() call with appropriate parameters. The value returned by this function is the native value from write() system call.

Parameters:
[in] buf The a buffer with data to write
[in] s The number of bytes to write
Returns:
The number of bytes successfully written or -1 if there was an error (use errno to get error code)


Generated on Thu May 6 16:10:58 2010 for VoiceMan by  doxygen 1.5.9