From 531df586d086e10ac6eb97506888145c95bf9fa1 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Thu, 31 Jan 2019 09:33:52 -0500 Subject: [PATCH] Problem: rm_fd code duplicated across stream_connecter_t subclasses Solution: pull up tcp_connecter_t::rm_handle and use in all subclasses --- src/ipc_connecter.cpp | 6 ++---- src/stream_connecter_base.cpp | 6 ++++++ src/stream_connecter_base.hpp | 3 +++ src/tcp_connecter.cpp | 6 ------ src/tcp_connecter.hpp | 3 --- src/tipc_connecter.cpp | 6 ++---- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/ipc_connecter.cpp b/src/ipc_connecter.cpp index f848d124..c88d5aae 100644 --- a/src/ipc_connecter.cpp +++ b/src/ipc_connecter.cpp @@ -70,8 +70,7 @@ void zmq::ipc_connecter_t::process_term (int linger_) } if (_handle) { - rm_fd (_handle); - _handle = static_cast (NULL); + rm_handle (); } if (_s != retired_fd) @@ -91,8 +90,7 @@ void zmq::ipc_connecter_t::in_event () void zmq::ipc_connecter_t::out_event () { fd_t fd = connect (); - rm_fd (_handle); - _handle = static_cast (NULL); + rm_handle (); // Handle the error condition by attempt to reconnect. if (fd == retired_fd) { diff --git a/src/stream_connecter_base.cpp b/src/stream_connecter_base.cpp index 6f582427..bc041f29 100644 --- a/src/stream_connecter_base.cpp +++ b/src/stream_connecter_base.cpp @@ -97,3 +97,9 @@ int zmq::stream_connecter_base_t::get_new_reconnect_ivl () std::min (_current_reconnect_ivl * 2, options.reconnect_ivl_max); return interval; } + +void zmq::stream_connecter_base_t::rm_handle () +{ + rm_fd (_handle); + _handle = static_cast (NULL); +} diff --git a/src/stream_connecter_base.hpp b/src/stream_connecter_base.hpp index 30a022fa..2075c26a 100644 --- a/src/stream_connecter_base.hpp +++ b/src/stream_connecter_base.hpp @@ -75,6 +75,9 @@ class stream_connecter_base_t : public own_t, public io_object_t // Internal function to add a reconnect timer void add_reconnect_timer (); + // Removes the handle from the poller. + void rm_handle (); + // Address to connect to. Owned by session_base_t. // It is non-const since some parts may change during opening. address_t *const _addr; diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index 20d772ec..8999edba 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -142,12 +142,6 @@ void zmq::tcp_connecter_t::out_event () _socket->event_connected (_endpoint, fd); } -void zmq::tcp_connecter_t::rm_handle () -{ - rm_fd (_handle); - _handle = static_cast (NULL); -} - void zmq::tcp_connecter_t::timer_event (int id_) { zmq_assert (id_ == reconnect_timer_id || id_ == connect_timer_id); diff --git a/src/tcp_connecter.hpp b/src/tcp_connecter.hpp index 3cf5a7b3..2cb0a5c8 100644 --- a/src/tcp_connecter.hpp +++ b/src/tcp_connecter.hpp @@ -63,9 +63,6 @@ class tcp_connecter_t : public stream_connecter_base_t void out_event (); void timer_event (int id_); - // Removes the handle from the poller. - void rm_handle (); - // Internal function to start the actual connection establishment. void start_connecting (); diff --git a/src/tipc_connecter.cpp b/src/tipc_connecter.cpp index 2b82e938..ca18da55 100644 --- a/src/tipc_connecter.cpp +++ b/src/tipc_connecter.cpp @@ -72,8 +72,7 @@ void zmq::tipc_connecter_t::process_term (int linger_) } if (_handle) { - rm_fd (_handle); - _handle = static_cast (NULL); + rm_handle (); } if (_s != retired_fd) @@ -93,8 +92,7 @@ void zmq::tipc_connecter_t::in_event () void zmq::tipc_connecter_t::out_event () { fd_t fd = connect (); - rm_fd (_handle); - _handle = static_cast (NULL); + rm_handle (); // Handle the error condition by attempt to reconnect. if (fd == retired_fd) {