I am trying to write a server in C, and it uses a function called epoll() to handle connections, I want to implement a timeout on idle sockets so I can prevent a bunch of idle sockets from eating up resources, but I dont want to write a bunch of complicated timeout code using timerfd(). I know that on Linux it is possible to configure network traffic settings, I want to know if there is a way so that the OS can terminate idle tcp connections after 15 seconds of inactivity. I know that it will have an effect on other programs using TCP, but I only plan on having this one program be running on my linux machine.
Is there a way to have the kernel (or whatever controls TCP traffic) terminate tcp connections after being idle for a set period of time?
Having such a feature takes resources to implement and maintain. I don't think that there is a relevant real world use case where a global idle timeout over every TCP socket on the system is needed. Therefore I don't think that this is implemented. Applications can easily implement their own timeout handling and be also more flexible here, like different timeouts per application, per state of application protocol on the socket (like header vs. body), depending on load, number of open sockets, ...