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

[Libevent-users] how to consume partial buffer in bufferevent filter callback



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