[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] how to consume partial buffer in bufferevent filter callback
- To: libevent-users@xxxxxxxxxxxxx
- Subject: [Libevent-users] how to consume partial buffer in bufferevent filter callback
- From: Wayne Shao <wshao99@xxxxxxxxx>
- Date: Tue, 8 Feb 2011 11:16:15 -0800
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Tue, 08 Feb 2011 14:16:23 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=ZAhT3iEmK1g5E9ju/EKki+0RIeIfpG6WOINOwmm9zi0=; b=Kz+ysBhwsLj509APDhwPUlwgXjjhuGXL7AoyZJw//szqytlRuT2GyiIUkb+1ALWV9p 3enKffZo4ySRpXhGdaMet3RoXqYVloqWvQ0W/8gcZgna3q2P9I0CZDxDKLmntdXZRFEz +0tgLK/fh1fJEuOKX5s8HBY+bBwUab9nEk3SA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=ti1rHEdwmSA2evTbaEV/uYZpDrAUyuXB4O/5uk8DpBFfBHEynB4jYr8fFTYHq2+5Qj zbCudNcIj5Xz4u5pFJqrcEkOC9r/tzTuttSMdd0xmT14Nx4d4KAu6N02UDEOpK3Odghf 4aT7jwJv+02m2QnmPJPe0vdzslX337und6KV8=
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
Hi,
I am using a filter to read packets from the peer. The packet format is typical header + payload, where total length is encoded in the header.
In the filter callback, is it possible to only consume part of the source buffer?
e.g, if my protocol packet size is 100 bytes but the source buffer has 130 bytes, I'd like to read
the whole packet and leave the remaining and hope to process that in the next callback.
I do not want to copy the whole thing and manage it from a separate buffer.
Is this possible?
or is there any good example/reference on the typical packet decoding with bufferevent API?
// The filter method:
enum bufferevent_filter_result filter_cb(struct evbuffer *source,
struct evbuffer *destination, ev_ssize_t dst_limit,
enum bufferevent_flush_mode mode, void *ctx) {
// this is an input buffer.
// I'd like to consume one protocol packet
// Question: if the source buffer has more than one protocol packet, is it possible
// to only process partial data?
}
thanks,
--
W. Shao