Re: [Jack-Devel] jack ringbuffer, what to do when bytes returned < expected?

PrevNext  Index
DateFri, 08 Jul 2011 09:10:45 -0400
From Paul Davis <[hidden] at linuxaudiosystems dot com>
ToJames Morris <[hidden] at gmail dot com>
CcJack-Devel <[hidden] at lists dot jackaudio dot org>
In-Reply-ToJames Morris [Jack-Devel] jack ringbuffer, what to do when bytes returned < expected?
On Fri, Jul 8, 2011 at 6:46 AM, James Morris <[hidden]> wrote:
> Hi,
>
> The documentation of jack_ringbuffer_read and jack_ringbuffer_write
> suggest failures to write an entire 'item' to the buffer might occur.
> Can I assume - in what I shall label as 'regular circumstances' - that
> if a ring buffer is created which is a multiple of sizeof(item), that
> the read/write on the buffer will never be partial, that is, it will
> either fail completely, or succeed completely - the return value will
> either be 0 or sizeof(item).

the jack ringbuffers are sized in bytes, not items. if you were using
an "item-sized" buffer and only writing whole items, then you could
assume this, but the jack ringbuffers are not item-sized. Ardour has a
C++ ringbuffer (actually two of them) that work that way. for jack,
the "item" is 1 byte, and since you can't write less than a byte on
any relevant machine the same rules apply, but the result is not that
useful.

> Can I assume that the return value of these functions would be >0 && <
> expected only in 'irregular circumstances' where items of differing
> sizeof()s are read/written (though who'd want the pain of that I'll
> never (want to) know)?

yes, but the return value could be 0 if the buffer is full.

> If in 'regular circumstances' I can expect the return values to be > 0
> &&  < expected, I take it another call should take care of it, without
> having to resort to the more manual methods of accessing the
> ringbuffer?

no, because time plays a role. if it returns < expected, there's no
way to know when you will be able to write the remaining data. you
need to either sleep, or do something else for a while, or block on
some kind of communication/sync primitive that will let you know when
space is available.
PrevNext  Index

1310130669.17517_0.ltw:2,a <CAFa_cKnYQ8JX86gY58yeVCT0BCQ+gpkkTkincQvAfrb6+v9+Rg at mail dot gmail dot com>