On Sun, Jan 26, 2014 at 2:58 AM, Yucong Sun <[email protected]> wrote: > Hi there, > > So I need to implement a zlib bufferevent filter to transparent > compress the data passing through a bufferevent. and but I want the > zlib work to be done in a separate thread to offload main loop. > > I currently call bufferevent_write() on main thread, would the filter > code executed immediately? if I call bufferevent_write() from > another thread, would the code be executed over that thread instead? > (locking is all properly setuped).
The thread in which callbacks happen isn't currently specified by the documentation. So it is allowed to change in future versions. In practice right now, I believe that filters are greedy: they consume all input as soon as you give it to them, and they process data from the underlying bufferevent as soon as it's read. They do this in the same thread where the they receive the data. (This is affected by watermarks on the underlying bufferevent.) > Also.. how does this play out with flush? is the filter code executed > only when calling flush? flushing on a filtered buffferevent makes the filter get called immediately with the provided mode. Ordinarily, you use it to finish or clean-up a stream. The filter code is also called with BEV_FINISHED or BEV_NORMAL as you add data to the buffer. hope this helps, -- Nick *********************************************************************** To unsubscribe, send an e-mail to [email protected] with unsubscribe libevent-users in the body.
