mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-26 18:42:43 +01:00
Problem: inconsistent naming style for private data members, conflicts with naming of local variables and member functions
Solution: apply and check _lower_case naming style for private data members
This commit is contained in:
@@ -71,19 +71,19 @@ zmq::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_,
|
||||
bool delayed_start_) :
|
||||
own_t (io_thread_, options_),
|
||||
io_object_t (io_thread_),
|
||||
addr (addr_),
|
||||
s (retired_fd),
|
||||
handle (static_cast<handle_t> (NULL)),
|
||||
delayed_start (delayed_start_),
|
||||
connect_timer_started (false),
|
||||
reconnect_timer_started (false),
|
||||
session (session_),
|
||||
current_reconnect_ivl (options.reconnect_ivl),
|
||||
socket (session->get_socket ())
|
||||
_addr (addr_),
|
||||
_s (retired_fd),
|
||||
_handle (static_cast<handle_t> (NULL)),
|
||||
_delayed_start (delayed_start_),
|
||||
_connect_timer_started (false),
|
||||
_reconnect_timer_started (false),
|
||||
_session (session_),
|
||||
_current_reconnect_ivl (options.reconnect_ivl),
|
||||
_socket (_session->get_socket ())
|
||||
{
|
||||
zmq_assert (addr);
|
||||
zmq_assert (addr->protocol == "tcp");
|
||||
addr->to_string (endpoint);
|
||||
zmq_assert (_addr);
|
||||
zmq_assert (_addr->protocol == "tcp");
|
||||
_addr->to_string (_endpoint);
|
||||
// TODO the return value is unused! what if it fails? if this is impossible
|
||||
// or does not matter, change such that endpoint in initialized using an
|
||||
// initializer, and make endpoint const
|
||||
@@ -91,15 +91,15 @@ zmq::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_,
|
||||
|
||||
zmq::tcp_connecter_t::~tcp_connecter_t ()
|
||||
{
|
||||
zmq_assert (!connect_timer_started);
|
||||
zmq_assert (!reconnect_timer_started);
|
||||
zmq_assert (!handle);
|
||||
zmq_assert (s == retired_fd);
|
||||
zmq_assert (!_connect_timer_started);
|
||||
zmq_assert (!_reconnect_timer_started);
|
||||
zmq_assert (!_handle);
|
||||
zmq_assert (_s == retired_fd);
|
||||
}
|
||||
|
||||
void zmq::tcp_connecter_t::process_plug ()
|
||||
{
|
||||
if (delayed_start)
|
||||
if (_delayed_start)
|
||||
add_reconnect_timer ();
|
||||
else
|
||||
start_connecting ();
|
||||
@@ -107,21 +107,21 @@ void zmq::tcp_connecter_t::process_plug ()
|
||||
|
||||
void zmq::tcp_connecter_t::process_term (int linger_)
|
||||
{
|
||||
if (connect_timer_started) {
|
||||
if (_connect_timer_started) {
|
||||
cancel_timer (connect_timer_id);
|
||||
connect_timer_started = false;
|
||||
_connect_timer_started = false;
|
||||
}
|
||||
|
||||
if (reconnect_timer_started) {
|
||||
if (_reconnect_timer_started) {
|
||||
cancel_timer (reconnect_timer_id);
|
||||
reconnect_timer_started = false;
|
||||
_reconnect_timer_started = false;
|
||||
}
|
||||
|
||||
if (handle) {
|
||||
if (_handle) {
|
||||
rm_handle ();
|
||||
}
|
||||
|
||||
if (s != retired_fd)
|
||||
if (_s != retired_fd)
|
||||
close ();
|
||||
|
||||
own_t::process_term (linger_);
|
||||
@@ -137,9 +137,9 @@ void zmq::tcp_connecter_t::in_event ()
|
||||
|
||||
void zmq::tcp_connecter_t::out_event ()
|
||||
{
|
||||
if (connect_timer_started) {
|
||||
if (_connect_timer_started) {
|
||||
cancel_timer (connect_timer_id);
|
||||
connect_timer_started = false;
|
||||
_connect_timer_started = false;
|
||||
}
|
||||
|
||||
rm_handle ();
|
||||
@@ -155,34 +155,34 @@ void zmq::tcp_connecter_t::out_event ()
|
||||
|
||||
// Create the engine object for this connection.
|
||||
stream_engine_t *engine =
|
||||
new (std::nothrow) stream_engine_t (fd, options, endpoint);
|
||||
new (std::nothrow) stream_engine_t (fd, options, _endpoint);
|
||||
alloc_assert (engine);
|
||||
|
||||
// Attach the engine to the corresponding session object.
|
||||
send_attach (session, engine);
|
||||
send_attach (_session, engine);
|
||||
|
||||
// Shut the connecter down.
|
||||
terminate ();
|
||||
|
||||
socket->event_connected (endpoint, fd);
|
||||
_socket->event_connected (_endpoint, fd);
|
||||
}
|
||||
|
||||
void zmq::tcp_connecter_t::rm_handle ()
|
||||
{
|
||||
rm_fd (handle);
|
||||
handle = static_cast<handle_t> (NULL);
|
||||
rm_fd (_handle);
|
||||
_handle = static_cast<handle_t> (NULL);
|
||||
}
|
||||
|
||||
void zmq::tcp_connecter_t::timer_event (int id_)
|
||||
{
|
||||
zmq_assert (id_ == reconnect_timer_id || id_ == connect_timer_id);
|
||||
if (id_ == connect_timer_id) {
|
||||
connect_timer_started = false;
|
||||
_connect_timer_started = false;
|
||||
rm_handle ();
|
||||
close ();
|
||||
add_reconnect_timer ();
|
||||
} else if (id_ == reconnect_timer_id) {
|
||||
reconnect_timer_started = false;
|
||||
_reconnect_timer_started = false;
|
||||
start_connecting ();
|
||||
}
|
||||
}
|
||||
@@ -194,15 +194,15 @@ void zmq::tcp_connecter_t::start_connecting ()
|
||||
|
||||
// Connect may succeed in synchronous manner.
|
||||
if (rc == 0) {
|
||||
handle = add_fd (s);
|
||||
_handle = add_fd (_s);
|
||||
out_event ();
|
||||
}
|
||||
|
||||
// Connection establishment may be delayed. Poll for its completion.
|
||||
else if (rc == -1 && errno == EINPROGRESS) {
|
||||
handle = add_fd (s);
|
||||
set_pollout (handle);
|
||||
socket->event_connect_delayed (endpoint, zmq_errno ());
|
||||
_handle = add_fd (_s);
|
||||
set_pollout (_handle);
|
||||
_socket->event_connect_delayed (_endpoint, zmq_errno ());
|
||||
|
||||
// add userspace connect timeout
|
||||
add_connect_timer ();
|
||||
@@ -210,7 +210,7 @@ void zmq::tcp_connecter_t::start_connecting ()
|
||||
|
||||
// Handle any other error condition by eventual reconnect.
|
||||
else {
|
||||
if (s != retired_fd)
|
||||
if (_s != retired_fd)
|
||||
close ();
|
||||
add_reconnect_timer ();
|
||||
}
|
||||
@@ -220,7 +220,7 @@ void zmq::tcp_connecter_t::add_connect_timer ()
|
||||
{
|
||||
if (options.connect_timeout > 0) {
|
||||
add_timer (options.connect_timeout, connect_timer_id);
|
||||
connect_timer_started = true;
|
||||
_connect_timer_started = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,94 +228,94 @@ void zmq::tcp_connecter_t::add_reconnect_timer ()
|
||||
{
|
||||
const int interval = get_new_reconnect_ivl ();
|
||||
add_timer (interval, reconnect_timer_id);
|
||||
socket->event_connect_retried (endpoint, interval);
|
||||
reconnect_timer_started = true;
|
||||
_socket->event_connect_retried (_endpoint, interval);
|
||||
_reconnect_timer_started = true;
|
||||
}
|
||||
|
||||
int zmq::tcp_connecter_t::get_new_reconnect_ivl ()
|
||||
{
|
||||
// The new interval is the current interval + random value.
|
||||
const int interval =
|
||||
current_reconnect_ivl + generate_random () % options.reconnect_ivl;
|
||||
_current_reconnect_ivl + generate_random () % options.reconnect_ivl;
|
||||
|
||||
// Only change the current reconnect interval if the maximum reconnect
|
||||
// interval was set and if it's larger than the reconnect interval.
|
||||
if (options.reconnect_ivl_max > 0
|
||||
&& options.reconnect_ivl_max > options.reconnect_ivl)
|
||||
// Calculate the next interval
|
||||
current_reconnect_ivl =
|
||||
std::min (current_reconnect_ivl * 2, options.reconnect_ivl_max);
|
||||
_current_reconnect_ivl =
|
||||
std::min (_current_reconnect_ivl * 2, options.reconnect_ivl_max);
|
||||
return interval;
|
||||
}
|
||||
|
||||
int zmq::tcp_connecter_t::open ()
|
||||
{
|
||||
zmq_assert (s == retired_fd);
|
||||
zmq_assert (_s == retired_fd);
|
||||
|
||||
// Resolve the address
|
||||
if (addr->resolved.tcp_addr != NULL) {
|
||||
LIBZMQ_DELETE (addr->resolved.tcp_addr);
|
||||
if (_addr->resolved.tcp_addr != NULL) {
|
||||
LIBZMQ_DELETE (_addr->resolved.tcp_addr);
|
||||
}
|
||||
|
||||
addr->resolved.tcp_addr = new (std::nothrow) tcp_address_t ();
|
||||
alloc_assert (addr->resolved.tcp_addr);
|
||||
int rc = addr->resolved.tcp_addr->resolve (addr->address.c_str (), false,
|
||||
options.ipv6);
|
||||
_addr->resolved.tcp_addr = new (std::nothrow) tcp_address_t ();
|
||||
alloc_assert (_addr->resolved.tcp_addr);
|
||||
int rc = _addr->resolved.tcp_addr->resolve (_addr->address.c_str (), false,
|
||||
options.ipv6);
|
||||
if (rc != 0) {
|
||||
LIBZMQ_DELETE (addr->resolved.tcp_addr);
|
||||
LIBZMQ_DELETE (_addr->resolved.tcp_addr);
|
||||
return -1;
|
||||
}
|
||||
zmq_assert (addr->resolved.tcp_addr != NULL);
|
||||
const tcp_address_t *const tcp_addr = addr->resolved.tcp_addr;
|
||||
zmq_assert (_addr->resolved.tcp_addr != NULL);
|
||||
const tcp_address_t *const tcp_addr = _addr->resolved.tcp_addr;
|
||||
|
||||
// Create the socket.
|
||||
s = open_socket (tcp_addr->family (), SOCK_STREAM, IPPROTO_TCP);
|
||||
_s = open_socket (tcp_addr->family (), SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
// IPv6 address family not supported, try automatic downgrade to IPv4.
|
||||
if (s == zmq::retired_fd && tcp_addr->family () == AF_INET6
|
||||
if (_s == zmq::retired_fd && tcp_addr->family () == AF_INET6
|
||||
&& errno == EAFNOSUPPORT && options.ipv6) {
|
||||
rc = addr->resolved.tcp_addr->resolve (addr->address.c_str (), false,
|
||||
false);
|
||||
rc = _addr->resolved.tcp_addr->resolve (_addr->address.c_str (), false,
|
||||
false);
|
||||
if (rc != 0) {
|
||||
LIBZMQ_DELETE (addr->resolved.tcp_addr);
|
||||
LIBZMQ_DELETE (_addr->resolved.tcp_addr);
|
||||
return -1;
|
||||
}
|
||||
s = open_socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
_s = open_socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
|
||||
if (s == retired_fd) {
|
||||
if (_s == retired_fd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// On some systems, IPv4 mapping in IPv6 sockets is disabled by default.
|
||||
// Switch it on in such cases.
|
||||
if (tcp_addr->family () == AF_INET6)
|
||||
enable_ipv4_mapping (s);
|
||||
enable_ipv4_mapping (_s);
|
||||
|
||||
// Set the IP Type-Of-Service priority for this socket
|
||||
if (options.tos != 0)
|
||||
set_ip_type_of_service (s, options.tos);
|
||||
set_ip_type_of_service (_s, options.tos);
|
||||
|
||||
// Bind the socket to a device if applicable
|
||||
if (!options.bound_device.empty ())
|
||||
bind_to_device (s, options.bound_device);
|
||||
bind_to_device (_s, options.bound_device);
|
||||
|
||||
// Set the socket to non-blocking mode so that we get async connect().
|
||||
unblock_socket (s);
|
||||
unblock_socket (_s);
|
||||
|
||||
// Set the socket to loopback fastpath if configured.
|
||||
if (options.loopback_fastpath)
|
||||
tcp_tune_loopback_fast_path (s);
|
||||
tcp_tune_loopback_fast_path (_s);
|
||||
|
||||
// Set the socket buffer limits for the underlying socket.
|
||||
if (options.sndbuf >= 0)
|
||||
set_tcp_send_buffer (s, options.sndbuf);
|
||||
set_tcp_send_buffer (_s, options.sndbuf);
|
||||
if (options.rcvbuf >= 0)
|
||||
set_tcp_receive_buffer (s, options.rcvbuf);
|
||||
set_tcp_receive_buffer (_s, options.rcvbuf);
|
||||
|
||||
// Set the IP Type-Of-Service for the underlying socket
|
||||
if (options.tos != 0)
|
||||
set_ip_type_of_service (s, options.tos);
|
||||
set_ip_type_of_service (_s, options.tos);
|
||||
|
||||
// Set a source address for conversations
|
||||
if (tcp_addr->has_src_addr ()) {
|
||||
@@ -323,23 +323,23 @@ int zmq::tcp_connecter_t::open ()
|
||||
// using the same source port on the client.
|
||||
int flag = 1;
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR,
|
||||
rc = setsockopt (_s, SOL_SOCKET, SO_REUSEADDR,
|
||||
reinterpret_cast<const char *> (&flag), sizeof (int));
|
||||
wsa_assert (rc != SOCKET_ERROR);
|
||||
#elif defined ZMQ_HAVE_VXWORKS
|
||||
rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *) &flag,
|
||||
rc = setsockopt (_s, SOL_SOCKET, SO_REUSEADDR, (char *) &flag,
|
||||
sizeof (int));
|
||||
errno_assert (rc == 0);
|
||||
#else
|
||||
rc = setsockopt (s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int));
|
||||
rc = setsockopt (_s, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int));
|
||||
errno_assert (rc == 0);
|
||||
#endif
|
||||
|
||||
#if defined ZMQ_HAVE_VXWORKS
|
||||
rc = ::bind (s, (sockaddr *) tcp_addr->src_addr (),
|
||||
rc = ::bind (_s, (sockaddr *) tcp_addr->src_addr (),
|
||||
tcp_addr->src_addrlen ());
|
||||
#else
|
||||
rc = ::bind (s, tcp_addr->src_addr (), tcp_addr->src_addrlen ());
|
||||
rc = ::bind (_s, tcp_addr->src_addr (), tcp_addr->src_addrlen ());
|
||||
#endif
|
||||
if (rc == -1)
|
||||
return -1;
|
||||
@@ -347,9 +347,9 @@ int zmq::tcp_connecter_t::open ()
|
||||
|
||||
// Connect to the remote peer.
|
||||
#if defined ZMQ_HAVE_VXWORKS
|
||||
rc = ::connect (s, (sockaddr *) tcp_addr->addr (), tcp_addr->addrlen ());
|
||||
rc = ::connect (_s, (sockaddr *) tcp_addr->addr (), tcp_addr->addrlen ());
|
||||
#else
|
||||
rc = ::connect (s, tcp_addr->addr (), tcp_addr->addrlen ());
|
||||
rc = ::connect (_s, tcp_addr->addr (), tcp_addr->addrlen ());
|
||||
#endif
|
||||
// Connect was successful immediately.
|
||||
if (rc == 0) {
|
||||
@@ -381,7 +381,7 @@ zmq::fd_t zmq::tcp_connecter_t::connect ()
|
||||
socklen_t len = sizeof err;
|
||||
#endif
|
||||
|
||||
const int rc = getsockopt (s, SOL_SOCKET, SO_ERROR,
|
||||
const int rc = getsockopt (_s, SOL_SOCKET, SO_ERROR,
|
||||
reinterpret_cast<char *> (&err), &len);
|
||||
|
||||
// Assert if the error was caused by 0MQ bug.
|
||||
@@ -414,8 +414,8 @@ zmq::fd_t zmq::tcp_connecter_t::connect ()
|
||||
#endif
|
||||
|
||||
// Return the newly connected socket.
|
||||
const fd_t result = s;
|
||||
s = retired_fd;
|
||||
const fd_t result = _s;
|
||||
_s = retired_fd;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -431,14 +431,14 @@ bool zmq::tcp_connecter_t::tune_socket (const fd_t fd_)
|
||||
|
||||
void zmq::tcp_connecter_t::close ()
|
||||
{
|
||||
zmq_assert (s != retired_fd);
|
||||
zmq_assert (_s != retired_fd);
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
const int rc = closesocket (s);
|
||||
const int rc = closesocket (_s);
|
||||
wsa_assert (rc != SOCKET_ERROR);
|
||||
#else
|
||||
const int rc = ::close (s);
|
||||
const int rc = ::close (_s);
|
||||
errno_assert (rc == 0);
|
||||
#endif
|
||||
socket->event_closed (endpoint, s);
|
||||
s = retired_fd;
|
||||
_socket->event_closed (_endpoint, _s);
|
||||
_s = retired_fd;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user