mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-07 22:40:55 +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:
@@ -65,29 +65,29 @@ zmq::tcp_listener_t::tcp_listener_t (io_thread_t *io_thread_,
|
||||
const options_t &options_) :
|
||||
own_t (io_thread_, options_),
|
||||
io_object_t (io_thread_),
|
||||
s (retired_fd),
|
||||
handle (static_cast<handle_t> (NULL)),
|
||||
socket (socket_)
|
||||
_s (retired_fd),
|
||||
_handle (static_cast<handle_t> (NULL)),
|
||||
_socket (socket_)
|
||||
{
|
||||
}
|
||||
|
||||
zmq::tcp_listener_t::~tcp_listener_t ()
|
||||
{
|
||||
zmq_assert (s == retired_fd);
|
||||
zmq_assert (!handle);
|
||||
zmq_assert (_s == retired_fd);
|
||||
zmq_assert (!_handle);
|
||||
}
|
||||
|
||||
void zmq::tcp_listener_t::process_plug ()
|
||||
{
|
||||
// Start polling for incoming connections.
|
||||
handle = add_fd (s);
|
||||
set_pollin (handle);
|
||||
_handle = add_fd (_s);
|
||||
set_pollin (_handle);
|
||||
}
|
||||
|
||||
void zmq::tcp_listener_t::process_term (int linger_)
|
||||
{
|
||||
rm_fd (handle);
|
||||
handle = static_cast<handle_t> (NULL);
|
||||
rm_fd (_handle);
|
||||
_handle = static_cast<handle_t> (NULL);
|
||||
close ();
|
||||
own_t::process_term (linger_);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ void zmq::tcp_listener_t::in_event ()
|
||||
// If connection was reset by the peer in the meantime, just ignore it.
|
||||
// TODO: Handle specific errors like ENFILE/EMFILE etc.
|
||||
if (fd == retired_fd) {
|
||||
socket->event_accept_failed (endpoint, zmq_errno ());
|
||||
_socket->event_accept_failed (_endpoint, zmq_errno ());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,13 +110,13 @@ void zmq::tcp_listener_t::in_event ()
|
||||
options.tcp_keepalive_idle, options.tcp_keepalive_intvl);
|
||||
rc = rc | tune_tcp_maxrt (fd, options.tcp_maxrt);
|
||||
if (rc != 0) {
|
||||
socket->event_accept_failed (endpoint, zmq_errno ());
|
||||
_socket->event_accept_failed (_endpoint, zmq_errno ());
|
||||
return;
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// Choose I/O thread to run connecter in. Given that we are already
|
||||
@@ -126,26 +126,26 @@ void zmq::tcp_listener_t::in_event ()
|
||||
|
||||
// Create and launch a session object.
|
||||
session_base_t *session =
|
||||
session_base_t::create (io_thread, false, socket, options, NULL);
|
||||
session_base_t::create (io_thread, false, _socket, options, NULL);
|
||||
errno_assert (session);
|
||||
session->inc_seqnum ();
|
||||
launch_child (session);
|
||||
send_attach (session, engine, false);
|
||||
socket->event_accepted (endpoint, fd);
|
||||
_socket->event_accepted (_endpoint, fd);
|
||||
}
|
||||
|
||||
void zmq::tcp_listener_t::close ()
|
||||
{
|
||||
zmq_assert (s != retired_fd);
|
||||
zmq_assert (_s != retired_fd);
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
int rc = closesocket (s);
|
||||
int rc = closesocket (_s);
|
||||
wsa_assert (rc != SOCKET_ERROR);
|
||||
#else
|
||||
int rc = ::close (s);
|
||||
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;
|
||||
}
|
||||
|
||||
int zmq::tcp_listener_t::get_address (std::string &addr_)
|
||||
@@ -157,7 +157,7 @@ int zmq::tcp_listener_t::get_address (std::string &addr_)
|
||||
#else
|
||||
socklen_t sl = sizeof (ss);
|
||||
#endif
|
||||
int rc = getsockname (s, reinterpret_cast<struct sockaddr *> (&ss), &sl);
|
||||
int rc = getsockname (_s, reinterpret_cast<struct sockaddr *> (&ss), &sl);
|
||||
|
||||
if (rc != 0) {
|
||||
addr_.clear ();
|
||||
@@ -171,77 +171,78 @@ int zmq::tcp_listener_t::get_address (std::string &addr_)
|
||||
int zmq::tcp_listener_t::set_address (const char *addr_)
|
||||
{
|
||||
// Convert the textual address into address structure.
|
||||
int rc = address.resolve (addr_, true, options.ipv6);
|
||||
int rc = _address.resolve (addr_, true, options.ipv6);
|
||||
if (rc != 0)
|
||||
return -1;
|
||||
|
||||
address.to_string (endpoint);
|
||||
_address.to_string (_endpoint);
|
||||
|
||||
if (options.use_fd != -1) {
|
||||
s = options.use_fd;
|
||||
socket->event_listening (endpoint, s);
|
||||
_s = options.use_fd;
|
||||
_socket->event_listening (_endpoint, _s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create a listening socket.
|
||||
s = open_socket (address.family (), SOCK_STREAM, IPPROTO_TCP);
|
||||
_s = open_socket (_address.family (), SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
// IPv6 address family not supported, try automatic downgrade to IPv4.
|
||||
if (s == zmq::retired_fd && address.family () == AF_INET6
|
||||
if (_s == zmq::retired_fd && _address.family () == AF_INET6
|
||||
&& errno == EAFNOSUPPORT && options.ipv6) {
|
||||
rc = address.resolve (addr_, true, false);
|
||||
rc = _address.resolve (addr_, true, false);
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
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;
|
||||
}
|
||||
make_socket_noninheritable (s);
|
||||
make_socket_noninheritable (_s);
|
||||
|
||||
// On some systems, IPv4 mapping in IPv6 sockets is disabled by default.
|
||||
// Switch it on in such cases.
|
||||
if (address.family () == AF_INET6)
|
||||
enable_ipv4_mapping (s);
|
||||
if (_address.family () == AF_INET6)
|
||||
enable_ipv4_mapping (_s);
|
||||
|
||||
// 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 the socket to loopback fastpath if configured.
|
||||
if (options.loopback_fastpath)
|
||||
tcp_tune_loopback_fast_path (s);
|
||||
tcp_tune_loopback_fast_path (_s);
|
||||
|
||||
// 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 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);
|
||||
|
||||
// Allow reusing of the address.
|
||||
int flag = 1;
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
rc = setsockopt (s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
||||
rc = setsockopt (_s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
|
||||
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, sizeof (int));
|
||||
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
|
||||
|
||||
// Bind the socket to the network interface and port.
|
||||
#if defined ZMQ_HAVE_VXWORKS
|
||||
rc = bind (s, (sockaddr *) address.addr (), address.addrlen ());
|
||||
rc = bind (_s, (sockaddr *) _address.addr (), _address.addrlen ());
|
||||
#else
|
||||
rc = bind (s, address.addr (), address.addrlen ());
|
||||
rc = bind (_s, _address.addr (), _address.addrlen ());
|
||||
#endif
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
if (rc == SOCKET_ERROR) {
|
||||
@@ -254,7 +255,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
|
||||
#endif
|
||||
|
||||
// Listen for incoming connections.
|
||||
rc = listen (s, options.backlog);
|
||||
rc = listen (_s, options.backlog);
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
if (rc == SOCKET_ERROR) {
|
||||
errno = wsa_error_to_errno (WSAGetLastError ());
|
||||
@@ -265,7 +266,7 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
|
||||
goto error;
|
||||
#endif
|
||||
|
||||
socket->event_listening (endpoint, s);
|
||||
_socket->event_listening (_endpoint, _s);
|
||||
return 0;
|
||||
|
||||
error:
|
||||
@@ -280,7 +281,7 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
|
||||
// The situation where connection cannot be accepted due to insufficient
|
||||
// resources is considered valid and treated by ignoring the connection.
|
||||
// Accept one connection and deal with different failure modes.
|
||||
zmq_assert (s != retired_fd);
|
||||
zmq_assert (_s != retired_fd);
|
||||
|
||||
struct sockaddr_storage ss;
|
||||
memset (&ss, 0, sizeof (ss));
|
||||
@@ -290,10 +291,10 @@ zmq::fd_t zmq::tcp_listener_t::accept ()
|
||||
socklen_t ss_len = sizeof (ss);
|
||||
#endif
|
||||
#if defined ZMQ_HAVE_SOCK_CLOEXEC && defined HAVE_ACCEPT4
|
||||
fd_t sock = ::accept4 (s, (struct sockaddr *) &ss, &ss_len, SOCK_CLOEXEC);
|
||||
fd_t sock = ::accept4 (_s, (struct sockaddr *) &ss, &ss_len, SOCK_CLOEXEC);
|
||||
#else
|
||||
fd_t sock =
|
||||
::accept (s, reinterpret_cast<struct sockaddr *> (&ss), &ss_len);
|
||||
::accept (_s, reinterpret_cast<struct sockaddr *> (&ss), &ss_len);
|
||||
#endif
|
||||
|
||||
if (sock == retired_fd) {
|
||||
|
||||
Reference in New Issue
Block a user