#ifndef TOUT_HPP_
#define TOUT_HPP_
#include "common.hpp"
#include "pool.hpp"
#include "fdtable.hpp"


class ToutQueue {
    private:
        typedef struct tout_node_s {
            struct tout_node_s* prev;
            struct tout_node_s* next;
            int fd;
            time_t at;
        } tout_node_t;

        TPool<tout_node_t> pool;
        tout_node_t* head;
        tout_node_t* tail;
        FdTable<tout_node_t*> fds;

    public:
        ToutQueue();
        ~ToutQueue();

        void push(int fd, time_t now); ///< push into queue as last one active
        int pop(time_t tout); ///< timeouted fd(s) or -1
        void pop(int fd); ///< remove from queue (got an event)

        bool empty() const;
};


#endif