0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-27 15:41:05 +08:00

Problem: formatting errors

Solution: run make clang-format-diff
This commit is contained in:
Luca Boccassi 2020-06-26 23:45:39 +01:00
parent c04f6581e0
commit 1ddfeb56ec
4 changed files with 138 additions and 122 deletions

View File

@ -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, // special case: connecting to non-ZMTP process which immediately drops connection,
// or which never responds with greeting, should be treated as a protocol error // or which never responds with greeting, should be treated as a protocol error
// (i.e. stop reconnect) // (i.e. stop reconnect)
if ( ( (reason_ == connection_error) || (reason_ == timeout_error) ) if (((reason_ == connection_error) || (reason_ == timeout_error))
&& (_options.reconnect_stop & ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED)) { && (_options.reconnect_stop
& ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED)) {
reason_ = protocol_error; reason_ = protocol_error;
} }
} }

View File

@ -224,7 +224,7 @@ void reconnect_stop_on_handshake_failed ()
{ {
char bind_address[MAX_SOCKET_STRING]; char bind_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (bind_address); 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_bind (dummy, "tcp://127.0.0.1:0"));
TEST_ASSERT_SUCCESS_ERRNO ( TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (dummy, ZMQ_LAST_ENDPOINT, bind_address, &addr_length)); 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")); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub_mon, "inproc://monitor-sub"));
// set handshake interval (i.e., timeout) to a more reasonable value // set handshake interval (i.e., timeout) to a more reasonable value
int handshakeInterval = 1000; int handshakeInterval = 1000;
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_HANDSHAKE_IVL, TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (
&handshakeInterval, sub, ZMQ_HANDSHAKE_IVL, &handshakeInterval, sizeof (handshakeInterval)));
sizeof (handshakeInterval)));
// set option to stop reconnecting on failed handshake // set option to stop reconnecting on failed handshake
int stopReconnectOnError = ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED; int stopReconnectOnError = ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED;
TEST_ASSERT_SUCCESS_ERRNO (zmq_setsockopt (sub, ZMQ_RECONNECT_STOP, 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 // connect to dummy stream socket above
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sub, bind_address)); 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 // 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_CONNECT_DELAYED);
expect_monitor_event (sub_mon, ZMQ_EVENT_CONNECTED); 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_HANDSHAKE_FAILED_NO_DETAIL);
expect_monitor_event (sub_mon, ZMQ_EVENT_DISCONNECTED); expect_monitor_event (sub_mon, ZMQ_EVENT_DISCONNECTED);
#else #else
print_events(sub_mon, 2 * 1000, 1000); print_events (sub_mon, 2 * 1000, 1000);
#endif #endif
// Close sub // Close sub
// TODO why does this use zero_linger? // TODO why does this use zero_linger?
@ -290,9 +289,9 @@ int main (void)
RUN_TEST (reconnect_default); RUN_TEST (reconnect_default);
RUN_TEST (reconnect_success); 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_refused);
RUN_TEST (reconnect_stop_on_handshake_failed); RUN_TEST (reconnect_stop_on_handshake_failed);
#endif #endif
return UNITY_END (); return UNITY_END ();
} }

View File

@ -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) { switch (event) {
case ZMQ_EVENT_CONNECTED : return "CONNECTED"; case ZMQ_EVENT_CONNECTED:
case ZMQ_EVENT_CONNECT_DELAYED : return "CONNECT_DELAYED"; return "CONNECTED";
case ZMQ_EVENT_CONNECT_RETRIED : return "CONNECT_RETRIED"; case ZMQ_EVENT_CONNECT_DELAYED:
case ZMQ_EVENT_LISTENING : return "LISTENING"; return "CONNECT_DELAYED";
case ZMQ_EVENT_BIND_FAILED : return "BIND_FAILED"; case ZMQ_EVENT_CONNECT_RETRIED:
case ZMQ_EVENT_ACCEPTED : return "ACCEPTED"; return "CONNECT_RETRIED";
case ZMQ_EVENT_ACCEPT_FAILED : return "ACCEPT_FAILED"; case ZMQ_EVENT_LISTENING:
case ZMQ_EVENT_CLOSED : return "CLOSED"; return "LISTENING";
case ZMQ_EVENT_CLOSE_FAILED : return "CLOSE_FAILED"; case ZMQ_EVENT_BIND_FAILED:
case ZMQ_EVENT_DISCONNECTED : return "DISCONNECTED"; return "BIND_FAILED";
case ZMQ_EVENT_MONITOR_STOPPED : return "MONITOR_STOPPED"; case ZMQ_EVENT_ACCEPTED:
case ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL : return "HANDSHAKE_FAILED_NO_DETAIL"; return "ACCEPTED";
case ZMQ_EVENT_HANDSHAKE_SUCCEEDED : return "HANDSHAKE_SUCCEEDED"; case ZMQ_EVENT_ACCEPT_FAILED:
case ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL : return "HANDSHAKE_FAILED_PROTOCOL"; return "ACCEPT_FAILED";
case ZMQ_EVENT_HANDSHAKE_FAILED_AUTH : return "HANDSHAKE_FAILED_AUTH"; case ZMQ_EVENT_CLOSED:
default : return "UNKNOWN"; 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 // print events received
int value; int value;
char *event_address; char *event_address;
int event = get_monitor_event_with_timeout (socket, &value, &event_address, int event =
timeout); get_monitor_event_with_timeout (socket, &value, &event_address, timeout);
int i = 0;; int i = 0;
;
while ((event != -1) && (++i < limit)) { while ((event != -1) && (++i < limit)) {
const char* eventName = get_zmqEventName(event); const char *eventName = get_zmqEventName (event);
printf("Got event: %s\n", eventName); printf ("Got event: %s\n", eventName);
event = get_monitor_event_with_timeout (socket, &value, &event_address, event = get_monitor_event_with_timeout (socket, &value, &event_address,
timeout); timeout);
} }
} }

View File

@ -1,83 +1,83 @@
/* /*
Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file
This file is part of libzmq, the ZeroMQ core engine in C++. 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 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 the terms of the GNU Lesser General Public License (LGPL) as published
by the Free Software Foundation; either version 3 of the License, or by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
As a special exception, the Contributors give you permission to link As a special exception, the Contributors give you permission to link
this library with independent modules to produce an executable, this library with independent modules to produce an executable,
regardless of the license terms of these independent modules, and to regardless of the license terms of these independent modules, and to
copy and distribute the resulting executable under terms of your choice, copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the provided that you also meet, for each linked independent module, the
terms and conditions of the license of that module. An independent 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. 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 If you modify this library, you must extend this exception to your
version of the library. version of the library.
libzmq is distributed in the hope that it will be useful, but WITHOUT libzmq is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details. License for more details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __TESTUTIL_MONITORING_HPP_INCLUDED__ #ifndef __TESTUTIL_MONITORING_HPP_INCLUDED__
#define __TESTUTIL_MONITORING_HPP_INCLUDED__ #define __TESTUTIL_MONITORING_HPP_INCLUDED__
#include "../include/zmq.h" #include "../include/zmq.h"
#include "../src/stdint.hpp" #include "../src/stdint.hpp"
#include <stddef.h> #include <stddef.h>
// General, i.e. non-security specific, monitor utilities // General, i.e. non-security specific, monitor utilities
int get_monitor_event_with_timeout (void *monitor_, int get_monitor_event_with_timeout (void *monitor_,
int *value_, int *value_,
char **address_, char **address_,
int timeout_); int timeout_);
// Read one event off the monitor socket; return value and address // Read one event off the monitor socket; return value and address
// by reference, if not null, and event number by value. Returns -1 // by reference, if not null, and event number by value. Returns -1
// in case of error. // in case of error.
int get_monitor_event (void *monitor_, int *value_, char **address_); int get_monitor_event (void *monitor_, int *value_, char **address_);
void expect_monitor_event (void *monitor_, int expected_event_); void expect_monitor_event (void *monitor_, int expected_event_);
void print_unexpected_event_stderr (int event_, void print_unexpected_event_stderr (int event_,
int err_, int err_,
int expected_event_, int expected_event_,
int expected_err_); int expected_err_);
// expects that one or more occurrences of the expected event are received // expects that one or more occurrences of the expected event are received
// via the specified socket monitor // via the specified socket monitor
// returns the number of occurrences of the expected event // returns the number of occurrences of the expected event
// interrupts, if a ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with EPIPE, ECONNRESET // interrupts, if a ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with EPIPE, ECONNRESET
// or ECONNABORTED occurs; in this case, 0 is returned // or ECONNABORTED occurs; in this case, 0 is returned
// this should be investigated further, see // this should be investigated further, see
// https://github.com/zeromq/libzmq/issues/2644 // https://github.com/zeromq/libzmq/issues/2644
int expect_monitor_event_multiple (void *server_mon_, int expect_monitor_event_multiple (void *server_mon_,
int expected_event_, int expected_event_,
int expected_err_ = -1, int expected_err_ = -1,
bool optional_ = false); bool optional_ = false);
int64_t get_monitor_event_v2 (void *monitor_, int64_t get_monitor_event_v2 (void *monitor_,
uint64_t *value_, uint64_t *value_,
char **local_address_, char **local_address_,
char **remote_address_); char **remote_address_);
void expect_monitor_event_v2 (void *monitor_, void expect_monitor_event_v2 (void *monitor_,
int64_t expected_event_, int64_t expected_event_,
const char *expected_local_address_ = NULL, const char *expected_local_address_ = NULL,
const char *expected_remote_address_ = NULL); const char *expected_remote_address_ = NULL);
const char* get_zmqEventName(uint64_t event); const char *get_zmqEventName (uint64_t event);
void print_events(void* socket, int timeout, int limit); void print_events (void *socket, int timeout, int limit);
#endif #endif