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

Re: [Libevent-users] a question of evbuffer_pullup



On Thu, Aug 23, 2012 at 2:35 PM, simon zhang <hapopen@xxxxxxxxx> wrote:
> I don't understand âmust first ensure that the front of the buffer
> really is contiguousâ.
>
> I can get 100 bytes from evbuffer by evbuffer_pullup() or evbuffer_remove().
> evbuffer_pullup()ïget some contiguous data.
> evbuffer_remove():get some discontinuous data???
>
> Some discontinuous data??Why we need this.We can't handle some
> discontinuous data.

Internally, an evbuffer is represented by a linked list of chunks.
This means that you can't be sure that any given number of bytes is
actually stored adjacently to one another.

Usually you don't care.  But some specialized code wants to get a look
at data inside the evbuffer, and make sure that the data is stored in
a single chunk.

So for example, evbuffer_pullup(buf,100) ensures that the first 100
bytes of the buffer all occupy the same chunk, so that it can return a
pointer to those bytes that an application can safely use to inspect
or modify the data.  This usually isn't a good idea, but some programs
want to do it anyway.

Unlike evbuffer_remove(), evbuffer_pullup() doesn't actually take any
bytes out of the buffer.

Unlike evbuffer_copyout(), evbuffer_pullup() gives a pointer to the
actual internals of the evbuffer.

Unlike evbuffer_peek(), evbuffer_pullup() might have to reallocate or copy data.

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