well, I wrote a timer with a callback function func
struct Timer
{
std::function<void(int)> func; //---- sockfd
//...
Timer(int fd) : clientFd(fd)
{
//...
}
};
has a time wheel
class TimeWheel
{
private:
std::array<std::list<Timer*>, N> slots; // N , Si
//...
public:
//...
void tick();
};
tick function of the time wheel
void TimeWheel::tick()
{
auto it = slots[currentSlot].begin();
//...
(*it)->func((*it)->clientFd); //
slots[currentSlot].erase(it);
//...
}
then there is a time wheel variable timeWheel, in epoll that encapsulates a timer every time there is a new connection, adds you to the corresponding slot of the time wheel, and executes tick
every time the timer expires.void Epoll::shutDownFd(int fd)
{
// int op = EPOLL_CTL_DEL;
// epoll_Ctl(fd, op);
close(fd);
}
void Epoll::addToTimeWheel(int fd) // fd
{
Timer* timer = new Timer(fd);
timer->func = bind(&Epoll::shutDownFd, *this, placeholders::_1);
timeWheel.addTimer(timer);
}
// timerfd_create epoll
if (events[i].data.fd == timerFd)
{
timeWheel.tick(); //
}
but now the gPP compiler reports an error, and several pages of error messages are mainly:
no matching function for call to "std::tuple<Epoll, std::_Placeholder<1> >::tuple(Epoll&, const std::_Placeholder<1>&)"
: _M_f(std::move(__f)), _M_bound_args(std::forward<_Args>(__args)...)
/usr/include/cPP/7/tuple:981:16: error: no type named "type" in "struct std::enable_if<false, bool>"
bool>::type = false>
/usr/include/cPP/7/tuple:970:16: error: no type named "type" in "struct std::enable_if<false, bool>"
bool>::type = true>
^
/usr/include/cPP/7/tuple:955:16: error: no type named "type" in "struct std::enable_if<false, bool>"
bool>::type = false>
this kind of thing, after checking for a day, I still don"t have a clue. I can"t thank you enough to kneel down and ask the boss for advice.