[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] Re: libevent & evbuffer_add_reference
- To: Roman Puls <puls@xxxxxxxxxxxx>
- Subject: [Libevent-users] Re: libevent & evbuffer_add_reference
- From: Nick Mathewson <nickm@xxxxxxxxxxxxx>
- Date: Sat, 27 Feb 2010 15:46:46 -0500
- Cc: libevent-users@xxxxxxxxxxxxx
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Sat, 27 Feb 2010 15:46:52 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=eMrJ5edb2YiaEKJPVSvZCXY5SOC9VaK9Ujrzq857dPU=; b=aC4YEqV4+DrnQK3ZBu+iAneoUO8fX6FTGvCiSDkblmbhbg3Iojje/RwR+srWGLaYyc PXNwmGBlEgUK7411SuzictCNlB6Kase8WZo2Xxd1eUhPe6YWbA/7a4y8yvcdJSgLZARB AWgb2jKr4uIrh/IZ8iJxQIsdEk2mqcy0FMtQw=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=ivfGnh+x8zyfHbeSl9SUhSVoDP7Eml3GJhwPXW7RCHrx6UD0e/vhOI5GHeSA4IkA3r C/UEF3QiLAcyQmPOW34EGY19x7ctKCu5UQAgHVa2B7VG+vqjSHxGmXveuuQjEPwL7kAY kzEw/M0zvWHDlbjpQ+4X9QZWd/8J6Yl7C4sQ0=
- In-reply-to: <4B89148E.1090009@xxxxxxxxxxxx>
- References: <4B89148E.1090009@xxxxxxxxxxxx>
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
On Sat, Feb 27, 2010 at 7:48 AM, Roman Puls <puls@xxxxxxxxxxxx> wrote:
> Hi Nick,
>
> a short one about events: I was assuming that
>
> evbuffer_add_reference(evb, tx.buffer.ptr, tx.buffer.slen, onsent, ref);
>
> would call the "onsent" callback asynchroneously (having a bufferevent with
> the BEV_OPT_DEFER_CALLBACKS option set on instantiation).
>
> Apparently, this is not right, as the onsent-callback appears instantly (as
> long as the bev is not on its high watermark).
>
> My idea was to use that kind of callback to fetch the next piece of data to
> send, but in the current implementation, this leads to a recursion (on the
> stack).
>
> So my question: is that intended behaviour? If yes, should I queue an event
> (e.g. timer with timeval = { 0, 0 }) to unwind the stack before actually
> calling my onsent handler?
The "cleanupfn" callback is meant for resource management, so you can
free the chunk of data (or remove a reference to it, or whatever) once
it's no longer needed by the evbuffer.
The usual way to do what you're proposing is to have the bufferevent's
write callback add more chunks of data as needed. This avoids the
recursion problem you're reporting, and has the advantage that it
works with all data, not just data that you've added to the evbuffer
by reference.
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.