o Shave 22 bytes off struct event on 32-bit platforms by shrinking and re-ordering fields. The savings on 64-bit platforms is likely higher.
o Cap the maximum number of priorities at 256.
o Change the semantics of evbuffer_cb_set_flags() to be set-flag only; add a new evbuffer_cb_clear_flags() to remove set flags.
+ o Change the interface of evbuffer_add_reference so that the cleanup callback gets more information
Changes in 2.0.1-alpha:
struct evbuffer_chain_reference,
chain);
if (info->cleanupfn)
- (*info->cleanupfn)(info->extra);
+ (*info->cleanupfn)(chain->buffer,
+ chain->buffer_len,
+ info->extra);
}
#ifdef _EVENT_HAVE_MMAP
if (chain->flags & EVBUFFER_MMAP) {
int
evbuffer_add_reference(struct evbuffer *outbuf,
const void *data, size_t datlen,
- void (*cleanupfn)(void *extra), void *extra)
+ evbuffer_ref_cleanup_cb cleanupfn, void *extra)
{
struct evbuffer_chain *chain;
struct evbuffer_chain_reference *info;
/** callback for a reference buffer; lets us know what to do with it when
* we're done with it. */
struct evbuffer_chain_reference {
- void (*cleanupfn)(void *extra);
+ evbuffer_ref_cleanup_cb cleanupfn;
void *extra;
};
*/
int evbuffer_add_buffer(struct evbuffer *outbuf, struct evbuffer *inbuf);
+
+typedef void (*evbuffer_ref_cleanup_cb)(const void *data,
+ size_t datalen, void *extra);
+
/**
Reference memory into an evbuffer without copying.
@param extra optional argument to the cleanup callback
@return 0 if successful, or -1 if an error occurred
*/
-/* XXXX Should the cleanupfn get a copy of the data pointer too? */
int evbuffer_add_reference(struct evbuffer *outbuf,
const void *data, size_t datlen,
- void (*cleanupfn)(void *extra), void *extra);
+ evbuffer_ref_cleanup_cb cleanupfn, void *extra);
/**
Move data from a file into the evbuffer for writing to a socket.
static int reference_cb_called;
static void
-reference_cb(void *extra)
+reference_cb(const void *data, size_t len, void *extra)
{
+ tt_str_op(data, ==, "this is what we add as read-only memory.");
+ tt_int_op(len, ==, strlen(data));
tt_want(extra == (void *)0xdeadaffe);
++reference_cb_called;
+end:
+ ;
}
static void
static int ref_done_cb_called_count = 0;
static void *ref_done_cb_called_with = NULL;
-static void ref_done_cb(void *data)
+static const void *ref_done_cb_called_with_data = NULL;
+static size_t ref_done_cb_called_with_len = 0;
+static void ref_done_cb(const void *data, size_t len, void *info)
{
++ref_done_cb_called_count;
- ref_done_cb_called_with = data;
+ ref_done_cb_called_with = info;
+ ref_done_cb_called_with_data = data;
+ ref_done_cb_called_with_len = len;
}
static void
evbuffer_remove(buf1, tmp, 1);
tt_int_op(tmp[0], ==, 'm');
tt_assert(ref_done_cb_called_with == (void*)111);
+ tt_assert(ref_done_cb_called_with_data == chunk1);
+ tt_assert(ref_done_cb_called_with_len == len1);
tt_int_op(ref_done_cb_called_count, ==, 1);
/* Drain some of the remaining chunk, then add it to another buffer */