libevent: Reading all bytes from buffer
<p>I have following read callback function <code>readcb</code> which is invoked on read event. My issue is, <code>bufferevent_get_input</code> is reading only 4096 bytes from the underlying buffer. How can I make it to read all bytes. I have used a variant also, given below as <code>readcb_variant</code>. It also reads only 4096 bytes and exists with <code>n = 0</code>, means no more bytes to read.</p>

<pre><code>void readcb(struct bufferevent *bev, void *ctx){
    size_t bytesread;
    char buf[10000];
    struct evbuffer *input, *output;
    input = bufferevent_get_input(bev);

    bytesread = evbuffer_get_length(input);
    evbuffer_remove(input, buf, bytesread);

    printf("%zu\n", bytesread ); // prints 4096 for long (&gt; 4096) byte stream
    do_some_cool_stuff(buf);
}


void readcb_variant(struct bufferevent *bev, void *ctx){
    char tmp[1000], buf[10000];
    size_t n, bytesread = 0;
    char *runner = buf;

    while(1){
        n = bufferevent_read(bev, tmp, sizeof(tmp));
        if (n &lt;= 0){
            printf("%zu\n", n); // prints '0';
            break;
        }
        memcpy(runner, tmp, n);
        runner += n;
        bytesread += n;
    }
    printf("%zu\n", bytesread ); // prints 4096 for long (&gt; 4096) byte stream
    do_some_cool_stuff(buf);
}
</code></pre>

<p><strong>Update</strong>
After a close look into the source code of libevent, I found this line of code <code>#define EVBUFFER_MAX_READ   4096</code> at <a href="https://github.com/libevent/libevent/blob/master/buffer.c#L2198" rel="nofollow">source code</a>. Hard coded limit.</p>