static inline void
evbuffer_invoke_callbacks(struct evbuffer *buffer, size_t old_size)
{
+ struct evbuffer_cb_entry *cbent, *next;
size_t new_size = buffer->total_len;
- if (!TAILQ_EMPTY(&buffer->callbacks) && old_size != new_size) {
- struct evbuffer_cb_entry *cbent, *next;
- for (cbent = TAILQ_FIRST(&buffer->callbacks);
- cbent != TAILQ_END(&buffer->callbacks);
- cbent = next) {
- next = TAILQ_NEXT(cbent, next);
+ if (TAILQ_EMPTY(&buffer->callbacks) || old_size == new_size)
+ return;
+
+
+ for (cbent = TAILQ_FIRST(&buffer->callbacks);
+ cbent != TAILQ_END(&buffer->callbacks);
+ cbent = next) {
+ /* Get the 'next' pointer now in case this callback decides
+ * to remove itself or something. */
+ next = TAILQ_NEXT(cbent, next);
+ if ((cbent->flags & EVBUFFER_CB_ENABLED))
cbent->cb(buffer, old_size, new_size, cbent->cbarg);
- }
}
}
return NULL;
e->cb = cb;
e->cbarg = cbarg;
+ e->flags = EVBUFFER_CB_ENABLED;
TAILQ_INSERT_HEAD(&buffer->callbacks, e, next);
return e;
}
}
return -1;
}
+
+int
+evbuffer_cb_set_flags(struct evbuffer *buffer,
+ struct evbuffer_cb_entry *cb, unsigned flags)
+{
+ (void)buffer; /* unused */
+ cb->flags = flags;
+ return 0;
+}
+
*/
int evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb cb, void *cbarg);
+#define EVBUFFER_CB_ENABLED 1
+/** Change whether a given callback is enabled on a buffer or not. A
+ disabled callback is not invoked even when the buffer size changes.
+
+ @param buffer the evbuffer that the callback is watching.
+ @param cb the callback whose status we want to change.
+ @param flags EVBUFFER_CB_ENABLED to enable the callback, or 0 to
+ disable it.
+ @return 0 on success, -1 on failure.
+ */
+int evbuffer_cb_set_flags(struct evbuffer *buffer,
+ struct evbuffer_cb_entry *cb, unsigned flags);
+
/**
Makes the data at the begging of an evbuffer contiguous.