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

Re: [Libevent-users] How to activate read callback when not all data was read



Hi Nils,

I have a similar use case and I am following the approach described below.

1. Determine an ideal low watermark for the read callback.
2. I'm not sure if there are any disadvantages to this approach, but you could try to read within a loop inside the read callback till there is no further data to be drained. i.e on each read callback read as much data as possible.

Hope this works.

--
Thanks
Sanjiv


On Tue, Apr 10, 2012 at 2:40 PM, Nils Rennebarth <nils.rennebarth@xxxxxxxxx> wrote:
Hi,

In my daemon which uses libevent, i use bufferevent to read client commands
from a socket, set everything up to eventually generate the reply, and return to
the event loop.

Now a client may send several commands in one go. If I only read the first
command and drain the corresponding bytes from the bufferevent's input
buffer, the read callback will not be called until *more* data arrives,
so if a client sends two commands in one go, I need to somehow queue
the second (and further) commands before returning to the main loop,
otherwise the commands never gets processed.

Is there some other way, to get the second command processed,
something like "return to the main loop, but mark this callback as
still pending, and call it again"

In other words, bufferevent forces me to do edge-triggered event
handling. Is there a way to let me do level-triggered event handling
instead.

Or is there something like a idle task, that get called when there is
nothing else to do? Working with timeouts would introduce arbitrary gaps
in command handling, event if there are no other clients that want
work, so I won't go that route. Or does setting a timeout of { 0, 0 }
work?

--

Mit freundlichen Grüßen / with kind regards

Nils Rennebarth, Software Developer

--
Funkwerk IP-Appliances GmbH
Mönchhaldenstraße 28
D-70191 Stuttgart

Tel: +49 711 900300 - 0
Fax: +49 711 900300 - 90

E-Mail: Nils.Rennebarth@xxxxxxxxxxxxxxx

Location: GmbH Nuernberg, Local Court Nuernberg, HRB 25481
Managing Directors: Torsten Urban
--------------------------------
The information contained in this e-mail has been carefully researched,
but the possibility of it being inapplicable in individual cases cannot
be ruled out. We therefore regret that we cannot accept responsibility
or liability of any kind whatsoever for the correctness of the
information given. Please notify us if you discover that information is
inapplicable.

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



--
Sanjiv Raj


Marvin: I've been talking to the ship's computer.
Arthur: And?
Marvin: It hates me.