]> granicus.if.org Git - libevent/commitdiff
Fix BEV_IS_SSL() macro
authorAzat Khuzhin <azat@libevent.org>
Sat, 31 Oct 2020 19:48:37 +0000 (22:48 +0300)
committerAzat Khuzhin <azat@libevent.org>
Sat, 31 Oct 2020 19:50:04 +0000 (22:50 +0300)
We cannot use the same trick with external declaration,
since there are copy of bufferevent_ops_ssl in each library:
- openssl
- mbedlts

However we can just compare the name of the bufferevent type for now.
(It is totally fine to use memcmp() here since it will be optimized by the compiler).

bufferevent-internal.h

index da56759429209bba7b2d84870abf0c92db294479..3ad0acf0f0255d88fa744a5ee88f20163ad99782 100644 (file)
@@ -307,8 +307,15 @@ extern const struct bufferevent_ops bufferevent_ops_pair;
 #define BEV_IS_PAIR(bevp) ((bevp)->be_ops == &bufferevent_ops_pair)
 
 #if defined(EVENT__HAVE_OPENSSL) || defined(EVENT__HAVE_MBEDTLS)
-extern const struct bufferevent_ops bufferevent_ops_ssl;
-#define BEV_IS_SSL(bevp) ((bevp)->be_ops == &bufferevent_ops_ssl)
+/* We cannot use the same trick with external declaration,
+ * since there are copy of bufferevent_ops_ssl in each library:
+ * - openssl
+ * - mbedlts
+ *
+ * However we can just compare the name of the bufferevent type for now.
+ * (It is totally fine to use memcmp() here since it will be optimized by the compiler).
+ */
+#define BEV_IS_SSL(bevp) (!memcmp((bevp)->be_ops->type, "ssl", 3))
 #else
 #define BEV_IS_SSL(bevp) 0
 #endif