From 368eff9ecbb35e31bd870eeeb1d56c15eed83f90 Mon Sep 17 00:00:00 2001 From: sigiesec Date: Fri, 2 Feb 2018 17:08:52 +0100 Subject: [PATCH] Problem: several fields are non-const without need Solution: add const where easily possible --- src/address.hpp | 2 +- src/decoder_allocators.hpp | 2 +- src/encoder.hpp | 6 +++--- src/mailbox_safe.hpp | 2 +- src/mechanism.hpp | 2 +- src/metadata.hpp | 2 +- src/object.hpp | 2 +- src/signaler.cpp | 6 +++--- src/socket_base.hpp | 2 +- src/stream_engine.hpp | 2 +- src/tcp_connecter.cpp | 7 +++++-- src/tcp_connecter.hpp | 6 +++--- src/v1_decoder.hpp | 2 +- 13 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/address.hpp b/src/address.hpp index f94d9ad6..7c767b7e 100644 --- a/src/address.hpp +++ b/src/address.hpp @@ -56,7 +56,7 @@ struct address_t const std::string protocol; const std::string address; - ctx_t *parent; + ctx_t *const parent; // Protocol specific resolved address union diff --git a/src/decoder_allocators.hpp b/src/decoder_allocators.hpp index e760cba6..a47ac358 100644 --- a/src/decoder_allocators.hpp +++ b/src/decoder_allocators.hpp @@ -122,7 +122,7 @@ class shared_message_memory_allocator private: unsigned char *buf; std::size_t bufsize; - std::size_t max_size; + const std::size_t max_size; zmq::msg_t::content_t *msg_content; std::size_t maxCounters; }; diff --git a/src/encoder.hpp b/src/encoder.hpp index be7e29c4..92b1a2e7 100644 --- a/src/encoder.hpp +++ b/src/encoder.hpp @@ -60,9 +60,9 @@ template class encoder_base_t : public i_encoder next (NULL), new_msg_flag (false), bufsize (bufsize_), + buf ((unsigned char *) malloc (bufsize_)), in_progress (NULL) { - buf = (unsigned char *) malloc (bufsize_); alloc_assert (buf); } @@ -166,8 +166,8 @@ template class encoder_base_t : public i_encoder bool new_msg_flag; // The buffer for encoded data. - size_t bufsize; - unsigned char *buf; + const size_t bufsize; + unsigned char *const buf; encoder_base_t (const encoder_base_t &); void operator= (const encoder_base_t &); diff --git a/src/mailbox_safe.hpp b/src/mailbox_safe.hpp index 90ddb0ea..a4f03799 100644 --- a/src/mailbox_safe.hpp +++ b/src/mailbox_safe.hpp @@ -77,7 +77,7 @@ class mailbox_safe_t : public i_mailbox condition_variable_t cond_var; // Synchronize access to the mailbox from receivers and senders - mutex_t *sync; + mutex_t *const sync; std::vector signalers; diff --git a/src/mechanism.hpp b/src/mechanism.hpp index 4bce7e12..7f595151 100644 --- a/src/mechanism.hpp +++ b/src/mechanism.hpp @@ -128,7 +128,7 @@ class mechanism_t // Properties received from ZAP server. metadata_t::dict_t zap_properties; - options_t options; + const options_t options; private: blob_t routing_id; diff --git a/src/metadata.hpp b/src/metadata.hpp index aaa17d70..8966f986 100644 --- a/src/metadata.hpp +++ b/src/metadata.hpp @@ -62,7 +62,7 @@ class metadata_t atomic_counter_t ref_cnt; // Dictionary holding metadata. - dict_t dict; + const dict_t dict; }; } diff --git a/src/object.hpp b/src/object.hpp index 10cdacac..6bfd0c6e 100644 --- a/src/object.hpp +++ b/src/object.hpp @@ -134,7 +134,7 @@ class object_t private: // Context provides access to the global state. - zmq::ctx_t *ctx; + zmq::ctx_t *const ctx; // Thread ID of the thread the object belongs to. uint32_t tid; diff --git a/src/signaler.cpp b/src/signaler.cpp index e02660eb..0665470c 100644 --- a/src/signaler.cpp +++ b/src/signaler.cpp @@ -670,9 +670,9 @@ int zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_) *w_ = *r_ = -1; return -1; } else { - // If there's no SOCK_CLOEXEC, let's try the second best option. Note that - // race condition can cause socket not to be closed (if fork happens - // between socket creation and this point). + // If there's no SOCK_CLOEXEC, let's try the second best option. Note that + // race condition can cause socket not to be closed (if fork happens + // between socket creation and this point). #if !defined ZMQ_HAVE_SOCK_CLOEXEC && defined FD_CLOEXEC rc = fcntl (sv[0], F_SETFD, FD_CLOEXEC); errno_assert (rc != -1); diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 8d85bd5f..4054b197 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -285,7 +285,7 @@ class socket_base_t : public own_t, std::string last_endpoint; // Indicate if the socket is thread safe - bool thread_safe; + const bool thread_safe; // Signaler to be used in the reaping stage signaler_t *reaper_signaler; diff --git a/src/stream_engine.hpp b/src/stream_engine.hpp index 8398ffe3..0b422c25 100644 --- a/src/stream_engine.hpp +++ b/src/stream_engine.hpp @@ -178,7 +178,7 @@ class stream_engine_t : public io_object_t, public i_engine // The session this engine is attached to. zmq::session_base_t *session; - options_t options; + const options_t options; // String representation of endpoint std::string endpoint; diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index 4a98a8cb..73e71f06 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -72,12 +72,15 @@ zmq::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_, connect_timer_started (false), reconnect_timer_started (false), session (session_), - current_reconnect_ivl (options.reconnect_ivl) + current_reconnect_ivl (options.reconnect_ivl), + socket (session->get_socket ()) { zmq_assert (addr); zmq_assert (addr->protocol == "tcp"); addr->to_string (endpoint); - socket = session->get_socket (); + // 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 } zmq::tcp_connecter_t::~tcp_connecter_t () diff --git a/src/tcp_connecter.hpp b/src/tcp_connecter.hpp index a65272ee..2910b6e7 100644 --- a/src/tcp_connecter.hpp +++ b/src/tcp_connecter.hpp @@ -97,7 +97,7 @@ class tcp_connecter_t : public own_t, public io_object_t fd_t connect (); // Address to connect to. Owned by session_base_t. - address_t *addr; + address_t *const addr; // Underlying socket. fd_t s; @@ -117,7 +117,7 @@ class tcp_connecter_t : public own_t, public io_object_t bool reconnect_timer_started; // Reference to the session we belong to. - zmq::session_base_t *session; + zmq::session_base_t *const session; // Current reconnect ivl, updated for backoff strategy int current_reconnect_ivl; @@ -126,7 +126,7 @@ class tcp_connecter_t : public own_t, public io_object_t std::string endpoint; // Socket - zmq::socket_base_t *socket; + zmq::socket_base_t *const socket; tcp_connecter_t (const tcp_connecter_t &); const tcp_connecter_t &operator= (const tcp_connecter_t &); diff --git a/src/v1_decoder.hpp b/src/v1_decoder.hpp index 8ccc9c56..999930e8 100644 --- a/src/v1_decoder.hpp +++ b/src/v1_decoder.hpp @@ -54,7 +54,7 @@ class v1_decoder_t : public zmq::c_single_allocator, unsigned char tmpbuf[8]; msg_t in_progress; - int64_t maxmsgsize; + const int64_t maxmsgsize; v1_decoder_t (const v1_decoder_t &); void operator= (const v1_decoder_t &);