/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 * 
 * The iWear Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#ifndef __IWEAR_SOCKETSET_H
#define __IWEAR_SOCKETSET_H

#ifndef __IWEAR_SOCKETCONNECTION_H
#include <net/socketconnection.h>
#endif

#include <iwear/sorted_sequence.h>

extern "C" {
#include <poll.h>
}
#include <map>
#include <vector>

namespace iwear
{
    namespace net
    {

/**
 * This is a class that can know about several sockets and can check them all
 * for <b>read</b> events efficiently, without waiting on every single timeout.
 */
class SocketSet
{
private:   
protected:
    /**
     */
    sorted_sequence<struct pollfd,true> fds;
    std::vector<SocketConnection*> scs;
public:
    SocketSet();
    virtual ~SocketSet();
    /**
     * You need to make sure yourself that you don't add the same fd multiple times.
     */
    void add( SocketConnection& );
    void remove( const SocketConnection& );

    std::vector<SocketConnection*>::size_type size( void ) { return scs.size(); }

    /**
     * This returns a vector consisting of all the SocketConnections that are
     * ready to read. You <b>need</b> to  read them with checkfd set to false,
     * otherwise a subsequent select will be issued which will block forever or
     * return error conditions etc.
     */
    std::vector<SocketConnection*> get_read( double timeout );
};

}
}
#endif
