wolfgang wrote:
Hi,

I dived into libevent a couple of days ago.

To learn how to use libevent, I've been surfing sorce codes of simple
servers in
google codes using libevent and found two similar functions to read data from a
file descriptor:

"evbuffer_read" and "bufferevent_read".

The former is to read data from a file descriptor and store it in a
buffer(evbuffer).
The latter is to read data from a bufferevent and store it in a buffer(void *).

From my perspective, they are all same.
I mean they use a different way but they actually accomplish the same
goal which is
to get data from a file descriptor.
( Although the latter doesn't read data directly from a file
descriptor, bufferevent's
internal buffer is automatically filled with data from a file descriptor.)

bufferevent uses evbuffer_read to read the data from its file descriptor into
buffervent's internal input evbuffer:

static void
bufferevent_readcb(evutil_socket_t fd, short event, void *arg)
{
    struct bufferevent *bufev = arg;
    struct evbuffer *input;

    ...

    input = bufev->input;

    ....

    res = evbuffer_read(input, fd, howmuch);
        
    ...
}

bufferevent_read then uses evbuffer_remove to return data from this ebuffer:

size_t
bufferevent_read(struct bufferevent *bufev, void *data, size_t size)
{
    return (evbuffer_remove(bufev->input, data, size));
}


Now, my question is in what kinda situation should I use the former or
the latter function ?

Use bufferevent_read if you're using bufferevents, or evbuffer_read if
you're using evbuffers. Bufferevent is great for most normal uses, although
for some special purposes (e.g. SSL) it doesn't do everything you might
need it to.


Thanks in advance.

-wolfgang


HTH

 -- Tero Marttila
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users

Reply via email to