libevent in OpenBSD/i386 3.9-release

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

libevent in OpenBSD/i386 3.9-release

Bruno Carnazzi
   Hi misc,

I'm currently playing with libevent and there is something that I
don't understand. I've made a small echo server using bufferevent_read
and bufferevent_write. Here's the read_handler :

   96 void
   97 client_read(struct bufferevent *bufev, void *arg)
   98 {
   99     char buf[BUFLEN];
  100     int n, p;
  101     n = bufferevent_read(bufev, buf, BUFLEN);
  102     p = bufferevent_write(bufev, buf, n);
  103
  104     logmsg(LOG_DEBUG, "client read %d bytes (%d write)", n, p);
  105 }

While this code works (echo some text), bufferevent_write() always return 0 !

This is confusing, because man event(3) says :

The bufferevent_write() function can be used to write data to the file
     descriptor.  The data is appended to the output buffer and written to the
     descriptor automatically as it becomes available for writing.  The
     bufferevent_read() function is used to read data from the input buffer.
->  Both functions return the amount of data written or read.

Is my code broken or man page not accurate ?

Best regards,

Bruno.

Reply | Threaded
Open this post in threaded view
|

Re: libevent in OpenBSD/i386 3.9-release

Jared Yanovich
On Thu, 19 Oct 2006 10:18:40 +0400
"Bruno Carnazzi" <[hidden email]> wrote:

> Is my code broken or man page not accurate ?

It would appear the manual page is inaccurate.

libevent/evbuffer.c:

/*
 * Returns 0 on success;
 *        -1 on failure.
 */

int
bufferevent_write(struct bufferevent *bufev, void *data, size_t size)