The Micro C++ Library
micxx::SocketSet Class Reference

A SocketSet resembles fd_set the BSD compliant set of sockets used with select and synchronous I/O multiplexing. More...

#include <micxx.hxx>

Inherits micxx::Mutex.

List of all members.

Public Types

typedef std::map< socket_t,
Socket * > 
SocketMap
typedef SocketMap::iterator iterator
typedef SocketMap::const_iterator const_iterator

Public Member Functions

 SocketSet ()
 Create a new and empty SocketSet.
virtual ~SocketSet ()
 Deletes all pointers of micxx::Sockets that are still stored within this SocketSet.
virtual void add (Socket *socket)
 Add the specified socket to the stored set of sockets.
virtual iterator begin ()
 An iterator that points to the first Socket of this SocketSet.
virtual const_iterator begin () const
 A const_iterator that points to the first Socket of this SocketSet.
virtual iterator end ()
 An iterator that points behind the last Socket of this SocketSet.
virtual const_iterator end () const
 An const_iterator that points behind the last Socket of this SocketSet.
virtual void clear ()
 Remove all Sockets from the stored set of sockets.
virtual void close ()
 Close all Sockets from this SocketSet.
virtual bool remove (Socket *socket)
 Remove the specified socket from this SocketSet.
virtual SocketselectRead ()
 Wait until data is available to be read from one of the stored Sockets without blocking the calling thread.

Detailed Description

A SocketSet resembles fd_set the BSD compliant set of sockets used with select and synchronous I/O multiplexing.

For this purpose references to Sockets must be added to the SocketSet and then a call to selectRead() would block the calling thread, until one of the stored Sockets from this SocketSet changes its state, so that at least some data could be read from the returned Socket without blocking the calling thread.

Note:
Although SocketSet is derived from Mutex, itself does no locking at all. If you intend to use SocketSet concurrently from different threads, you could use the inherited Mutex to synchronize access to the instance (depending on the scenario in which it is used).
Author:
Norbert Klose
Date:
February, 2007

Member Typedef Documentation

typedef SocketMap::const_iterator micxx::SocketSet::const_iterator
typedef SocketMap::iterator micxx::SocketSet::iterator

Constructor & Destructor Documentation

micxx::SocketSet::SocketSet ( )

Create a new and empty SocketSet.

virtual micxx::SocketSet::~SocketSet ( ) [virtual]

Deletes all pointers of micxx::Sockets that are still stored within this SocketSet.


Member Function Documentation

virtual void micxx::SocketSet::add ( Socket socket) [virtual]

Add the specified socket to the stored set of sockets.

As long as the socket is not removed from this SocketSet (either by remove(Socket*) or by clear()), the socket is deleted automatically when this SocketSet is deallocated.

Note:
The socket must already be bound, so that
 (socket_t)socket != INVALID_SOCKET.
virtual iterator micxx::SocketSet::begin ( ) [inline, virtual]

An iterator that points to the first Socket of this SocketSet.

    {
        return sockets.begin();
    }
virtual const_iterator micxx::SocketSet::begin ( ) const [inline, virtual]

A const_iterator that points to the first Socket of this SocketSet.

    {
        return sockets.begin();
    }
virtual void micxx::SocketSet::clear ( ) [inline, virtual]

Remove all Sockets from the stored set of sockets.

The removed Sockets are not deleted by clear(). The application regains ownership of all removed Sockets.

    {
        sockets.clear();
    }
virtual void micxx::SocketSet::close ( ) [virtual]

Close all Sockets from this SocketSet.

virtual const_iterator micxx::SocketSet::end ( ) const [inline, virtual]

An const_iterator that points behind the last Socket of this SocketSet.

    {
        return sockets.end();
    }
virtual iterator micxx::SocketSet::end ( ) [inline, virtual]

An iterator that points behind the last Socket of this SocketSet.

    {
        return sockets.end();
    }
virtual bool micxx::SocketSet::remove ( Socket socket) [virtual]

Remove the specified socket from this SocketSet.

The removed Socket is not deleted by remove(Socket*). The application regains ownership of the removed Socket.

Returns:
true, if the socket has been removed,
false otherwise.
virtual Socket* micxx::SocketSet::selectRead ( ) [virtual]

Wait until data is available to be read from one of the stored Sockets without blocking the calling thread.

If data is available on more than one Socket the returned Socket is selected in a round robin fashion.

See also:
select(int, fd_set*, 0, fd_set*, 0)

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