[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] Using evbuffer_peek



Hi,

I've seen a few mails talking about evbuffer_peek, but no solid usage of it.  The doxygen on the libevent page doesn't cover it generating my own from 2.0.8 has shed little light on its use to me.

Basically, for my test case I have two bytes in network order that make up a short.  These are one byte into the buffer.

uint16_t ulen;
struct evbuffer_ptr bufpos;
struct evbuffer_iovec bufvec[2];

if (evbuffer_ptr_set(input, &bufpos, 1, EVBUFFER_PTR_SET) < 0)
  return(-1); // Add proper error handling
if (evbuffer_peek(input, 2, &bufpos, bufvec, 1) < 0)
  return(-1); // Add proper error handling

ulen = ntohs((uint16_t)bufvec[0].iov_base);

I've tried using many variations with the pointers.  I can't even read out each byte individually.  What am I doing wrong?

Regards,
Kevin