Spoon
2006-04-18 22:57:55 UTC
Hello,
I am trying to understand how to write a simple network program that
sends UDP packets at a specified rate.
For example, let's say I want to send 500-byte packets at 40 Mbit/s
This means I want to send one packet every 0.1 ms
In my mind, the naive way to do that would be to write:
(pseudo code...)
while (1)
{
send(500-byte UDP packet);
sleep(0.1 ms);
}
But I don't think any of the sleep functions (nanosleep?) will let me
sleep for such a short period, will they?
Maybe I could send 10 packets, then sleep 1 ms? That might solve the
sleep problem, but my traffic would be very bursty.
I suppose I could waste time in a busy loop, but I don't like that solution.
Is there a (simple?) way to send 500-byte packets every 0.1 ms without
pegging the CPU to 100%?
I am trying to understand how to write a simple network program that
sends UDP packets at a specified rate.
For example, let's say I want to send 500-byte packets at 40 Mbit/s
This means I want to send one packet every 0.1 ms
In my mind, the naive way to do that would be to write:
(pseudo code...)
while (1)
{
send(500-byte UDP packet);
sleep(0.1 ms);
}
But I don't think any of the sleep functions (nanosleep?) will let me
sleep for such a short period, will they?
Maybe I could send 10 packets, then sleep 1 ms? That might solve the
sleep problem, but my traffic would be very bursty.
I suppose I could waste time in a busy loop, but I don't like that solution.
Is there a (simple?) way to send 500-byte packets every 0.1 ms without
pegging the CPU to 100%?