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 via email to