[icecast-dev] net/sock.c question

Alexander Haväng alexander at netintact.se
Wed Feb 11 11:03:27 PST 2004



> Any other sugestions welcomed. Thanks!

Only one. Don't do it like that.

Keep a byte counter.
Before each sock_write(), first check if we can write without sleeping.

I.e if (counter > (maxval * ms)) then we cannot write and have to sleep.

maxval is in KiloBytes per second here, and ms is the millisecond
fraction of the current second. (i.e from gettimeofday()).
counter is in bytes before the write.

Instead of sleeping, it's nicer to queue the packet in some priority
queue, and have another thread read from that queue and send the packets
out at a specified time (sendtime).

The sendtime is calculated using (counter/maxval) - ms, and is relative
to "now". It could also be used for sleeping.

If you choose to queue, add the data_length to counter when you queue
the packet, and if you choose to sleep, add data_length to counter when
you are done sleeping. This helps keep the code tidy and without ugly
locks.

You have to keep a timestamp also, to reset the counter to 0 every
second. Check that before each write, and not somewhere else (you have
to do a gettimeofday() anyway).

//Alexander

--- >8 ----
List archives:  http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Icecast-dev mailing list