41 uint32_t _tail =
tail;
62 uint32_t _head =
head;
69 ret += _head -
tail - 1;
82 const auto n_vec =
reserve(vec, len);
85 for (
int i = 0; i < n_vec; i++) {
86 memcpy(vec[i].data, data + ret, vec[i].len);
108 memcpy(&
buf[head], data, n);
111 memcpy(&
buf[0], data, len-n);
141 iovec[0].
data =
const_cast<uint8_t *
>(b);
149 iovec[1].
len = len - n;
163 for (
int i = 0; i < n_vec; i++) {
164 memcpy(data + ret, vec[i].data, vec[i].len);
173 uint32_t n =
space();
194 iovec[1].
len = len - n;
225 int16_t ret =
peek(0);
240 uint32_t _tail =
tail;
243 return available_bytes ? &
buf[
head] :
nullptr;
uint32_t available(void) const
const uint8_t * readptr(uint32_t &available_bytes)
std::atomic< uint32_t > head
ByteBuffer(uint32_t size)
bool commit(uint32_t len)
uint32_t space(void) const
bool update(const uint8_t *data, uint32_t len)
void * calloc(size_t nmemb, size_t size)
bool set_size(uint32_t size)
uint32_t read(uint8_t *data, uint32_t len)
uint32_t peekbytes(uint8_t *data, uint32_t len)
uint32_t write(const uint8_t *data, uint32_t len)
uint8_t peekiovec(IoVec vec[2], uint32_t len)
int16_t peek(uint32_t ofs) const
uint8_t reserve(IoVec vec[2], uint32_t len)
std::atomic< uint32_t > tail
bool read_byte(uint8_t *data)