31 Dec 2012 ncm   » (Master)

Here is the most satisfying function I have written in years:

int init_iovec_from_circular_buffer(
struct iovec* iov, char* buf, size_t size, size_t tail, size_t head)
{
int count = 0;
if (head < tail) { // wrapped
iov->iov_base = buf + tail;
iov->iov_len = size - tail;
tail = 0; ++iov; count = 1;
}
if (tail < head) {
iov->iov_base = buf + tail;
iov->iov_len = head - tail;
++count;
}
return count;
}
It sets an iovec array to point to the occupied part of a circular buffer, ready to pass to writev(). Pass trivially different values for head and tail, and it sets up iov to pass to readv(). If it can be improved upon, I don't know how.

dmarti: Thank you, as always. The Xiph article was especially enlightening. Mims's article wouldn't load, although I didn't try enabling quantserve's javascript.

But Simon Doonan cannot be trusted. He is in thrall to Camille Paglia, whose metier is rhetorical tricks that rely mainly on confirmation bias. Not everything Paglia writes is false; only (1) what disagrees with people equipped to know better, or (2) what seems gratifying to believe. But that's almost everything.

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!