Discussion:
Retry buffered event writes on partial write or error?
(too old to reply)
Jeffrey Walton
2014-02-25 15:43:22 UTC
Permalink
Raw Message
I'm trying to understand retry strategies on buffered events. I'm
using the hello-world.c as an example.

Suppose I have a listener created with evconnlistener_new_bind. A
connection is made and the listener_cb is invoked.

The listener_cb sets two callbacks for the write - conn_writecb and
conn_eventcb:

bev = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);
bufferevent_setcb(bev, NULL, conn_writecb, conn_eventcb, NULL);
bufferevent_write(bev, MESSAGE, strlen(MESSAGE));

The conn_writecb is shown below.

conn_writecb(struct bufferevent *bev, void *user_data)
{
struct evbuffer *output = bufferevent_get_output(bev);
if (evbuffer_get_length(output) == 0) {
bufferevent_free(bev);
}
}

I see the buffered event is cleaned up on a successful write.

conn_eventcb(struct bufferevent *bev, short events, void *user_data)
{
if (events & BEV_EVENT_EOF) {
printf("Connection closed.\n");
} else if (events & BEV_EVENT_ERROR) {
printf("Got an error on the connection: %s\n",
strerror(errno));/*XXX win32*/
}
bufferevent_free(bev);
}

In the case of an error, I only see the close.

How do I retry it if there's a partial write? Is this a case, should I
call event_add an attempt to finish the write? Would that occur in
conn_writecb or conn_eventcb?

Thanks in advance.
***********************************************************************
To unsubscribe, send an e-mail to ***@freehaven.net with
unsubscribe libevent-users in the body.

Loading...