I have to write a TFTP (Trivial File Transfer Protocol) server on Windows and Linux for a university course. I'm using C++ and I want to use one thread and select() to check for new incoming packets. TFTP requires that if a packet is not acknowledged for a certain amount of time, that the packet is re-sent. I'm wondering what the best way is to manage these multiple timeouts.
I was thinking about creating an std::list, which contains objects that associate a connection with the absolute time at which the timeout occurs. The list is ordered by increasing timeout times (all timeouts are the same when they are assigned, so a new timeout is always the greatest and can go to the end of the list - otherwise I would need a map instead of the list).
Since I need to reset the timeout for a connection, if a packet arrives in time, I want to create an std::map that associates a connection with an iterator pointing to its place in the list. When a connection's timeout is updated the element in the list can be found quickly, updated and moved to the end of the list (again assuming that a new timeout is the greatest).
Is this a good way to handle the problem or is there anything simpler?