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

Re: [Libevent-users] bufferevents and write signalling



On Thu, Aug 5, 2010 at 2:13 PM, Mark Ellzey <mthomas@xxxxxxxxxx> wrote:
>
> This is an odd question that hopefully someone can help me out with. I
> have a function right now that looks a bit like this:
>
> void
> read_data(struct bufferevent *bev, void *args) {
>        evbuffer *data;
>
>        data = bufferevent_get_input(bev)
>
>  if (evbuffer_get_length(data) < some_size) {
>                /* waiting for some specific amount of data */
>                return;
>
>  .... process data here ....
>
>        evbuffer_drain(data, some_size);
>
>  if (evbuffer_get_length(data)) {
>                return read_data(bev, args);
>        }
> }
>
> If more data is present at the time it has finished reading one block of
> data it was interested in, if you were to return, you never get notified
> unless something was added.

Right.  The read callback is invoked when more data *arrives,* not
whenever there is data.

If you want it to handle all the data, why not just use a loop:

   while (evbuffer_get_length(data) >= some_size) {
       /* ... */
   }

That way you avoid the arbitrary recursion.

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