mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-16 15:56:15 -04:00
New semantics for evbuffer_cb_set_flags().
Previously, set_flags() would replace all previous user-visible flags. Now it just sets the flags, and there is a clear_flags() function to clear other flags. svn:r1293
This commit is contained in:
parent
b4886ec80d
commit
bba69e03f8
@ -26,6 +26,8 @@ Changes in 2.0.2-alpha:
|
|||||||
o Make bufferevent_setfd() return an error code if the operation is not successful.
|
o Make bufferevent_setfd() return an error code if the operation is not successful.
|
||||||
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 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 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.
|
||||||
|
|
||||||
|
|
||||||
Changes in 2.0.1-alpha:
|
Changes in 2.0.1-alpha:
|
||||||
o free minheap on event_base_free(); from Christopher Layne
|
o free minheap on event_base_free(); from Christopher Layne
|
||||||
|
16
buffer.c
16
buffer.c
@ -2253,8 +2253,22 @@ int
|
|||||||
evbuffer_cb_set_flags(struct evbuffer *buffer,
|
evbuffer_cb_set_flags(struct evbuffer *buffer,
|
||||||
struct evbuffer_cb_entry *cb, ev_uint32_t flags)
|
struct evbuffer_cb_entry *cb, ev_uint32_t flags)
|
||||||
{
|
{
|
||||||
|
/* the user isn't allowed to mess with these. */
|
||||||
|
flags &= ~EVBUFFER_CB_INTERNAL_FLAGS;
|
||||||
EVBUFFER_LOCK(buffer, EVTHREAD_WRITE);
|
EVBUFFER_LOCK(buffer, EVTHREAD_WRITE);
|
||||||
cb->flags = (cb->flags & EVBUFFER_CB_INTERNAL_FLAGS) | flags;
|
cb->flags |= flags;
|
||||||
|
EVBUFFER_UNLOCK(buffer, EVTHREAD_WRITE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
evbuffer_cb_clear_flags(struct evbuffer *buffer,
|
||||||
|
struct evbuffer_cb_entry *cb, ev_uint32_t flags)
|
||||||
|
{
|
||||||
|
/* the user isn't allowed to mess with these. */
|
||||||
|
flags &= ~EVBUFFER_CB_INTERNAL_FLAGS;
|
||||||
|
EVBUFFER_LOCK(buffer, EVTHREAD_WRITE);
|
||||||
|
cb->flags &= ~flags;
|
||||||
EVBUFFER_UNLOCK(buffer, EVTHREAD_WRITE);
|
EVBUFFER_UNLOCK(buffer, EVTHREAD_WRITE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -438,9 +438,9 @@ bufferevent_setwatermark(struct bufferevent *bufev, short events,
|
|||||||
} else {
|
} else {
|
||||||
/* There is now no high-water mark for read. */
|
/* There is now no high-water mark for read. */
|
||||||
if (bufev_private->read_watermarks_cb)
|
if (bufev_private->read_watermarks_cb)
|
||||||
evbuffer_cb_set_flags(bufev->input,
|
evbuffer_cb_clear_flags(bufev->input,
|
||||||
bufev_private->read_watermarks_cb,
|
bufev_private->read_watermarks_cb,
|
||||||
EVBUFFER_CB_DISABLED);
|
EVBUFFER_CB_ENABLED);
|
||||||
bufferevent_wm_unsuspend_read(bufev);
|
bufferevent_wm_unsuspend_read(bufev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -494,23 +494,30 @@ int evbuffer_remove_cb_entry(struct evbuffer *buffer,
|
|||||||
*/
|
*/
|
||||||
int evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg);
|
int evbuffer_remove_cb(struct evbuffer *buffer, evbuffer_cb_func cb, void *cbarg);
|
||||||
|
|
||||||
#define EVBUFFER_CB_DISABLED 0
|
/** If this flag is not set, then a callback is temporarily disabled, and
|
||||||
|
* should not be invoked. */
|
||||||
#define EVBUFFER_CB_ENABLED 1
|
#define EVBUFFER_CB_ENABLED 1
|
||||||
|
|
||||||
/** Change whether a given callback is enabled on a buffer or not. A
|
/** Change the flags that are set for a callback on a buffer by adding more.
|
||||||
disabled callback is not invoked even when the buffer size changes.
|
|
||||||
|
|
||||||
@param buffer the evbuffer that the callback is watching.
|
@param buffer the evbuffer that the callback is watching.
|
||||||
@param cb the callback whose status we want to change.
|
@param cb the callback whose status we want to change.
|
||||||
@param flags EVBUFFER_CB_ENABLED to enable the callback, or
|
@param flags EVBUFFER_CB_ENABLED to re-enable the callback.
|
||||||
EVBUFFER_CB_DISABLED to disable it.
|
|
||||||
@return 0 on success, -1 on failure.
|
@return 0 on success, -1 on failure.
|
||||||
*/
|
*/
|
||||||
/* XXXX It would be better to have a set_flags() and a clear_flags()
|
|
||||||
* interface, and make them separate. -nickm FIXME */
|
|
||||||
int evbuffer_cb_set_flags(struct evbuffer *buffer,
|
int evbuffer_cb_set_flags(struct evbuffer *buffer,
|
||||||
struct evbuffer_cb_entry *cb, ev_uint32_t flags);
|
struct evbuffer_cb_entry *cb, ev_uint32_t flags);
|
||||||
|
|
||||||
|
/** Change the flags that are set for a callback on a buffer by removing some
|
||||||
|
|
||||||
|
@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 disable the callback.
|
||||||
|
@return 0 on success, -1 on failure.
|
||||||
|
*/
|
||||||
|
int evbuffer_cb_clear_flags(struct evbuffer *buffer,
|
||||||
|
struct evbuffer_cb_entry *cb, ev_uint32_t flags);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/** Postpone calling a given callback until unsuspend is called later.
|
/** Postpone calling a given callback until unsuspend is called later.
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ test_evbuffer_callbacks(void *ptr)
|
|||||||
* adds a summary of length changes to buf_out1/buf_out2 when called. */
|
* adds a summary of length changes to buf_out1/buf_out2 when called. */
|
||||||
/* size: 0-> 36. */
|
/* size: 0-> 36. */
|
||||||
evbuffer_add_printf(buf, "The %d magic words are spotty pudding", 2);
|
evbuffer_add_printf(buf, "The %d magic words are spotty pudding", 2);
|
||||||
evbuffer_cb_set_flags(buf, cb2, 0);
|
evbuffer_cb_clear_flags(buf, cb2, EVBUFFER_CB_ENABLED);
|
||||||
evbuffer_drain(buf, 10); /*36->26*/
|
evbuffer_drain(buf, 10); /*36->26*/
|
||||||
evbuffer_prepend(buf, "Hello", 5);/*26->31*/
|
evbuffer_prepend(buf, "Hello", 5);/*26->31*/
|
||||||
evbuffer_cb_set_flags(buf, cb2, EVBUFFER_CB_ENABLED);
|
evbuffer_cb_set_flags(buf, cb2, EVBUFFER_CB_ENABLED);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user