On Thu, Nov 11, 2010 at 9:00 PM, Nick Mathewson <ni...@freehaven.net> wrote:
> On Thu, Nov 11, 2010 at 10:42 PM, Kevin Bowling > <kevin.bowl...@kev009.com> wrote: > > 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. > > Ugly? You bet! evbuffer_peek is really only optimized for the case > where you do not want to take any performance hit for copying data out > of the evbuffer, and you're willing to make your code more complex > because of it. Instead, I'd suggest evbuffer_copyout(), which is way > easier for what you seem to be doing: > > uint8_t tmp[3]; > if (evbuffer_copyout(input, tmp, 3) < 3) > return -1; > ulen = (tmp[1]<<8) | tmp[2]; > > Hi Nick, I've got it working with the copyout method and that works great for this simple case. The one thing that wories me is that there are other variable length packets with internal length headers after a larger number of bytes. Is there any way to offset with copyout, or would it be better to serialize and use a pointer or use peek with vectors? Regards, Kevin