From 1ddfeb56ec4fb355160daa0dc750d05494e6d54e Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 26 Jun 2020 23:45:39 +0100 Subject: [PATCH] Problem: formatting errors Solution: run make clang-format-diff --- src/stream_engine_base.cpp | 5 +- tests/test_reconnect_options.cpp | 19 ++-- tests/testutil_monitoring.cpp | 70 ++++++++----- tests/testutil_monitoring.hpp | 166 +++++++++++++++---------------- 4 files changed, 138 insertions(+), 122 deletions(-) diff --git a/src/stream_engine_base.cpp b/src/stream_engine_base.cpp index 31f41896..275be24d 100644 --- a/src/stream_engine_base.cpp +++ b/src/stream_engine_base.cpp @@ -697,8 +697,9 @@ void zmq::stream_engine_base_t::error (error_reason_t reason_) // special case: connecting to non-ZMTP process which immediately drops connection, // or which never responds with greeting, should be treated as a protocol error // (i.e. stop reconnect) - if ( ( (reason_ == connection_error) || (reason_ == timeout_error) ) - && (_options.reconnect_stop & ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED)) { + if (((reason_ == connection_error) || (reason_ == timeout_error)) + && (_options.reconnect_stop + & ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED)) { reason_ = protocol_error; } } diff --git a/tests/test_reconnect_options.cpp b/tests/test_reconnect_options.cpp index 57eafaae..ba461177 100644 --- a/tests/test_reconnect_options.cpp +++ b/tests/test_reconnect_options.cpp @@ -224,7 +224,7 @@ void reconnect_stop_on_handshake_failed () { char bind_address[MAX_SOCKET_STRING]; size_t addr_length = sizeof (bind_address); - void* dummy = test_context_socket (ZMQ_STREAM); + void *dummy = test_context_socket (ZMQ_STREAM); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (dummy, "tcp://127.0.0.1:0")); TEST_ASSERT_SUCCESS_ERRNO ( zmq_getsockopt (dummy, ZMQ_LAST_ENDPOINT, bind_address, &addr_length)); @@ -240,9 +240,8 @@ void reconnect_stop_on_handshake_failed () TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_mon, "inproc://monitor-sub")); // set handshake interval (i.e., timeout) to a more reasonable value int handshakeInterval = 1000; - TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_HANDSHAKE_IVL, - &handshakeInterval, - sizeof (handshakeInterval))); + TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt ( + sub, ZMQ_HANDSHAKE_IVL, &handshakeInterval, sizeof (handshakeInterval))); // set option to stop reconnecting on failed handshake int stopReconnectOnError = ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED; TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_RECONNECT_STOP, @@ -251,15 +250,15 @@ void reconnect_stop_on_handshake_failed () // connect to dummy stream socket above TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, bind_address)); - #if 1 +#if 1 // ZMQ_EVENT_DISCONNECTED should be last event, because of ZMQ_RECONNECT_STOP set above expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECT_DELAYED); expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL); expect_monitor_event (sub_mon, ZMQ_EVENT_DISCONNECTED); - #else - print_events(sub_mon, 2 * 1000, 1000); - #endif +#else + print_events (sub_mon, 2 * 1000, 1000); +#endif // Close sub // TODO why does this use zero_linger? @@ -290,9 +289,9 @@ int main (void) RUN_TEST (reconnect_default); RUN_TEST (reconnect_success); - #ifdef ZMQ_BUILD_DRAFT_API +#ifdef ZMQ_BUILD_DRAFT_API RUN_TEST (reconnect_stop_on_refused); RUN_TEST (reconnect_stop_on_handshake_failed); - #endif +#endif return UNITY_END (); } diff --git a/tests/testutil_monitoring.cpp b/tests/testutil_monitoring.cpp index cb4393e8..06406270 100644 --- a/tests/testutil_monitoring.cpp +++ b/tests/testutil_monitoring.cpp @@ -345,41 +345,57 @@ void expect_monitor_event_v2 (void *monitor_, } -const char* get_zmqEventName(uint64_t event) +const char *get_zmqEventName (uint64_t event) { - switch(event) { - case ZMQ_EVENT_CONNECTED : return "CONNECTED"; - case ZMQ_EVENT_CONNECT_DELAYED : return "CONNECT_DELAYED"; - case ZMQ_EVENT_CONNECT_RETRIED : return "CONNECT_RETRIED"; - case ZMQ_EVENT_LISTENING : return "LISTENING"; - case ZMQ_EVENT_BIND_FAILED : return "BIND_FAILED"; - case ZMQ_EVENT_ACCEPTED : return "ACCEPTED"; - case ZMQ_EVENT_ACCEPT_FAILED : return "ACCEPT_FAILED"; - case ZMQ_EVENT_CLOSED : return "CLOSED"; - case ZMQ_EVENT_CLOSE_FAILED : return "CLOSE_FAILED"; - case ZMQ_EVENT_DISCONNECTED : return "DISCONNECTED"; - case ZMQ_EVENT_MONITOR_STOPPED : return "MONITOR_STOPPED"; - case ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL : return "HANDSHAKE_FAILED_NO_DETAIL"; - case ZMQ_EVENT_HANDSHAKE_SUCCEEDED : return "HANDSHAKE_SUCCEEDED"; - case ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL : return "HANDSHAKE_FAILED_PROTOCOL"; - case ZMQ_EVENT_HANDSHAKE_FAILED_AUTH : return "HANDSHAKE_FAILED_AUTH"; - default : return "UNKNOWN"; - } + switch (event) { + case ZMQ_EVENT_CONNECTED: + return "CONNECTED"; + case ZMQ_EVENT_CONNECT_DELAYED: + return "CONNECT_DELAYED"; + case ZMQ_EVENT_CONNECT_RETRIED: + return "CONNECT_RETRIED"; + case ZMQ_EVENT_LISTENING: + return "LISTENING"; + case ZMQ_EVENT_BIND_FAILED: + return "BIND_FAILED"; + case ZMQ_EVENT_ACCEPTED: + return "ACCEPTED"; + case ZMQ_EVENT_ACCEPT_FAILED: + return "ACCEPT_FAILED"; + case ZMQ_EVENT_CLOSED: + return "CLOSED"; + case ZMQ_EVENT_CLOSE_FAILED: + return "CLOSE_FAILED"; + case ZMQ_EVENT_DISCONNECTED: + return "DISCONNECTED"; + case ZMQ_EVENT_MONITOR_STOPPED: + return "MONITOR_STOPPED"; + case ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL: + return "HANDSHAKE_FAILED_NO_DETAIL"; + case ZMQ_EVENT_HANDSHAKE_SUCCEEDED: + return "HANDSHAKE_SUCCEEDED"; + case ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL: + return "HANDSHAKE_FAILED_PROTOCOL"; + case ZMQ_EVENT_HANDSHAKE_FAILED_AUTH: + return "HANDSHAKE_FAILED_AUTH"; + default: + return "UNKNOWN"; + } } -void print_events(void* socket, int timeout, int limit) +void print_events (void *socket, int timeout, int limit) { // print events received int value; char *event_address; - int event = get_monitor_event_with_timeout (socket, &value, &event_address, - timeout); - int i = 0;; + int event = + get_monitor_event_with_timeout (socket, &value, &event_address, timeout); + int i = 0; + ; while ((event != -1) && (++i < limit)) { - const char* eventName = get_zmqEventName(event); - printf("Got event: %s\n", eventName); + const char *eventName = get_zmqEventName (event); + printf ("Got event: %s\n", eventName); event = get_monitor_event_with_timeout (socket, &value, &event_address, - timeout); + timeout); } - } diff --git a/tests/testutil_monitoring.hpp b/tests/testutil_monitoring.hpp index 2e4ac79e..a69db290 100644 --- a/tests/testutil_monitoring.hpp +++ b/tests/testutil_monitoring.hpp @@ -1,83 +1,83 @@ -/* - Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file - - This file is part of libzmq, the ZeroMQ core engine in C++. - - libzmq is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License (LGPL) as published - by the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - As a special exception, the Contributors give you permission to link - this library with independent modules to produce an executable, - regardless of the license terms of these independent modules, and to - copy and distribute the resulting executable under terms of your choice, - provided that you also meet, for each linked independent module, the - terms and conditions of the license of that module. An independent - module is a module which is not derived from or based on this library. - If you modify this library, you must extend this exception to your - version of the library. - - libzmq is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef __TESTUTIL_MONITORING_HPP_INCLUDED__ -#define __TESTUTIL_MONITORING_HPP_INCLUDED__ - -#include "../include/zmq.h" -#include "../src/stdint.hpp" - -#include - -// General, i.e. non-security specific, monitor utilities - -int get_monitor_event_with_timeout (void *monitor_, - int *value_, - char **address_, - int timeout_); - -// Read one event off the monitor socket; return value and address -// by reference, if not null, and event number by value. Returns -1 -// in case of error. -int get_monitor_event (void *monitor_, int *value_, char **address_); - -void expect_monitor_event (void *monitor_, int expected_event_); - -void print_unexpected_event_stderr (int event_, - int err_, - int expected_event_, - int expected_err_); - -// expects that one or more occurrences of the expected event are received -// via the specified socket monitor -// returns the number of occurrences of the expected event -// interrupts, if a ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with EPIPE, ECONNRESET -// or ECONNABORTED occurs; in this case, 0 is returned -// this should be investigated further, see -// https://github.com/zeromq/libzmq/issues/2644 -int expect_monitor_event_multiple (void *server_mon_, - int expected_event_, - int expected_err_ = -1, - bool optional_ = false); - -int64_t get_monitor_event_v2 (void *monitor_, - uint64_t *value_, - char **local_address_, - char **remote_address_); - -void expect_monitor_event_v2 (void *monitor_, - int64_t expected_event_, - const char *expected_local_address_ = NULL, - const char *expected_remote_address_ = NULL); - - -const char* get_zmqEventName(uint64_t event); -void print_events(void* socket, int timeout, int limit); - -#endif +/* + Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file + + This file is part of libzmq, the ZeroMQ core engine in C++. + + libzmq is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License (LGPL) as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + As a special exception, the Contributors give you permission to link + this library with independent modules to produce an executable, + regardless of the license terms of these independent modules, and to + copy and distribute the resulting executable under terms of your choice, + provided that you also meet, for each linked independent module, the + terms and conditions of the license of that module. An independent + module is a module which is not derived from or based on this library. + If you modify this library, you must extend this exception to your + version of the library. + + libzmq is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . +*/ + +#ifndef __TESTUTIL_MONITORING_HPP_INCLUDED__ +#define __TESTUTIL_MONITORING_HPP_INCLUDED__ + +#include "../include/zmq.h" +#include "../src/stdint.hpp" + +#include + +// General, i.e. non-security specific, monitor utilities + +int get_monitor_event_with_timeout (void *monitor_, + int *value_, + char **address_, + int timeout_); + +// Read one event off the monitor socket; return value and address +// by reference, if not null, and event number by value. Returns -1 +// in case of error. +int get_monitor_event (void *monitor_, int *value_, char **address_); + +void expect_monitor_event (void *monitor_, int expected_event_); + +void print_unexpected_event_stderr (int event_, + int err_, + int expected_event_, + int expected_err_); + +// expects that one or more occurrences of the expected event are received +// via the specified socket monitor +// returns the number of occurrences of the expected event +// interrupts, if a ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with EPIPE, ECONNRESET +// or ECONNABORTED occurs; in this case, 0 is returned +// this should be investigated further, see +// https://github.com/zeromq/libzmq/issues/2644 +int expect_monitor_event_multiple (void *server_mon_, + int expected_event_, + int expected_err_ = -1, + bool optional_ = false); + +int64_t get_monitor_event_v2 (void *monitor_, + uint64_t *value_, + char **local_address_, + char **remote_address_); + +void expect_monitor_event_v2 (void *monitor_, + int64_t expected_event_, + const char *expected_local_address_ = NULL, + const char *expected_remote_address_ = NULL); + + +const char *get_zmqEventName (uint64_t event); +void print_events (void *socket, int timeout, int limit); + +#endif