ztforster
ztforster

Reputation: 1639

How can I use standard C/C++ "UNIX timers" to create a series of packet timeout handlers for sliding-window data transmission protocols

I am working on implementing sliding window data transmission protocols for a school project. After each packet of data is sent out over a socket, an acknowledgement must be received within a certain amount of time. If not, the packet should be resent (this is the part that would go in the callback function), and its timer should be reset.

We were encouraged to implement this part of the algorithm using "UNIX timers." Does "UNIX timers" mean timer_create(), setitimer(), alarm(), or none of those?

If I were to use a function that made use of signal handlers as my timeout handler functions, the problem would be telling the handler which packet to resend. I could keep an ordered, global list of packets waiting for acknowledgement, to be accessed from the signal handler. However, I've heard that signal handlers can be called while a data structure is being modified, leaving it in a corrupted state. What is the best way to go here?

Upvotes: 1

Views: 224

Answers (1)

Dmitry Rubanovich
Dmitry Rubanovich

Reputation: 2627

alarm() has second-level granularity. You don't want to use it. Lookup up select() call. You can use it with no file descriptors for much lower level time granularity. You can also use it to wait on fd's.

Upvotes: 0

Related Questions