Socket Class Reference

Common base class for both client and server sockets. More...

#include <Socket.h>

Inheritance diagram for Socket:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 Socket ()
 Create a new "empty" unconnected socket.
 Socket (int fd)
 Create a socket connected to fd.
int getError ()
 Get errors, not all functions (constructors, etc) can return errors.
int close ()
 Close this socket.
ssize_t read (void *buf, size_t nbytes) const
 Blocking read() on this socket.
ssize_t write (const void *buf, size_t nbytes) const
 write() on this socket.

Protected Attributes

bool connected
 Is this socket connected?
int sockID
 The "fd" this socket is connected to (for use with read() and write()).
int error
 Error value indicating what went wrong, usually errno is copied here.

Detailed Description

Common base class for both client and server sockets.

Author:
Daniel Aarno
Version:
v0.1.1


Constructor & Destructor Documentation

Socket::Socket (  )  [inline]

Create a new "empty" unconnected socket.

Socket::Socket ( int  fd  )  [inline]

Create a socket connected to fd.

WARNING This constructor does NOT connect to fd, it assumes it is already a valid socket id. This constructor should probably NOT be used!

Parameters:
fd An already connected socket identifier


Member Function Documentation

int Socket::close (  )  [inline]

Close this socket.

int Socket::getError (  )  [inline]

Get errors, not all functions (constructors, etc) can return errors.

In order not to depend on exceptions this function can be called after calls to certain memberfunctions to see if an error occured.

Returns:
Error value indicating what went wrong

ssize_t Socket::read ( void *  buf,
size_t  nbytes 
) const [inline]

Blocking read() on this socket.

Note that this function does NOT take notice of byte-order, so if you are reading anything other than strings you should take care of converting it to the correct byte-order after reading it.

Parameters:
buf data buffer to used store result, of size nbytes or more
nbytes The numer of bytes to read.
Returns:
number of bytes read, this should be the same as nbytes, a negative error value is returned if something goes wrong (-errno)

ssize_t Socket::write ( const void *  buf,
size_t  nbytes 
) const [inline]

write() on this socket.

Note that this function does NOT take notice of byte-order, so if you are writing anything other than strings you should take care of converting it to the correct byte-order before writing it.

Parameters:
buf data buffer to write FROM, of size nbytes or more
nbytes The numer of bytes to write from buf.
Returns:
number of bytes written, this should be the same as nbytes, a negative error value is returned if something goes wrong (-errno)


Member Data Documentation

bool Socket::connected [protected]

Is this socket connected?

int Socket::error [protected]

Error value indicating what went wrong, usually errno is copied here.

int Socket::sockID [protected]

The "fd" this socket is connected to (for use with read() and write()).


The documentation for this class was generated from the following file:
Generated on Sun Mar 11 15:33:26 2007 for MetalWarriors by  doxygen 1.4.7