Logo Search packages:      
Sourcecode: jamin version File versions

size_t jack_ringbuffer_write ( jack_ringbuffer_t *  rb,
const char *  src,
size_t  cnt 
)

Write data into the ringbuffer.

Parameters:
rb a pointer to the ringbuffer structure.
src a pointer to the data to be written to the ringbuffer.
cnt the number of bytes to write.
Returns:
the number of bytes write, which may range from 0 to cnt

Definition at line 176 of file ringbuffer.c.

{
  size_t free_cnt;
  size_t cnt2;
  size_t to_write;
  size_t n1, n2;

  if ((free_cnt = jack_ringbuffer_write_space (rb)) == 0) {
    return 0;
  }

  to_write = cnt > free_cnt ? free_cnt : cnt;

  cnt2 = rb->write_ptr + to_write;

  if (cnt2 > rb->size) {
    n1 = rb->size - rb->write_ptr;
    n2 = cnt2 & rb->size_mask;
  } else {
    n1 = to_write;
    n2 = 0;
  }

  memcpy (&(rb->buf[rb->write_ptr]), src, n1);
  rb->write_ptr += n1;
  rb->write_ptr &= rb->size_mask;

  if (n2) {
    memcpy (&(rb->buf[rb->write_ptr]), src + n1, n2);
    rb->write_ptr += n2;
    rb->write_ptr &= rb->size_mask;
  }

  return to_write;
}


Generated by  Doxygen 1.6.0   Back to index