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

Re: [Libevent-users] Bufferevent client read callback sporadically not called

Dear Nick,

thank you so much for your help. The test program is working now.

On 11/05/2012, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
> * In server_read_cb, you do an evbuffer_add() to queue data to be sent
> followed immediately by a bufferevent_free() on the same buffer.
> That's not a safe pattern: bufferevent_free() does not guarantee how
> much data (if any) is sent before the bufferevent gets closed.

That was my principal mistake. In particular evbuffer_add() does not
per se make a callback pending. This is clear to me now, but maybe you
want to insert a line like "However, existing data in buffers is not
necessarily guaranteed to be written before the call to close()"
before the last sentence in the description of bufferevent_free() in
your book, for the sake of other newbies.

> * In server_read_cb, you don't handle partial writes.  There is no
> guarantee that the entire message from the client, including the
> newline, will arrive in a single readv call.  (When it's all on
> localhost, it *should* work ok with a few small messages, but it's not
> a habit to get into)

Well, I do handle them, by aborting the program if they occur ;)

What *is* missing, however, is a protocol sync check, that no client
writes several lines at once.

> * You're using LEV_OPT_DEFERRED_ACCEPT, but your protocol doesn't
> entitle you to do that.  LEV_OPT_DEFERRED_ACCEPT tells the OS kernel
> that it does not have to not treat the connection as having been
> accepted until the client actually writes something.  Your clients
> don't write anything until they *get* a message, so Linux doesn't need
> to tell Libevent "hey, you could accept some more sockets" until they
> do.

Yes, I completely misunderstood the purpose of that option. Thanks for
the clarification.

Thank you again for your help.

Best regards,
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.