]> granicus.if.org Git - libevent/commitdiff
bufferevent: refactor to use type check macros
authorDominic Chen <d.c.ddcc@gmail.com>
Thu, 13 Apr 2017 18:58:13 +0000 (14:58 -0400)
committerAzat Khuzhin <azat@libevent.org>
Sat, 2 Feb 2019 12:13:50 +0000 (15:13 +0300)
(cherry picked from commit 92cc0b9c3db38088f79c5d1e432c429fbc366968)

bufferevent-internal.h
bufferevent_async.c
bufferevent_filter.c
bufferevent_openssl.c
bufferevent_pair.c
bufferevent_sock.c

index b448eeadf18e49f6aac995a0425f264c1b49f8e4..f79e74d3d3ccde77638de9518c0398e51f4b6cff 100644 (file)
@@ -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)
index 6395e57a9f0c67faac04cc619dbafc7379b9aad5..1521d896af0d4d94b9bc0c551eb8c4d10e6c3a8d 100644 (file)
@@ -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;
index b5efd5c04a5c03f5b65d92cd29780e2a8a61db44..d9e8540f273143d37a12ae879bea15ba683e2aa4 100644 (file)
@@ -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;
 }
 
index da3963af06a89663b073161a092818f67778dd23..252627ecc90b4cdc706749262d25b4887cafae50 100644 (file)
@@ -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;
 }
 
@@ -803,7 +803,7 @@ consider_reading(struct bufferevent_openssl *bev_ssl)
 
                if (bev_ssl->bev.read_suspended)
                        break;
-        
+
                /* Read all pending data.  This won't hit the network
                 * again, and will (most importantly) put us in a state
                 * where we don't need to read anything else until the
index 1e93f57293d2e0b4b90c6b8216d428911407334d..f88cd751de1b9113dfb0206defd1add3c48f9254 100644 (file)
@@ -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;
 }
 
index 93aedb33fa2140f97af709fbf845e2c30b8bbfd7..e305ec55fd9cbdc0bf88aaef72f840634810e581 100644 (file)
@@ -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;