From d452e009ce43f7d0ac2e250b52e0b4b40344df18 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Fri, 20 Mar 2020 09:00:20 -0700 Subject: [PATCH] libevent 2.0 compat --- src/clientconn.cpp | 2 +- src/pvxs/version.h | 2 ++ src/util.cpp | 3 +++ test/testev.cpp | 1 - test/testsock.cpp | 1 - test/testudp.cpp | 1 - 6 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/clientconn.cpp b/src/clientconn.cpp index 955c888..bac9ddd 100644 --- a/src/clientconn.cpp +++ b/src/clientconn.cpp @@ -27,7 +27,7 @@ Connection::Connection(const std::shared_ptr& context, const SockA timeval timo = {30, 0}; bufferevent_set_timeouts(bev.get(), &timo, &timo); - if(bufferevent_socket_connect(bev.get(), &peerAddr->sa, peerAddr.size())) + if(bufferevent_socket_connect(bev.get(), const_cast(&peerAddr->sa), peerAddr.size())) throw std::runtime_error("Unable to begin connecting"); log_debug_printf(io, "Connecting to %s\n", peerName.c_str()); diff --git a/src/pvxs/version.h b/src/pvxs/version.h index b17710c..85527aa 100644 --- a/src/pvxs/version.h +++ b/src/pvxs/version.h @@ -56,6 +56,8 @@ unsigned long version_int(); /** Free some internal global allocations to avoid false positives in * valgrind (or similar) tools looking for memory leaks. * + * Calls libevent_global_shutdown() when available (libevent >=2.1). + * * @warning This function is optional. * If you don't understand the intended use case, then do not call it! * diff --git a/src/util.cpp b/src/util.cpp index 5140b1f..c0e6e24 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -45,6 +45,9 @@ unsigned long version_int() void cleanup_for_valgrind() { +#if LIBEVENT_VERSION_NUMBER >= 0x02010000 + libevent_global_shutdown(); +#endif impl::logger_shutdown(); impl::UDPManager::cleanup(); } diff --git a/test/testev.cpp b/test/testev.cpp index 107795f..77c55aa 100644 --- a/test/testev.cpp +++ b/test/testev.cpp @@ -115,7 +115,6 @@ MAIN(testev) testPlan(14); test_call(); test_fill_evbuf(); - libevent_global_shutdown(); cleanup_for_valgrind(); return testDone(); } diff --git a/test/testsock.cpp b/test/testsock.cpp index f0b1b56..8d00f29 100644 --- a/test/testsock.cpp +++ b/test/testsock.cpp @@ -212,7 +212,6 @@ MAIN(testsock) test_from_wire(); test_to_wire(); testDiag("Done"); - libevent_global_shutdown(); cleanup_for_valgrind(); return testDone(); } diff --git a/test/testudp.cpp b/test/testudp.cpp index 3c37f3b..f0f9bba 100644 --- a/test/testudp.cpp +++ b/test/testudp.cpp @@ -158,7 +158,6 @@ int main(int argc, char *argv[]) testSearch(false, {"hello"}); testSearch(true , {"one", "two"}); testSearch(false, {"one", "two"}); - libevent_global_shutdown(); cleanup_for_valgrind(); return testDone(); }