I am trying to implement the the timeout mechanism in my c implementation of TFTP, and i am looking for some general help.
What I am wondering is how to manage the timeout situation. The premature timeout mechanism that I used is with signal/alarm functions, but somehow I am stuck in how to handle my timeouts, that is if the packet (ack or data) is missed and a timeout occurs how to send back the previous packet or ack to the server.
Avoid signal and alarm if possible.
Either use SO_RCVTIMEO socket option or just use select with a timeout of T seconds.
If the select() call returns and your socket is not in the read set, or if recvfrom returns with a timeout error, then you can take appropriately action in your code.
Example of timeout usage:
Example of select usage: