diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-05-13 20:37:21 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-05-13 20:37:21 +0000 |
commit | 31d89f274bc28655bca3e6aec19b90080cb09add (patch) | |
tree | 1ca699851545515488eeee32f7cb410b2d6da0c3 /bufferevent.c | |
parent | 83f46e51d77759cc1857519f4bc94e833404980d (diff) | |
download | libevent-31d89f274bc28655bca3e6aec19b90080cb09add.tar.gz |
Add a "ctrl" mechanism to bufferevents for property access.
OpenSSL uses something like this to implement get/set access for
properties on its BIOs, so that it doesn't need to add a pair of
get/set functions to the vtable struct for every new abstract property
it provides an accessor for.
Doing this lets us make bufferevent_setfd abstract, and implement an
abstract bufferevent_getfd.
svn:r1284
Diffstat (limited to 'bufferevent.c')
-rw-r--r-- | bufferevent.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/bufferevent.c b/bufferevent.c index 2d614dae..06386844 100644 --- a/bufferevent.c +++ b/bufferevent.c @@ -531,3 +531,41 @@ bufferevent_enable_locking(struct bufferevent *bufev, void *lock) #endif } +int +bufferevent_setfd(struct bufferevent *bev, evutil_socket_t fd) +{ + union bufferevent_ctrl_data d; + int res = -1; + d.fd = fd; + BEV_LOCK(bev); + if (bev->be_ops->ctrl) + res = bev->be_ops->ctrl(bev, BEV_CTRL_SET_FD, &d); + BEV_UNLOCK(bev); + return res; +} + +evutil_socket_t +bufferevent_getfd(struct bufferevent *bev) +{ + union bufferevent_ctrl_data d; + int res = -1; + d.fd = -1; + BEV_LOCK(bev); + if (bev->be_ops->ctrl) + res = bev->be_ops->ctrl(bev, BEV_CTRL_GET_FD, &d); + BEV_UNLOCK(bev); + return (res<0) ? -1 : d.fd; +} + +struct bufferevent * +bufferevent_get_underlying(struct bufferevent *bev) +{ + union bufferevent_ctrl_data d; + int res = -1; + d.ptr = NULL; + BEV_LOCK(bev); + if (bev->be_ops->ctrl) + res = bev->be_ops->ctrl(bev, BEV_CTRL_GET_UNDERLYING, &d); + BEV_UNLOCK(bev); + return (res<0) ? NULL : d.ptr; +} |