Add a bufferevent_getcb() to find a bufferevent's current callbacks

This commit is contained in:
Nick Mathewson 2012-02-11 12:04:15 -05:00
parent bf2c5a7797
commit a6503944dd
3 changed files with 53 additions and 1 deletions

View File

@ -358,6 +358,26 @@ bufferevent_setcb(struct bufferevent *bufev,
BEV_UNLOCK(bufev);
}
void
bufferevent_getcb(struct bufferevent *bufev,
bufferevent_data_cb *readcb_ptr,
bufferevent_data_cb *writecb_ptr,
bufferevent_event_cb *eventcb_ptr,
void **cbarg_ptr)
{
BEV_LOCK(bufev);
if (readcb_ptr)
*readcb_ptr = bufev->readcb;
if (writecb_ptr)
*writecb_ptr = bufev->writecb;
if (eventcb_ptr)
*eventcb_ptr = bufev->errorcb;
if (cbarg_ptr)
*cbarg_ptr = bufev->cbarg;
BEV_UNLOCK(bufev);
}
struct evbuffer *
bufferevent_get_input(struct bufferevent *bufev)
{

View File

@ -300,6 +300,26 @@ void bufferevent_setcb(struct bufferevent *bufev,
bufferevent_data_cb readcb, bufferevent_data_cb writecb,
bufferevent_event_cb eventcb, void *cbarg);
/**
Retrieves the callbacks for a bufferevent.
@param bufev the bufferevent to examine.
@param readcb_ptr if readcb_ptr is nonnull, *readcb_ptr is set to the current
read callback for the bufferevent.
@param writecb_ptr if writecb_ptr is nonnull, *writecb_ptr is set to the
current write callback for the bufferevent.
@param eventcb_ptr if eventcb_ptr is nonnull, *eventcb_ptr is set to the
current event callback for the bufferevent.
@param cbarg_ptr if cbarg_ptr is nonnull, *cbarg_ptr is set to the current
callback argument for the bufferevent.
@see buffervent_setcb()
*/
void bufferevent_getcb(struct bufferevent *bufev,
bufferevent_data_cb *readcb_ptr,
bufferevent_data_cb *writecb_ptr,
bufferevent_event_cb *eventcb_ptr,
void **cbarg_ptr);
/**
Changes the file descriptor on which the bufferevent operates.
Not supported for all bufferevent types.

View File

@ -132,7 +132,7 @@ test_bufferevent_impl(int use_pair)
tt_assert(0 == bufferevent_pair_new(NULL, 0, pair));
bev1 = pair[0];
bev2 = pair[1];
bufferevent_setcb(bev1, readcb, writecb, errorcb, NULL);
bufferevent_setcb(bev1, readcb, writecb, errorcb, bev1);
bufferevent_setcb(bev2, readcb, writecb, errorcb, NULL);
tt_int_op(bufferevent_getfd(bev1), ==, -1);
tt_ptr_op(bufferevent_get_underlying(bev1), ==, NULL);
@ -147,6 +147,18 @@ test_bufferevent_impl(int use_pair)
tt_ptr_op(bufferevent_pair_get_partner(bev2), ==, NULL);
}
{
/* Test getcb. */
bufferevent_data_cb r, w;
bufferevent_event_cb e;
void *a;
bufferevent_getcb(bev1, &r, &w, &e, &a);
tt_ptr_op(r, ==, readcb);
tt_ptr_op(w, ==, writecb);
tt_ptr_op(e, ==, errorcb);
tt_ptr_op(a, ==, use_pair ? bev1 : NULL);
}
bufferevent_disable(bev1, EV_READ);
bufferevent_enable(bev2, EV_READ);