mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
bufferevent: refactor to use type check macros
This commit is contained in:
parent
266f43af77
commit
92cc0b9c3d
@ -306,6 +306,13 @@ extern const struct bufferevent_ops bufferevent_ops_pair;
|
||||
#define BEV_IS_FILTER(bevp) ((bevp)->be_ops == &bufferevent_ops_filter)
|
||||
#define BEV_IS_PAIR(bevp) ((bevp)->be_ops == &bufferevent_ops_pair)
|
||||
|
||||
#if defined(EVENT__HAVE_OPENSSL)
|
||||
extern const struct bufferevent_ops bufferevent_ops_openssl;
|
||||
#define BEV_IS_OPENSSL(bevp) ((bevp)->be_ops == &bufferevent_ops_openssl)
|
||||
#else
|
||||
#define BEV_IS_OPENSSL(bevp) 0
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
extern const struct bufferevent_ops bufferevent_ops_async;
|
||||
#define BEV_IS_ASYNC(bevp) ((bevp)->be_ops == &bufferevent_ops_async)
|
||||
|
@ -104,7 +104,7 @@ static inline struct bufferevent_async *
|
||||
upcast(struct bufferevent *bev)
|
||||
{
|
||||
struct bufferevent_async *bev_a;
|
||||
if (bev->be_ops != &bufferevent_ops_async)
|
||||
if (!BEV_IS_ASYNC(bev))
|
||||
return NULL;
|
||||
bev_a = EVUTIL_UPCAST(bev, struct bufferevent_async, bev.bev);
|
||||
return bev_a;
|
||||
|
@ -118,11 +118,11 @@ static inline struct bufferevent_filtered *
|
||||
upcast(struct bufferevent *bev)
|
||||
{
|
||||
struct bufferevent_filtered *bev_f;
|
||||
if (bev->be_ops != &bufferevent_ops_filter)
|
||||
if (!BEV_IS_FILTER(bev))
|
||||
return NULL;
|
||||
bev_f = (void*)( ((char*)bev) -
|
||||
evutil_offsetof(struct bufferevent_filtered, bev.bev));
|
||||
EVUTIL_ASSERT(bev_f->bev.bev.be_ops == &bufferevent_ops_filter);
|
||||
EVUTIL_ASSERT(BEV_IS_FILTER(&bev_f->bev.bev));
|
||||
return bev_f;
|
||||
}
|
||||
|
||||
|
@ -354,11 +354,11 @@ static inline struct bufferevent_openssl *
|
||||
upcast(struct bufferevent *bev)
|
||||
{
|
||||
struct bufferevent_openssl *bev_o;
|
||||
if (bev->be_ops != &bufferevent_ops_openssl)
|
||||
if (!BEV_IS_OPENSSL(bev))
|
||||
return NULL;
|
||||
bev_o = (void*)( ((char*)bev) -
|
||||
evutil_offsetof(struct bufferevent_openssl, bev.bev));
|
||||
EVUTIL_ASSERT(bev_o->bev.bev.be_ops == &bufferevent_ops_openssl);
|
||||
EVUTIL_ASSERT(BEV_IS_OPENSSL(&bev_o->bev.bev));
|
||||
return bev_o;
|
||||
}
|
||||
|
||||
|
@ -56,10 +56,10 @@ static inline struct bufferevent_pair *
|
||||
upcast(struct bufferevent *bev)
|
||||
{
|
||||
struct bufferevent_pair *bev_p;
|
||||
if (bev->be_ops != &bufferevent_ops_pair)
|
||||
if (!BEV_IS_PAIR(bev))
|
||||
return NULL;
|
||||
bev_p = EVUTIL_UPCAST(bev, struct bufferevent_pair, bev.bev);
|
||||
EVUTIL_ASSERT(bev_p->bev.bev.be_ops == &bufferevent_ops_pair);
|
||||
EVUTIL_ASSERT(BEV_IS_PAIR(&bev_p->bev.bev));
|
||||
return bev_p;
|
||||
}
|
||||
|
||||
|
@ -607,7 +607,7 @@ be_socket_destruct(struct bufferevent *bufev)
|
||||
struct bufferevent_private *bufev_p =
|
||||
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
||||
evutil_socket_t fd;
|
||||
EVUTIL_ASSERT(bufev->be_ops == &bufferevent_ops_socket);
|
||||
EVUTIL_ASSERT(BEV_IS_SOCKET(bufev));
|
||||
|
||||
fd = event_get_fd(&bufev->ev_read);
|
||||
|
||||
@ -632,7 +632,7 @@ be_socket_setfd(struct bufferevent *bufev, evutil_socket_t fd)
|
||||
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
||||
|
||||
BEV_LOCK(bufev);
|
||||
EVUTIL_ASSERT(bufev->be_ops == &bufferevent_ops_socket);
|
||||
EVUTIL_ASSERT(BEV_IS_SOCKET(bufev));
|
||||
|
||||
event_del(&bufev->ev_read);
|
||||
event_del(&bufev->ev_write);
|
||||
@ -662,7 +662,7 @@ bufferevent_priority_set(struct bufferevent *bufev, int priority)
|
||||
EVUTIL_UPCAST(bufev, struct bufferevent_private, bev);
|
||||
|
||||
BEV_LOCK(bufev);
|
||||
if (bufev->be_ops != &bufferevent_ops_socket)
|
||||
if (!BEV_IS_SOCKET(bufev))
|
||||
goto done;
|
||||
|
||||
if (event_priority_set(&bufev->ev_read, priority) == -1)
|
||||
@ -685,7 +685,7 @@ bufferevent_base_set(struct event_base *base, struct bufferevent *bufev)
|
||||
int res = -1;
|
||||
|
||||
BEV_LOCK(bufev);
|
||||
if (bufev->be_ops != &bufferevent_ops_socket)
|
||||
if (!BEV_IS_SOCKET(bufev))
|
||||
goto done;
|
||||
|
||||
bufev->ev_base = base;
|
||||
|
Loading…
x
Reference in New Issue
Block a user