On Thu, Aug 23, 2012 at 2:35 PM, simon zhang <[email protected]> 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 [email protected] with unsubscribe libevent-users in the body.
