YukunJ/Turtle

Feature Request: Timer

Closed this issue · 3 comments

YukunJ commented

New Features Timer should be added to track those inactive client Connection and terminate them to save system socket resources.

The basic idea is to maintain a list/set of individual timers in a container use the system calls

 #include <sys/timerfd.h>

int timerfd_create(int clockid, int flags);

int timerfd_settime(int fd, int flags,
                const struct itimerspec *new_value,
                struct itimerspec *old_value);
int timerfd_gettime(int fd, struct itimerspec *curr_value);

to set the alarm to be the earliest timeout time from the whole container individual timer. Upon timeout triggered, prune the container so as to delete expired Connection. And when tackle new messages from a connection, the timer for that Connection should be refreshed, and potentially reset the timer_fd's alarm time if it happens to be the earliest timeout.

One caveat is that, we need to be careful about the life time management of Connection. Hopefully, if we terminate the connection by closing the fd, it will not appear in next round's Epoll call.

To be done in April/May when I have some free time.

YukunJ commented

It seems that timer fd in form of file descriptor is Linux only. There is no easy substitute on MacOS.

Edit:

Kqueue on MacOS might do the job.

YukunJ commented

Actually I think it's just not worth it to be MacOS compatible. Will remove this compatibility along with the release of Timer functionality.