On Mon, Nov 21, 2011 at 7:52 AM, <aa...@beaker.tv> wrote: > Hey all, I'm using evbuffer_add_file() to add a bunch of open file > descriptors to a buffer event. It works good, until there are many connected > clients requesting many different files. I'm using a technique similar to > HTTP pipelining (not using HTTP though) so a workaround would be to have a > queue of files to send, and once one has finished sending, send the next one > in the queue. I've had a look around for a callback mechanism to work with > evbuffer_add_file(), but can't figure it out. Is there a way I can provide a > callback for after evbuffer_add_file() finishes sending the whole file?
You can't do this directly, but there are two plausible ways to fake it with the current Libevent 2 APIs. You can either add a callback to the evbuffer, or set a watermark on the bufferevent. The evbuffer callback will get notified when _any_ data is added or drained from the evbuffer, so you could keep track of how much data had been drained, and decide that the file as a whole was sent when all the data was gone. More realistically, you can just set a write low-watermark for the bufferevent, so that you get a write callback once the amount of data pending to be written gets low enough. cheers, -- Nick *********************************************************************** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-users in the body.