Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Use feature tests for checking if we have zmq::socket::disconnect
Browse files Browse the repository at this point in the history
Since 9c02de3 (- Commit after merge with NextRelease branch at release 22135, 2013-02-22)
we check the libzmq version to decide if cppzmq's socket class has a
disconnect method or not.

This currently fails on debian wheezy.

As that is also the wrong approach in general, we now use a compilation
test in the cmake setup phase to determine if we have the disconnect method
or not. This is only done on non-Windows platforms, on Windows we assume
that we have a disconnect method (we currently always compile against a
cppzmq version which has it).

In addition the define got also renamed from ZMQ_HAS_DISCONNECT to
TANGO_ZMQ_HAS_DISCONNECT to make it clear that this is our define.
  • Loading branch information
t-b committed Oct 27, 2019
1 parent 7e7846d commit c69c293
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
12 changes: 12 additions & 0 deletions configure/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ Please install cppzmq (https://github.com/zeromq/cppzmq) on your system and/or u
<OMNI_BASE>/include and system include directories).")
endif()

if(NOT WIN32)
try_compile(TANGO_ZMQ_HAS_DISCONNECT ${CMAKE_BINARY_DIR}/test_cppzmq_disconnect
SOURCES ${CMAKE_SOURCE_DIR}/configure/test_cppzmq_disconnect.cpp
COMPILE_DEFINITIONS "-I ${CPPZMQ_BASE}/include -I ${ZMQ_BASE}/include"
LINK_LIBRARIES "${ZMQ_PKG_LIBRARIES}")

message(STATUS "Check if zmq::socket has a disconnect method: ${TANGO_ZMQ_HAS_DISCONNECT}")
else()
set(TANGO_ZMQ_HAS_DISCONNECT TRUE)
message(STATUS "Check if zmq::socket has a disconnect method: ${TANGO_ZMQ_HAS_DISCONNECT} (hardcoded)")
endif(NOT WIN32)

message("Verifying ${OMNIIDL_PATH}omniidl")
if(WIN32)
execute_process(COMMAND ${OMNIIDL_PATH}omniidl.exe -V RESULT_VARIABLE FAILED)
Expand Down
8 changes: 8 additions & 0 deletions configure/test_cppzmq_disconnect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <zmq.hpp>

int main(int, char**)
{
zmq::context_t c;
zmq::socket_t s(c, ZMQ_REQ);
s.disconnect("some endpoint");
}
7 changes: 0 additions & 7 deletions cppapi/client/eventconsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@

#include <zmq.hpp>

#ifdef ZMQ_VERSION
#if ZMQ_VERSION > 30201
#define ZMQ_HAS_DISCONNECT
#endif
#endif


namespace Tango
{

Expand Down
6 changes: 3 additions & 3 deletions cppapi/client/eventkeepalive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ bool EventConsumerKeepAliveThread::reconnect_to_zmq_channel(EvChanIte &ipos,Even

string adm_name = ipos->second.full_adm_name;

#ifdef ZMQ_HAS_DISCONNECT
#ifdef TANGO_ZMQ_HAS_DISCONNECT
//
// Forget exception which could happen during massive restart of device server process running on the same host
//
Expand Down Expand Up @@ -406,7 +406,7 @@ void EventConsumerKeepAliveThread::re_subscribe_event(EvCbIte &epos,EvChanIte &i
void EventConsumerKeepAliveThread::reconnect_to_zmq_event(EvChanIte &ipos,EventConsumer *event_consumer,DeviceData &dd)
{
EvCbIte epos;
#ifdef ZMQ_HAS_DISCONNECT
#ifdef TANGO_ZMQ_HAS_DISCONNECT
bool disconnect_called = false;
#endif

Expand Down Expand Up @@ -448,7 +448,7 @@ void EventConsumerKeepAliveThread::reconnect_to_zmq_event(EvChanIte &ipos,EventC
string prefix = fqen.substr(0,pos + 1);
d_name.insert(0,prefix);

#ifdef ZMQ_HAS_DISCONNECT
#ifdef TANGO_ZMQ_HAS_DISCONNECT
if (disconnect_called == false)
{
event_consumer->disconnect_event(epos->second.fully_qualified_event_name,epos->second.endpoint);
Expand Down
10 changes: 5 additions & 5 deletions cppapi/client/zmqeventconsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_
//

const char *event_name = &(tmp_ptr[1]);
#ifdef ZMQ_HAS_DISCONNECT
#ifdef TANGO_ZMQ_HAS_DISCONNECT
const char *endpoint = &(tmp_ptr[1 + ::strlen(event_name) + 1]);
const char *endpoint_event = &(tmp_ptr[1 + ::strlen(event_name) + ::strlen(endpoint) + 2]);
#endif
Expand All @@ -822,7 +822,7 @@ bool ZmqEventConsumer::process_ctrl(zmq::message_t &received_ctrl,zmq::pollitem_
multi_tango_host(heartbeat_sub_sock,UNSUBSCRIBE,base_name);
}

#ifdef ZMQ_HAS_DISCONNECT
#ifdef TANGO_ZMQ_HAS_DISCONNECT
//
// Remove the endpoint in the vector of already connected heartbeat and disconnect the socket to this endpoint
//
Expand Down Expand Up @@ -1349,7 +1349,7 @@ void ZmqEventConsumer::connect_event_channel(string &channel_name,TANGO_UNUSED(D
buffer[length] = ZMQ_CONNECT_HEARTBEAT;
length++;

#ifdef ZMQ_HAS_DISCONNECT
#ifdef TANGO_ZMQ_HAS_DISCONNECT
buffer[length] = 0;
#else
if (reconnect == true)
Expand Down Expand Up @@ -1721,7 +1721,7 @@ void ZmqEventConsumer::connect_event_system(TANGO_UNUSED(string &device_name),TA
buffer[length] = ZMQ_CONNECT_EVENT;
length++;

#ifdef ZMQ_HAS_DISCONNECT
#ifdef TANGO_ZMQ_HAS_DISCONNECT
buffer[length] = 0;
#else
if (filters.size() == 1 && filters[0] == "reconnect")
Expand Down Expand Up @@ -3546,7 +3546,7 @@ ReceivedFromAdmin ZmqEventConsumer::initialize_received_from_admin(const Tango::
return result;
}

#ifdef ZMQ_HAS_DISCONNECT
#ifdef TANGO_ZMQ_HAS_DISCONNECT
void ZmqEventConsumer::disconnect_socket(zmq::socket_t& socket, const char* endpoint)
{
try
Expand Down
2 changes: 2 additions & 0 deletions cppapi/server/tango_const.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ const int PUB_HWM = 1000;
const int SUB_HWM = 1000;
const int SUB_SEND_HWM = 10000;

#cmakedefine TANGO_ZMQ_HAS_DISCONNECT

//
// Event when using a file as database stuff
//
Expand Down

0 comments on commit c69c293

Please sign in to comment.