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

Re: [Libevent-users] async writes for bufferevent_write/bufferevent_write_buffer?



Thanks for your response!

I have an overly simplified, single threaded SSL test server (based on examples found in the libevent documentation) that has the following callback funcs:

static void
ssl_readcb(struct bufferevent * bev, void * arg)
{
    struct evbuffer *in = bufferevent_get_input(bev);

    printf("Received %zu bytes\n", evbuffer_get_length(in));
    printf("----- data ----\n");
    printf("%.*s\n", (int)evbuffer_get_length(in), evbuffer_pullup(in, -1));

    bufferevent_write_buffer(bev, in);
    printf("::: wrote to the buffer\n");
    sleep(2);
    printf("::: done sleeping\n");
}

static void
ssl_writecb(struct bufferevent * bev, void * arg)
{
    printf("writecb: in\n");
}


I connect to the server with the following:

openssl s_client -connect 0:9999


With the code as written above, because of the 'sleep(2)', I would expect the following in a fully async model:

  1. type 'hello' on the client
  2. see the server receive 'hello' by printing the '---- data ----', etc lines
  3. see the server print '::: wrote to the buffer'
  4. 2 seconds to elapse
  5. see the server print '::: done sleeping'
  6. see the client receive the echo 'hello'
  7. server prints 'writecb: in'

Instead, this happens:

  1. type 'hello' on the client
  2. see the server receive 'hello' by printing the '---- data ----', etc lines
  3. see the server print '::: wrote to the buffer'
  4. see the client receive the echo 'hello'
  5. 2 seconds elapse
  6. see the server print '::: done sleeping'
  7. server prints 'writecb: in'


The write is being sent to the client immediately from within the readcb.   Please let me know if I'm doing something wrong, but I'm not sure how to interpret this behavior other than there's at least one synchronous write happening from within the read handler?

Thanks!


- scott


On Jul 18, 2013, at 6:13 AM, Mark Ellzey <mthomas@xxxxxxxxxx> wrote:

On Thu, Jul 18, 2013 at 04:09:20AM -0600, J. Scott Dorr wrote:
So, when using bufferevent_write/write_buffer, is there a way to enforce asynchronicity?



Bufferevents *are* async. How are you determining it is not?