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

Re: [Libevent-users] evbuffer_find versus evbuffer_search



On Wed, Apr 10, 2013 at 11:12 PM, Sashan Govender <sashang@xxxxxxxxx> wrote:
> Hi
>
> I'm porting some code from libevent 1.4 to 2.0 and in the 1.4 version some
> of the code is using evbuffer_find find a pointer to the start of a sequence
> then calculating a pointer difference from it:
>
>     u_char* end = evbuffer_find(input, pattern, 2);
> ...
>      ptrdiff_t len = end - input->buffer;
>
> But in 2.0 the evbuffer struct is now opaque and I can't access members of
> it (i.e. the dereference here input->buffer will not compile). How should I
> change this so that it works with 2.0.

So, even if the structure were exposed, that wouldn't work any more:
evbuffers are no longer stored contiguously.  Instead, you would try
something like:

struct evbuffer_ptr ptr;
ptr = evbuffer_search(input, pattern, 2, NULL);
if (ptr.pos < 0) // not found
   ...
ptrdiff_t len = pos.pos;


You might find the reference manual helpful:
  http://www.wangafu.net/~nickm/libevent-book/Ref7_evbuffer.html


yrs,
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.