stop reconnect after called zmq_disconnect() (#4053)

This commit is contained in:
C-sir 2020-09-28 16:59:57 +08:00 committed by GitHub
parent dfc85af4d0
commit d4f03edd47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 0 deletions

15
RELICENSE/C-Sir.md Normal file
View File

@ -0,0 +1,15 @@
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current ZeroMQ BDFL
This is a statement by C-Sir
that grants permission to relicense its copyrights in the libzmq C++
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current ZeroMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the Github handle "C-Sir", with
commit author "C-Sir <942510829@qq.com>", are copyright of C-Sir.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
C-Sir
2020/09/28

View File

@ -741,6 +741,10 @@ connection attempts to non-0MQ sockets. Note that when specifying this option
you may also want to set `ZMQ_HANDSHAKE_IVL` -- the default handshake interval
is 30000 (30 seconds), which is typically too large.
The 'ZMQ_RECONNECT_STOP_AFTER_DISCONNECT' option will stop reconnection when
called zmq_disconnect(). This can be useful when the user request failed(server not
ready),the sokcet do not need to continue to reconnect after user disconnect actively.
NOTE: in DRAFT state, not yet available in stable releases.
[horizontal]

View File

@ -685,6 +685,7 @@ ZMQ_EXPORT void zmq_threadclose (void *thread_);
/* DRAFT ZMQ_RECONNECT_STOP options */
#define ZMQ_RECONNECT_STOP_CONN_REFUSED 0x1
#define ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED 0x2
#define ZMQ_RECONNECT_STOP_AFTER_DISCONNECT 0x3
/* DRAFT Context options */
#define ZMQ_ZERO_COPY_RECV 10

View File

@ -100,6 +100,13 @@ void zmq::ipc_connecter_t::start_connecting ()
// should be done here as well (and then this could be pulled up to
// stream_connecter_base_t).
}
//stop connecting after called zmq_disconnect
else if (rc == -1
&& (options.reconnect_stop & ZMQ_RECONNECT_STOP_AFTER_DISCONNECT)
&& errno == ECONNREFUSED && _socket->is_disconnected ()) {
if (_s != retired_fd)
close ();
}
// Handle any other error condition by eventual reconnect.
else {

View File

@ -1216,6 +1216,11 @@ int zmq::socket_base_t::term_endpoint (const char *endpoint_uri_)
term_child (it->second.first);
}
_endpoints.erase (range.first, range.second);
if (options.reconnect_stop & ZMQ_RECONNECT_STOP_AFTER_DISCONNECT) {
_disconnected = true;
}
return 0;
}
@ -2051,6 +2056,11 @@ void zmq::socket_base_t::stop_monitor (bool send_monitor_stopped_event_)
}
}
bool zmq::socket_base_t::is_disconnected () const
{
return _disconnected;
}
zmq::routing_socket_base_t::routing_socket_base_t (class ctx_t *parent_,
uint32_t tid_,
int sid_) :

View File

@ -164,6 +164,8 @@ class socket_base_t : public own_t,
// after gathering the data asynchronously. Requires event monitoring to
// be enabled.
int query_pipes_stats ();
bool is_disconnected () const;
protected:
socket_base_t (zmq::ctx_t *parent_,
@ -345,6 +347,9 @@ class socket_base_t : public own_t,
mutex_t _monitor_sync;
ZMQ_NON_COPYABLE_NOR_MOVABLE (socket_base_t)
// Add a flag for mark disconnect action
bool _disconnected;
};
class routing_socket_base_t : public socket_base_t

View File

@ -72,6 +72,7 @@
/* DRAFT ZMQ_RECONNECT_STOP options */
#define ZMQ_RECONNECT_STOP_CONN_REFUSED 0x1
#define ZMQ_RECONNECT_STOP_HANDSHAKE_FAILED 0x2
#define ZMQ_RECONNECT_STOP_AFTER_DISCONNECT 0x3
/* DRAFT Context options */
#define ZMQ_ZERO_COPY_RECV 10