#ifndef _FDSET_
#define _FDSET_

#include "../sys/sys"
#include "../error/error"
#include "../config/config"

using namespace std;

class Fdset {
public:
    Fdset(int t);

    int timeout() const 	{ return tsec; }
    void timeout (int t) 	{ tsec = t; }

    void add (int fd) 		{ set.push_back(fd); }

    unsigned size() const 	{ return set.size(); }

    int fd (unsigned index) 	{ return set[index]; }

    void wait(bool wait_read, bool wait_write);
    void wait_rw()		{ wait(true, true); }
    void wait_r()		{ wait(true, false); }
    void wait_w()		{ wait(false, true); }
    
    bool readable(int fd)  	{ return FD_ISSET(fd, &readset); }
    bool writeable(int fd) 	{ return FD_ISSET(fd, &writeset); }
    
    
private:
    int tsec;
    fd_set readset, writeset, exceptset;
    vector<int> set;
};

#endif
