On Tue, Aug 24, 2010 at 11:14 AM, Andrei Chirila <andre...@gmail.com> wrote: > Hello, > > I'm using libevent 2.0.6 on a startup project, I just updated from 2.0.5. > I've written a server and I had the surprise, after testing it for a while, > that, for some messages, if I'm using the zlib filter, the last fragment of > data doesn't get send.
The current way to solve the problem you describe above is to not close the underlying bufferevent immediately, but rather to disconnect it from the filter, and give it a write callback of its own, to close it once it is finally done writing its data. > Using tcpdump on the port I'm using I can see that > the data never leaves the server. I'm calling in client_write function > bufferevent_flush(client->event), but, as I saw in bufferevent_sock.c, the > flush method is not implemented. Yeah; the behavior for bufferevent_flush() is not currently specified (or implemented) for sockets that connect to the network. For a filtering bufferevent, flushing is no problem: there is another bufferevent, one level lower, that's ready to take all the data you give it, and you can tell bufferevent_flush() to explicitly ignore its high-water mark. But for a socket, it's a bit trickier: there is no guarantee that you actually _can_ flush all the data waiting for a network socket without blocking. (For example, if the amout of data queued in the bufferevent's outbuf exceeds what the kernel can buffer for writing, calling send() on that data will eventually tell you "EAGAIN", unless the user is willing to block until the data is written -- and they probably aren't, since they're using Libevent.) So, having "flush a socket-based bufferevent" mean "write all the data to the network right now" is basically out, since that isn't (in the general case) possible. Here are some other things it *could* mean that wouldn't solve your original problem: * "Write as much data to the network as you can without blocking". * "Write as much data to the network as you can without blocking, and if you empty the buffer, send a FIN packet" > Where should I start writing if I want to write this function? I'd start with specifying what exactly you think it should do. peace, -- Nick *********************************************************************** To unsubscribe, send an e-mail to majord...@freehaven.net with unsubscribe libevent-users in the body.