From 628adf1cb73f0f42473ac337eb9b715d55fbc75c Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 24 Dec 2019 10:39:26 +0100 Subject: [PATCH 1/6] Problem: inconsistent polymorphic inheritance Solution: consistently use virtual, override and final --- .clang-tidy | 4 +++ src/client.hpp | 20 +++++++------- src/ctx.hpp | 2 +- src/curve_client.hpp | 14 +++++----- src/curve_mechanism_base.hpp | 4 +-- src/curve_server.hpp | 14 +++++----- src/dealer.hpp | 22 ++++++++------- src/decoder.hpp | 10 +++---- src/devpoll.hpp | 6 ++-- src/dgram.hpp | 20 +++++++------- src/dish.hpp | 36 ++++++++++++------------ src/encoder.hpp | 8 ++---- src/epoll.hpp | 6 ++-- src/gather.hpp | 14 +++++----- src/gssapi_client.hpp | 14 +++++----- src/gssapi_mechanism_base.hpp | 2 +- src/gssapi_server.hpp | 17 ++++++------ src/io_object.hpp | 8 +++--- src/io_thread.hpp | 12 ++++---- src/ipc_connecter.hpp | 6 ++-- src/ipc_listener.hpp | 9 +++--- src/kqueue.hpp | 6 ++-- src/macros.hpp | 16 +++++++++++ src/mailbox.hpp | 10 +++---- src/mailbox_safe.hpp | 10 +++---- src/norm_engine.hpp | 18 ++++++------ src/null_mechanism.hpp | 12 ++++---- src/own.hpp | 12 ++++---- src/pair.hpp | 20 +++++++------- src/pgm_receiver.hpp | 2 +- src/pgm_sender.hpp | 2 +- src/pipe.hpp | 29 ++++++++++---------- src/plain_client.hpp | 10 +++---- src/plain_server.hpp | 8 +++--- src/poll.hpp | 4 +-- src/poller_base.cpp | 4 --- src/poller_base.hpp | 4 +-- src/pollset.hpp | 6 ++-- src/pub.hpp | 10 +++---- src/pull.hpp | 14 +++++----- src/push.hpp | 14 +++++----- src/radio.hpp | 33 +++++++++++----------- src/raw_decoder.hpp | 15 +++++----- src/raw_encoder.hpp | 4 +-- src/raw_engine.hpp | 10 +++---- src/reaper.hpp | 16 +++++------ src/rep.hpp | 12 ++++---- src/req.hpp | 25 +++++++++-------- src/router.hpp | 22 ++++++++------- src/scatter.hpp | 14 +++++----- src/select.hpp | 6 ++-- src/server.hpp | 20 +++++++------- src/session_base.hpp | 18 ++++++------ src/socket_base.hpp | 44 ++++++++++++++++-------------- src/socks_connecter.hpp | 10 +++---- src/stream.hpp | 21 +++++++------- src/stream_connecter_base.hpp | 10 +++---- src/stream_engine_base.hpp | 21 +++++++------- src/stream_listener_base.hpp | 6 ++-- src/sub.hpp | 11 ++++---- src/tcp_connecter.hpp | 12 ++++---- src/tcp_listener.hpp | 7 +++-- src/tipc_connecter.hpp | 6 ++-- src/tipc_listener.hpp | 7 +++-- src/udp_engine.hpp | 21 +++++++------- src/v1_decoder.hpp | 6 ++-- src/v1_encoder.hpp | 4 +-- src/v2_decoder.hpp | 6 ++-- src/v2_encoder.hpp | 4 +-- src/vmci_connecter.hpp | 2 +- src/vmci_listener.hpp | 2 +- src/ws_connecter.hpp | 14 +++++----- src/ws_decoder.hpp | 6 ++-- src/ws_encoder.hpp | 4 +-- src/ws_engine.hpp | 4 +-- src/ws_listener.hpp | 11 ++++---- src/xpub.hpp | 21 +++++++------- src/xsub.hpp | 24 ++++++++-------- src/ypipe.hpp | 14 +++++----- src/ypipe_conflate.hpp | 17 +++++++----- src/zap_client.hpp | 8 +++--- src/zmtp_engine.hpp | 16 +++++------ unittests/unittest_ip_resolver.cpp | 13 +++++---- unittests/unittest_poller.cpp | 6 ++-- 84 files changed, 525 insertions(+), 487 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index b136b173..5a7c53eb 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -420,3 +420,7 @@ CheckOptions: # value: '0' # - key: readability-simplify-boolean-expr.ChainedConditionalReturn # value: '0' + - key: modernize-use-override.OverrideSpelling + value: 'ZMQ_OVERRIDE' + - key: modernize-use-override.FinalSpelling + value: 'ZMQ_FINAL' diff --git a/src/client.hpp b/src/client.hpp index bee1916a..65723c31 100644 --- a/src/client.hpp +++ b/src/client.hpp @@ -41,24 +41,24 @@ class msg_t; class pipe_t; class io_thread_t; -class client_t : public socket_base_t +class client_t ZMQ_FINAL : public socket_base_t { public: client_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~client_t (); + ~client_t () ZMQ_FINAL; protected: // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // Messages are fair-queued from inbound pipes. And load-balanced to diff --git a/src/ctx.hpp b/src/ctx.hpp index 3e76b707..593f9f70 100644 --- a/src/ctx.hpp +++ b/src/ctx.hpp @@ -90,7 +90,7 @@ class thread_ctx_t // Context object encapsulates all the global state associated with // the library. -class ctx_t : public thread_ctx_t +class ctx_t ZMQ_FINAL : public thread_ctx_t { public: // Create the context object. diff --git a/src/curve_client.hpp b/src/curve_client.hpp index c786e764..c85d1b78 100644 --- a/src/curve_client.hpp +++ b/src/curve_client.hpp @@ -41,18 +41,18 @@ namespace zmq class msg_t; class session_base_t; -class curve_client_t : public curve_mechanism_base_t +class curve_client_t ZMQ_FINAL : public curve_mechanism_base_t { public: curve_client_t (session_base_t *session_, const options_t &options_); - virtual ~curve_client_t (); + ~curve_client_t () ZMQ_FINAL; // mechanism implementation - virtual int next_handshake_command (msg_t *msg_); - virtual int process_handshake_command (msg_t *msg_); - virtual int encode (msg_t *msg_); - virtual int decode (msg_t *msg_); - virtual status_t status () const; + int next_handshake_command (msg_t *msg_) ZMQ_FINAL; + int process_handshake_command (msg_t *msg_) ZMQ_FINAL; + int encode (msg_t *msg_) ZMQ_FINAL; + int decode (msg_t *msg_) ZMQ_FINAL; + status_t status () const ZMQ_FINAL; private: enum state_t diff --git a/src/curve_mechanism_base.hpp b/src/curve_mechanism_base.hpp index 72b9b969..0b84f10c 100644 --- a/src/curve_mechanism_base.hpp +++ b/src/curve_mechanism_base.hpp @@ -61,8 +61,8 @@ class curve_mechanism_base_t : public virtual mechanism_base_t const char *decode_nonce_prefix_); // mechanism implementation - virtual int encode (msg_t *msg_); - virtual int decode (msg_t *msg_); + int encode (msg_t *msg_) ZMQ_OVERRIDE; + int decode (msg_t *msg_) ZMQ_OVERRIDE; protected: const char *encode_nonce_prefix; diff --git a/src/curve_server.hpp b/src/curve_server.hpp index b3d2dd73..2d0ec936 100644 --- a/src/curve_server.hpp +++ b/src/curve_server.hpp @@ -42,20 +42,20 @@ namespace zmq #pragma warning(push) #pragma warning(disable : 4250) #endif -class curve_server_t : public zap_client_common_handshake_t, - public curve_mechanism_base_t +class curve_server_t ZMQ_FINAL : public zap_client_common_handshake_t, + public curve_mechanism_base_t { public: curve_server_t (session_base_t *session_, const std::string &peer_address_, const options_t &options_); - virtual ~curve_server_t (); + ~curve_server_t () ZMQ_FINAL; // mechanism implementation - virtual int next_handshake_command (msg_t *msg_); - virtual int process_handshake_command (msg_t *msg_); - virtual int encode (msg_t *msg_); - virtual int decode (msg_t *msg_); + int next_handshake_command (msg_t *msg_) ZMQ_FINAL; + int process_handshake_command (msg_t *msg_) ZMQ_FINAL; + int encode (msg_t *msg_) ZMQ_FINAL; + int decode (msg_t *msg_) ZMQ_FINAL; private: // Our secret key (s) diff --git a/src/dealer.hpp b/src/dealer.hpp index 98097b02..5515fd39 100644 --- a/src/dealer.hpp +++ b/src/dealer.hpp @@ -47,21 +47,23 @@ class dealer_t : public socket_base_t { public: dealer_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~dealer_t (); + ~dealer_t () ZMQ_OVERRIDE; protected: // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xsetsockopt (int option_, + const void *optval_, + size_t optvallen_) ZMQ_OVERRIDE; + int xsend (zmq::msg_t *msg_) ZMQ_OVERRIDE; + int xrecv (zmq::msg_t *msg_) ZMQ_OVERRIDE; + bool xhas_in () ZMQ_OVERRIDE; + bool xhas_out () ZMQ_OVERRIDE; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_OVERRIDE; // Send and recv - knowing which pipe was used. int sendpipe (zmq::msg_t *msg_, zmq::pipe_t **pipe_); diff --git a/src/decoder.hpp b/src/decoder.hpp index 3dcbb1fe..a2cd5a99 100644 --- a/src/decoder.hpp +++ b/src/decoder.hpp @@ -66,12 +66,10 @@ class decoder_base_t : public i_decoder _buf = _allocator.allocate (); } - // The destructor doesn't have to be virtual. It is made virtual - // just to keep ICC and code checking tools from complaining. - virtual ~decoder_base_t () { _allocator.deallocate (); } + ~decoder_base_t () ZMQ_OVERRIDE { _allocator.deallocate (); } // Returns a buffer to be filled with binary data. - void get_buffer (unsigned char **data_, std::size_t *size_) + void get_buffer (unsigned char **data_, std::size_t *size_) ZMQ_FINAL { _buf = _allocator.allocate (); @@ -101,7 +99,7 @@ class decoder_base_t : public i_decoder // Number of bytes processed is returned in bytes_used_. int decode (const unsigned char *data_, std::size_t size_, - std::size_t &bytes_used_) + std::size_t &bytes_used_) ZMQ_FINAL { bytes_used_ = 0; @@ -149,7 +147,7 @@ class decoder_base_t : public i_decoder return 0; } - virtual void resize_buffer (std::size_t new_size_) + void resize_buffer (std::size_t new_size_) ZMQ_FINAL { _allocator.resize (new_size_); } diff --git a/src/devpoll.hpp b/src/devpoll.hpp index 733ec4d4..e57814b9 100644 --- a/src/devpoll.hpp +++ b/src/devpoll.hpp @@ -47,13 +47,13 @@ struct i_poll_events; // Implements socket polling mechanism using the "/dev/poll" interface. -class devpoll_t : public worker_poller_base_t +class devpoll_t ZMQ_FINAL : public worker_poller_base_t { public: typedef fd_t handle_t; devpoll_t (const thread_ctx_t &ctx_); - ~devpoll_t (); + ~devpoll_t () ZMQ_FINAL; // "poller" concept. handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_); @@ -68,7 +68,7 @@ class devpoll_t : public worker_poller_base_t private: // Main event loop. - void loop (); + void loop () ZMQ_FINAL; // File descriptor referring to "/dev/poll" pseudo-device. fd_t devpoll_fd; diff --git a/src/dgram.hpp b/src/dgram.hpp index 40bba774..b819d127 100644 --- a/src/dgram.hpp +++ b/src/dgram.hpp @@ -41,23 +41,23 @@ class msg_t; class pipe_t; class io_thread_t; -class dgram_t : public socket_base_t +class dgram_t ZMQ_FINAL : public socket_base_t { public: dgram_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~dgram_t (); + ~dgram_t () ZMQ_FINAL; // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: zmq::pipe_t *_pipe; diff --git a/src/dish.hpp b/src/dish.hpp index 929a19ee..c0986449 100644 --- a/src/dish.hpp +++ b/src/dish.hpp @@ -44,27 +44,27 @@ class ctx_t; class pipe_t; class io_thread_t; -class dish_t : public socket_base_t +class dish_t ZMQ_FINAL : public socket_base_t { public: dish_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~dish_t (); + ~dish_t () ZMQ_FINAL; protected: // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsend (zmq::msg_t *msg_); - bool xhas_out (); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - void xhiccuped (pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); - int xjoin (const char *group_); - int xleave (const char *group_); + bool locally_initiated_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xhiccuped (pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; + int xjoin (const char *group_) ZMQ_FINAL; + int xleave (const char *group_) ZMQ_FINAL; private: int xxrecv (zmq::msg_t *msg_); @@ -90,7 +90,7 @@ class dish_t : public socket_base_t ZMQ_NON_COPYABLE_NOR_MOVABLE (dish_t) }; -class dish_session_t : public session_base_t +class dish_session_t ZMQ_FINAL : public session_base_t { public: dish_session_t (zmq::io_thread_t *io_thread_, @@ -98,12 +98,12 @@ class dish_session_t : public session_base_t zmq::socket_base_t *socket_, const options_t &options_, address_t *addr_); - ~dish_session_t (); + ~dish_session_t () ZMQ_FINAL; // Overrides of the functions from session_base_t. - int push_msg (msg_t *msg_); - int pull_msg (msg_t *msg_); - void reset (); + int push_msg (msg_t *msg_) ZMQ_FINAL; + int pull_msg (msg_t *msg_) ZMQ_FINAL; + void reset () ZMQ_FINAL; private: enum diff --git a/src/encoder.hpp b/src/encoder.hpp index 9359b9ce..ce65d69c 100644 --- a/src/encoder.hpp +++ b/src/encoder.hpp @@ -66,14 +66,12 @@ template class encoder_base_t : public i_encoder alloc_assert (_buf); } - // The destructor doesn't have to be virtual. It is made virtual - // just to keep ICC and code checking tools from complaining. - inline virtual ~encoder_base_t () { free (_buf); } + inline ~encoder_base_t () ZMQ_OVERRIDE { free (_buf); } // The function returns a batch of binary data. The data // are filled to a supplied buffer. If no buffer is supplied (data_ // points to NULL) decoder object will provide buffer of its own. - inline size_t encode (unsigned char **data_, size_t size_) + inline size_t encode (unsigned char **data_, size_t size_) ZMQ_FINAL { unsigned char *buffer = !*data_ ? _buf : *data_; size_t buffersize = !*data_ ? _buf_size : size_; @@ -128,7 +126,7 @@ template class encoder_base_t : public i_encoder return pos; } - void load_msg (msg_t *msg_) + void load_msg (msg_t *msg_) ZMQ_FINAL { zmq_assert (in_progress () == NULL); _in_progress = msg_; diff --git a/src/epoll.hpp b/src/epoll.hpp index 548d36c8..6ace0003 100644 --- a/src/epoll.hpp +++ b/src/epoll.hpp @@ -55,13 +55,13 @@ struct i_poll_events; // This class implements socket polling mechanism using the Linux-specific // epoll mechanism. -class epoll_t : public worker_poller_base_t +class epoll_t ZMQ_FINAL : public worker_poller_base_t { public: typedef void *handle_t; epoll_t (const thread_ctx_t &ctx_); - ~epoll_t (); + ~epoll_t () ZMQ_OVERRIDE; // "poller" concept. handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_); @@ -87,7 +87,7 @@ class epoll_t : public worker_poller_base_t #endif // Main event loop. - void loop (); + void loop () ZMQ_FINAL; // Main epoll file descriptor epoll_fd_t _epoll_fd; diff --git a/src/gather.hpp b/src/gather.hpp index 3edbdc78..7dcab48c 100644 --- a/src/gather.hpp +++ b/src/gather.hpp @@ -39,21 +39,21 @@ class ctx_t; class pipe_t; class msg_t; -class gather_t : public socket_base_t +class gather_t ZMQ_FINAL : public socket_base_t { public: gather_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~gather_t (); + ~gather_t () ZMQ_FINAL; protected: // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - void xread_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // Fair queueing object for inbound pipes. diff --git a/src/gssapi_client.hpp b/src/gssapi_client.hpp index 02d72fc9..18d428c8 100644 --- a/src/gssapi_client.hpp +++ b/src/gssapi_client.hpp @@ -39,18 +39,18 @@ namespace zmq class msg_t; class session_base_t; -class gssapi_client_t : public gssapi_mechanism_base_t +class gssapi_client_t ZMQ_FINAL : public gssapi_mechanism_base_t { public: gssapi_client_t (session_base_t *session_, const options_t &options_); - virtual ~gssapi_client_t (); + ~gssapi_client_t () ZMQ_FINAL; // mechanism implementation - virtual int next_handshake_command (msg_t *msg_); - virtual int process_handshake_command (msg_t *msg_); - virtual int encode (msg_t *msg_); - virtual int decode (msg_t *msg_); - virtual status_t status () const; + int next_handshake_command (msg_t *msg_) ZMQ_FINAL; + int process_handshake_command (msg_t *msg_) ZMQ_FINAL; + int encode (msg_t *msg_) ZMQ_FINAL; + int decode (msg_t *msg_) ZMQ_FINAL; + status_t status () const ZMQ_FINAL; private: enum state_t diff --git a/src/gssapi_mechanism_base.hpp b/src/gssapi_mechanism_base.hpp index 4e14809c..dec53d0b 100644 --- a/src/gssapi_mechanism_base.hpp +++ b/src/gssapi_mechanism_base.hpp @@ -53,7 +53,7 @@ class gssapi_mechanism_base_t : public virtual mechanism_base_t public: gssapi_mechanism_base_t (session_base_t *session_, const options_t &options_); - virtual ~gssapi_mechanism_base_t () = 0; + ~gssapi_mechanism_base_t () ZMQ_OVERRIDE = 0; protected: // Produce a context-level GSSAPI token (INITIATE command) diff --git a/src/gssapi_server.hpp b/src/gssapi_server.hpp index d4a0dd93..26130115 100644 --- a/src/gssapi_server.hpp +++ b/src/gssapi_server.hpp @@ -40,21 +40,22 @@ namespace zmq class msg_t; class session_base_t; -class gssapi_server_t : public gssapi_mechanism_base_t, public zap_client_t +class gssapi_server_t ZMQ_FINAL : public gssapi_mechanism_base_t, + public zap_client_t { public: gssapi_server_t (session_base_t *session_, const std::string &peer_address, const options_t &options_); - virtual ~gssapi_server_t (); + ~gssapi_server_t () ZMQ_FINAL; // mechanism implementation - virtual int next_handshake_command (msg_t *msg_); - virtual int process_handshake_command (msg_t *msg_); - virtual int encode (msg_t *msg_); - virtual int decode (msg_t *msg_); - virtual int zap_msg_available (); - virtual status_t status () const; + int next_handshake_command (msg_t *msg_) ZMQ_FINAL; + int process_handshake_command (msg_t *msg_) ZMQ_FINAL; + int encode (msg_t *msg_) ZMQ_FINAL; + int decode (msg_t *msg_) ZMQ_FINAL; + int zap_msg_available () ZMQ_FINAL; + status_t status () const ZMQ_FINAL; private: enum state_t diff --git a/src/io_object.hpp b/src/io_object.hpp index 50ead7ed..703af7ef 100644 --- a/src/io_object.hpp +++ b/src/io_object.hpp @@ -48,7 +48,7 @@ class io_object_t : public i_poll_events { public: io_object_t (zmq::io_thread_t *io_thread_ = NULL); - ~io_object_t (); + ~io_object_t () ZMQ_OVERRIDE; // When migrating an object from one I/O thread to another, first // unplug it, then migrate it, then plug it to the new thread. @@ -69,9 +69,9 @@ class io_object_t : public i_poll_events void cancel_timer (int id_); // i_poll_events interface implementation. - void in_event (); - void out_event (); - void timer_event (int id_); + void in_event () ZMQ_OVERRIDE; + void out_event () ZMQ_OVERRIDE; + void timer_event (int id_) ZMQ_OVERRIDE; private: poller_t *_poller; diff --git a/src/io_thread.hpp b/src/io_thread.hpp index d6a598a7..98552e15 100644 --- a/src/io_thread.hpp +++ b/src/io_thread.hpp @@ -43,14 +43,14 @@ class ctx_t; // Generic part of the I/O thread. Polling-mechanism-specific features // are implemented in separate "polling objects". -class io_thread_t : public object_t, public i_poll_events +class io_thread_t ZMQ_FINAL : public object_t, public i_poll_events { public: io_thread_t (zmq::ctx_t *ctx_, uint32_t tid_); // Clean-up. If the thread was started, it's necessary to call 'stop' // before invoking destructor. Otherwise the destructor would hang up. - ~io_thread_t (); + ~io_thread_t () ZMQ_FINAL; // Launch the physical thread. void start (); @@ -62,15 +62,15 @@ class io_thread_t : public object_t, public i_poll_events mailbox_t *get_mailbox (); // i_poll_events implementation. - void in_event (); - void out_event (); - void timer_event (int id_); + void in_event () ZMQ_FINAL; + void out_event () ZMQ_FINAL; + void timer_event (int id_) ZMQ_FINAL; // Used by io_objects to retrieve the associated poller object. poller_t *get_poller (); // Command handlers. - void process_stop (); + void process_stop () ZMQ_FINAL; // Returns load experienced by the I/O thread. int get_load (); diff --git a/src/ipc_connecter.hpp b/src/ipc_connecter.hpp index 4d727220..df09c51f 100644 --- a/src/ipc_connecter.hpp +++ b/src/ipc_connecter.hpp @@ -37,7 +37,7 @@ namespace zmq { -class ipc_connecter_t : public stream_connecter_base_t +class ipc_connecter_t ZMQ_FINAL : public stream_connecter_base_t { public: // If 'delayed_start' is true connecter first waits for a while, @@ -50,10 +50,10 @@ class ipc_connecter_t : public stream_connecter_base_t private: // Handlers for I/O events. - void out_event (); + void out_event () ZMQ_FINAL; // Internal function to start the actual connection establishment. - void start_connecting (); + void start_connecting () ZMQ_FINAL; // Open IPC connecting socket. Returns -1 in case of error, // 0 if connect was successful immediately. Returns -1 with diff --git a/src/ipc_listener.hpp b/src/ipc_listener.hpp index 969e33ec..2281549f 100644 --- a/src/ipc_listener.hpp +++ b/src/ipc_listener.hpp @@ -39,7 +39,7 @@ namespace zmq { -class ipc_listener_t : public stream_listener_base_t +class ipc_listener_t ZMQ_FINAL : public stream_listener_base_t { public: ipc_listener_t (zmq::io_thread_t *io_thread_, @@ -50,11 +50,12 @@ class ipc_listener_t : public stream_listener_base_t int set_local_address (const char *addr_); protected: - std::string get_socket_name (fd_t fd_, socket_end_t socket_end_) const; + std::string get_socket_name (fd_t fd_, + socket_end_t socket_end_) const ZMQ_FINAL; private: // Handlers for I/O events. - void in_event (); + void in_event () ZMQ_FINAL; // Filter new connections if the OS provides a mechanism to get // the credentials of the peer process. Called from accept(). @@ -62,7 +63,7 @@ class ipc_listener_t : public stream_listener_base_t bool filter (fd_t sock_); #endif - int close (); + int close () ZMQ_FINAL; // Accept the new connection. Returns the file descriptor of the // newly created connection. The function may return retired_fd diff --git a/src/kqueue.hpp b/src/kqueue.hpp index f51596c9..002fbab3 100644 --- a/src/kqueue.hpp +++ b/src/kqueue.hpp @@ -49,13 +49,13 @@ struct i_poll_events; // Implements socket polling mechanism using the BSD-specific // kqueue interface. -class kqueue_t : public worker_poller_base_t +class kqueue_t ZMQ_FINAL : public worker_poller_base_t { public: typedef void *handle_t; kqueue_t (const thread_ctx_t &ctx_); - ~kqueue_t (); + ~kqueue_t () ZMQ_FINAL; // "poller" concept. handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_); @@ -70,7 +70,7 @@ class kqueue_t : public worker_poller_base_t private: // Main event loop. - void loop (); + void loop () ZMQ_FINAL; // File descriptor referring to the kernel event queue. fd_t kqueue_fd; diff --git a/src/macros.hpp b/src/macros.hpp index 93cf30a1..427a9e25 100644 --- a/src/macros.hpp +++ b/src/macros.hpp @@ -20,6 +20,22 @@ #endif #endif +#if !defined ZMQ_OVERRIDE +#if defined ZMQ_HAVE_NOEXCEPT +#define ZMQ_OVERRIDE override +#else +#define ZMQ_OVERRIDE +#endif +#endif + +#if !defined ZMQ_FINAL +#if defined ZMQ_HAVE_NOEXCEPT +#define ZMQ_FINAL final +#else +#define ZMQ_FINAL +#endif +#endif + #if !defined ZMQ_DEFAULT #if defined ZMQ_HAVE_NOEXCEPT #define ZMQ_DEFAULT = default; diff --git a/src/mailbox.hpp b/src/mailbox.hpp index fe945924..80556b47 100644 --- a/src/mailbox.hpp +++ b/src/mailbox.hpp @@ -42,15 +42,15 @@ namespace zmq { -class mailbox_t : public i_mailbox +class mailbox_t ZMQ_FINAL : public i_mailbox { public: mailbox_t (); - ~mailbox_t (); + ~mailbox_t () ZMQ_FINAL; fd_t get_fd () const; - void send (const command_t &cmd_); - int recv (command_t *cmd_, int timeout_); + void send (const command_t &cmd_) ZMQ_FINAL; + int recv (command_t *cmd_, int timeout_) ZMQ_FINAL; bool valid () const; @@ -58,7 +58,7 @@ class mailbox_t : public i_mailbox // close the file descriptors in the signaller. This is used in a forked // child process to close the file descriptors so that they do not interfere // with the context in the parent process. - void forked () { _signaler.forked (); } + void forked () ZMQ_FINAL { _signaler.forked (); } #endif private: diff --git a/src/mailbox_safe.hpp b/src/mailbox_safe.hpp index 580f02f6..4c7a9807 100644 --- a/src/mailbox_safe.hpp +++ b/src/mailbox_safe.hpp @@ -44,14 +44,14 @@ namespace zmq { -class mailbox_safe_t : public i_mailbox +class mailbox_safe_t ZMQ_FINAL : public i_mailbox { public: mailbox_safe_t (mutex_t *sync_); - ~mailbox_safe_t (); + ~mailbox_safe_t () ZMQ_FINAL; - void send (const command_t &cmd_); - int recv (command_t *cmd_, int timeout_); + void send (const command_t &cmd_) ZMQ_FINAL; + int recv (command_t *cmd_, int timeout_) ZMQ_FINAL; // Add signaler to mailbox which will be called when a message is ready void add_signaler (signaler_t *signaler_); @@ -62,7 +62,7 @@ class mailbox_safe_t : public i_mailbox // close the file descriptors in the signaller. This is used in a forked // child process to close the file descriptors so that they do not interfere // with the context in the parent process. - void forked () + void forked () ZMQ_FINAL { // TODO: call fork on the condition variable } diff --git a/src/norm_engine.hpp b/src/norm_engine.hpp index 46adcaf9..f4007a99 100644 --- a/src/norm_engine.hpp +++ b/src/norm_engine.hpp @@ -18,11 +18,11 @@ class io_thread_t; class msg_t; class session_base_t; -class norm_engine_t : public io_object_t, public i_engine +class norm_engine_t ZMQ_FINAL : public io_object_t, public i_engine { public: norm_engine_t (zmq::io_thread_t *parent_, const options_t &options_); - ~norm_engine_t (); + ~norm_engine_t () ZMQ_FINAL; // create NORM instance, session, etc int init (const char *network_, bool send, bool recv); @@ -30,24 +30,24 @@ class norm_engine_t : public io_object_t, public i_engine // i_engine interface implementation. // Plug the engine to the session. - virtual void plug (zmq::io_thread_t *io_thread_, - class session_base_t *session_); + void plug (zmq::io_thread_t *io_thread_, + class session_base_t *session_) ZMQ_FINAL; // Terminate and deallocate the engine. Note that 'detached' // events are not fired on termination. - virtual void terminate (); + void terminate () ZMQ_FINAL; // This method is called by the session to signalise that more // messages can be written to the pipe. - virtual bool restart_input (); + bool restart_input () ZMQ_FINAL; // This method is called by the session to signalise that there // are messages to send available. - virtual void restart_output (); + void restart_output () ZMQ_FINAL; - virtual void zap_msg_available (){}; + void zap_msg_available () ZMQ_FINAL {} - virtual const endpoint_uri_pair_t &get_endpoint () const; + const endpoint_uri_pair_t &get_endpoint () const ZMQ_FINAL; // i_poll_events interface implementation. // (we only need in_event() for NormEvent notification) diff --git a/src/null_mechanism.hpp b/src/null_mechanism.hpp index b3f32c55..7e85b504 100644 --- a/src/null_mechanism.hpp +++ b/src/null_mechanism.hpp @@ -39,19 +39,19 @@ namespace zmq class msg_t; class session_base_t; -class null_mechanism_t : public zap_client_t +class null_mechanism_t ZMQ_FINAL : public zap_client_t { public: null_mechanism_t (session_base_t *session_, const std::string &peer_address_, const options_t &options_); - virtual ~null_mechanism_t (); + ~null_mechanism_t () ZMQ_FINAL; // mechanism implementation - virtual int next_handshake_command (msg_t *msg_); - virtual int process_handshake_command (msg_t *msg_); - virtual int zap_msg_available (); - virtual status_t status () const; + int next_handshake_command (msg_t *msg_) ZMQ_FINAL; + int process_handshake_command (msg_t *msg_) ZMQ_FINAL; + int zap_msg_available () ZMQ_FINAL; + status_t status () const ZMQ_FINAL; private: bool _ready_command_sent; diff --git a/src/own.hpp b/src/own.hpp index 98e342ac..25fe5a6d 100644 --- a/src/own.hpp +++ b/src/own.hpp @@ -90,12 +90,12 @@ class own_t : public object_t // others to invoke the destructor. At the same time, it has to be // virtual so that generic own_t deallocation mechanism destroys // specific type of the owned object correctly. - virtual ~own_t (); + ~own_t () ZMQ_OVERRIDE; // Term handler is protected rather than private so that it can // be intercepted by the derived class. This is useful to add custom // steps to the beginning of the termination process. - void process_term (int linger_); + void process_term (int linger_) ZMQ_OVERRIDE; // A place to hook in when physical destruction of the object // is to be delayed. @@ -109,10 +109,10 @@ class own_t : public object_t void set_owner (own_t *owner_); // Handlers for incoming commands. - void process_own (own_t *object_); - void process_term_req (own_t *object_); - void process_term_ack (); - void process_seqnum (); + void process_own (own_t *object_) ZMQ_OVERRIDE; + void process_term_req (own_t *object_) ZMQ_OVERRIDE; + void process_term_ack () ZMQ_OVERRIDE; + void process_seqnum () ZMQ_OVERRIDE; // Check whether all the pending term acks were delivered. // If so, deallocate this object. diff --git a/src/pair.hpp b/src/pair.hpp index 02dcaf84..4e60ec13 100644 --- a/src/pair.hpp +++ b/src/pair.hpp @@ -41,23 +41,23 @@ class msg_t; class pipe_t; class io_thread_t; -class pair_t : public socket_base_t +class pair_t ZMQ_FINAL : public socket_base_t { public: pair_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~pair_t (); + ~pair_t () ZMQ_FINAL; // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: zmq::pipe_t *_pipe; diff --git a/src/pgm_receiver.hpp b/src/pgm_receiver.hpp index 64c74744..8e5e9991 100644 --- a/src/pgm_receiver.hpp +++ b/src/pgm_receiver.hpp @@ -46,7 +46,7 @@ namespace zmq class io_thread_t; class session_base_t; -class pgm_receiver_t : public io_object_t, public i_engine +class pgm_receiver_t ZMQ_FINAL : public io_object_t, public i_engine { public: pgm_receiver_t (zmq::io_thread_t *parent_, const options_t &options_); diff --git a/src/pgm_sender.hpp b/src/pgm_sender.hpp index a3d23a27..a2a04383 100644 --- a/src/pgm_sender.hpp +++ b/src/pgm_sender.hpp @@ -45,7 +45,7 @@ namespace zmq class io_thread_t; class session_base_t; -class pgm_sender_t : public io_object_t, public i_engine +class pgm_sender_t ZMQ_FINAL : public io_object_t, public i_engine { public: pgm_sender_t (zmq::io_thread_t *parent_, const options_t &options_); diff --git a/src/pipe.hpp b/src/pipe.hpp index 3f894e8c..9453c98c 100644 --- a/src/pipe.hpp +++ b/src/pipe.hpp @@ -71,10 +71,10 @@ struct i_pipe_events // The array of inbound pipes (1), the array of outbound pipes (2) and // the generic array of pipes to be deallocated (3). -class pipe_t : public object_t, - public array_item_t<1>, - public array_item_t<2>, - public array_item_t<3> +class pipe_t ZMQ_FINAL : public object_t, + public array_item_t<1>, + public array_item_t<2>, + public array_item_t<3> { // This allows pipepair to create pipe objects. friend int pipepair (zmq::object_t *parents_[2], @@ -152,15 +152,16 @@ class pipe_t : public object_t, typedef ypipe_base_t upipe_t; // Command handlers. - void process_activate_read (); - void process_activate_write (uint64_t msgs_read_); - void process_hiccup (void *pipe_); - void process_pipe_peer_stats (uint64_t queue_count_, - own_t *socket_base_, - endpoint_uri_pair_t *endpoint_pair_); - void process_pipe_term (); - void process_pipe_term_ack (); - void process_pipe_hwm (int inhwm_, int outhwm_); + void process_activate_read () ZMQ_OVERRIDE; + void process_activate_write (uint64_t msgs_read_) ZMQ_OVERRIDE; + void process_hiccup (void *pipe_) ZMQ_OVERRIDE; + void + process_pipe_peer_stats (uint64_t queue_count_, + own_t *socket_base_, + endpoint_uri_pair_t *endpoint_pair_) ZMQ_OVERRIDE; + void process_pipe_term () ZMQ_OVERRIDE; + void process_pipe_term_ack () ZMQ_OVERRIDE; + void process_pipe_hwm (int inhwm_, int outhwm_) ZMQ_OVERRIDE; // Handler for delimiter read from the pipe. void process_delimiter (); @@ -179,7 +180,7 @@ class pipe_t : public object_t, void set_peer (pipe_t *peer_); // Destructor is private. Pipe objects destroy themselves. - ~pipe_t (); + ~pipe_t () ZMQ_OVERRIDE; // Underlying pipes for both directions. upipe_t *_in_pipe; diff --git a/src/plain_client.hpp b/src/plain_client.hpp index 70cb728e..76d91ae3 100644 --- a/src/plain_client.hpp +++ b/src/plain_client.hpp @@ -37,16 +37,16 @@ namespace zmq { class msg_t; -class plain_client_t : public mechanism_base_t +class plain_client_t ZMQ_FINAL : public mechanism_base_t { public: plain_client_t (session_base_t *const session_, const options_t &options_); - virtual ~plain_client_t (); + ~plain_client_t () ZMQ_FINAL; // mechanism implementation - virtual int next_handshake_command (msg_t *msg_); - virtual int process_handshake_command (msg_t *msg_); - virtual status_t status () const; + int next_handshake_command (msg_t *msg_) ZMQ_FINAL; + int process_handshake_command (msg_t *msg_) ZMQ_FINAL; + status_t status () const ZMQ_FINAL; private: enum state_t diff --git a/src/plain_server.hpp b/src/plain_server.hpp index 29c3a6d6..19d3c827 100644 --- a/src/plain_server.hpp +++ b/src/plain_server.hpp @@ -38,17 +38,17 @@ namespace zmq class msg_t; class session_base_t; -class plain_server_t : public zap_client_common_handshake_t +class plain_server_t ZMQ_FINAL : public zap_client_common_handshake_t { public: plain_server_t (session_base_t *session_, const std::string &peer_address_, const options_t &options_); - virtual ~plain_server_t (); + ~plain_server_t () ZMQ_FINAL; // mechanism implementation - virtual int next_handshake_command (msg_t *msg_); - virtual int process_handshake_command (msg_t *msg_); + int next_handshake_command (msg_t *msg_) ZMQ_FINAL; + int process_handshake_command (msg_t *msg_) ZMQ_FINAL; private: void produce_welcome (msg_t *msg_) const; diff --git a/src/poll.hpp b/src/poll.hpp index 628ceae0..4c274425 100644 --- a/src/poll.hpp +++ b/src/poll.hpp @@ -56,7 +56,7 @@ struct i_poll_events; // Implements socket polling mechanism using the POSIX.1-2001 // poll() system call. -class poll_t : public worker_poller_base_t +class poll_t ZMQ_FINAL : public worker_poller_base_t { public: typedef fd_t handle_t; @@ -78,7 +78,7 @@ class poll_t : public worker_poller_base_t private: // Main event loop. - virtual void loop (); + void loop () ZMQ_FINAL; void cleanup_retired (); diff --git a/src/poller_base.cpp b/src/poller_base.cpp index db38b910..b81bd6c5 100644 --- a/src/poller_base.cpp +++ b/src/poller_base.cpp @@ -32,10 +32,6 @@ #include "i_poll_events.hpp" #include "err.hpp" -zmq::poller_base_t::poller_base_t () -{ -} - zmq::poller_base_t::~poller_base_t () { // Make sure there is no more load on the shutdown. diff --git a/src/poller_base.hpp b/src/poller_base.hpp index d5f2fef2..d167d797 100644 --- a/src/poller_base.hpp +++ b/src/poller_base.hpp @@ -114,7 +114,7 @@ struct i_poll_events; // a container that is being iterated by the poller. -// A class that can be used as a base class for implementations of the poller +// A class that can be used as abase class for implementations of the poller // concept. // // For documentation of the public methods, see the description of the poller_t @@ -122,7 +122,7 @@ struct i_poll_events; class poller_base_t { public: - poller_base_t (); + poller_base_t () ZMQ_DEFAULT; virtual ~poller_base_t (); // Methods from the poller concept. diff --git a/src/pollset.hpp b/src/pollset.hpp index 66a003ff..8286bed2 100644 --- a/src/pollset.hpp +++ b/src/pollset.hpp @@ -50,13 +50,13 @@ struct i_poll_events; // This class implements socket polling mechanism using the AIX-specific // pollset mechanism. -class pollset_t : public poller_base_t +class pollset_t ZMQ_FINAL : public poller_base_t { public: typedef void *handle_t; pollset_t (const thread_ctx_t &ctx_); - ~pollset_t (); + ~pollset_t () ZMQ_FINAL; // "poller" concept. handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_); @@ -75,7 +75,7 @@ class pollset_t : public poller_base_t static void worker_routine (void *arg_); // Main event loop. - void loop (); + void loop () ZMQ_FINAL; // Reference to ZMQ context. const thread_ctx_t &ctx; diff --git a/src/pub.hpp b/src/pub.hpp index 86a0c2ee..779cbcc2 100644 --- a/src/pub.hpp +++ b/src/pub.hpp @@ -39,18 +39,18 @@ class io_thread_t; class socket_base_t; class msg_t; -class pub_t : public xpub_t +class pub_t ZMQ_FINAL : public xpub_t { public: pub_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~pub_t (); + ~pub_t () ZMQ_FINAL; // Implementations of virtual functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_ = false, - bool locally_initiated_ = false); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); + bool locally_initiated_ = false) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; ZMQ_NON_COPYABLE_NOR_MOVABLE (pub_t) }; diff --git a/src/pull.hpp b/src/pull.hpp index f90f4827..fc9fb22f 100644 --- a/src/pull.hpp +++ b/src/pull.hpp @@ -41,21 +41,21 @@ class pipe_t; class msg_t; class io_thread_t; -class pull_t : public socket_base_t +class pull_t ZMQ_FINAL : public socket_base_t { public: pull_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~pull_t (); + ~pull_t () ZMQ_FINAL; protected: // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - void xread_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // Fair queueing object for inbound pipes. diff --git a/src/push.hpp b/src/push.hpp index cc3e8c37..6fe05ea6 100644 --- a/src/push.hpp +++ b/src/push.hpp @@ -41,21 +41,21 @@ class pipe_t; class msg_t; class io_thread_t; -class push_t : public socket_base_t +class push_t ZMQ_FINAL : public socket_base_t { public: push_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~push_t (); + ~push_t () ZMQ_FINAL; protected: // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsend (zmq::msg_t *msg_); - bool xhas_out (); - void xwrite_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // Load balancer managing the outbound pipes. diff --git a/src/radio.hpp b/src/radio.hpp index 6becfe09..29d73c55 100644 --- a/src/radio.hpp +++ b/src/radio.hpp @@ -45,24 +45,25 @@ class ctx_t; class pipe_t; class io_thread_t; -class radio_t : public socket_base_t +class radio_t ZMQ_FINAL : public socket_base_t { public: radio_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~radio_t (); + ~radio_t () ZMQ_FINAL; // Implementations of virtual functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_ = false, - bool locally_initiated_ = false); - int xsend (zmq::msg_t *msg_); - bool xhas_out (); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_ = false) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + int + xsetsockopt (int option_, const void *optval_, size_t optvallen_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // List of all subscriptions mapped to corresponding pipes. @@ -82,7 +83,7 @@ class radio_t : public socket_base_t ZMQ_NON_COPYABLE_NOR_MOVABLE (radio_t) }; -class radio_session_t : public session_base_t +class radio_session_t ZMQ_FINAL : public session_base_t { public: radio_session_t (zmq::io_thread_t *io_thread_, @@ -90,12 +91,12 @@ class radio_session_t : public session_base_t zmq::socket_base_t *socket_, const options_t &options_, address_t *addr_); - ~radio_session_t (); + ~radio_session_t () ZMQ_FINAL; // Overrides of the functions from session_base_t. - int push_msg (msg_t *msg_); - int pull_msg (msg_t *msg_); - void reset (); + int push_msg (msg_t *msg_) ZMQ_FINAL; + int pull_msg (msg_t *msg_) ZMQ_FINAL; + void reset () ZMQ_FINAL; private: enum diff --git a/src/raw_decoder.hpp b/src/raw_decoder.hpp index 32b5d091..bc09b05f 100644 --- a/src/raw_decoder.hpp +++ b/src/raw_decoder.hpp @@ -39,22 +39,23 @@ namespace zmq { // Decoder for 0MQ v1 framing protocol. Converts data stream into messages. -class raw_decoder_t : public i_decoder +class raw_decoder_t ZMQ_FINAL : public i_decoder { public: raw_decoder_t (size_t bufsize_); - virtual ~raw_decoder_t (); + ~raw_decoder_t () ZMQ_FINAL; // i_decoder interface. - virtual void get_buffer (unsigned char **data_, size_t *size_); + void get_buffer (unsigned char **data_, size_t *size_) ZMQ_FINAL; - virtual int - decode (const unsigned char *data_, size_t size_, size_t &bytes_used_); + int decode (const unsigned char *data_, + size_t size_, + size_t &bytes_used_) ZMQ_FINAL; - virtual msg_t *msg () { return &_in_progress; } + msg_t *msg () ZMQ_FINAL { return &_in_progress; } - virtual void resize_buffer (size_t) {} + void resize_buffer (size_t) ZMQ_FINAL {} private: msg_t _in_progress; diff --git a/src/raw_encoder.hpp b/src/raw_encoder.hpp index fcd0a3f4..acbe609c 100644 --- a/src/raw_encoder.hpp +++ b/src/raw_encoder.hpp @@ -40,11 +40,11 @@ namespace zmq { // Encoder for 0MQ framing protocol. Converts messages into data batches. -class raw_encoder_t : public encoder_base_t +class raw_encoder_t ZMQ_FINAL : public encoder_base_t { public: raw_encoder_t (size_t bufsize_); - ~raw_encoder_t (); + ~raw_encoder_t () ZMQ_FINAL; private: void raw_message_ready (); diff --git a/src/raw_engine.hpp b/src/raw_engine.hpp index 0064aee9..6ea01b06 100644 --- a/src/raw_engine.hpp +++ b/src/raw_engine.hpp @@ -54,18 +54,18 @@ class mechanism_t; // This engine handles any socket with SOCK_STREAM semantics, // e.g. TCP socket or an UNIX domain socket. -class raw_engine_t : public stream_engine_base_t +class raw_engine_t ZMQ_FINAL : public stream_engine_base_t { public: raw_engine_t (fd_t fd_, const options_t &options_, const endpoint_uri_pair_t &endpoint_uri_pair_); - ~raw_engine_t (); + ~raw_engine_t () ZMQ_FINAL; protected: - void error (error_reason_t reason_); - void plug_internal (); - bool handshake (); + void error (error_reason_t reason_) ZMQ_FINAL; + void plug_internal () ZMQ_FINAL; + bool handshake () ZMQ_FINAL; private: int push_raw_msg_to_session (msg_t *msg_); diff --git a/src/reaper.hpp b/src/reaper.hpp index d2227c7a..a3fe0170 100644 --- a/src/reaper.hpp +++ b/src/reaper.hpp @@ -40,11 +40,11 @@ namespace zmq class ctx_t; class socket_base_t; -class reaper_t : public object_t, public i_poll_events +class reaper_t ZMQ_FINAL : public object_t, public i_poll_events { public: reaper_t (zmq::ctx_t *ctx_, uint32_t tid_); - ~reaper_t (); + ~reaper_t () ZMQ_FINAL; mailbox_t *get_mailbox (); @@ -52,15 +52,15 @@ class reaper_t : public object_t, public i_poll_events void stop (); // i_poll_events implementation. - void in_event (); - void out_event (); - void timer_event (int id_); + void in_event () ZMQ_FINAL; + void out_event () ZMQ_FINAL; + void timer_event (int id_) ZMQ_FINAL; private: // Command handlers. - void process_stop (); - void process_reap (zmq::socket_base_t *socket_); - void process_reaped (); + void process_stop () ZMQ_FINAL; + void process_reap (zmq::socket_base_t *socket_) ZMQ_FINAL; + void process_reaped () ZMQ_FINAL; // Reaper thread accesses incoming commands via this mailbox. mailbox_t _mailbox; diff --git a/src/rep.hpp b/src/rep.hpp index e3cdd2e7..4537ec26 100644 --- a/src/rep.hpp +++ b/src/rep.hpp @@ -39,17 +39,17 @@ class msg_t; class io_thread_t; class socket_base_t; -class rep_t : public router_t +class rep_t ZMQ_FINAL : public router_t { public: rep_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~rep_t (); + ~rep_t () ZMQ_FINAL; // Overrides of functions from socket_base_t. - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; private: // If true, we are in process of sending the reply. If false we are diff --git a/src/req.hpp b/src/req.hpp index 4d27ee21..f5a49e39 100644 --- a/src/req.hpp +++ b/src/req.hpp @@ -40,19 +40,20 @@ class msg_t; class io_thread_t; class socket_base_t; -class req_t : public dealer_t +class req_t ZMQ_FINAL : public dealer_t { public: req_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~req_t (); + ~req_t () ZMQ_FINAL; // Overrides of functions from socket_base_t. - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); - void xpipe_terminated (zmq::pipe_t *pipe_); + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + int + xsetsockopt (int option_, const void *optval_, size_t optvallen_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; protected: // Receive only from the pipe the request was sent to, discarding @@ -86,7 +87,7 @@ class req_t : public dealer_t ZMQ_NON_COPYABLE_NOR_MOVABLE (req_t) }; -class req_session_t : public session_base_t +class req_session_t ZMQ_FINAL : public session_base_t { public: req_session_t (zmq::io_thread_t *io_thread_, @@ -94,11 +95,11 @@ class req_session_t : public session_base_t zmq::socket_base_t *socket_, const options_t &options_, address_t *addr_); - ~req_session_t (); + ~req_session_t () ZMQ_FINAL; // Overrides of the functions from session_base_t. - int push_msg (msg_t *msg_); - void reset (); + int push_msg (msg_t *msg_) ZMQ_FINAL; + void reset () ZMQ_FINAL; private: enum diff --git a/src/router.hpp b/src/router.hpp index a2d70830..f020672f 100644 --- a/src/router.hpp +++ b/src/router.hpp @@ -49,20 +49,22 @@ class router_t : public routing_socket_base_t { public: router_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~router_t (); + ~router_t () ZMQ_OVERRIDE; // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); - void xread_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); - int get_peer_state (const void *routing_id_, size_t routing_id_size_) const; + bool locally_initiated_) ZMQ_FINAL; + int + xsetsockopt (int option_, const void *optval_, size_t optvallen_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_OVERRIDE; + int xrecv (zmq::msg_t *msg_) ZMQ_OVERRIDE; + bool xhas_in () ZMQ_OVERRIDE; + bool xhas_out () ZMQ_OVERRIDE; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; + int get_peer_state (const void *routing_id_, + size_t routing_id_size_) const ZMQ_FINAL; protected: // Rollback any message parts that were sent but not yet flushed. diff --git a/src/scatter.hpp b/src/scatter.hpp index 0c61adef..a3db5ee9 100644 --- a/src/scatter.hpp +++ b/src/scatter.hpp @@ -41,21 +41,21 @@ class pipe_t; class msg_t; class io_thread_t; -class scatter_t : public socket_base_t +class scatter_t ZMQ_FINAL : public socket_base_t { public: scatter_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~scatter_t (); + ~scatter_t () ZMQ_FINAL; protected: // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsend (zmq::msg_t *msg_); - bool xhas_out (); - void xwrite_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // Load balancer managing the outbound pipes. diff --git a/src/select.hpp b/src/select.hpp index 708dcf8b..8f18a383 100644 --- a/src/select.hpp +++ b/src/select.hpp @@ -57,13 +57,13 @@ struct i_poll_events; // Implements socket polling mechanism using POSIX.1-2001 select() // function. -class select_t : public worker_poller_base_t +class select_t ZMQ_FINAL : public worker_poller_base_t { public: typedef fd_t handle_t; select_t (const thread_ctx_t &ctx_); - ~select_t (); + ~select_t () ZMQ_FINAL; // "poller" concept. handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_); @@ -78,7 +78,7 @@ class select_t : public worker_poller_base_t private: // Main event loop. - void loop (); + void loop () ZMQ_FINAL; // Internal state. struct fds_set_t diff --git a/src/server.hpp b/src/server.hpp index cef1e4d2..b990d1d9 100644 --- a/src/server.hpp +++ b/src/server.hpp @@ -45,23 +45,23 @@ class msg_t; class pipe_t; // TODO: This class uses O(n) scheduling. Rewrite it to use O(1) algorithm. -class server_t : public socket_base_t +class server_t ZMQ_FINAL : public socket_base_t { public: server_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~server_t (); + ~server_t () ZMQ_FINAL; // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // Fair queueing object for inbound pipes. diff --git a/src/session_base.hpp b/src/session_base.hpp index 42b84e6d..dfe909b8 100644 --- a/src/session_base.hpp +++ b/src/session_base.hpp @@ -65,10 +65,10 @@ class session_base_t : public own_t, public io_object_t, public i_pipe_events void engine_error (zmq::i_engine::error_reason_t reason_); // i_pipe_events interface implementation. - void read_activated (zmq::pipe_t *pipe_); - void write_activated (zmq::pipe_t *pipe_); - void hiccuped (zmq::pipe_t *pipe_); - void pipe_terminated (zmq::pipe_t *pipe_); + void read_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void write_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void hiccuped (zmq::pipe_t *pipe_) ZMQ_FINAL; + void pipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; // Delivers a message. Returns 0 if successful; -1 otherwise. // The function takes ownership of the message. @@ -101,7 +101,7 @@ class session_base_t : public own_t, public io_object_t, public i_pipe_events zmq::socket_base_t *socket_, const options_t &options_, address_t *addr_); - virtual ~session_base_t (); + ~session_base_t () ZMQ_OVERRIDE; private: void start_connecting (bool wait_); @@ -138,12 +138,12 @@ class session_base_t : public own_t, public io_object_t, public i_pipe_events void reconnect (); // Handlers for incoming commands. - void process_plug (); - void process_attach (zmq::i_engine *engine_); - void process_term (int linger_); + void process_plug () ZMQ_FINAL; + void process_attach (zmq::i_engine *engine_) ZMQ_FINAL; + void process_term (int linger_) ZMQ_FINAL; // i_poll_events handlers. - void timer_event (int id_); + void timer_event (int id_) ZMQ_FINAL; // Remove any half processed messages. Flush unflushed messages. // Call this function when engine disconnect to get rid of leftovers. diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 5fd0f485..82742a86 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -107,15 +107,15 @@ class socket_base_t : public own_t, // i_poll_events implementation. This interface is used when socket // is handled by the poller in the reaper thread. - void in_event (); - void out_event (); - void timer_event (int id_); + void in_event () ZMQ_FINAL; + void out_event () ZMQ_FINAL; + void timer_event (int id_) ZMQ_FINAL; // i_pipe_events interface implementation. - void read_activated (pipe_t *pipe_); - void write_activated (pipe_t *pipe_); - void hiccuped (pipe_t *pipe_); - void pipe_terminated (pipe_t *pipe_); + void read_activated (pipe_t *pipe_) ZMQ_FINAL; + void write_activated (pipe_t *pipe_) ZMQ_FINAL; + void hiccuped (pipe_t *pipe_) ZMQ_FINAL; + void pipe_terminated (pipe_t *pipe_) ZMQ_FINAL; void lock (); void unlock (); @@ -170,7 +170,7 @@ class socket_base_t : public own_t, uint32_t tid_, int sid_, bool thread_safe_ = false); - virtual ~socket_base_t (); + ~socket_base_t () ZMQ_OVERRIDE; // Concrete algorithms for the x- methods are to be defined by // individual socket types. @@ -179,7 +179,7 @@ class socket_base_t : public own_t, bool locally_initiated_ = false) = 0; // The default implementation assumes there are no specific socket - // options for the particular socket type. If not so, override this + // options for the particular socket type. If not so, ZMQ_FINAL this // method. virtual int xsetsockopt (int option_, const void *optval_, size_t optvallen_); @@ -203,7 +203,7 @@ class socket_base_t : public own_t, virtual int xleave (const char *group_); // Delay actual destruction of the socket. - void process_destroy (); + void process_destroy () ZMQ_FINAL; private: // test if event should be sent and then dispatch it @@ -284,13 +284,14 @@ class socket_base_t : public own_t, int process_commands (int timeout_, bool throttle_); // Handlers for incoming commands. - void process_stop (); - void process_bind (zmq::pipe_t *pipe_); - void process_pipe_stats_publish (uint64_t outbound_queue_count_, - uint64_t inbound_queue_count_, - endpoint_uri_pair_t *endpoint_pair_); - void process_term (int linger_); - void process_term_endpoint (std::string *endpoint_); + void process_stop () ZMQ_FINAL; + void process_bind (zmq::pipe_t *pipe_) ZMQ_FINAL; + void + process_pipe_stats_publish (uint64_t outbound_queue_count_, + uint64_t inbound_queue_count_, + endpoint_uri_pair_t *endpoint_pair_) ZMQ_FINAL; + void process_term (int linger_) ZMQ_FINAL; + void process_term_endpoint (std::string *endpoint_) ZMQ_FINAL; void update_pipe_options (int option_); @@ -348,12 +349,13 @@ class routing_socket_base_t : public socket_base_t { protected: routing_socket_base_t (class ctx_t *parent_, uint32_t tid_, int sid_); - ~routing_socket_base_t (); + ~routing_socket_base_t () ZMQ_OVERRIDE; // methods from socket_base_t - virtual int - xsetsockopt (int option_, const void *optval_, size_t optvallen_); - virtual void xwrite_activated (pipe_t *pipe_); + int xsetsockopt (int option_, + const void *optval_, + size_t optvallen_) ZMQ_OVERRIDE; + void xwrite_activated (pipe_t *pipe_) ZMQ_FINAL; // own methods std::string extract_connect_routing_id (); diff --git a/src/socks_connecter.hpp b/src/socks_connecter.hpp index 549f29f5..3e17a2e1 100644 --- a/src/socks_connecter.hpp +++ b/src/socks_connecter.hpp @@ -41,7 +41,7 @@ class io_thread_t; class session_base_t; struct address_t; -class socks_connecter_t : public stream_connecter_base_t +class socks_connecter_t ZMQ_FINAL : public stream_connecter_base_t { public: // If 'delayed_start' is true connecter first waits for a while, @@ -52,7 +52,7 @@ class socks_connecter_t : public stream_connecter_base_t address_t *addr_, address_t *proxy_addr_, bool delayed_start_); - ~socks_connecter_t (); + ~socks_connecter_t () ZMQ_FINAL; void set_auth_method_basic (const std::string &username, const std::string &password); @@ -82,11 +82,11 @@ class socks_connecter_t : public stream_connecter_base_t }; // Handlers for I/O events. - virtual void in_event (); - virtual void out_event (); + void in_event () ZMQ_FINAL; + void out_event () ZMQ_FINAL; // Internal function to start the actual connection establishment. - void start_connecting (); + void start_connecting () ZMQ_FINAL; int process_server_response (const socks_choice_t &response_); int process_server_response (const socks_response_t &response_); diff --git a/src/stream.hpp b/src/stream.hpp index 3ac95a84..89fdf1af 100644 --- a/src/stream.hpp +++ b/src/stream.hpp @@ -39,23 +39,24 @@ namespace zmq class ctx_t; class pipe_t; -class stream_t : public routing_socket_base_t +class stream_t ZMQ_FINAL : public routing_socket_base_t { public: stream_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~stream_t (); + ~stream_t () ZMQ_FINAL; // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsend (zmq::msg_t *msg_); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - bool xhas_out (); - void xread_activated (zmq::pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); + bool locally_initiated_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; + int + xsetsockopt (int option_, const void *optval_, size_t optvallen_) ZMQ_FINAL; private: // Generate peer's id and update lookup map diff --git a/src/stream_connecter_base.hpp b/src/stream_connecter_base.hpp index 2d580451..c2accbe3 100644 --- a/src/stream_connecter_base.hpp +++ b/src/stream_connecter_base.hpp @@ -51,16 +51,16 @@ class stream_connecter_base_t : public own_t, public io_object_t address_t *addr_, bool delayed_start_); - ~stream_connecter_base_t (); + ~stream_connecter_base_t () ZMQ_OVERRIDE; protected: // Handlers for incoming commands. - void process_plug (); - void process_term (int linger_); + void process_plug () ZMQ_FINAL; + void process_term (int linger_) ZMQ_OVERRIDE; // Handlers for I/O events. - void in_event (); - void timer_event (int id_); + void in_event () ZMQ_OVERRIDE; + void timer_event (int id_) ZMQ_OVERRIDE; // Internal function to create the engine after connection was established. virtual void create_engine (fd_t fd, const std::string &local_address_); diff --git a/src/stream_engine_base.hpp b/src/stream_engine_base.hpp index a063ece1..16ecc96f 100644 --- a/src/stream_engine_base.hpp +++ b/src/stream_engine_base.hpp @@ -58,20 +58,21 @@ class stream_engine_base_t : public io_object_t, public i_engine stream_engine_base_t (fd_t fd_, const options_t &options_, const endpoint_uri_pair_t &endpoint_uri_pair_); - ~stream_engine_base_t (); + ~stream_engine_base_t () ZMQ_OVERRIDE; // i_engine interface implementation. - void plug (zmq::io_thread_t *io_thread_, zmq::session_base_t *session_); - void terminate (); - bool restart_input (); - void restart_output (); - void zap_msg_available (); - const endpoint_uri_pair_t &get_endpoint () const; + void plug (zmq::io_thread_t *io_thread_, + zmq::session_base_t *session_) ZMQ_FINAL; + void terminate () ZMQ_FINAL; + bool restart_input () ZMQ_FINAL; + void restart_output () ZMQ_FINAL; + void zap_msg_available () ZMQ_FINAL; + const endpoint_uri_pair_t &get_endpoint () const ZMQ_FINAL; // i_poll_events interface implementation. - void in_event (); - void out_event (); - void timer_event (int id_); + void in_event () ZMQ_FINAL; + void out_event () ZMQ_FINAL; + void timer_event (int id_) ZMQ_FINAL; protected: typedef metadata_t::dict_t properties_t; diff --git a/src/stream_listener_base.hpp b/src/stream_listener_base.hpp index 4d85d555..71582541 100644 --- a/src/stream_listener_base.hpp +++ b/src/stream_listener_base.hpp @@ -49,7 +49,7 @@ class stream_listener_base_t : public own_t, public io_object_t stream_listener_base_t (zmq::io_thread_t *io_thread_, zmq::socket_base_t *socket_, const options_t &options_); - ~stream_listener_base_t (); + ~stream_listener_base_t () ZMQ_OVERRIDE; // Get the bound address for use with wildcards int get_local_address (std::string &addr_) const; @@ -60,8 +60,8 @@ class stream_listener_base_t : public own_t, public io_object_t private: // Handlers for incoming commands. - void process_plug (); - void process_term (int linger_); + void process_plug () ZMQ_FINAL; + void process_term (int linger_) ZMQ_FINAL; protected: // Close the listening socket. diff --git a/src/sub.hpp b/src/sub.hpp index 9b493dfc..046e838c 100644 --- a/src/sub.hpp +++ b/src/sub.hpp @@ -39,16 +39,17 @@ class msg_t; class io_thread_t; class socket_base_t; -class sub_t : public xsub_t +class sub_t ZMQ_FINAL : public xsub_t { public: sub_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~sub_t (); + ~sub_t () ZMQ_FINAL; protected: - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); - int xsend (zmq::msg_t *msg_); - bool xhas_out (); + int + xsetsockopt (int option_, const void *optval_, size_t optvallen_) ZMQ_FINAL; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; ZMQ_NON_COPYABLE_NOR_MOVABLE (sub_t) }; diff --git a/src/tcp_connecter.hpp b/src/tcp_connecter.hpp index 4ad581b3..1202718e 100644 --- a/src/tcp_connecter.hpp +++ b/src/tcp_connecter.hpp @@ -36,7 +36,7 @@ namespace zmq { -class tcp_connecter_t : public stream_connecter_base_t +class tcp_connecter_t ZMQ_FINAL : public stream_connecter_base_t { public: // If 'delayed_start' is true connecter first waits for a while, @@ -46,7 +46,7 @@ class tcp_connecter_t : public stream_connecter_base_t const options_t &options_, address_t *addr_, bool delayed_start_); - ~tcp_connecter_t (); + ~tcp_connecter_t () ZMQ_FINAL; private: // ID of the timer used to check the connect timeout, must be different from stream_connecter_base_t::reconnect_timer_id. @@ -56,14 +56,14 @@ class tcp_connecter_t : public stream_connecter_base_t }; // Handlers for incoming commands. - void process_term (int linger_); + void process_term (int linger_) ZMQ_FINAL; // Handlers for I/O events. - void out_event (); - void timer_event (int id_); + void out_event () ZMQ_FINAL; + void timer_event (int id_) ZMQ_FINAL; // Internal function to start the actual connection establishment. - void start_connecting (); + void start_connecting () ZMQ_FINAL; // Internal function to add a connect timer void add_connect_timer (); diff --git a/src/tcp_listener.hpp b/src/tcp_listener.hpp index 60aac5a0..b0080572 100644 --- a/src/tcp_listener.hpp +++ b/src/tcp_listener.hpp @@ -36,7 +36,7 @@ namespace zmq { -class tcp_listener_t : public stream_listener_base_t +class tcp_listener_t ZMQ_FINAL : public stream_listener_base_t { public: tcp_listener_t (zmq::io_thread_t *io_thread_, @@ -47,11 +47,12 @@ class tcp_listener_t : public stream_listener_base_t int set_local_address (const char *addr_); protected: - std::string get_socket_name (fd_t fd_, socket_end_t socket_end_) const; + std::string get_socket_name (fd_t fd_, + socket_end_t socket_end_) const ZMQ_FINAL; private: // Handlers for I/O events. - void in_event (); + void in_event () ZMQ_FINAL; // Accept the new connection. Returns the file descriptor of the // newly created connection. The function may return retired_fd diff --git a/src/tipc_connecter.hpp b/src/tipc_connecter.hpp index 56fb337f..e12643ff 100644 --- a/src/tipc_connecter.hpp +++ b/src/tipc_connecter.hpp @@ -39,7 +39,7 @@ namespace zmq { -class tipc_connecter_t : public stream_connecter_base_t +class tipc_connecter_t ZMQ_FINAL : public stream_connecter_base_t { public: // If 'delayed_start' is true connecter first waits for a while, @@ -52,10 +52,10 @@ class tipc_connecter_t : public stream_connecter_base_t private: // Handlers for I/O events. - void out_event (); + void out_event () ZMQ_FINAL; // Internal function to start the actual connection establishment. - void start_connecting (); + void start_connecting () ZMQ_FINAL; // Get the file descriptor of newly created connection. Returns // retired_fd if the connection was unsuccessful. diff --git a/src/tipc_listener.hpp b/src/tipc_listener.hpp index 9ffbb943..040a99e6 100644 --- a/src/tipc_listener.hpp +++ b/src/tipc_listener.hpp @@ -42,7 +42,7 @@ namespace zmq { -class tipc_listener_t : public stream_listener_base_t +class tipc_listener_t ZMQ_FINAL : public stream_listener_base_t { public: tipc_listener_t (zmq::io_thread_t *io_thread_, @@ -53,11 +53,12 @@ class tipc_listener_t : public stream_listener_base_t int set_local_address (const char *addr_); protected: - std::string get_socket_name (fd_t fd_, socket_end_t socket_end_) const; + std::string get_socket_name (fd_t fd_, + socket_end_t socket_end_) const ZMQ_FINAL; private: // Handlers for I/O events. - void in_event (); + void in_event () ZMQ_FINAL; // Accept the new connection. Returns the file descriptor of the // newly created connection. The function may return retired_fd diff --git a/src/udp_engine.hpp b/src/udp_engine.hpp index db4c30c5..084e4dfe 100644 --- a/src/udp_engine.hpp +++ b/src/udp_engine.hpp @@ -14,36 +14,37 @@ namespace zmq class io_thread_t; class session_base_t; -class udp_engine_t : public io_object_t, public i_engine +class udp_engine_t ZMQ_FINAL : public io_object_t, public i_engine { public: udp_engine_t (const options_t &options_); - ~udp_engine_t (); + ~udp_engine_t () ZMQ_FINAL; int init (address_t *address_, bool send_, bool recv_); // i_engine interface implementation. // Plug the engine to the session. - void plug (zmq::io_thread_t *io_thread_, class session_base_t *session_); + void plug (zmq::io_thread_t *io_thread_, + class session_base_t *session_) ZMQ_FINAL; // Terminate and deallocate the engine. Note that 'detached' // events are not fired on termination. - void terminate (); + void terminate () ZMQ_FINAL; // This method is called by the session to signalise that more // messages can be written to the pipe. - bool restart_input (); + bool restart_input () ZMQ_FINAL; // This method is called by the session to signalise that there // are messages to send available. - void restart_output (); + void restart_output () ZMQ_FINAL; - void zap_msg_available (){}; + void zap_msg_available () ZMQ_FINAL{}; - void in_event (); - void out_event (); + void in_event () ZMQ_FINAL; + void out_event () ZMQ_FINAL; - const endpoint_uri_pair_t &get_endpoint () const; + const endpoint_uri_pair_t &get_endpoint () const ZMQ_FINAL; private: int resolve_raw_address (char *name_, size_t length_); diff --git a/src/v1_decoder.hpp b/src/v1_decoder.hpp index 6c153bbe..6b219a64 100644 --- a/src/v1_decoder.hpp +++ b/src/v1_decoder.hpp @@ -36,13 +36,13 @@ namespace zmq { // Decoder for ZMTP/1.0 protocol. Converts data batches into messages. -class v1_decoder_t : public decoder_base_t +class v1_decoder_t ZMQ_FINAL : public decoder_base_t { public: v1_decoder_t (size_t bufsize_, int64_t maxmsgsize_); - ~v1_decoder_t (); + ~v1_decoder_t () ZMQ_FINAL; - virtual msg_t *msg () { return &_in_progress; } + msg_t *msg () ZMQ_FINAL { return &_in_progress; } private: int one_byte_size_ready (unsigned char const *); diff --git a/src/v1_encoder.hpp b/src/v1_encoder.hpp index ef85bb6d..5427b241 100644 --- a/src/v1_encoder.hpp +++ b/src/v1_encoder.hpp @@ -36,11 +36,11 @@ namespace zmq { // Encoder for ZMTP/1.0 protocol. Converts messages into data batches. -class v1_encoder_t : public encoder_base_t +class v1_encoder_t ZMQ_FINAL : public encoder_base_t { public: v1_encoder_t (size_t bufsize_); - ~v1_encoder_t (); + ~v1_encoder_t () ZMQ_FINAL; private: void size_ready (); diff --git a/src/v2_decoder.hpp b/src/v2_decoder.hpp index 04020486..fa91accd 100644 --- a/src/v2_decoder.hpp +++ b/src/v2_decoder.hpp @@ -38,15 +38,15 @@ namespace zmq // Decoder for ZMTP/2.x framing protocol. Converts data stream into messages. // The class has to inherit from shared_message_memory_allocator because // the base class calls allocate in its constructor. -class v2_decoder_t +class v2_decoder_t ZMQ_FINAL : public decoder_base_t { public: v2_decoder_t (size_t bufsize_, int64_t maxmsgsize_, bool zero_copy_); - virtual ~v2_decoder_t (); + ~v2_decoder_t () ZMQ_FINAL; // i_decoder interface. - virtual msg_t *msg () { return &_in_progress; } + msg_t *msg () ZMQ_FINAL { return &_in_progress; } private: int flags_ready (unsigned char const *); diff --git a/src/v2_encoder.hpp b/src/v2_encoder.hpp index 8cb7b394..36cfa9e4 100644 --- a/src/v2_encoder.hpp +++ b/src/v2_encoder.hpp @@ -36,11 +36,11 @@ namespace zmq { // Encoder for 0MQ framing protocol. Converts messages into data stream. -class v2_encoder_t : public encoder_base_t +class v2_encoder_t ZMQ_FINAL : public encoder_base_t { public: v2_encoder_t (size_t bufsize_); - virtual ~v2_encoder_t (); + ~v2_encoder_t () ZMQ_FINAL; private: void size_ready (); diff --git a/src/vmci_connecter.hpp b/src/vmci_connecter.hpp index ca391cd9..d0ebaac9 100644 --- a/src/vmci_connecter.hpp +++ b/src/vmci_connecter.hpp @@ -46,7 +46,7 @@ class session_base_t; struct address_t; // TODO consider refactoring this to derive from stream_connecter_base_t -class vmci_connecter_t : public own_t, public io_object_t +class vmci_connecter_t ZMQ_FINAL : public own_t, public io_object_t { public: // If 'delayed_start' is true connecter first waits for a while, diff --git a/src/vmci_listener.hpp b/src/vmci_listener.hpp index ab2efa7c..4ab11842 100644 --- a/src/vmci_listener.hpp +++ b/src/vmci_listener.hpp @@ -47,7 +47,7 @@ class io_thread_t; class socket_base_t; // TODO consider refactoring this to derive from stream_listener_base_t -class vmci_listener_t : public own_t, public io_object_t +class vmci_listener_t ZMQ_FINAL : public own_t, public io_object_t { public: vmci_listener_t (zmq::io_thread_t *io_thread_, diff --git a/src/ws_connecter.hpp b/src/ws_connecter.hpp index 20b8b1b9..a6410772 100644 --- a/src/ws_connecter.hpp +++ b/src/ws_connecter.hpp @@ -36,7 +36,7 @@ namespace zmq { -class ws_connecter_t : public stream_connecter_base_t +class ws_connecter_t ZMQ_FINAL : public stream_connecter_base_t { public: // If 'delayed_start' is true connecter first waits for a while, @@ -48,10 +48,10 @@ class ws_connecter_t : public stream_connecter_base_t bool delayed_start_, bool wss_, const std::string &tls_hostname_); - ~ws_connecter_t (); + ~ws_connecter_t () ZMQ_FINAL; protected: - void create_engine (fd_t fd, const std::string &local_address_); + void create_engine (fd_t fd, const std::string &local_address_) ZMQ_FINAL; private: // ID of the timer used to check the connect timeout, must be different from stream_connecter_base_t::reconnect_timer_id. @@ -61,14 +61,14 @@ class ws_connecter_t : public stream_connecter_base_t }; // Handlers for incoming commands. - void process_term (int linger_); + void process_term (int linger_) ZMQ_FINAL; // Handlers for I/O events. - void out_event (); - void timer_event (int id_); + void out_event () ZMQ_FINAL; + void timer_event (int id_) ZMQ_FINAL; // Internal function to start the actual connection establishment. - void start_connecting (); + void start_connecting () ZMQ_FINAL; // Internal function to add a connect timer void add_connect_timer (); diff --git a/src/ws_decoder.hpp b/src/ws_decoder.hpp index 8e13ba25..00eb4014 100644 --- a/src/ws_decoder.hpp +++ b/src/ws_decoder.hpp @@ -39,7 +39,7 @@ namespace zmq // Decoder for Web socket framing protocol. Converts data stream into messages. // The class has to inherit from shared_message_memory_allocator because // the base class calls allocate in its constructor. -class ws_decoder_t +class ws_decoder_t ZMQ_FINAL : public decoder_base_t { public: @@ -47,10 +47,10 @@ class ws_decoder_t int64_t maxmsgsize_, bool zero_copy_, bool must_mask_); - virtual ~ws_decoder_t (); + ~ws_decoder_t () ZMQ_FINAL; // i_decoder interface. - virtual msg_t *msg () { return &_in_progress; } + msg_t *msg () ZMQ_FINAL { return &_in_progress; } private: int opcode_ready (unsigned char const *); diff --git a/src/ws_encoder.hpp b/src/ws_encoder.hpp index 98f6d2b2..ad7b1784 100644 --- a/src/ws_encoder.hpp +++ b/src/ws_encoder.hpp @@ -36,11 +36,11 @@ namespace zmq { // Encoder for web socket framing protocol. Converts messages into data stream. -class ws_encoder_t : public encoder_base_t +class ws_encoder_t ZMQ_FINAL : public encoder_base_t { public: ws_encoder_t (size_t bufsize_, bool must_mask_); - virtual ~ws_encoder_t (); + ~ws_encoder_t () ZMQ_FINAL; private: void size_ready (); diff --git a/src/ws_engine.hpp b/src/ws_engine.hpp index 5846c918..f573e675 100644 --- a/src/ws_engine.hpp +++ b/src/ws_engine.hpp @@ -124,7 +124,7 @@ typedef enum client_handshake_error = -1 } ws_client_handshake_state_t; -class ws_engine_t : public stream_engine_base_t +class ws_engine_t ZMQ_FINAL : public stream_engine_base_t { public: ws_engine_t (fd_t fd_, @@ -132,7 +132,7 @@ class ws_engine_t : public stream_engine_base_t const endpoint_uri_pair_t &endpoint_uri_pair_, ws_address_t &address_, bool client_); - ~ws_engine_t (); + ~ws_engine_t () ZMQ_FINAL; protected: int decode_and_push (msg_t *msg_); diff --git a/src/ws_listener.hpp b/src/ws_listener.hpp index bce8e1a2..509ba33e 100644 --- a/src/ws_listener.hpp +++ b/src/ws_listener.hpp @@ -40,7 +40,7 @@ namespace zmq { -class ws_listener_t : public stream_listener_base_t +class ws_listener_t ZMQ_FINAL : public stream_listener_base_t { public: ws_listener_t (zmq::io_thread_t *io_thread_, @@ -48,18 +48,19 @@ class ws_listener_t : public stream_listener_base_t const options_t &options_, bool wss_); - ~ws_listener_t (); + ~ws_listener_t () ZMQ_FINAL; // Set address to listen on. int set_local_address (const char *addr_); protected: - std::string get_socket_name (fd_t fd_, socket_end_t socket_end_) const; - void create_engine (fd_t fd); + std::string get_socket_name (fd_t fd_, + socket_end_t socket_end_) const ZMQ_FINAL; + void create_engine (fd_t fd) ZMQ_FINAL; private: // Handlers for I/O events. - void in_event (); + void in_event () ZMQ_FINAL; // Accept the new connection. Returns the file descriptor of the // newly created connection. The function may return retired_fd diff --git a/src/xpub.hpp b/src/xpub.hpp index 5414dd0d..82504b0e 100644 --- a/src/xpub.hpp +++ b/src/xpub.hpp @@ -48,20 +48,21 @@ class xpub_t : public socket_base_t { public: xpub_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~xpub_t (); + ~xpub_t () ZMQ_OVERRIDE; // Implementations of virtual functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_ = false, - bool locally_initiated_ = false); - int xsend (zmq::msg_t *msg_); - bool xhas_out (); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_ = false) ZMQ_OVERRIDE; + int xsend (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_out () ZMQ_FINAL; + int xrecv (zmq::msg_t *msg_) ZMQ_OVERRIDE; + bool xhas_in () ZMQ_OVERRIDE; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + int + xsetsockopt (int option_, const void *optval_, size_t optvallen_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // Function to be applied to the trie to send all the subscriptions diff --git a/src/xsub.hpp b/src/xsub.hpp index cea6c288..6bbbce07 100644 --- a/src/xsub.hpp +++ b/src/xsub.hpp @@ -50,22 +50,24 @@ class xsub_t : public socket_base_t { public: xsub_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_); - ~xsub_t (); + ~xsub_t () ZMQ_OVERRIDE; protected: // Overrides of functions from socket_base_t. void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_, - bool locally_initiated_); - int xsetsockopt (int option_, const void *optval_, size_t optvallen_); - int xsend (zmq::msg_t *msg_); - bool xhas_out (); - int xrecv (zmq::msg_t *msg_); - bool xhas_in (); - void xread_activated (zmq::pipe_t *pipe_); - void xwrite_activated (zmq::pipe_t *pipe_); - void xhiccuped (pipe_t *pipe_); - void xpipe_terminated (zmq::pipe_t *pipe_); + bool locally_initiated_) ZMQ_FINAL; + int xsetsockopt (int option_, + const void *optval_, + size_t optvallen_) ZMQ_OVERRIDE; + int xsend (zmq::msg_t *msg_) ZMQ_OVERRIDE; + bool xhas_out () ZMQ_OVERRIDE; + int xrecv (zmq::msg_t *msg_) ZMQ_FINAL; + bool xhas_in () ZMQ_FINAL; + void xread_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xwrite_activated (zmq::pipe_t *pipe_) ZMQ_FINAL; + void xhiccuped (pipe_t *pipe_) ZMQ_FINAL; + void xpipe_terminated (zmq::pipe_t *pipe_) ZMQ_FINAL; private: // Check whether the message matches at least one subscription. diff --git a/src/ypipe.hpp b/src/ypipe.hpp index f8d68ca5..d730b467 100644 --- a/src/ypipe.hpp +++ b/src/ypipe.hpp @@ -43,7 +43,7 @@ namespace zmq // N is granularity of the pipe, i.e. how many items are needed to // perform next memory allocation. -template class ypipe_t : public ypipe_base_t +template class ypipe_t ZMQ_FINAL : public ypipe_base_t { public: // Initialises the pipe. @@ -71,7 +71,7 @@ template class ypipe_t : public ypipe_base_t // set to true the item is assumed to be continued by items // subsequently written to the pipe. Incomplete items are never // flushed down the stream. - inline void write (const T &value_, bool incomplete_) + inline void write (const T &value_, bool incomplete_) ZMQ_FINAL { // Place the value to the queue, add new terminator element. _queue.back () = value_; @@ -88,7 +88,7 @@ template class ypipe_t : public ypipe_base_t // Pop an incomplete item from the pipe. Returns true if such // item exists, false otherwise. - inline bool unwrite (T *value_) + inline bool unwrite (T *value_) ZMQ_FINAL { if (_f == &_queue.back ()) return false; @@ -100,7 +100,7 @@ template class ypipe_t : public ypipe_base_t // Flush all the completed items into the pipe. Returns false if // the reader thread is sleeping. In that case, caller is obliged to // wake the reader up before using the pipe again. - inline bool flush () + inline bool flush () ZMQ_FINAL { // If there are no un-flushed items, do nothing. if (_w == _f) @@ -125,7 +125,7 @@ template class ypipe_t : public ypipe_base_t } // Check whether item is available for reading. - inline bool check_read () + inline bool check_read () ZMQ_FINAL { // Was the value prefetched already? If so, return. if (&_queue.front () != _r && _r) @@ -150,7 +150,7 @@ template class ypipe_t : public ypipe_base_t // Reads an item from the pipe. Returns false if there is no value. // available. - inline bool read (T *value_) + inline bool read (T *value_) ZMQ_FINAL { // Try to prefetch a value. if (!check_read ()) @@ -166,7 +166,7 @@ template class ypipe_t : public ypipe_base_t // Applies the function fn to the first elemenent in the pipe // and returns the value returned by the fn. // The pipe mustn't be empty or the function crashes. - inline bool probe (bool (*fn_) (const T &)) + inline bool probe (bool (*fn_) (const T &)) ZMQ_FINAL { bool rc = check_read (); zmq_assert (rc); diff --git a/src/ypipe_conflate.hpp b/src/ypipe_conflate.hpp index 48ba3cfd..fe010d72 100644 --- a/src/ypipe_conflate.hpp +++ b/src/ypipe_conflate.hpp @@ -43,7 +43,7 @@ namespace zmq // reader_awake flag is needed here to mimic ypipe delicate behaviour // around the reader being asleep (see 'c' pointer being NULL in ypipe.hpp) -template class ypipe_conflate_t : public ypipe_base_t +template class ypipe_conflate_t ZMQ_FINAL : public ypipe_base_t { public: // Initialises the pipe. @@ -57,7 +57,7 @@ template class ypipe_conflate_t : public ypipe_base_t #pragma message save #pragma message disable(UNINIT) #endif - inline void write (const T &value_, bool incomplete_) + inline void write (const T &value_, bool incomplete_) ZMQ_FINAL { (void) incomplete_; @@ -69,16 +69,16 @@ template class ypipe_conflate_t : public ypipe_base_t #endif // There are no incomplete items for conflate ypipe - inline bool unwrite (T *) { return false; } + inline bool unwrite (T *) ZMQ_FINAL { return false; } // Flush is no-op for conflate ypipe. Reader asleep behaviour // is as of the usual ypipe. // Returns false if the reader thread is sleeping. In that case, // caller is obliged to wake the reader up before using the pipe again. - inline bool flush () { return reader_awake; } + inline bool flush () ZMQ_FINAL { return reader_awake; } // Check whether item is available for reading. - inline bool check_read () + inline bool check_read () ZMQ_FINAL { bool res = dbuffer.check_read (); if (!res) @@ -89,7 +89,7 @@ template class ypipe_conflate_t : public ypipe_base_t // Reads an item from the pipe. Returns false if there is no value. // available. - inline bool read (T *value_) + inline bool read (T *value_) ZMQ_FINAL { if (!check_read ()) return false; @@ -100,7 +100,10 @@ template class ypipe_conflate_t : public ypipe_base_t // Applies the function fn to the first elemenent in the pipe // and returns the value returned by the fn. // The pipe mustn't be empty or the function crashes. - inline bool probe (bool (*fn_) (const T &)) { return dbuffer.probe (fn_); } + inline bool probe (bool (*fn_) (const T &)) ZMQ_FINAL + { + return dbuffer.probe (fn_); + } protected: dbuffer_t dbuffer; diff --git a/src/zap_client.hpp b/src/zap_client.hpp index b51ca4be..2f4fc100 100644 --- a/src/zap_client.hpp +++ b/src/zap_client.hpp @@ -83,12 +83,12 @@ class zap_client_common_handshake_t : public zap_client_t state_t zap_reply_ok_state_); // methods from mechanism_t - status_t status () const; - int zap_msg_available (); + status_t status () const ZMQ_FINAL; + int zap_msg_available () ZMQ_FINAL; // zap_client_t methods - int receive_and_process_zap_reply (); - void handle_zap_status_code (); + int receive_and_process_zap_reply () ZMQ_FINAL; + void handle_zap_status_code () ZMQ_FINAL; // Current FSM state state_t state; diff --git a/src/zmtp_engine.hpp b/src/zmtp_engine.hpp index aac21be8..d9f9e75e 100644 --- a/src/zmtp_engine.hpp +++ b/src/zmtp_engine.hpp @@ -59,24 +59,24 @@ class mechanism_t; // This engine handles any socket with SOCK_STREAM semantics, // e.g. TCP socket or an UNIX domain socket. -class zmtp_engine_t : public stream_engine_base_t +class zmtp_engine_t ZMQ_FINAL : public stream_engine_base_t { public: zmtp_engine_t (fd_t fd_, const options_t &options_, const endpoint_uri_pair_t &endpoint_uri_pair_); - ~zmtp_engine_t (); + ~zmtp_engine_t () ZMQ_FINAL; protected: // Detects the protocol used by the peer. - bool handshake (); + bool handshake () ZMQ_FINAL; - void plug_internal (); + void plug_internal () ZMQ_FINAL; - int process_command_message (msg_t *msg_); - int produce_ping_message (msg_t *msg_); - int process_heartbeat_message (msg_t *msg_); - int produce_pong_message (msg_t *msg_); + int process_command_message (msg_t *msg_) ZMQ_FINAL; + int produce_ping_message (msg_t *msg_) ZMQ_FINAL; + int process_heartbeat_message (msg_t *msg_) ZMQ_FINAL; + int produce_pong_message (msg_t *msg_) ZMQ_FINAL; private: // Receive the greeting from the peer. diff --git a/unittests/unittest_ip_resolver.cpp b/unittests/unittest_ip_resolver.cpp index b50d6c75..3d1fa8c2 100644 --- a/unittests/unittest_ip_resolver.cpp +++ b/unittests/unittest_ip_resolver.cpp @@ -18,6 +18,7 @@ along with this program. If not, see . */ #include +#include "../src/macros.hpp" #include "../tests/testutil.hpp" #include "../tests/testutil_unity.hpp" #include "../unittests/unittest_resolver_common.hpp" @@ -39,7 +40,7 @@ void tearDown () { } -class test_ip_resolver_t : public zmq::ip_resolver_t +class test_ip_resolver_t ZMQ_FINAL : public zmq::ip_resolver_t { public: test_ip_resolver_t (zmq::ip_resolver_options_t opts_) : @@ -55,10 +56,10 @@ class test_ip_resolver_t : public zmq::ip_resolver_t const char *ipv6; }; - virtual int do_getaddrinfo (const char *node_, - const char *service_, - const struct addrinfo *hints_, - struct addrinfo **res_) + int do_getaddrinfo (const char *node_, + const char *service_, + const struct addrinfo *hints_, + struct addrinfo **res_) ZMQ_FINAL { static const struct dns_lut_t dns_lut[] = { {"ip.zeromq.org", "10.100.0.1", "fdf5:d058:d656::1"}, @@ -105,7 +106,7 @@ class test_ip_resolver_t : public zmq::ip_resolver_t return zmq::ip_resolver_t::do_getaddrinfo (ip, NULL, &ai, res_); } - virtual unsigned int do_if_nametoindex (const char *ifname_) + unsigned int do_if_nametoindex (const char *ifname_) ZMQ_FINAL { static const char *dummy_interfaces[] = { "lo0", diff --git a/unittests/unittest_poller.cpp b/unittests/unittest_poller.cpp index 7f800685..a7a7457a 100644 --- a/unittests/unittest_poller.cpp +++ b/unittests/unittest_poller.cpp @@ -63,7 +63,7 @@ struct test_events_t : zmq::i_poll_events (void) _fd; } - virtual void in_event () + void in_event () ZMQ_OVERRIDE { _poller.rm_fd (_handle); _handle = (zmq::poller_t::handle_t) NULL; @@ -73,13 +73,13 @@ struct test_events_t : zmq::i_poll_events } - virtual void out_event () + void out_event () ZMQ_OVERRIDE { // TODO } - virtual void timer_event (int id_) + void timer_event (int id_) ZMQ_OVERRIDE { LIBZMQ_UNUSED (id_); _poller.rm_fd (_handle); From f8f79137374e16794d4db00ca9213bcf0af690a7 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 24 Dec 2019 16:39:04 +0100 Subject: [PATCH 2/6] Problem: irregular loop conditions Solution: use standard loop constructs and optimize some loops --- src/ctx.cpp | 23 +++++++++++++++-------- src/generic_mtrie_impl.hpp | 34 +++++++++++++++------------------- src/ipc_listener.cpp | 7 ++++--- src/pipe.cpp | 7 ++++--- src/radix_tree.cpp | 32 ++++++++++++++++++-------------- src/socket_base.cpp | 7 ++++--- src/socket_base.hpp | 5 +++-- src/tcp_listener.cpp | 6 ++++-- src/thread.cpp | 5 +++-- src/ws_encoder.cpp | 3 ++- 10 files changed, 72 insertions(+), 57 deletions(-) diff --git a/src/ctx.cpp b/src/ctx.cpp index 108c2d0e..8ba83a95 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -117,12 +117,13 @@ zmq::ctx_t::~ctx_t () // Ask I/O threads to terminate. If stop signal wasn't sent to I/O // thread subsequent invocation of destructor would hang-up. - for (io_threads_t::size_type i = 0; i != _io_threads.size (); i++) { + const io_threads_t::size_type io_threads_size = _io_threads.size (); + for (io_threads_t::size_type i = 0; i != io_threads_size; i++) { _io_threads[i]->stop (); } // Wait till I/O threads actually terminate. - for (io_threads_t::size_type i = 0; i != _io_threads.size (); i++) { + for (io_threads_t::size_type i = 0; i != io_threads_size; i++) { LIBZMQ_DELETE (_io_threads[i]); } @@ -176,9 +177,10 @@ int zmq::ctx_t::terminate () if (_pid != getpid ()) { // we are a forked child process. Close all file descriptors // inherited from the parent. - for (sockets_t::size_type i = 0; i != _sockets.size (); i++) + for (sockets_t::size_type i = 0, size = _sockets.size (); i != size; + i++) { _sockets[i]->get_mailbox ()->forked (); - + } _term_mailbox.forked (); } #endif @@ -193,8 +195,10 @@ int zmq::ctx_t::terminate () // First send stop command to sockets so that any blocking calls // can be interrupted. If there are no sockets we can ask reaper // thread to stop. - for (sockets_t::size_type i = 0; i != _sockets.size (); i++) + for (sockets_t::size_type i = 0, size = _sockets.size (); i != size; + i++) { _sockets[i]->stop (); + } if (_sockets.empty ()) _reaper->stop (); } @@ -239,8 +243,10 @@ int zmq::ctx_t::shutdown () // Send stop command to sockets so that any blocking calls // can be interrupted. If there are no sockets we can ask reaper // thread to stop. - for (sockets_t::size_type i = 0; i != _sockets.size (); i++) + for (sockets_t::size_type i = 0, size = _sockets.size (); i != size; + i++) { _sockets[i]->stop (); + } if (_sockets.empty ()) _reaper->stop (); } @@ -666,9 +672,10 @@ zmq::io_thread_t *zmq::ctx_t::choose_io_thread (uint64_t affinity_) // Find the I/O thread with minimum load. int min_load = -1; io_thread_t *selected_io_thread = NULL; - for (io_threads_t::size_type i = 0; i != _io_threads.size (); i++) { + for (io_threads_t::size_type i = 0, size = _io_threads.size (); i != size; + i++) { if (!affinity_ || (affinity_ & (uint64_t (1) << i))) { - int load = _io_threads[i]->get_load (); + const int load = _io_threads[i]->get_load (); if (selected_io_thread == NULL || load < min_load) { min_load = load; selected_io_thread = _io_threads[i]; diff --git a/src/generic_mtrie_impl.hpp b/src/generic_mtrie_impl.hpp index 35162bab..6faf984d 100644 --- a/src/generic_mtrie_impl.hpp +++ b/src/generic_mtrie_impl.hpp @@ -427,13 +427,14 @@ void zmq::generic_mtrie_t::match (prefix_t data_, void (*func_) (value_t *pipe_, Arg arg_), Arg arg_) { - generic_mtrie_t *current = this; - while (true) { + for (generic_mtrie_t *current = this; current; data_++, size_--) { // Signal the pipes attached to this node. if (current->_pipes) { - for (typename pipes_t::iterator it = current->_pipes->begin (); - it != current->_pipes->end (); ++it) + for (typename pipes_t::iterator it = current->_pipes->begin (), + end = current->_pipes->end (); + it != end; ++it) { func_ (*it, arg_); + } } // If we are at the end of the message, there's nothing more to match. @@ -444,25 +445,20 @@ void zmq::generic_mtrie_t::match (prefix_t data_, if (current->_count == 0) break; - // If there's one subnode (optimisation). if (current->_count == 1) { - if (data_[0] != current->_min) + // If there's one subnode (optimisation). + if (data_[0] != current->_min) { break; + } current = current->_next.node; - data_++; - size_--; - continue; + } else { + // If there are multiple subnodes. + if (data_[0] < current->_min + || data_[0] >= current->_min + current->_count) { + break; + } + current = current->_next.table[data_[0] - current->_min]; } - - // If there are multiple subnodes. - if (data_[0] < current->_min - || data_[0] >= current->_min + current->_count) - break; - if (!current->_next.table[data_[0] - current->_min]) - break; - current = current->_next.table[data_[0] - current->_min]; - data_++; - size_--; } } diff --git a/src/ipc_listener.cpp b/src/ipc_listener.cpp index baffc373..f74c06bc 100644 --- a/src/ipc_listener.cpp +++ b/src/ipc_listener.cpp @@ -253,9 +253,10 @@ bool zmq::ipc_listener_t::filter (fd_t sock_) if (!(pw = getpwuid (cred.uid))) return false; - for (options_t::ipc_gid_accept_filters_t::const_iterator it = - options.ipc_gid_accept_filters.begin (); - it != options.ipc_gid_accept_filters.end (); it++) { + for (options_t::ipc_gid_accept_filters_t::const_iterator + it = options.ipc_gid_accept_filters.begin (), + end = options.ipc_gid_accept_filters.end (); + it != end; it++) { if (!(gr = getgrgid (*it))) continue; for (char **mem = gr->gr_mem; *mem; mem++) { diff --git a/src/pipe.cpp b/src/pipe.cpp index 9f1e8d9e..ccb1bc58 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -188,7 +188,7 @@ bool zmq::pipe_t::read (msg_t *msg_) if (unlikely (_state != active && _state != waiting_for_delimiter)) return false; - for (bool payload_read = false; !payload_read;) { + while (true) { if (!_in_pipe->read (msg_)) { _in_active = false; return false; @@ -198,8 +198,9 @@ bool zmq::pipe_t::read (msg_t *msg_) if (unlikely (msg_->is_credential ())) { const int rc = msg_->close (); zmq_assert (rc == 0); - } else - payload_read = true; + } else { + break; + } } // If delimiter was read, start termination process of the pipe. diff --git a/src/radix_tree.cpp b/src/radix_tree.cpp index 1f2c029f..e239a3eb 100644 --- a/src/radix_tree.cpp +++ b/src/radix_tree.cpp @@ -34,6 +34,7 @@ #include #include +#include #include node_t::node_t (unsigned char *data_) : _data (data_) @@ -187,7 +188,7 @@ zmq::radix_tree_t::radix_tree_t () : _root (make_node (0, 0, 0)), _size (0) static void free_nodes (node_t node_) { - for (size_t i = 0; i < node_.edgecount (); ++i) + for (size_t i = 0, count = node_.edgecount (); i < count; ++i) free_nodes (node_.node_at (i)); free (node_._data); } @@ -234,18 +235,19 @@ match_result_t zmq::radix_tree_t::match (const unsigned char *key_, size_t parent_edge_index = 0; while (current_node.prefix_length () > 0 || current_node.edgecount () > 0) { + const unsigned char *const prefix = current_node.prefix (); + const size_t prefix_length = current_node.prefix_length (); + for (prefix_byte_index = 0; - prefix_byte_index < current_node.prefix_length () - && key_byte_index < key_size_; + prefix_byte_index < prefix_length && key_byte_index < key_size_; ++prefix_byte_index, ++key_byte_index) { - if (current_node.prefix ()[prefix_byte_index] - != key_[key_byte_index]) + if (prefix[prefix_byte_index] != key_[key_byte_index]) break; } // Even if a prefix of the key matches and we're doing a // lookup, this means we've found a matching subscription. - if (is_lookup_ && prefix_byte_index == current_node.prefix_length () + if (is_lookup_ && prefix_byte_index == prefix_length && current_node.refcount () > 0) { key_byte_index = key_size_; break; @@ -253,14 +255,14 @@ match_result_t zmq::radix_tree_t::match (const unsigned char *key_, // There was a mismatch or we've matched the whole key, so // there's nothing more to do. - if (prefix_byte_index != current_node.prefix_length () - || key_byte_index == key_size_) + if (prefix_byte_index != prefix_length || key_byte_index == key_size_) break; // We need to match the rest of the key. Check if there's an // outgoing edge from this node. node_t next_node = current_node; - for (size_t i = 0; i < current_node.edgecount (); ++i) { + for (size_t i = 0, edgecount = current_node.edgecount (); i < edgecount; + ++i) { if (current_node.first_byte_at (i) == key_[key_byte_index]) { parent_edge_index = edge_index; edge_index = i; @@ -543,18 +545,20 @@ visit_keys (node_t node_, void (*func_) (unsigned char *data_, size_t size_, void *arg_), void *arg_) { - for (size_t i = 0; i < node_.prefix_length (); ++i) - buffer_.push_back (node_.prefix ()[i]); + const size_t prefix_length = node_.prefix_length (); + buffer_.reserve (buffer_.size () + prefix_length); + std::copy (node_.prefix (), node_.prefix () + prefix_length, + std::back_inserter (buffer_)); if (node_.refcount () > 0) { zmq_assert (!buffer_.empty ()); func_ (&buffer_[0], buffer_.size (), arg_); } - for (size_t i = 0; i < node_.edgecount (); ++i) + for (size_t i = 0, edgecount = node_.edgecount (); i < edgecount; ++i) { visit_keys (node_.node_at (i), buffer_, func_, arg_); - for (size_t i = 0; i < node_.prefix_length (); ++i) - buffer_.pop_back (); + } + buffer_.resize (buffer_.size () - prefix_length); } void zmq::radix_tree_t::apply ( diff --git a/src/socket_base.cpp b/src/socket_base.cpp index fd756218..421e6c5c 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -1469,8 +1469,9 @@ void zmq::socket_base_t::process_term (int linger_) unregister_endpoints (this); // Ask all attached pipes to terminate. - for (pipes_t::size_type i = 0; i != _pipes.size (); ++i) + for (pipes_t::size_type i = 0, size = _pipes.size (); i != size; ++i) { _pipes[i]->terminate (false); + } register_term_acks (static_cast (_pipes.size ())); // Continue the termination process immediately. @@ -1515,7 +1516,7 @@ int zmq::socket_base_t::query_pipes_stats () errno = EAGAIN; return -1; } - for (pipes_t::size_type i = 0; i != _pipes.size (); ++i) { + for (pipes_t::size_type i = 0, size = _pipes.size (); i != size; ++i) { _pipes[i]->send_stats_to_peer (this); } @@ -1525,7 +1526,7 @@ int zmq::socket_base_t::query_pipes_stats () void zmq::socket_base_t::update_pipe_options (int option_) { if (option_ == ZMQ_SNDHWM || option_ == ZMQ_RCVHWM) { - for (pipes_t::size_type i = 0; i != _pipes.size (); ++i) { + for (pipes_t::size_type i = 0, size = _pipes.size (); i != size; ++i) { _pipes[i]->set_hwms (options.rcvhwm, options.sndhwm); _pipes[i]->send_hwms_to_peer (options.sndhwm, options.rcvhwm); } diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 82742a86..64e211d8 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -376,8 +376,9 @@ class routing_socket_base_t : public socket_base_t template bool any_of_out_pipes (Func func_) { bool res = false; - for (out_pipes_t::iterator it = _out_pipes.begin (); - it != _out_pipes.end () && !res; ++it) { + for (out_pipes_t::iterator it = _out_pipes.begin (), + end = _out_pipes.end (); + it != end && !res; ++it) { res |= func_ (*it->second.pipe); } diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index 54d3bfe7..67a923b9 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -232,8 +232,10 @@ zmq::fd_t zmq::tcp_listener_t::accept () if (!options.tcp_accept_filters.empty ()) { bool matched = false; - for (options_t::tcp_accept_filters_t::size_type i = 0; - i != options.tcp_accept_filters.size (); ++i) { + for (options_t::tcp_accept_filters_t::size_type + i = 0, + size = options.tcp_accept_filters.size (); + i != size; ++i) { if (options.tcp_accept_filters[i].match_address ( reinterpret_cast (&ss), ss_len)) { matched = true; diff --git a/src/thread.cpp b/src/thread.cpp index ff1f0706..22d03a00 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -355,8 +355,9 @@ void zmq::thread_t:: if (!_thread_affinity_cpus.empty ()) { cpu_set_t cpuset; CPU_ZERO (&cpuset); - for (std::set::const_iterator it = _thread_affinity_cpus.begin (); - it != _thread_affinity_cpus.end (); it++) { + for (std::set::const_iterator it = _thread_affinity_cpus.begin (), + end = _thread_affinity_cpus.end (); + it != end; it++) { CPU_SET ((int) (*it), &cpuset); } rc = diff --git a/src/ws_encoder.cpp b/src/ws_encoder.cpp index eaa605de..4d1e8080 100644 --- a/src/ws_encoder.cpp +++ b/src/ws_encoder.cpp @@ -117,7 +117,8 @@ void zmq::ws_encoder_t::size_ready () static_cast (_masked_msg.data ()); unsigned char *src = static_cast (in_progress ()->data ()); - for (size_t i = 0; i < in_progress ()->size (); ++i, mask_index++) + for (size_t i = 0, size = in_progress ()->size (); i < size; + ++i, mask_index++) dest[i] = src[i] ^ _mask[mask_index % 4]; next_step (_masked_msg.data (), _masked_msg.size (), From 759fed8e7e78b5d96e2fceb5e47b906e15192ea9 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Tue, 24 Dec 2019 16:49:32 +0100 Subject: [PATCH 3/6] Problem: meaningless inline specified on function declarations Solution: remove them --- src/radix_tree.hpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/radix_tree.hpp b/src/radix_tree.hpp index ca84e692..02e74969 100644 --- a/src/radix_tree.hpp +++ b/src/radix_tree.hpp @@ -67,24 +67,23 @@ struct node_t bool operator== (node_t other_) const; bool operator!= (node_t other_) const; - inline uint32_t refcount (); - inline uint32_t prefix_length (); - inline uint32_t edgecount (); - inline unsigned char *prefix (); - inline unsigned char *first_bytes (); - inline unsigned char first_byte_at (size_t index_); - inline unsigned char *node_pointers (); - inline node_t node_at (size_t index_); - inline void set_refcount (uint32_t value_); - inline void set_prefix_length (uint32_t value_); - inline void set_edgecount (uint32_t value_); - inline void set_prefix (const unsigned char *bytes_); - inline void set_first_bytes (const unsigned char *bytes_); - inline void set_first_byte_at (size_t index_, unsigned char byte_); - inline void set_node_pointers (const unsigned char *pointers_); - inline void set_node_at (size_t index_, node_t node_); - inline void - set_edge_at (size_t index_, unsigned char first_byte_, node_t node_); + uint32_t refcount (); + uint32_t prefix_length (); + uint32_t edgecount (); + unsigned char *prefix (); + unsigned char *first_bytes (); + unsigned char first_byte_at (size_t index_); + unsigned char *node_pointers (); + node_t node_at (size_t index_); + void set_refcount (uint32_t value_); + void set_prefix_length (uint32_t value_); + void set_edgecount (uint32_t value_); + void set_prefix (const unsigned char *bytes_); + void set_first_bytes (const unsigned char *bytes_); + void set_first_byte_at (size_t index_, unsigned char byte_); + void set_node_pointers (const unsigned char *pointers_); + void set_node_at (size_t index_, node_t node_); + void set_edge_at (size_t index_, unsigned char first_byte_, node_t node_); void resize (size_t prefix_length_, size_t edgecount_); unsigned char *_data; @@ -137,7 +136,7 @@ class radix_tree_t size_t size () const; private: - inline match_result_t + match_result_t match (const unsigned char *key_, size_t key_size_, bool is_lookup_) const; node_t _root; From 41e3f14d6a7c34ddd5e990c57a6d65653014122f Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 25 Dec 2019 13:51:21 +0100 Subject: [PATCH 4/6] Problem: ptr/ref parameters and local variables are non-const but never modified Solution: add const --- src/atomic_counter.hpp | 2 +- src/clock.cpp | 4 ++-- src/ctx.cpp | 31 +++++++++++++------------ src/ctx.hpp | 9 ++++---- src/curve_client.cpp | 2 +- src/curve_client_tools.hpp | 2 +- src/curve_mechanism_base.cpp | 2 +- src/dealer.cpp | 2 +- src/dgram.cpp | 4 ++-- src/dish.cpp | 16 ++++++------- src/dist.cpp | 6 ++--- src/encoder.hpp | 4 ++-- src/epoll.cpp | 18 +++++++-------- src/err.cpp | 4 ++-- src/fq.cpp | 2 +- src/ip.cpp | 33 ++++++++++++++------------- src/ip_resolver.cpp | 12 +++++----- src/ipc_connecter.cpp | 14 ++++++------ src/ipc_listener.cpp | 14 ++++++------ src/lb.cpp | 4 ++-- src/mailbox_safe.cpp | 4 ++-- src/metadata.cpp | 2 +- src/msg.cpp | 2 +- src/msg.hpp | 2 +- src/object.cpp | 4 ++-- src/object.hpp | 4 ++-- src/options.cpp | 4 ++-- src/pair.cpp | 2 +- src/pipe.cpp | 10 ++++---- src/pipe.hpp | 10 ++++---- src/proxy.cpp | 6 ++--- src/radio.cpp | 6 ++--- src/radix_tree.cpp | 38 +++++++++++++++---------------- src/random.cpp | 4 ++-- src/reaper.cpp | 2 +- src/rep.cpp | 8 +++---- src/req.cpp | 6 ++--- src/router.cpp | 20 ++++++++-------- src/server.cpp | 11 +++++---- src/session_base.cpp | 4 ++-- src/socket_base.cpp | 10 ++++---- src/socket_base.hpp | 8 +++---- src/socket_poller.cpp | 18 +++++++-------- src/socket_poller.hpp | 2 +- src/stream.cpp | 10 ++++---- src/stream_engine_base.cpp | 14 ++++++------ src/tcp.cpp | 23 ++++++++++--------- src/tcp_address.cpp | 2 +- src/tcp_listener.cpp | 10 ++++---- src/thread.cpp | 6 ++--- src/trie.cpp | 2 +- src/trie.hpp | 2 +- src/tweetnacl.c | 2 +- src/udp_address.cpp | 6 ++--- src/udp_engine.cpp | 34 +++++++++++++++------------- src/udp_engine.hpp | 4 ++-- src/v1_decoder.cpp | 2 +- src/v2_decoder.cpp | 2 +- src/ws_connecter.cpp | 2 +- src/ws_decoder.cpp | 6 ++--- src/ws_encoder.cpp | 4 ++-- src/ws_engine.cpp | 20 ++++++++-------- src/ws_engine.hpp | 4 ++-- src/ws_listener.cpp | 10 ++++---- src/xpub.cpp | 14 ++++++------ src/xsub.cpp | 14 ++++++------ src/ypipe.hpp | 2 +- src/ypipe_conflate.hpp | 2 +- src/zmq.cpp | 44 ++++++++++++++++++------------------ src/zmq_utils.cpp | 12 +++++----- src/zmtp_engine.cpp | 6 ++--- 71 files changed, 319 insertions(+), 312 deletions(-) diff --git a/src/atomic_counter.hpp b/src/atomic_counter.hpp index 3863f4d0..fcd9e4ae 100644 --- a/src/atomic_counter.hpp +++ b/src/atomic_counter.hpp @@ -156,7 +156,7 @@ class atomic_counter_t __atomic_sub_fetch (&_value, decrement_, __ATOMIC_ACQ_REL); return nv != 0; #elif defined ZMQ_ATOMIC_COUNTER_CXX11 - integer_t old = + const integer_t old = _value.fetch_sub (decrement_, std::memory_order_acq_rel); return old - decrement_ != 0; #elif defined ZMQ_ATOMIC_COUNTER_ATOMIC_H diff --git a/src/clock.cpp b/src/clock.cpp index 4cfcfc2a..bb3bca62 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -103,7 +103,7 @@ f_compatible_get_tick_count64 init_compatible_get_tick_count64 () f_compatible_get_tick_count64 func = NULL; #if !defined ZMQ_HAVE_WINDOWS_UWP - HMODULE module = ::LoadLibraryA ("Kernel32.dll"); + const HMODULE module = ::LoadLibraryA ("Kernel32.dll"); if (module != NULL) func = reinterpret_cast ( ::GetProcAddress (module, "GetTickCount64")); @@ -200,7 +200,7 @@ uint64_t zmq::clock_t::now_us () uint64_t zmq::clock_t::now_ms () { - uint64_t tsc = rdtsc (); + const uint64_t tsc = rdtsc (); // If TSC is not supported, get precise time and chop off the microseconds. if (!tsc) { diff --git a/src/ctx.cpp b/src/ctx.cpp index 8ba83a95..b4185f3f 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -157,7 +157,7 @@ int zmq::ctx_t::terminate () { _slot_sync.lock (); - bool save_terminating = _terminating; + const bool save_terminating = _terminating; _terminating = false; // Connect up any pending inproc connections, otherwise we will hang @@ -187,7 +187,7 @@ int zmq::ctx_t::terminate () // Check whether termination was already underway, but interrupted and now // restarted. - bool restarted = _terminating; + const bool restarted = _terminating; _terminating = true; // First attempt to terminate the context. @@ -206,7 +206,7 @@ int zmq::ctx_t::terminate () // Wait till reaper thread closes all the sockets. command_t cmd; - int rc = _term_mailbox.recv (&cmd, -1); + const int rc = _term_mailbox.recv (&cmd, -1); if (rc == -1 && errno == EINTR) return -1; errno_assert (rc == 0); @@ -257,7 +257,7 @@ int zmq::ctx_t::shutdown () int zmq::ctx_t::set (int option_, const void *optval_, size_t optvallen_) { - bool is_int = (optvallen_ == sizeof (int)); + const bool is_int = (optvallen_ == sizeof (int)); int value = 0; if (is_int) memcpy (&value, optval_, sizeof (int)); @@ -320,7 +320,7 @@ int zmq::ctx_t::set (int option_, const void *optval_, size_t optvallen_) return -1; } -int zmq::ctx_t::get (int option_, void *optval_, size_t *optvallen_) +int zmq::ctx_t::get (int option_, void *optval_, const size_t *optvallen_) { const bool is_int = (*optvallen_ == sizeof (int)); int *value = static_cast (optval_); @@ -412,7 +412,7 @@ bool zmq::ctx_t::start () const int mazmq = _max_sockets; const int ios = _io_thread_count; _opt_sync.unlock (); - int slot_count = mazmq + ios + term_and_reaper_threads_count; + const int slot_count = mazmq + ios + term_and_reaper_threads_count; try { _slots.reserve (slot_count); _empty_slots.reserve (slot_count - term_and_reaper_threads_count); @@ -498,11 +498,11 @@ zmq::socket_base_t *zmq::ctx_t::create_socket (int type_) } // Choose a slot for the socket. - uint32_t slot = _empty_slots.back (); + const uint32_t slot = _empty_slots.back (); _empty_slots.pop_back (); // Generate new unique socket ID. - int sid = (static_cast (max_socket_id.add (1))) + 1; + const int sid = (static_cast (max_socket_id.add (1))) + 1; // Create the socket and register its mailbox. socket_base_t *s = socket_base_t::create (type_, this, slot, sid); @@ -521,7 +521,7 @@ void zmq::ctx_t::destroy_socket (class socket_base_t *socket_) scoped_lock_t locker (_slot_sync); // Free the associated thread slot. - uint32_t tid = socket_->get_tid (); + const uint32_t tid = socket_->get_tid (); _empty_slots.push_back (tid); _slots[tid] = NULL; @@ -563,7 +563,7 @@ void zmq::thread_ctx_t::start_thread (thread_t &thread_, int zmq::thread_ctx_t::set (int option_, const void *optval_, size_t optvallen_) { - bool is_int = (optvallen_ == sizeof (int)); + const bool is_int = (optvallen_ == sizeof (int)); int value = 0; if (is_int) memcpy (&value, optval_, sizeof (int)); @@ -701,7 +701,7 @@ int zmq::ctx_t::register_endpoint (const char *addr_, } int zmq::ctx_t::unregister_endpoint (const std::string &addr_, - socket_base_t *socket_) + const socket_base_t *const socket_) { scoped_lock_t locker (_endpoints_sync); @@ -717,7 +717,7 @@ int zmq::ctx_t::unregister_endpoint (const std::string &addr_, return 0; } -void zmq::ctx_t::unregister_endpoints (socket_base_t *socket_) +void zmq::ctx_t::unregister_endpoints (const socket_base_t *const socket_) { scoped_lock_t locker (_endpoints_sync); @@ -765,7 +765,7 @@ void zmq::ctx_t::pend_connection (const std::string &addr_, const pending_connection_t pending_connection = {endpoint_, pipes_[0], pipes_[1]}; - endpoints_t::iterator it = _endpoints.find (addr_); + const endpoints_t::iterator it = _endpoints.find (addr_); if (it == _endpoints.end ()) { // Still no bind. endpoint_.socket->inc_seqnum (); @@ -783,7 +783,8 @@ void zmq::ctx_t::connect_pending (const char *addr_, { scoped_lock_t locker (_endpoints_sync); - std::pair + const std::pair pending = _pending_connections.equal_range (addr_); for (pending_connections_t::iterator p = pending.first; p != pending.second; ++p) @@ -795,7 +796,7 @@ void zmq::ctx_t::connect_pending (const char *addr_, void zmq::ctx_t::connect_inproc_sockets ( zmq::socket_base_t *bind_socket_, - options_t &bind_options_, + const options_t &bind_options_, const pending_connection_t &pending_connection_, side side_) { diff --git a/src/ctx.hpp b/src/ctx.hpp index 593f9f70..e1315c6f 100644 --- a/src/ctx.hpp +++ b/src/ctx.hpp @@ -116,7 +116,7 @@ class ctx_t ZMQ_FINAL : public thread_ctx_t // Set and get context properties. int set (int option_, const void *optval_, size_t optvallen_); - int get (int option_, void *optval_, size_t *optvallen_); + int get (int option_, void *optval_, const size_t *optvallen_); int get (int option_); // Create and destroy a socket. @@ -136,8 +136,9 @@ class ctx_t ZMQ_FINAL : public thread_ctx_t // Management of inproc endpoints. int register_endpoint (const char *addr_, const endpoint_t &endpoint_); - int unregister_endpoint (const std::string &addr_, socket_base_t *socket_); - void unregister_endpoints (zmq::socket_base_t *socket_); + int unregister_endpoint (const std::string &addr_, + const socket_base_t *socket_); + void unregister_endpoints (const zmq::socket_base_t *socket_); endpoint_t find_endpoint (const char *addr_); void pend_connection (const std::string &addr_, const endpoint_t &endpoint_, @@ -254,7 +255,7 @@ class ctx_t ZMQ_FINAL : public thread_ctx_t }; void connect_inproc_sockets (zmq::socket_base_t *bind_socket_, - options_t &bind_options_, + const options_t &bind_options_, const pending_connection_t &pending_connection_, side side_); diff --git a/src/curve_client.cpp b/src/curve_client.cpp index 1e5cf42d..fff3e723 100644 --- a/src/curve_client.cpp +++ b/src/curve_client.cpp @@ -158,7 +158,7 @@ int zmq::curve_client_t::produce_hello (msg_t *msg_) int zmq::curve_client_t::process_welcome (const uint8_t *msg_data_, size_t msg_size_) { - int rc = _tools.process_welcome (msg_data_, msg_size_, cn_precom); + const int rc = _tools.process_welcome (msg_data_, msg_size_, cn_precom); if (rc == -1) { session->get_socket ()->event_handshake_failed_protocol ( diff --git a/src/curve_client_tools.hpp b/src/curve_client_tools.hpp index a6fc9d3e..4ee12570 100644 --- a/src/curve_client_tools.hpp +++ b/src/curve_client_tools.hpp @@ -70,7 +70,7 @@ struct curve_client_tools_t put_uint64 (hello_nonce + 16, cn_nonce_); // Create Box [64 * %x0](C'->S) - int rc = + const int rc = crypto_box (hello_box, &hello_plaintext[0], hello_plaintext.size (), hello_nonce, server_key_, cn_secret_); if (rc == -1) diff --git a/src/curve_mechanism_base.cpp b/src/curve_mechanism_base.cpp index d45fa9ac..50e8498c 100644 --- a/src/curve_mechanism_base.cpp +++ b/src/curve_mechanism_base.cpp @@ -125,7 +125,7 @@ int zmq::curve_mechanism_base_t::decode (msg_t *msg_) uint8_t message_nonce[crypto_box_NONCEBYTES]; memcpy (message_nonce, decode_nonce_prefix, 16); memcpy (message_nonce + 16, message + 8, 8); - uint64_t nonce = get_uint64 (message + 8); + const uint64_t nonce = get_uint64 (message + 8); if (nonce <= cn_peer_nonce) { session->get_socket ()->event_handshake_failed_protocol ( session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_SEQUENCE); diff --git a/src/dealer.cpp b/src/dealer.cpp index 0f888e63..d6c2710d 100644 --- a/src/dealer.cpp +++ b/src/dealer.cpp @@ -76,7 +76,7 @@ int zmq::dealer_t::xsetsockopt (int option_, const void *optval_, size_t optvallen_) { - bool is_int = (optvallen_ == sizeof (int)); + const bool is_int = (optvallen_ == sizeof (int)); int value = 0; if (is_int) memcpy (&value, optval_, sizeof (int)); diff --git a/src/dgram.cpp b/src/dgram.cpp index f0475e36..879ff4da 100644 --- a/src/dgram.cpp +++ b/src/dgram.cpp @@ -94,7 +94,7 @@ int zmq::dgram_t::xsend (msg_t *msg_) { // If there's no out pipe, just drop it. if (!_pipe) { - int rc = msg_->close (); + const int rc = msg_->close (); errno_assert (rc == 0); return -1; } @@ -127,7 +127,7 @@ int zmq::dgram_t::xsend (msg_t *msg_) _more_out = !_more_out; // Detach the message from the data buffer. - int rc = msg_->init (); + const int rc = msg_->init (); errno_assert (rc == 0); return 0; diff --git a/src/dish.cpp b/src/dish.cpp index cb9c0334..f3aca49c 100644 --- a/src/dish.cpp +++ b/src/dish.cpp @@ -44,13 +44,13 @@ zmq::dish_t::dish_t (class ctx_t *parent_, uint32_t tid_, int sid_) : // subscription commands are sent to the wire. options.linger.store (0); - int rc = _message.init (); + const int rc = _message.init (); errno_assert (rc == 0); } zmq::dish_t::~dish_t () { - int rc = _message.close (); + const int rc = _message.close (); errno_assert (rc == 0); } @@ -93,7 +93,7 @@ void zmq::dish_t::xhiccuped (pipe_t *pipe_) int zmq::dish_t::xjoin (const char *group_) { - std::string group = std::string (group_); + const std::string group = std::string (group_); if (group.length () > ZMQ_GROUP_MAX_LENGTH) { errno = EINVAL; @@ -117,7 +117,7 @@ int zmq::dish_t::xjoin (const char *group_) rc = _dist.send_to_all (&msg); if (rc != 0) err = errno; - int rc2 = msg.close (); + const int rc2 = msg.close (); errno_assert (rc2 == 0); if (rc != 0) errno = err; @@ -126,7 +126,7 @@ int zmq::dish_t::xjoin (const char *group_) int zmq::dish_t::xleave (const char *group_) { - std::string group = std::string (group_); + const std::string group = std::string (group_); if (group.length () > ZMQ_GROUP_MAX_LENGTH) { errno = EINVAL; @@ -149,7 +149,7 @@ int zmq::dish_t::xleave (const char *group_) rc = _dist.send_to_all (&msg); if (rc != 0) err = errno; - int rc2 = msg.close (); + const int rc2 = msg.close (); errno_assert (rc2 == 0); if (rc != 0) errno = err; @@ -269,7 +269,7 @@ int zmq::dish_session_t::push_msg (msg_t *msg_) _group_msg = *msg_; _state = body; - int rc = msg_->init (); + const int rc = msg_->init (); errno_assert (rc == 0); return 0; } @@ -312,7 +312,7 @@ int zmq::dish_session_t::pull_msg (msg_t *msg_) if (!msg_->is_join () && !msg_->is_leave ()) return rc; - int group_length = static_cast (strlen (msg_->group ())); + const int group_length = static_cast (strlen (msg_->group ())); msg_t command; int offset; diff --git a/src/dist.cpp b/src/dist.cpp index 346778bf..6ac27045 100644 --- a/src/dist.cpp +++ b/src/dist.cpp @@ -81,7 +81,7 @@ void zmq::dist_t::match (pipe_t *pipe_) void zmq::dist_t::reverse_match () { - pipes_t::size_type prev_matching = _matching; + const pipes_t::size_type prev_matching = _matching; // Reset matching to 0 unmatch (); @@ -145,7 +145,7 @@ int zmq::dist_t::send_to_all (msg_t *msg_) int zmq::dist_t::send_to_matching (msg_t *msg_) { // Is this end of a multipart message? - bool msg_more = (msg_->flags () & msg_t::more) != 0; + const bool msg_more = (msg_->flags () & msg_t::more) != 0; // Push the message to matching pipes. distribute (msg_); @@ -204,7 +204,7 @@ void zmq::dist_t::distribute (msg_t *msg_) // Detach the original message from the data buffer. Note that we don't // close the message. That's because we've already used all the references. - int rc = msg_->init (); + const int rc = msg_->init (); errno_assert (rc == 0); } diff --git a/src/encoder.hpp b/src/encoder.hpp index ce65d69c..76fb3627 100644 --- a/src/encoder.hpp +++ b/src/encoder.hpp @@ -74,7 +74,7 @@ template class encoder_base_t : public i_encoder inline size_t encode (unsigned char **data_, size_t size_) ZMQ_FINAL { unsigned char *buffer = !*data_ ? _buf : *data_; - size_t buffersize = !*data_ ? _buf_size : size_; + const size_t buffersize = !*data_ ? _buf_size : size_; if (in_progress () == NULL) return 0; @@ -115,7 +115,7 @@ template class encoder_base_t : public i_encoder } // Copy data to the buffer. If the buffer is full, return. - size_t to_copy = std::min (_to_write, buffersize - pos); + const size_t to_copy = std::min (_to_write, buffersize - pos); memcpy (buffer + pos, _write_pos, to_copy); pos += to_copy; _write_pos += to_copy; diff --git a/src/epoll.cpp b/src/epoll.cpp index 86634c07..7374986d 100644 --- a/src/epoll.cpp +++ b/src/epoll.cpp @@ -96,7 +96,7 @@ zmq::epoll_t::handle_t zmq::epoll_t::add_fd (fd_t fd_, i_poll_events *events_) pe->ev.data.ptr = pe; pe->events = events_; - int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_ADD, fd_, &pe->ev); + const int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_ADD, fd_, &pe->ev); errno_assert (rc != -1); // Increase the load metric of the thread. @@ -109,7 +109,7 @@ void zmq::epoll_t::rm_fd (handle_t handle_) { check_thread (); poll_entry_t *pe = static_cast (handle_); - int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_DEL, pe->fd, &pe->ev); + const int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_DEL, pe->fd, &pe->ev); errno_assert (rc != -1); pe->fd = retired_fd; _retired.push_back (pe); @@ -123,7 +123,7 @@ void zmq::epoll_t::set_pollin (handle_t handle_) check_thread (); poll_entry_t *pe = static_cast (handle_); pe->ev.events |= EPOLLIN; - int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); + const int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); errno_assert (rc != -1); } @@ -132,7 +132,7 @@ void zmq::epoll_t::reset_pollin (handle_t handle_) check_thread (); poll_entry_t *pe = static_cast (handle_); pe->ev.events &= ~(static_cast (EPOLLIN)); - int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); + const int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); errno_assert (rc != -1); } @@ -141,7 +141,7 @@ void zmq::epoll_t::set_pollout (handle_t handle_) check_thread (); poll_entry_t *pe = static_cast (handle_); pe->ev.events |= EPOLLOUT; - int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); + const int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); errno_assert (rc != -1); } @@ -150,7 +150,7 @@ void zmq::epoll_t::reset_pollout (handle_t handle_) check_thread (); poll_entry_t *pe = static_cast (handle_); pe->ev.events &= ~(static_cast (EPOLLOUT)); - int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); + const int rc = epoll_ctl (_epoll_fd, EPOLL_CTL_MOD, pe->fd, &pe->ev); errno_assert (rc != -1); } @@ -170,7 +170,7 @@ void zmq::epoll_t::loop () while (true) { // Execute any due timers. - int timeout = static_cast (execute_timers ()); + const int timeout = static_cast (execute_timers ()); if (get_load () == 0) { if (timeout == 0) @@ -181,8 +181,8 @@ void zmq::epoll_t::loop () } // Wait for events. - int n = epoll_wait (_epoll_fd, &ev_buf[0], max_io_events, - timeout ? timeout : -1); + const int n = epoll_wait (_epoll_fd, &ev_buf[0], max_io_events, + timeout ? timeout : -1); if (n == -1) { errno_assert (errno == EINTR); continue; diff --git a/src/err.cpp b/src/err.cpp index a73fc113..ea2a9b51 100644 --- a/src/err.cpp +++ b/src/err.cpp @@ -211,14 +211,14 @@ const char *zmq::wsa_error_no (int no_, const char *wsae_wouldblock_string_) void zmq::win_error (char *buffer_, size_t buffer_size_) { - DWORD errcode = GetLastError (); + const DWORD errcode = GetLastError (); #if defined _WIN32_WCE DWORD rc = FormatMessageW ( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR) buffer_, buffer_size_ / sizeof (wchar_t), NULL); #else - DWORD rc = FormatMessageA ( + const DWORD rc = FormatMessageA ( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errcode, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), buffer_, static_cast (buffer_size_), NULL); diff --git a/src/fq.cpp b/src/fq.cpp index e4cc572c..2a700977 100644 --- a/src/fq.cpp +++ b/src/fq.cpp @@ -90,7 +90,7 @@ int zmq::fq_t::recvpipe (msg_t *msg_, pipe_t **pipe_) while (_active > 0) { // Try to fetch new message. If we've already read part of the message // subsequent part should be immediately available. - bool fetched = _pipes[_current]->read (msg_); + const bool fetched = _pipes[_current]->read (msg_); // Note that when message is not fetched, current pipe is deactivated // and replaced by another active pipe. Thus we don't have to increase diff --git a/src/ip.cpp b/src/ip.cpp index 4bfbc9fd..2e6da4bf 100644 --- a/src/ip.cpp +++ b/src/ip.cpp @@ -128,7 +128,7 @@ void zmq::unblock_socket (fd_t s_) { #if defined ZMQ_HAVE_WINDOWS u_long nonblock = 1; - int rc = ioctlsocket (s_, FIONBIO, &nonblock); + const int rc = ioctlsocket (s_, FIONBIO, &nonblock); wsa_assert (rc != SOCKET_ERROR); #elif defined ZMQ_HAVE_OPENVMS || defined ZMQ_HAVE_VXWORKS int nonblock = 1; @@ -154,8 +154,8 @@ void zmq::enable_ipv4_mapping (fd_t s_) #else int flag = 0; #endif - int rc = setsockopt (s_, IPPROTO_IPV6, IPV6_V6ONLY, - reinterpret_cast (&flag), sizeof (flag)); + const int rc = setsockopt (s_, IPPROTO_IPV6, IPV6_V6ONLY, + reinterpret_cast (&flag), sizeof (flag)); #ifdef ZMQ_HAVE_WINDOWS wsa_assert (rc != SOCKET_ERROR); #else @@ -168,7 +168,7 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_) { struct sockaddr_storage ss; - zmq_socklen_t addrlen = + const zmq_socklen_t addrlen = get_socket_address (sockfd_, socket_end_remote, &ss); if (addrlen == 0) { @@ -186,8 +186,9 @@ int zmq::get_peer_ip_address (fd_t sockfd_, std::string &ip_addr_) } char host[NI_MAXHOST]; - int rc = getnameinfo (reinterpret_cast (&ss), addrlen, - host, sizeof host, NULL, 0, NI_NUMERICHOST); + const int rc = + getnameinfo (reinterpret_cast (&ss), addrlen, host, + sizeof host, NULL, 0, NI_NUMERICHOST); if (rc != 0) return 0; @@ -297,9 +298,9 @@ bool zmq::initialize_network () // Intialise Windows sockets. Note that WSAStartup can be called multiple // times given that WSACleanup will be called for each WSAStartup. - WORD version_requested = MAKEWORD (2, 2); + const WORD version_requested = MAKEWORD (2, 2); WSADATA wsa_data; - int rc = WSAStartup (version_requested, &wsa_data); + const int rc = WSAStartup (version_requested, &wsa_data); zmq_assert (rc == 0); zmq_assert (LOBYTE (wsa_data.wVersion) == 2 && HIBYTE (wsa_data.wVersion) == 2); @@ -312,7 +313,7 @@ void zmq::shutdown_network () { #ifdef ZMQ_HAVE_WINDOWS // On Windows, uninitialise socket layer. - int rc = WSACleanup (); + const int rc = WSACleanup (); wsa_assert (rc != SOCKET_ERROR); #endif @@ -327,7 +328,7 @@ void zmq::shutdown_network () static void tune_socket (const SOCKET socket_) { BOOL tcp_nodelay = 1; - int rc = + const int rc = setsockopt (socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast (&tcp_nodelay), sizeof tcp_nodelay); wsa_assert (rc != SOCKET_ERROR); @@ -363,7 +364,7 @@ static int make_fdpair_tcpip (zmq::fd_t *r_, zmq::fd_t *w_) // Create critical section only if using fixed signaler port // Use problematic Event implementation for compatibility if using old port 5905. // Otherwise use Mutex implementation. - int event_signaler_port = 5905; + const int event_signaler_port = 5905; if (zmq::signaler_port == event_signaler_port) { #if !defined _WIN32_WCE && !defined ZMQ_HAVE_WINDOWS_UWP @@ -431,7 +432,7 @@ static int make_fdpair_tcpip (zmq::fd_t *r_, zmq::fd_t *w_) if (sync != NULL) { // Enter the critical section. - DWORD dwrc = WaitForSingleObject (sync, INFINITE); + const DWORD dwrc = WaitForSingleObject (sync, INFINITE); zmq_assert (dwrc == WAIT_OBJECT_0 || dwrc == WAIT_ABANDONED); } @@ -468,7 +469,7 @@ static int make_fdpair_tcpip (zmq::fd_t *r_, zmq::fd_t *w_) // Send/receive large chunk to work around TCP slow start // This code is a workaround for #1608 if (*r_ != INVALID_SOCKET) { - size_t dummy_size = + const size_t dummy_size = 1024 * 1024; // 1M to overload default receive buffer unsigned char *dummy = static_cast (malloc (dummy_size)); @@ -561,7 +562,7 @@ int zmq::make_fdpair (fd_t *r_, fd_t *w_) std::string dirname, filename; // Create a listening socket. - SOCKET listener = open_socket (AF_UNIX, SOCK_STREAM, 0); + const SOCKET listener = open_socket (AF_UNIX, SOCK_STREAM, 0); if (listener == retired_fd) { // This may happen if the library was built on a system supporting AF_UNIX, but the system running doesn't support it. goto try_tcpip; @@ -801,8 +802,8 @@ void zmq::assert_success_or_recoverable (zmq::fd_t s_, int rc_) socklen_t len = sizeof err; #endif - int rc = getsockopt (s_, SOL_SOCKET, SO_ERROR, - reinterpret_cast (&err), &len); + const int rc = getsockopt (s_, SOL_SOCKET, SO_ERROR, + reinterpret_cast (&err), &len); // Assert if the error was caused by 0MQ bug. // Networking problems are OK. No need to assert. diff --git a/src/ip_resolver.cpp b/src/ip_resolver.cpp index 8f2a8640..c0bb25b3 100644 --- a/src/ip_resolver.cpp +++ b/src/ip_resolver.cpp @@ -200,7 +200,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_) } addr = std::string (name_, delim - name_); - std::string port_str = std::string (delim + 1); + const std::string port_str = std::string (delim + 1); if (port_str == "*") { if (_options.bindable ()) { @@ -229,7 +229,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_) // Check if path is allowed in ip address, if allowed it must be truncated if (_options.allow_path ()) { - size_t pos = addr.find ('/'); + const size_t pos = addr.find ('/'); if (pos != std::string::npos) addr = addr.substr (0, pos); } @@ -247,7 +247,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_) // Look for an interface name / zone_id in the address // Reference: https://tools.ietf.org/html/rfc4007 - std::size_t pos = addr.rfind ('%'); + const std::size_t pos = addr.rfind ('%'); uint32_t zone_id = 0; if (pos != std::string::npos) { @@ -277,7 +277,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_) if (!resolved && _options.allow_nic_name ()) { // Try to resolve the string as a NIC name. - int rc = resolve_nic_name (ip_addr_, addr_str); + const int rc = resolve_nic_name (ip_addr_, addr_str); if (rc == 0) { resolved = true; @@ -287,7 +287,7 @@ int zmq::ip_resolver_t::resolve (ip_addr_t *ip_addr_, const char *name_) } if (!resolved) { - int rc = resolve_getaddrinfo (ip_addr_, addr_str); + const int rc = resolve_getaddrinfo (ip_addr_, addr_str); if (rc != 0) { return rc; @@ -597,7 +597,7 @@ int zmq::ip_resolver_t::get_interface_name (unsigned long index_, int zmq::ip_resolver_t::wchar_to_utf8 (const WCHAR *src_, char **dest_) const { int rc; - int buffer_len = + const int buffer_len = WideCharToMultiByte (CP_UTF8, 0, src_, -1, NULL, 0, NULL, 0); char *buffer = static_cast (malloc (buffer_len)); diff --git a/src/ipc_connecter.cpp b/src/ipc_connecter.cpp index 8d3ba324..48e06f53 100644 --- a/src/ipc_connecter.cpp +++ b/src/ipc_connecter.cpp @@ -65,7 +65,7 @@ zmq::ipc_connecter_t::ipc_connecter_t (class io_thread_t *io_thread_, void zmq::ipc_connecter_t::out_event () { - fd_t fd = connect (); + const fd_t fd = connect (); rm_handle (); // Handle the error condition by attempt to reconnect. @@ -81,7 +81,7 @@ void zmq::ipc_connecter_t::out_event () void zmq::ipc_connecter_t::start_connecting () { // Open the connecting socket. - int rc = open (); + const int rc = open (); // Connect may succeed in synchronous manner. if (rc == 0) { @@ -122,8 +122,8 @@ int zmq::ipc_connecter_t::open () unblock_socket (_s); // Connect to the remote peer. - int rc = ::connect (_s, _addr->resolved.ipc_addr->addr (), - _addr->resolved.ipc_addr->addrlen ()); + const int rc = ::connect (_s, _addr->resolved.ipc_addr->addr (), + _addr->resolved.ipc_addr->addrlen ()); // Connect was successful immediately. if (rc == 0) @@ -153,8 +153,8 @@ zmq::fd_t zmq::ipc_connecter_t::connect () // implementations and Solaris. int err = 0; zmq_socklen_t len = static_cast (sizeof (err)); - int rc = getsockopt (_s, SOL_SOCKET, SO_ERROR, - reinterpret_cast (&err), &len); + const int rc = getsockopt (_s, SOL_SOCKET, SO_ERROR, + reinterpret_cast (&err), &len); if (rc == -1) { if (errno == ENOPROTOOPT) errno = 0; @@ -171,7 +171,7 @@ zmq::fd_t zmq::ipc_connecter_t::connect () return retired_fd; } - fd_t result = _s; + const fd_t result = _s; _s = retired_fd; return result; } diff --git a/src/ipc_listener.cpp b/src/ipc_listener.cpp index f74c06bc..6aec57a4 100644 --- a/src/ipc_listener.cpp +++ b/src/ipc_listener.cpp @@ -85,7 +85,7 @@ zmq::ipc_listener_t::ipc_listener_t (io_thread_t *io_thread_, void zmq::ipc_listener_t::in_event () { - fd_t fd = accept (); + const fd_t fd = accept (); // If connection was reset by the peer in the meantime, just ignore it. // TODO: Handle specific errors like ENFILE/EMFILE etc. @@ -134,7 +134,7 @@ int zmq::ipc_listener_t::set_local_address (const char *addr_) if (rc != 0) { if (!_tmp_socket_dirname.empty ()) { // We need to preserve errno to return to the user - int tmp_errno = errno; + const int tmp_errno = errno; ::rmdir (_tmp_socket_dirname.c_str ()); _tmp_socket_dirname.clear (); errno = tmp_errno; @@ -152,7 +152,7 @@ int zmq::ipc_listener_t::set_local_address (const char *addr_) if (_s == retired_fd) { if (!_tmp_socket_dirname.empty ()) { // We need to preserve errno to return to the user - int tmp_errno = errno; + const int tmp_errno = errno; ::rmdir (_tmp_socket_dirname.c_str ()); _tmp_socket_dirname.clear (); errno = tmp_errno; @@ -180,7 +180,7 @@ int zmq::ipc_listener_t::set_local_address (const char *addr_) return 0; error: - int err = errno; + const int err = errno; close (); errno = err; return -1; @@ -189,7 +189,7 @@ error: int zmq::ipc_listener_t::close () { zmq_assert (_s != retired_fd); - fd_t fd_for_event = _s; + const fd_t fd_for_event = _s; #ifdef ZMQ_HAVE_WINDOWS int rc = closesocket (_s); wsa_assert (rc != SOCKET_ERROR); @@ -313,7 +313,7 @@ zmq::fd_t zmq::ipc_listener_t::accept () socklen_t ss_len = sizeof (ss); #endif - fd_t sock = + const fd_t sock = ::accept (_s, reinterpret_cast (&ss), &ss_len); #endif if (sock == retired_fd) { @@ -342,7 +342,7 @@ zmq::fd_t zmq::ipc_listener_t::accept () if (zmq::set_nosigpipe (sock)) { #ifdef ZMQ_HAVE_WINDOWS - int rc = closesocket (sock); + const int rc = closesocket (sock); wsa_assert (rc != SOCKET_ERROR); #else int rc = ::close (sock); diff --git a/src/lb.cpp b/src/lb.cpp index 02af502b..e766b4f2 100644 --- a/src/lb.cpp +++ b/src/lb.cpp @@ -50,7 +50,7 @@ void zmq::lb_t::attach (pipe_t *pipe_) void zmq::lb_t::pipe_terminated (pipe_t *pipe_) { - pipes_t::size_type index = _pipes.index (pipe_); + const pipes_t::size_type index = _pipes.index (pipe_); // If we are in the middle of multipart message and current pipe // have disconnected, we have to drop the remainder of the message. @@ -151,7 +151,7 @@ int zmq::lb_t::sendpipe (msg_t *msg_, pipe_t **pipe_) } // Detach the message from the data buffer. - int rc = msg_->init (); + const int rc = msg_->init (); errno_assert (rc == 0); return 0; diff --git a/src/mailbox_safe.cpp b/src/mailbox_safe.cpp index f5eeedb0..f49fa957 100644 --- a/src/mailbox_safe.cpp +++ b/src/mailbox_safe.cpp @@ -62,7 +62,7 @@ void zmq::mailbox_safe_t::remove_signaler (signaler_t *signaler_) { // TODO: make a copy of array and signal outside the lock const std::vector::iterator end = _signalers.end (); - std::vector::iterator it = + const std::vector::iterator it = std::find (_signalers.begin (), end, signaler_); if (it != end) @@ -106,7 +106,7 @@ int zmq::mailbox_safe_t::recv (command_t *cmd_, int timeout_) _sync->lock (); } else { // Wait for signal from the command sender. - int rc = _cond_var.wait (_sync, timeout_); + const int rc = _cond_var.wait (_sync, timeout_); if (rc == -1) { errno_assert (errno == EAGAIN || errno == EINTR); return -1; diff --git a/src/metadata.cpp b/src/metadata.cpp index ca3cb86e..45a16a60 100644 --- a/src/metadata.cpp +++ b/src/metadata.cpp @@ -36,7 +36,7 @@ zmq::metadata_t::metadata_t (const dict_t &dict_) : _ref_cnt (1), _dict (dict_) const char *zmq::metadata_t::get (const std::string &property_) const { - dict_t::const_iterator it = _dict.find (property_); + const dict_t::const_iterator it = _dict.find (property_); if (it == _dict.end ()) { /** \todo remove this when support for the deprecated name "Identity" is dropped */ if (property_ == "Identity") diff --git a/src/msg.cpp b/src/msg.cpp index 5e9b28a7..0690a4ca 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -294,7 +294,7 @@ int zmq::msg_t::copy (msg_t &src_) return -1; } - int rc = close (); + const int rc = close (); if (unlikely (rc < 0)) return rc; diff --git a/src/msg.hpp b/src/msg.hpp index 8f449365..7673d894 100644 --- a/src/msg.hpp +++ b/src/msg.hpp @@ -289,7 +289,7 @@ class msg_t inline int close_and_return (zmq::msg_t *msg_, int echo_) { // Since we abort on close failure we preserve errno for success case. - int err = errno; + const int err = errno; const int rc = msg_->close (); errno_assert (rc == 0); errno = err; diff --git a/src/object.cpp b/src/object.cpp index 92b74557..97a91ac2 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -68,7 +68,7 @@ zmq::ctx_t *zmq::object_t::get_ctx () return _ctx; } -void zmq::object_t::process_command (command_t &cmd_) +void zmq::object_t::process_command (const command_t &cmd_) { switch (cmd_.type) { case command_t::activate_read: @@ -528,7 +528,7 @@ void zmq::object_t::process_seqnum () zmq_assert (false); } -void zmq::object_t::send_command (command_t &cmd_) +void zmq::object_t::send_command (const command_t &cmd_) { _ctx->send_command (cmd_.destination->get_tid (), cmd_); } diff --git a/src/object.hpp b/src/object.hpp index 304e67c4..19836339 100644 --- a/src/object.hpp +++ b/src/object.hpp @@ -62,7 +62,7 @@ class object_t uint32_t get_tid (); void set_tid (uint32_t id_); ctx_t *get_ctx (); - void process_command (zmq::command_t &cmd_); + void process_command (const zmq::command_t &cmd_); void send_inproc_connected (zmq::socket_base_t *socket_); void send_bind (zmq::own_t *destination_, zmq::pipe_t *pipe_, @@ -157,7 +157,7 @@ class object_t // Thread ID of the thread the object belongs to. uint32_t _tid; - void send_command (command_t &cmd_); + void send_command (const command_t &cmd_); ZMQ_NON_COPYABLE_NOR_MOVABLE (object_t) }; diff --git a/src/options.cpp b/src/options.cpp index 68a039da..28a44294 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -302,7 +302,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, size_t optvallen_) { - bool is_int = (optvallen_ == sizeof (int)); + const bool is_int = (optvallen_ == sizeof (int)); int value = 0; if (is_int) memcpy (&value, optval_, sizeof (int)); @@ -448,7 +448,7 @@ int zmq::options_t::setsockopt (int option_, /* Deprecated in favor of ZMQ_IPV6 */ case ZMQ_IPV4ONLY: { bool value; - int rc = + const int rc = do_setsockopt_int_as_bool_strict (optval_, optvallen_, &value); if (rc == 0) ipv6 = !value; diff --git a/src/pair.cpp b/src/pair.cpp index 05e00599..f3bfe34b 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -97,7 +97,7 @@ int zmq::pair_t::xsend (msg_t *msg_) _pipe->flush (); // Detach the original message from the data buffer. - int rc = msg_->init (); + const int rc = msg_->init (); errno_assert (rc == 0); return 0; diff --git a/src/pipe.cpp b/src/pipe.cpp index ccb1bc58..b183a97c 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -38,10 +38,10 @@ #include "ypipe.hpp" #include "ypipe_conflate.hpp" -int zmq::pipepair (class object_t *parents_[2], - class pipe_t *pipes_[2], - int hwms_[2], - bool conflate_[2]) +int zmq::pipepair (object_t *parents_[2], + pipe_t *pipes_[2], + const int hwms_[2], + const bool conflate_[2]) { // Creates two pipe objects. These objects are connected by two ypipes, // each to pass messages in one direction. @@ -233,7 +233,7 @@ bool zmq::pipe_t::check_write () return true; } -bool zmq::pipe_t::write (msg_t *msg_) +bool zmq::pipe_t::write (const msg_t *msg_) { if (unlikely (!check_write ())) return false; diff --git a/src/pipe.hpp b/src/pipe.hpp index 9453c98c..32b3daca 100644 --- a/src/pipe.hpp +++ b/src/pipe.hpp @@ -54,8 +54,8 @@ class pipe_t; // read (older messages are discarded) int pipepair (zmq::object_t *parents_[2], zmq::pipe_t *pipes_[2], - int hwms_[2], - bool conflate_[2]); + const int hwms_[2], + const bool conflate_[2]); struct i_pipe_events { @@ -79,8 +79,8 @@ class pipe_t ZMQ_FINAL : public object_t, // This allows pipepair to create pipe objects. friend int pipepair (zmq::object_t *parents_[2], zmq::pipe_t *pipes_[2], - int hwms_[2], - bool conflate_[2]); + const int hwms_[2], + const bool conflate_[2]); public: // Specifies the object to send events to. @@ -108,7 +108,7 @@ class pipe_t ZMQ_FINAL : public object_t, // Writes a message to the underlying pipe. Returns false if the // message does not pass check_write. If false, the message object // retains ownership of its message buffer. - bool write (msg_t *msg_); + bool write (const msg_t *msg_); // Remove unfinished parts of the outbound message from the pipe. void rollback () const; diff --git a/src/proxy.cpp b/src/proxy.cpp index 338f52d6..8a517c78 100644 --- a/src/proxy.cpp +++ b/src/proxy.cpp @@ -183,9 +183,9 @@ static int loop_and_send_multipart_stat (zmq::socket_base_t *control_, return rc; } -static int reply_stats (class zmq::socket_base_t *control_, - zmq_socket_stats_t *frontend_stats_, - zmq_socket_stats_t *backend_stats_) +static int reply_stats (zmq::socket_base_t *control_, + const zmq_socket_stats_t *frontend_stats_, + const zmq_socket_stats_t *backend_stats_) { // first part: frontend stats - the first send might fail due to HWM if (loop_and_send_multipart_stat (control_, frontend_stats_->msg_in, true, diff --git a/src/radio.cpp b/src/radio.cpp index 486732ac..ca8dc721 100644 --- a/src/radio.cpp +++ b/src/radio.cpp @@ -157,8 +157,8 @@ int zmq::radio_t::xsend (msg_t *msg_) _dist.unmatch (); - std::pair range = - _subscriptions.equal_range (std::string (msg_->group ())); + const std::pair + range = _subscriptions.equal_range (std::string (msg_->group ())); for (subscriptions_t::iterator it = range.first; it != range.second; ++it) _dist.match (it->second); @@ -262,7 +262,7 @@ int zmq::radio_session_t::pull_msg (msg_t *msg_) return rc; const char *group = _pending_msg.group (); - int length = static_cast (strlen (group)); + const int length = static_cast (strlen (group)); // First frame is the group rc = msg_->init_size (length); diff --git a/src/radix_tree.cpp b/src/radix_tree.cpp index e239a3eb..04374eec 100644 --- a/src/radix_tree.cpp +++ b/src/radix_tree.cpp @@ -155,8 +155,8 @@ bool node_t::operator!= (node_t other_) const void node_t::resize (size_t prefix_length_, size_t edgecount_) { - size_t node_size = 3 * sizeof (uint32_t) + prefix_length_ - + edgecount_ * (1 + sizeof (void *)); + const size_t node_size = 3 * sizeof (uint32_t) + prefix_length_ + + edgecount_ * (1 + sizeof (void *)); unsigned char *new_data = static_cast (realloc (_data, node_size)); zmq_assert (new_data); @@ -167,8 +167,8 @@ void node_t::resize (size_t prefix_length_, size_t edgecount_) node_t make_node (size_t refcount_, size_t prefix_length_, size_t edgecount_) { - size_t node_size = 3 * sizeof (uint32_t) + prefix_length_ - + edgecount_ * (1 + sizeof (void *)); + const size_t node_size = 3 * sizeof (uint32_t) + prefix_length_ + + edgecount_ * (1 + sizeof (void *)); unsigned char *data = static_cast (malloc (node_size)); zmq_assert (data); @@ -285,10 +285,10 @@ match_result_t zmq::radix_tree_t::match (const unsigned char *key_, bool zmq::radix_tree_t::add (const unsigned char *key_, size_t key_size_) { - match_result_t match_result = match (key_, key_size_); - size_t key_bytes_matched = match_result._key_bytes_matched; - size_t prefix_bytes_matched = match_result._prefix_bytes_matched; - size_t edge_index = match_result._edge_index; + const match_result_t match_result = match (key_, key_size_); + const size_t key_bytes_matched = match_result._key_bytes_matched; + const size_t prefix_bytes_matched = match_result._prefix_bytes_matched; + const size_t edge_index = match_result._edge_index; node_t current_node = match_result._current_node; node_t parent_node = match_result._parent_node; @@ -409,11 +409,11 @@ bool zmq::radix_tree_t::add (const unsigned char *key_, size_t key_size_) bool zmq::radix_tree_t::rm (const unsigned char *key_, size_t key_size_) { - match_result_t match_result = match (key_, key_size_); - size_t key_bytes_matched = match_result._key_bytes_matched; - size_t prefix_bytes_matched = match_result._prefix_bytes_matched; - size_t edge_index = match_result._edge_index; - size_t parent_edge_index = match_result._parent_edge_index; + const match_result_t match_result = match (key_, key_size_); + const size_t key_bytes_matched = match_result._key_bytes_matched; + const size_t prefix_bytes_matched = match_result._prefix_bytes_matched; + const size_t edge_index = match_result._edge_index; + const size_t parent_edge_index = match_result._parent_edge_index; node_t current_node = match_result._current_node; node_t parent_node = match_result._parent_node; node_t grandparent_node = match_result._grandparent_node; @@ -432,7 +432,7 @@ bool zmq::radix_tree_t::rm (const unsigned char *key_, size_t key_size_) if (current_node == _root) return true; - size_t outgoing_edges = current_node.edgecount (); + const size_t outgoing_edges = current_node.edgecount (); if (outgoing_edges > 1) // This node can't be merged with any other node, so there's // nothing more to do. @@ -445,7 +445,7 @@ bool zmq::radix_tree_t::rm (const unsigned char *key_, size_t key_size_) // Make room for the child node's prefix and edges. We need to // keep the old prefix length since resize() will overwrite // it. - uint32_t old_prefix_length = current_node.prefix_length (); + const uint32_t old_prefix_length = current_node.prefix_length (); current_node.resize (old_prefix_length + child.prefix_length (), child.edgecount ()); @@ -474,7 +474,7 @@ bool zmq::radix_tree_t::rm (const unsigned char *key_, size_t key_size_) // Make room for the child node's prefix and edges. We need to // keep the old prefix length since resize() will overwrite // it. - uint32_t old_prefix_length = parent_node.prefix_length (); + const uint32_t old_prefix_length = parent_node.prefix_length (); parent_node.resize (old_prefix_length + other_child.prefix_length (), other_child.edgecount ()); @@ -501,9 +501,9 @@ bool zmq::radix_tree_t::rm (const unsigned char *key_, size_t key_size_) // Replace the edge to the current node with the last edge. An // edge consists of a byte and a pointer to the next node. First // replace the byte. - size_t last_index = parent_node.edgecount () - 1; - unsigned char last_byte = parent_node.first_byte_at (last_index); - node_t last_node = parent_node.node_at (last_index); + const size_t last_index = parent_node.edgecount () - 1; + const unsigned char last_byte = parent_node.first_byte_at (last_index); + const node_t last_node = parent_node.node_at (last_index); parent_node.set_edge_at (edge_index, last_byte, last_node); // Move the chunk of pointers one byte to the left, effectively diff --git a/src/random.cpp b/src/random.cpp index 6a2c7e2b..17c3537d 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -49,7 +49,7 @@ void zmq::seed_random () { #if defined ZMQ_HAVE_WINDOWS - int pid = static_cast (GetCurrentProcessId ()); + const int pid = static_cast (GetCurrentProcessId ()); #else int pid = static_cast (getpid ()); #endif @@ -59,7 +59,7 @@ void zmq::seed_random () uint32_t zmq::generate_random () { // Compensate for the fact that rand() returns signed integer. - uint32_t low = static_cast (rand ()); + const uint32_t low = static_cast (rand ()); uint32_t high = static_cast (rand ()); high <<= (sizeof (int) * 8 - 1); return high | low; diff --git a/src/reaper.cpp b/src/reaper.cpp index ee9afb53..525bf578 100644 --- a/src/reaper.cpp +++ b/src/reaper.cpp @@ -93,7 +93,7 @@ void zmq::reaper_t::in_event () // Get the next command. If there is none, exit. command_t cmd; - int rc = _mailbox.recv (&cmd, 0); + const int rc = _mailbox.recv (&cmd, 0); if (rc != 0 && errno == EINTR) continue; if (rc != 0 && errno == EAGAIN) diff --git a/src/rep.cpp b/src/rep.cpp index fe0efed1..99707f89 100644 --- a/src/rep.cpp +++ b/src/rep.cpp @@ -52,10 +52,10 @@ int zmq::rep_t::xsend (msg_t *msg_) return -1; } - bool more = (msg_->flags () & msg_t::more) != 0; + const bool more = (msg_->flags () & msg_t::more) != 0; // Push message to the reply pipe. - int rc = router_t::xsend (msg_); + const int rc = router_t::xsend (msg_); if (rc != 0) return rc; @@ -84,7 +84,7 @@ int zmq::rep_t::xrecv (msg_t *msg_) if ((msg_->flags () & msg_t::more)) { // Empty message part delimits the traceback stack. - bool bottom = (msg_->size () == 0); + const bool bottom = (msg_->size () == 0); // Push it to the reply pipe. rc = router_t::xsend (msg_); @@ -103,7 +103,7 @@ int zmq::rep_t::xrecv (msg_t *msg_) } // Get next message part to return to the user. - int rc = router_t::xrecv (msg_); + const int rc = router_t::xrecv (msg_); if (rc != 0) return rc; diff --git a/src/req.cpp b/src/req.cpp index f82473c1..b9bb35b0 100644 --- a/src/req.cpp +++ b/src/req.cpp @@ -175,7 +175,7 @@ int zmq::req_t::xrecv (msg_t *msg_) _message_begins = false; } - int rc = recv_reply_pipe (msg_); + const int rc = recv_reply_pipe (msg_); if (rc != 0) return rc; @@ -210,7 +210,7 @@ int zmq::req_t::xsetsockopt (int option_, const void *optval_, size_t optvallen_) { - bool is_int = (optvallen_ == sizeof (int)); + const bool is_int = (optvallen_ == sizeof (int)); int value = 0; if (is_int) memcpy (&value, optval_, sizeof (int)); @@ -248,7 +248,7 @@ int zmq::req_t::recv_reply_pipe (msg_t *msg_) { while (true) { pipe_t *pipe = NULL; - int rc = dealer_t::recvpipe (msg_, &pipe); + const int rc = dealer_t::recvpipe (msg_, &pipe); if (rc != 0) return rc; if (!_reply_pipe || pipe == _reply_pipe) diff --git a/src/router.cpp b/src/router.cpp index 2e005691..b6e487dc 100644 --- a/src/router.cpp +++ b/src/router.cpp @@ -90,7 +90,7 @@ void zmq::router_t::xattach_pipe (pipe_t *pipe_, errno_assert (rc == 0); } - bool routing_id_ok = identify_peer (pipe_, locally_initiated_); + const bool routing_id_ok = identify_peer (pipe_, locally_initiated_); if (routing_id_ok) _fq.attach (pipe_); else @@ -171,7 +171,7 @@ void zmq::router_t::xpipe_terminated (pipe_t *pipe_) void zmq::router_t::xread_activated (pipe_t *pipe_) { - std::set::iterator it = _anonymous_pipes.find (pipe_); + const std::set::iterator it = _anonymous_pipes.find (pipe_); if (it == _anonymous_pipes.end ()) _fq.activated (pipe_); else { @@ -209,7 +209,7 @@ int zmq::router_t::xsend (msg_t *msg_) // Check whether pipe is closed or not if (!_current_out->check_write ()) { // Check whether pipe is full or not - bool pipe_full = !_current_out->check_hwm (); + const bool pipe_full = !_current_out->check_hwm (); out_pipe->active = false; _current_out = NULL; @@ -258,10 +258,10 @@ int zmq::router_t::xsend (msg_t *msg_) return 0; } - bool ok = _current_out->write (msg_); + const bool ok = _current_out->write (msg_); if (unlikely (!ok)) { // Message failed to send - we must close it ourselves. - int rc = msg_->close (); + const int rc = msg_->close (); errno_assert (rc == 0); // HWM was checked before, so the pipe must be gone. Roll back // messages that were piped, for example REP labels. @@ -274,12 +274,12 @@ int zmq::router_t::xsend (msg_t *msg_) } } } else { - int rc = msg_->close (); + const int rc = msg_->close (); errno_assert (rc == 0); } // Detach the message from the data buffer. - int rc = msg_->init (); + const int rc = msg_->init (); errno_assert (rc == 0); return 0; @@ -289,11 +289,11 @@ int zmq::router_t::xrecv (msg_t *msg_) { if (_prefetched) { if (!_routing_id_sent) { - int rc = msg_->move (_prefetched_id); + const int rc = msg_->move (_prefetched_id); errno_assert (rc == 0); _routing_id_sent = true; } else { - int rc = msg_->move (_prefetched_msg); + const int rc = msg_->move (_prefetched_msg); errno_assert (rc == 0); _prefetched = false; } @@ -469,7 +469,7 @@ bool zmq::router_t::identify_peer (pipe_t *pipe_, bool locally_initiated_) } else if (!options.raw_socket) { // Pick up handshake cases and also case where next integral routing id is set msg.init (); - bool ok = pipe_->read (&msg); + const bool ok = pipe_->read (&msg); if (!ok) return false; diff --git a/src/server.cpp b/src/server.cpp index 1e16d8f9..7295567b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -64,7 +64,8 @@ void zmq::server_t::xattach_pipe (pipe_t *pipe_, pipe_->set_server_socket_routing_id (routing_id); // Add the record into output pipes lookup table outpipe_t outpipe = {pipe_, true}; - bool ok = _out_pipes.ZMQ_MAP_INSERT_OR_EMPLACE (routing_id, outpipe).second; + const bool ok = + _out_pipes.ZMQ_MAP_INSERT_OR_EMPLACE (routing_id, outpipe).second; zmq_assert (ok); _fq.attach (pipe_); @@ -72,7 +73,7 @@ void zmq::server_t::xattach_pipe (pipe_t *pipe_, void zmq::server_t::xpipe_terminated (pipe_t *pipe_) { - out_pipes_t::iterator it = + const out_pipes_t::iterator it = _out_pipes.find (pipe_->get_server_socket_routing_id ()); zmq_assert (it != _out_pipes.end ()); _out_pipes.erase (it); @@ -105,7 +106,7 @@ int zmq::server_t::xsend (msg_t *msg_) return -1; } // Find the pipe associated with the routing stored in the message. - uint32_t routing_id = msg_->get_routing_id (); + const uint32_t routing_id = msg_->get_routing_id (); out_pipes_t::iterator it = _out_pipes.find (routing_id); if (it != _out_pipes.end ()) { @@ -123,7 +124,7 @@ int zmq::server_t::xsend (msg_t *msg_) int rc = msg_->reset_routing_id (); errno_assert (rc == 0); - bool ok = it->second.pipe->write (msg_); + const bool ok = it->second.pipe->write (msg_); if (unlikely (!ok)) { // Message failed to send - we must close it ourselves. rc = msg_->close (); @@ -161,7 +162,7 @@ int zmq::server_t::xrecv (msg_t *msg_) zmq_assert (pipe != NULL); - uint32_t routing_id = pipe->get_server_socket_routing_id (); + const uint32_t routing_id = pipe->get_server_socket_routing_id (); msg_->set_routing_id (routing_id); return 0; diff --git a/src/session_base.cpp b/src/session_base.cpp index cbd923d8..bc0eb248 100644 --- a/src/session_base.cpp +++ b/src/session_base.cpp @@ -173,7 +173,7 @@ int zmq::session_base_t::push_msg (msg_t *msg_) && !msg_->is_cancel ()) return 0; if (_pipe && _pipe->write (msg_)) { - int rc = msg_->init (); + const int rc = msg_->init (); errno_assert (rc == 0); return 0; } @@ -404,7 +404,7 @@ void zmq::session_base_t::process_attach (i_engine *engine_) int hwms[2] = {conflate ? -1 : options.rcvhwm, conflate ? -1 : options.sndhwm}; bool conflates[2] = {conflate, conflate}; - int rc = pipepair (parents, pipes, hwms, conflates); + const int rc = pipepair (parents, pipes, hwms, conflates); errno_assert (rc == 0); // Plug the local end of the pipe. diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 421e6c5c..ff6a8925 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -123,7 +123,7 @@ int zmq::socket_base_t::inprocs_t::erase_pipes ( return 0; } -void zmq::socket_base_t::inprocs_t::erase_pipe (pipe_t *pipe_) +void zmq::socket_base_t::inprocs_t::erase_pipe (const pipe_t *pipe_) { for (map_t::iterator it = _inprocs.begin (), end = _inprocs.end (); it != end; ++it) @@ -311,7 +311,7 @@ int zmq::socket_base_t::parse_uri (const char *uri_, { zmq_assert (uri_ != NULL); - std::string uri (uri_); + const std::string uri (uri_); const std::string::size_type pos = uri.find ("://"); if (pos == std::string::npos) { errno = EINVAL; @@ -1689,7 +1689,7 @@ void zmq::socket_base_t::pipe_terminated (pipe_t *pipe_) unregister_term_ack (); } -void zmq::socket_base_t::extract_flags (msg_t *msg_) +void zmq::socket_base_t::extract_flags (const msg_t *msg_) { // Test whether routing_id flag is valid for this socket type. if (unlikely (msg_->flags () & msg_t::routing_id)) @@ -1887,7 +1887,7 @@ void zmq::socket_base_t::event (const endpoint_uri_pair_t &endpoint_uri_pair_, // Send a monitor event void zmq::socket_base_t::monitor_event ( uint64_t event_, - uint64_t values_[], + const uint64_t values_[], uint64_t values_count_, const endpoint_uri_pair_t &endpoint_uri_pair_) const { @@ -2067,7 +2067,7 @@ zmq::routing_socket_base_t::lookup_out_pipe (const blob_t &routing_id_) const return it == _out_pipes.end () ? NULL : &it->second; } -void zmq::routing_socket_base_t::erase_out_pipe (pipe_t *pipe_) +void zmq::routing_socket_base_t::erase_out_pipe (const pipe_t *pipe_) { const size_t erased = _out_pipes.erase (pipe_->get_routing_id ()); zmq_assert (erased); diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 64e211d8..784147c9 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -214,7 +214,7 @@ class socket_base_t : public own_t, // Socket event data dispatch void monitor_event (uint64_t event_, - uint64_t values_[], + const uint64_t values_[], uint64_t values_count_, const endpoint_uri_pair_t &endpoint_uri_pair_) const; @@ -237,7 +237,7 @@ class socket_base_t : public own_t, public: void emplace (const char *endpoint_uri_, pipe_t *pipe_); int erase_pipes (const std::string &endpoint_uri_str_); - void erase_pipe (pipe_t *pipe_); + void erase_pipe (const pipe_t *pipe_); private: typedef std::multimap map_t; @@ -251,7 +251,7 @@ class socket_base_t : public own_t, // Moves the flags from the message to local variables, // to be later retrieved by getsockopt. - void extract_flags (msg_t *msg_); + void extract_flags (const msg_t *msg_); // Used to check whether the object is a socket. uint32_t _tag; @@ -371,7 +371,7 @@ class routing_socket_base_t : public socket_base_t bool has_out_pipe (const blob_t &routing_id_) const; out_pipe_t *lookup_out_pipe (const blob_t &routing_id_); const out_pipe_t *lookup_out_pipe (const blob_t &routing_id_) const; - void erase_out_pipe (pipe_t *pipe_); + void erase_out_pipe (const pipe_t *pipe_); out_pipe_t try_erase_out_pipe (const blob_t &routing_id_); template bool any_of_out_pipes (Func func_) { diff --git a/src/socket_poller.cpp b/src/socket_poller.cpp index e558a7e6..81afce5a 100644 --- a/src/socket_poller.cpp +++ b/src/socket_poller.cpp @@ -35,7 +35,7 @@ #include -static bool is_thread_safe (zmq::socket_base_t &socket_) +static bool is_thread_safe (const zmq::socket_base_t &socket_) { // do not use getsockopt here, since that would fail during context termination return socket_.is_thread_safe (); @@ -127,7 +127,7 @@ int zmq::socket_poller_t::add (socket_base_t *socket_, socket_->add_signaler (_signaler); } - item_t item = { + const item_t item = { socket_, 0, user_data_, @@ -159,7 +159,7 @@ int zmq::socket_poller_t::add_fd (fd_t fd_, void *user_data_, short events_) } } - item_t item = { + const item_t item = { NULL, fd_, user_data_, @@ -181,7 +181,7 @@ int zmq::socket_poller_t::add_fd (fd_t fd_, void *user_data_, short events_) return 0; } -int zmq::socket_poller_t::modify (socket_base_t *socket_, short events_) +int zmq::socket_poller_t::modify (const socket_base_t *socket_, short events_) { const items_t::iterator end = _items.end (); items_t::iterator it; @@ -322,7 +322,7 @@ int zmq::socket_poller_t::rebuild () if (it->socket) { if (!is_thread_safe (*it->socket)) { size_t fd_size = sizeof (zmq::fd_t); - int rc = it->socket->getsockopt ( + const int rc = it->socket->getsockopt ( ZMQ_FD, &_pollfds[item_nbr].fd, &fd_size); zmq_assert (rc == 0); @@ -457,7 +457,7 @@ int zmq::socket_poller_t::check_events (zmq::socket_poller_t::event_t *events_, else { #if defined ZMQ_POLL_BASED_ON_POLL - short revents = _pollfds[it->pollfd_index].revents; + const short revents = _pollfds[it->pollfd_index].revents; short events = 0; if (revents & POLLIN) @@ -542,7 +542,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, } if (_need_rebuild) { - int rc = rebuild (); + const int rc = rebuild (); if (rc == -1) return -1; } @@ -596,7 +596,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, static_cast (std::min (end - now, INT_MAX)); // Wait for events. - int rc = poll (_pollfds, _pollset_size, timeout); + const int rc = poll (_pollfds, _pollset_size, timeout); if (rc == -1 && errno == EINTR) { return -1; } @@ -607,7 +607,7 @@ int zmq::socket_poller_t::wait (zmq::socket_poller_t::event_t *events_, _signaler->recv (); // Check for the events. - int found = check_events (events_, n_events_); + const int found = check_events (events_, n_events_); if (found) { if (found > 0) zero_trail_events (events_, n_events_, found); diff --git a/src/socket_poller.hpp b/src/socket_poller.hpp index b3d8f2c0..c850b64a 100644 --- a/src/socket_poller.hpp +++ b/src/socket_poller.hpp @@ -69,7 +69,7 @@ class socket_poller_t } event_t; int add (socket_base_t *socket_, void *user_data_, short events_); - int modify (socket_base_t *socket_, short events_); + int modify (const socket_base_t *socket_, short events_); int remove (socket_base_t *socket_); int add_fd (fd_t fd_, void *user_data_, short events_); diff --git a/src/stream.cpp b/src/stream.cpp index da6768ee..3713c7e7 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -146,17 +146,17 @@ int zmq::stream_t::xsend (msg_t *msg_) _current_out = NULL; return 0; } - bool ok = _current_out->write (msg_); + const bool ok = _current_out->write (msg_); if (likely (ok)) _current_out->flush (); _current_out = NULL; } else { - int rc = msg_->close (); + const int rc = msg_->close (); errno_assert (rc == 0); } // Detach the message from the data buffer. - int rc = msg_->init (); + const int rc = msg_->init (); errno_assert (rc == 0); return 0; @@ -181,11 +181,11 @@ int zmq::stream_t::xrecv (msg_t *msg_) { if (_prefetched) { if (!_routing_id_sent) { - int rc = msg_->move (_prefetched_routing_id); + const int rc = msg_->move (_prefetched_routing_id); errno_assert (rc == 0); _routing_id_sent = true; } else { - int rc = msg_->move (_prefetched_msg); + const int rc = msg_->move (_prefetched_msg); errno_assert (rc == 0); _prefetched = false; } diff --git a/src/stream_engine_base.cpp b/src/stream_engine_base.cpp index f75968e3..68703fde 100644 --- a/src/stream_engine_base.cpp +++ b/src/stream_engine_base.cpp @@ -130,7 +130,7 @@ zmq::stream_engine_base_t::stream_engine_base_t ( _session (NULL), _socket (NULL) { - int rc = _tx_msg.init (); + const int rc = _tx_msg.init (); errno_assert (rc == 0); // Put the socket into non-blocking mode. @@ -143,7 +143,7 @@ zmq::stream_engine_base_t::~stream_engine_base_t () if (_s != retired_fd) { #ifdef ZMQ_HAVE_WINDOWS - int rc = closesocket (_s); + const int rc = closesocket (_s); wsa_assert (rc != SOCKET_ERROR); #else int rc = close (_s); @@ -158,7 +158,7 @@ zmq::stream_engine_base_t::~stream_engine_base_t () _s = retired_fd; } - int rc = _tx_msg.close (); + const int rc = _tx_msg.close (); errno_assert (rc == 0); // Drop reference to metadata and destroy it if we are @@ -275,7 +275,7 @@ bool zmq::stream_engine_base_t::in_event_internal () size_t bufsize = 0; _decoder->get_buffer (&_inpos, &bufsize); - int rc = read (_inpos, bufsize); + const int rc = read (_inpos, bufsize); if (rc == -1) { if (errno != EAGAIN) { @@ -343,7 +343,7 @@ void zmq::stream_engine_base_t::out_event () break; _encoder->load_msg (&_tx_msg); unsigned char *bufptr = _outpos + _outsize; - size_t n = + const size_t n = _encoder->encode (&bufptr, _options.out_batch_size - _outsize); zmq_assert (n > 0); if (_outpos == NULL) @@ -679,7 +679,7 @@ void zmq::stream_engine_base_t::error (error_reason_t reason_) if (reason_ != protocol_error && (_mechanism == NULL || _mechanism->status () == mechanism_t::handshaking)) { - int err = errno; + const int err = errno; _socket->event_handshake_failed_no_detail (_endpoint_uri_pair, err); } @@ -739,7 +739,7 @@ void zmq::stream_engine_base_t::timer_event (int id_) int zmq::stream_engine_base_t::read (void *data_, size_t size_) { - int rc = zmq::tcp_read (_s, data_, size_); + const int rc = zmq::tcp_read (_s, data_, size_); if (rc == 0) { // connection closed by peer diff --git a/src/tcp.cpp b/src/tcp.cpp index 237115db..188e4a47 100644 --- a/src/tcp.cpp +++ b/src/tcp.cpp @@ -60,8 +60,9 @@ int zmq::tune_tcp_socket (fd_t s_) // so using Nagle wouldn't improve throughput in anyway, but it would // hurt latency. int nodelay = 1; - int rc = setsockopt (s_, IPPROTO_TCP, TCP_NODELAY, - reinterpret_cast (&nodelay), sizeof (int)); + const int rc = + setsockopt (s_, IPPROTO_TCP, TCP_NODELAY, + reinterpret_cast (&nodelay), sizeof (int)); assert_success_or_recoverable (s_, rc); if (rc != 0) return rc; @@ -120,9 +121,9 @@ int zmq::tune_tcp_keepalives (fd_t s_, keepalive_opts.keepaliveinterval = keepalive_intvl_ != -1 ? keepalive_intvl_ * 1000 : 1000; DWORD num_bytes_returned; - int rc = WSAIoctl (s_, SIO_KEEPALIVE_VALS, &keepalive_opts, - sizeof (keepalive_opts), NULL, 0, - &num_bytes_returned, NULL, NULL); + const int rc = WSAIoctl (s_, SIO_KEEPALIVE_VALS, &keepalive_opts, + sizeof (keepalive_opts), NULL, 0, + &num_bytes_returned, NULL, NULL); assert_success_or_recoverable (s_, rc); if (rc == SOCKET_ERROR) return rc; @@ -193,7 +194,7 @@ int zmq::tune_tcp_maxrt (fd_t sockfd_, int timeout_) #if defined(ZMQ_HAVE_WINDOWS) && defined(TCP_MAXRT) // msdn says it's supported in >= Vista, >= Windows Server 2003 timeout_ /= 1000; // in seconds - int rc = + const int rc = setsockopt (sockfd_, IPPROTO_TCP, TCP_MAXRT, reinterpret_cast (&timeout_), sizeof (timeout_)); assert_success_or_recoverable (sockfd_, rc); @@ -213,7 +214,7 @@ int zmq::tcp_write (fd_t s_, const void *data_, size_t size_) { #ifdef ZMQ_HAVE_WINDOWS - int nbytes = send (s_, (char *) data_, static_cast (size_), 0); + const int nbytes = send (s_, (char *) data_, static_cast (size_), 0); // If not a single byte can be written to the socket in non-blocking mode // we'll get an error (this may happen during the speculative write). @@ -322,12 +323,12 @@ void zmq::tcp_tune_loopback_fast_path (const fd_t socket_) int sio_loopback_fastpath = 1; DWORD number_of_bytes_returned = 0; - int rc = WSAIoctl (socket_, SIO_LOOPBACK_FAST_PATH, &sio_loopback_fastpath, - sizeof sio_loopback_fastpath, NULL, 0, - &number_of_bytes_returned, 0, 0); + const int rc = WSAIoctl ( + socket_, SIO_LOOPBACK_FAST_PATH, &sio_loopback_fastpath, + sizeof sio_loopback_fastpath, NULL, 0, &number_of_bytes_returned, 0, 0); if (SOCKET_ERROR == rc) { - DWORD last_error = ::WSAGetLastError (); + const DWORD last_error = ::WSAGetLastError (); if (WSAEOPNOTSUPP == last_error) { // This system is not Windows 8 or Server 2012, and the call is not supported. diff --git a/src/tcp_address.cpp b/src/tcp_address.cpp index 23cfb69c..d788f3c4 100644 --- a/src/tcp_address.cpp +++ b/src/tcp_address.cpp @@ -75,7 +75,7 @@ int zmq::tcp_address_t::resolve (const char *name_, bool local_, bool ipv6_) // Test the ';' to know if we have a source address in name_ const char *src_delimiter = strrchr (name_, ';'); if (src_delimiter) { - std::string src_name (name_, src_delimiter - name_); + const std::string src_name (name_, src_delimiter - name_); ip_resolver_options_t src_resolver_opts; diff --git a/src/tcp_listener.cpp b/src/tcp_listener.cpp index 67a923b9..8e07c73d 100644 --- a/src/tcp_listener.cpp +++ b/src/tcp_listener.cpp @@ -68,7 +68,7 @@ zmq::tcp_listener_t::tcp_listener_t (io_thread_t *io_thread_, void zmq::tcp_listener_t::in_event () { - fd_t fd = accept (); + const fd_t fd = accept (); // If connection was reset by the peer in the meantime, just ignore it. // TODO: Handle specific errors like ENFILE/EMFILE etc. @@ -163,7 +163,7 @@ int zmq::tcp_listener_t::create_socket (const char *addr_) return 0; error: - int err = errno; + const int err = errno; close (); errno = err; return -1; @@ -205,7 +205,7 @@ zmq::fd_t zmq::tcp_listener_t::accept () fd_t sock = ::accept4 (_s, reinterpret_cast (&ss), &ss_len, SOCK_CLOEXEC); #else - fd_t sock = + const fd_t sock = ::accept (_s, reinterpret_cast (&ss), &ss_len); #endif @@ -244,7 +244,7 @@ zmq::fd_t zmq::tcp_listener_t::accept () } if (!matched) { #ifdef ZMQ_HAVE_WINDOWS - int rc = closesocket (sock); + const int rc = closesocket (sock); wsa_assert (rc != SOCKET_ERROR); #else int rc = ::close (sock); @@ -256,7 +256,7 @@ zmq::fd_t zmq::tcp_listener_t::accept () if (zmq::set_nosigpipe (sock)) { #ifdef ZMQ_HAVE_WINDOWS - int rc = closesocket (sock); + const int rc = closesocket (sock); wsa_assert (rc != SOCKET_ERROR); #else int rc = ::close (sock); diff --git a/src/thread.cpp b/src/thread.cpp index 22d03a00..c40e3061 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -82,9 +82,9 @@ bool zmq::thread_t::is_current_thread () const void zmq::thread_t::stop () { if (_started) { - DWORD rc = WaitForSingleObject (_descriptor, INFINITE); + const DWORD rc = WaitForSingleObject (_descriptor, INFINITE); win_assert (rc != WAIT_FAILED); - BOOL rc2 = CloseHandle (_descriptor); + const BOOL rc2 = CloseHandle (_descriptor); win_assert (rc2 != 0); } } @@ -154,7 +154,7 @@ void zmq::thread_t:: // push our handler, raise, and finally pop our handler tib->ExceptionList = (_EXCEPTION_REGISTRATION_RECORD *) &rec; - DWORD MS_VC_EXCEPTION = 0x406D1388; + const DWORD MS_VC_EXCEPTION = 0x406D1388; RaiseException (MS_VC_EXCEPTION, 0, sizeof (thread_info) / sizeof (ULONG_PTR), (ULONG_PTR *) &thread_info); diff --git a/src/trie.cpp b/src/trie.cpp index 7331caa8..bd8a8ba3 100644 --- a/src/trie.cpp +++ b/src/trie.cpp @@ -236,7 +236,7 @@ bool zmq::trie_t::rm (unsigned char *prefix_, size_t size_) return ret; } -bool zmq::trie_t::check (unsigned char *data_, size_t size_) +bool zmq::trie_t::check (const unsigned char *data_, size_t size_) { // This function is on critical path. It deliberately doesn't use // recursion to get a bit better performance. diff --git a/src/trie.hpp b/src/trie.hpp index 3fe7764e..65055c6b 100644 --- a/src/trie.hpp +++ b/src/trie.hpp @@ -52,7 +52,7 @@ class trie_t bool rm (unsigned char *prefix_, size_t size_); // Check whether particular key is in the trie. - bool check (unsigned char *data_, size_t size_); + bool check (const unsigned char *data_, size_t size_); // Apply the function supplied to each subscription in the trie. void apply (void (*func_) (unsigned char *data_, size_t size_, void *arg_), diff --git a/src/tweetnacl.c b/src/tweetnacl.c index 5d21c516..6e6f657c 100644 --- a/src/tweetnacl.c +++ b/src/tweetnacl.c @@ -679,7 +679,7 @@ sv scalarmult(gf p[4],gf q[4],const u8 *s) set25519(p[2],gf1); set25519(p[3],gf0); for (i = 255;i >= 0;--i) { - u8 b = (s[i/8]>>(i&7))&1; + const u8 b = (s[i/8]>>(i&7))&1; cswap(p,q,b); add(q,p); add(p,p); diff --git a/src/udp_address.cpp b/src/udp_address.cpp index 96d66c1c..76d4bac4 100644 --- a/src/udp_address.cpp +++ b/src/udp_address.cpp @@ -68,7 +68,7 @@ int zmq::udp_address_t::resolve (const char *name_, bool bind_, bool ipv6_) // URL const char *src_delimiter = strrchr (name_, ';'); if (src_delimiter) { - std::string src_name (name_, src_delimiter - name_); + const std::string src_name (name_, src_delimiter - name_); ip_resolver_options_t src_resolver_opts; @@ -128,13 +128,13 @@ int zmq::udp_address_t::resolve (const char *name_, bool bind_, bool ipv6_) ip_resolver_t resolver (resolver_opts); - int rc = resolver.resolve (&_target_address, name_); + const int rc = resolver.resolve (&_target_address, name_); if (rc != 0) { return -1; } _is_multicast = _target_address.is_multicast (); - uint16_t port = _target_address.port (); + const uint16_t port = _target_address.port (); if (has_interface) { // If we have an interface specifier then the target address must be a diff --git a/src/udp_engine.cpp b/src/udp_engine.cpp index 2f0da1e6..9d90634f 100644 --- a/src/udp_engine.cpp +++ b/src/udp_engine.cpp @@ -73,7 +73,7 @@ zmq::udp_engine_t::~udp_engine_t () if (_fd != retired_fd) { #ifdef ZMQ_HAVE_WINDOWS - int rc = closesocket (_fd); + const int rc = closesocket (_fd); wsa_assert (rc != SOCKET_ERROR); #else int rc = close (_fd); @@ -135,7 +135,7 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) _out_address_len = out->sockaddr_len (); if (out->is_multicast ()) { - bool is_ipv6 = (out->family () == AF_INET6); + const bool is_ipv6 = (out->family () == AF_INET6); rc = rc | set_udp_multicast_loop (_fd, is_ipv6, _options.multicast_loop); @@ -163,7 +163,7 @@ void zmq::udp_engine_t::plug (io_thread_t *io_thread_, session_base_t *session_) ip_addr_t any = ip_addr_t::any (bind_addr->family ()); const ip_addr_t *real_bind_addr; - bool multicast = udp_addr->is_mcast (); + const bool multicast = udp_addr->is_mcast (); if (multicast) { // Multicast addresses should be allowed to bind to more than @@ -236,8 +236,8 @@ int zmq::udp_engine_t::set_udp_multicast_loop (fd_t s_, } int loop = loop_ ? 1 : 0; - int rc = setsockopt (s_, level, optname, reinterpret_cast (&loop), - sizeof (loop)); + const int rc = setsockopt (s_, level, optname, + reinterpret_cast (&loop), sizeof (loop)); assert_success_or_recoverable (s_, rc); return rc; } @@ -252,8 +252,9 @@ int zmq::udp_engine_t::set_udp_multicast_ttl (fd_t s_, bool is_ipv6_, int hops_) level = IPPROTO_IP; } - int rc = setsockopt (s_, level, IP_MULTICAST_TTL, - reinterpret_cast (&hops_), sizeof (hops_)); + const int rc = + setsockopt (s_, level, IP_MULTICAST_TTL, + reinterpret_cast (&hops_), sizeof (hops_)); assert_success_or_recoverable (s_, rc); return rc; } @@ -291,8 +292,8 @@ int zmq::udp_engine_t::set_udp_multicast_iface (fd_t s_, int zmq::udp_engine_t::set_udp_reuse_address (fd_t s_, bool on_) { int on = on_ ? 1 : 0; - int rc = setsockopt (s_, SOL_SOCKET, SO_REUSEADDR, - reinterpret_cast (&on), sizeof (on)); + const int rc = setsockopt (s_, SOL_SOCKET, SO_REUSEADDR, + reinterpret_cast (&on), sizeof (on)); assert_success_or_recoverable (s_, rc); return rc; } @@ -325,7 +326,7 @@ int zmq::udp_engine_t::add_membership (fd_t s_, const udp_address_t *addr_) } else if (mcast_addr->family () == AF_INET6) { struct ipv6_mreq mreq; - int iface = addr_->bind_if (); + const int iface = addr_->bind_if (); zmq_assert (iface >= -1); @@ -360,7 +361,8 @@ void zmq::udp_engine_t::terminate () delete this; } -void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg_, sockaddr_in *addr_) +void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg_, + const sockaddr_in *addr_) { const char *const name = inet_ntoa (addr_->sin_addr); @@ -387,7 +389,7 @@ void zmq::udp_engine_t::sockaddr_to_msg (zmq::msg_t *msg_, sockaddr_in *addr_) *address = 0; } -int zmq::udp_engine_t::resolve_raw_address (char *name_, size_t length_) +int zmq::udp_engine_t::resolve_raw_address (const char *name_, size_t length_) { memset (&_raw_address, 0, sizeof _raw_address); @@ -396,7 +398,7 @@ int zmq::udp_engine_t::resolve_raw_address (char *name_, size_t length_) // Find delimiter, cannot use memrchr as it is not supported on windows if (length_ != 0) { int chars_left = static_cast (length_); - char *current_char = name_ + length_; + const char *current_char = name_ + length_; do { if (*(--current_char) == ':') { delimiter = current_char; @@ -410,11 +412,11 @@ int zmq::udp_engine_t::resolve_raw_address (char *name_, size_t length_) return -1; } - std::string addr_str (name_, delimiter - name_); - std::string port_str (delimiter + 1, name_ + length_ - delimiter - 1); + const std::string addr_str (name_, delimiter - name_); + const std::string port_str (delimiter + 1, name_ + length_ - delimiter - 1); // Parse the port number (0 is not a valid port). - uint16_t port = static_cast (atoi (port_str.c_str ())); + const uint16_t port = static_cast (atoi (port_str.c_str ())); if (port == 0) { errno = EINVAL; return -1; diff --git a/src/udp_engine.hpp b/src/udp_engine.hpp index 084e4dfe..a81da2d5 100644 --- a/src/udp_engine.hpp +++ b/src/udp_engine.hpp @@ -47,8 +47,8 @@ class udp_engine_t ZMQ_FINAL : public io_object_t, public i_engine const endpoint_uri_pair_t &get_endpoint () const ZMQ_FINAL; private: - int resolve_raw_address (char *name_, size_t length_); - void sockaddr_to_msg (zmq::msg_t *msg_, sockaddr_in *addr_); + int resolve_raw_address (const char *name_, size_t length_); + void sockaddr_to_msg (zmq::msg_t *msg_, const sockaddr_in *addr_); int set_udp_reuse_address (fd_t s_, bool on_); int set_udp_reuse_port (fd_t s_, bool on_); diff --git a/src/v1_decoder.cpp b/src/v1_decoder.cpp index 2c8c97a7..e988ed72 100644 --- a/src/v1_decoder.cpp +++ b/src/v1_decoder.cpp @@ -52,7 +52,7 @@ zmq::v1_decoder_t::v1_decoder_t (size_t bufsize_, int64_t maxmsgsize_) : zmq::v1_decoder_t::~v1_decoder_t () { - int rc = _in_progress.close (); + const int rc = _in_progress.close (); errno_assert (rc == 0); } diff --git a/src/v2_decoder.cpp b/src/v2_decoder.cpp index 9e0256db..92e37fce 100644 --- a/src/v2_decoder.cpp +++ b/src/v2_decoder.cpp @@ -55,7 +55,7 @@ zmq::v2_decoder_t::v2_decoder_t (size_t bufsize_, zmq::v2_decoder_t::~v2_decoder_t () { - int rc = _in_progress.close (); + const int rc = _in_progress.close (); errno_assert (rc == 0); } diff --git a/src/ws_connecter.cpp b/src/ws_connecter.cpp index 29b551cc..07083c34 100644 --- a/src/ws_connecter.cpp +++ b/src/ws_connecter.cpp @@ -193,7 +193,7 @@ int zmq::ws_connecter_t::open () #if defined ZMQ_HAVE_VXWORKS int rc = ::connect (_s, (sockaddr *) tcp_addr.addr (), tcp_addr.addrlen ()); #else - int rc = ::connect (_s, tcp_addr.addr (), tcp_addr.addrlen ()); + const int rc = ::connect (_s, tcp_addr.addr (), tcp_addr.addrlen ()); #endif // Connect was successful immediately. if (rc == 0) { diff --git a/src/ws_decoder.cpp b/src/ws_decoder.cpp index 4d5c616d..68c2e955 100644 --- a/src/ws_decoder.cpp +++ b/src/ws_decoder.cpp @@ -59,13 +59,13 @@ zmq::ws_decoder_t::ws_decoder_t (size_t bufsize_, zmq::ws_decoder_t::~ws_decoder_t () { - int rc = _in_progress.close (); + const int rc = _in_progress.close (); errno_assert (rc == 0); } int zmq::ws_decoder_t::opcode_ready (unsigned char const *) { - bool final = (_tmpbuf[0] & 0x80) != 0; // final bit + const bool final = (_tmpbuf[0] & 0x80) != 0; // final bit if (!final) return -1; // non final messages are not supported @@ -96,7 +96,7 @@ int zmq::ws_decoder_t::opcode_ready (unsigned char const *) int zmq::ws_decoder_t::size_first_byte_ready (unsigned char const *read_from_) { - bool is_masked = (_tmpbuf[0] & 0x80) != 0; + const bool is_masked = (_tmpbuf[0] & 0x80) != 0; if (is_masked != _must_mask) // wrong mask value return -1; diff --git a/src/ws_encoder.cpp b/src/ws_encoder.cpp index 4d1e8080..3f1cd1fe 100644 --- a/src/ws_encoder.cpp +++ b/src/ws_encoder.cpp @@ -82,7 +82,7 @@ void zmq::ws_encoder_t::message_ready () } if (_must_mask) { - uint32_t random = generate_random (); + const uint32_t random = generate_random (); put_uint32 (_tmp_buf + offset, random); put_uint32 (_mask, random); offset += 4; @@ -107,7 +107,7 @@ void zmq::ws_encoder_t::size_ready () { if (_must_mask) { assert (in_progress () != &_masked_msg); - size_t size = in_progress ()->size (); + const size_t size = in_progress ()->size (); _masked_msg.close (); _masked_msg.init_size (size); diff --git a/src/ws_engine.cpp b/src/ws_engine.cpp index 38120bf3..b071fcda 100644 --- a/src/ws_engine.cpp +++ b/src/ws_engine.cpp @@ -113,7 +113,7 @@ static void compute_accept_key (char *key_, zmq::ws_engine_t::ws_engine_t (fd_t fd_, const options_t &options_, const endpoint_uri_pair_t &endpoint_uri_pair_, - ws_address_t &address_, + const ws_address_t &address_, bool client_) : stream_engine_base_t (fd_, options_, endpoint_uri_pair_), _client (client_), @@ -203,7 +203,7 @@ void zmq::ws_engine_t::plug_internal () int zmq::ws_engine_t::routing_id_msg (msg_t *msg_) { - int rc = msg_->init_size (_options.routing_id_size); + const int rc = msg_->init_size (_options.routing_id_size); errno_assert (rc == 0); if (_options.routing_id_size > 0) memcpy (msg_->data (), _options.routing_id, _options.routing_id_size); @@ -216,7 +216,7 @@ int zmq::ws_engine_t::process_routing_id_msg (msg_t *msg_) { if (_options.recv_routing_id) { msg_->set_flags (msg_t::routing_id); - int rc = session ()->push_msg (msg_); + const int rc = session ()->push_msg (msg_); errno_assert (rc == 0); } else { int rc = msg_->close (); @@ -230,7 +230,7 @@ int zmq::ws_engine_t::process_routing_id_msg (msg_t *msg_) return 0; } -bool zmq::ws_engine_t::select_protocol (char *protocol_) +bool zmq::ws_engine_t::select_protocol (const char *protocol_) { if (_options.mechanism == ZMQ_NULL && (strcmp ("ZWS2.0", protocol_) == 0)) { _next_msg = static_cast ( @@ -309,7 +309,7 @@ bool zmq::ws_engine_t::handshake () bool zmq::ws_engine_t::server_handshake () { - int nbytes = read (_read_buffer, WS_BUFFER_SIZE); + const int nbytes = read (_read_buffer, WS_BUFFER_SIZE); if (nbytes == -1) { if (errno != EAGAIN) error (zmq::i_engine::connection_error); @@ -320,7 +320,7 @@ bool zmq::ws_engine_t::server_handshake () _insize = nbytes; while (_insize > 0) { - char c = static_cast (*_inpos); + const char c = static_cast (*_inpos); switch (_server_handshake_state) { case handshake_initial: @@ -529,13 +529,13 @@ bool zmq::ws_engine_t::server_handshake () unsigned char hash[SHA_DIGEST_LENGTH]; compute_accept_key (_websocket_key, hash); - int accept_key_len = encode_base64 ( + const int accept_key_len = encode_base64 ( hash, SHA_DIGEST_LENGTH, _websocket_accept, MAX_HEADER_VALUE_LENGTH); assert (accept_key_len > 0); _websocket_accept[accept_key_len] = '\0'; - int written = + const int written = snprintf (reinterpret_cast (_write_buffer), WS_BUFFER_SIZE, "HTTP/1.1 101 Switching Protocols\r\n" @@ -580,7 +580,7 @@ bool zmq::ws_engine_t::server_handshake () bool zmq::ws_engine_t::client_handshake () { - int nbytes = read (_read_buffer, WS_BUFFER_SIZE); + const int nbytes = read (_read_buffer, WS_BUFFER_SIZE); if (nbytes == -1) { if (errno != EAGAIN) error (zmq::i_engine::connection_error); @@ -591,7 +591,7 @@ bool zmq::ws_engine_t::client_handshake () _insize = nbytes; while (_insize > 0) { - char c = static_cast (*_inpos); + const char c = static_cast (*_inpos); switch (_client_handshake_state) { case client_handshake_initial: diff --git a/src/ws_engine.hpp b/src/ws_engine.hpp index f573e675..5fceabdf 100644 --- a/src/ws_engine.hpp +++ b/src/ws_engine.hpp @@ -130,7 +130,7 @@ class ws_engine_t ZMQ_FINAL : public stream_engine_base_t ws_engine_t (fd_t fd_, const options_t &options_, const endpoint_uri_pair_t &endpoint_uri_pair_, - ws_address_t &address_, + const ws_address_t &address_, bool client_); ~ws_engine_t () ZMQ_FINAL; @@ -150,7 +150,7 @@ class ws_engine_t ZMQ_FINAL : public stream_engine_base_t int produce_no_msg_after_close (msg_t *msg_); int close_connection_after_close (msg_t *msg_); - bool select_protocol (char *protocol); + bool select_protocol (const char *protocol); bool client_handshake (); bool server_handshake (); diff --git a/src/ws_listener.cpp b/src/ws_listener.cpp index e518d435..c8380818 100644 --- a/src/ws_listener.cpp +++ b/src/ws_listener.cpp @@ -99,7 +99,7 @@ zmq::ws_listener_t::~ws_listener_t () void zmq::ws_listener_t::in_event () { - fd_t fd = accept (); + const fd_t fd = accept (); // If connection was reset by the peer in the meantime, just ignore it. // TODO: Handle specific errors like ENFILE/EMFILE etc. @@ -193,7 +193,7 @@ int zmq::ws_listener_t::create_socket (const char *addr_) return 0; error: - int err = errno; + const int err = errno; close (); errno = err; return -1; @@ -206,7 +206,7 @@ int zmq::ws_listener_t::set_local_address (const char *addr_) // socket was already created by the application _s = options.use_fd; } else { - int rc = _address.resolve (addr_, true, options.ipv6); + const int rc = _address.resolve (addr_, true, options.ipv6); if (rc != 0) return -1; @@ -248,7 +248,7 @@ zmq::fd_t zmq::ws_listener_t::accept () fd_t sock = ::accept4 (_s, reinterpret_cast (&ss), &ss_len, SOCK_CLOEXEC); #else - fd_t sock = + const fd_t sock = ::accept (_s, reinterpret_cast (&ss), &ss_len); #endif @@ -275,7 +275,7 @@ zmq::fd_t zmq::ws_listener_t::accept () if (zmq::set_nosigpipe (sock)) { #ifdef ZMQ_HAVE_WINDOWS - int rc = closesocket (sock); + const int rc = closesocket (sock); wsa_assert (rc != SOCKET_ERROR); #else int rc = ::close (sock); diff --git a/src/xpub.cpp b/src/xpub.cpp index 089a9c12..0c81b413 100644 --- a/src/xpub.cpp +++ b/src/xpub.cpp @@ -79,9 +79,9 @@ void zmq::xpub_t::xattach_pipe (pipe_t *pipe_, if (_welcome_msg.size () > 0) { msg_t copy; copy.init (); - int rc = copy.copy (_welcome_msg); + const int rc = copy.copy (_welcome_msg); errno_assert (rc == 0); - bool ok = pipe_->write (©); + const bool ok = pipe_->write (©); zmq_assert (ok); pipe_->flush (); } @@ -103,7 +103,7 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_) bool subscribe = false; bool is_subscribe_or_cancel = false; - bool first_part = !_more_recv; + const bool first_part = !_more_recv; _more_recv = (msg.flags () & msg_t::more) != 0; if (first_part || _process_subscribe) { @@ -164,12 +164,12 @@ void zmq::xpub_t::xread_activated (pipe_t *pipe_) } else { bool notify; if (!subscribe) { - mtrie_t::rm_result rm_result = + const mtrie_t::rm_result rm_result = _subscriptions.rm (data, size, pipe_); // TODO reconsider what to do if rm_result == mtrie_t::not_found notify = rm_result != mtrie_t::values_remain || _verbose_unsubs; } else { - bool first_added = _subscriptions.add (data, size, pipe_); + const bool first_added = _subscriptions.add (data, size, pipe_); notify = first_added || _verbose_subs; } @@ -239,7 +239,7 @@ int zmq::xpub_t::xsetsockopt (int option_, _welcome_msg.close (); if (optvallen_ > 0) { - int rc = _welcome_msg.init_size (optvallen_); + const int rc = _welcome_msg.init_size (optvallen_); errno_assert (rc == 0); unsigned char *data = @@ -294,7 +294,7 @@ void zmq::xpub_t::mark_last_pipe_as_matching (pipe_t *pipe_, xpub_t *self_) int zmq::xpub_t::xsend (msg_t *msg_) { - bool msg_more = (msg_->flags () & msg_t::more) != 0; + const bool msg_more = (msg_->flags () & msg_t::more) != 0; // For the first part of multi-part message, find the matching pipes. if (!_more_send) { diff --git a/src/xsub.cpp b/src/xsub.cpp index dee9b7a5..404b7a89 100644 --- a/src/xsub.cpp +++ b/src/xsub.cpp @@ -48,13 +48,13 @@ zmq::xsub_t::xsub_t (class ctx_t *parent_, uint32_t tid_, int sid_) : // subscription commands are sent to the wire. options.linger.store (0); - int rc = _message.init (); + const int rc = _message.init (); errno_assert (rc == 0); } zmq::xsub_t::~xsub_t () { - int rc = _message.close (); + const int rc = _message.close (); errno_assert (rc == 0); } @@ -119,7 +119,7 @@ int zmq::xsub_t::xsend (msg_t *msg_) size_t size = msg_->size (); unsigned char *data = static_cast (msg_->data ()); - bool first_part = !_more_send; + const bool first_part = !_more_send; _more_send = (msg_->flags () & msg_t::more) != 0; if (first_part) { @@ -181,7 +181,7 @@ int zmq::xsub_t::xrecv (msg_t *msg_) // If there's already a message prepared by a previous call to zmq_poll, // return it straight ahead. if (_has_message) { - int rc = msg_->move (_message); + const int rc = msg_->move (_message); errno_assert (rc == 0); _has_message = false; _more_recv = (msg_->flags () & msg_t::more) != 0; @@ -257,7 +257,7 @@ bool zmq::xsub_t::xhas_in () bool zmq::xsub_t::match (msg_t *msg_) { - bool matching = _subscriptions.check ( + const bool matching = _subscriptions.check ( static_cast (msg_->data ()), msg_->size ()); return matching ^ options.invert_matching; @@ -271,7 +271,7 @@ void zmq::xsub_t::send_subscription (unsigned char *data_, // Create the subscription message. msg_t msg; - int rc = msg.init_size (size_ + 1); + const int rc = msg.init_size (size_ + 1); errno_assert (rc == 0); unsigned char *data = static_cast (msg.data ()); data[0] = 1; @@ -283,7 +283,7 @@ void zmq::xsub_t::send_subscription (unsigned char *data_, } // Send it to the pipe. - bool sent = pipe->write (&msg); + const bool sent = pipe->write (&msg); // If we reached the SNDHWM, and thus cannot send the subscription, drop // the subscription message instead. This matches the behaviour of // zmq_setsockopt(ZMQ_SUBSCRIBE, ...), which also drops subscriptions diff --git a/src/ypipe.hpp b/src/ypipe.hpp index d730b467..90af2a37 100644 --- a/src/ypipe.hpp +++ b/src/ypipe.hpp @@ -168,7 +168,7 @@ template class ypipe_t ZMQ_FINAL : public ypipe_base_t // The pipe mustn't be empty or the function crashes. inline bool probe (bool (*fn_) (const T &)) ZMQ_FINAL { - bool rc = check_read (); + const bool rc = check_read (); zmq_assert (rc); return (*fn_) (_queue.front ()); diff --git a/src/ypipe_conflate.hpp b/src/ypipe_conflate.hpp index fe010d72..693e21f4 100644 --- a/src/ypipe_conflate.hpp +++ b/src/ypipe_conflate.hpp @@ -80,7 +80,7 @@ template class ypipe_conflate_t ZMQ_FINAL : public ypipe_base_t // Check whether item is available for reading. inline bool check_read () ZMQ_FINAL { - bool res = dbuffer.check_read (); + const bool res = dbuffer.check_read (); if (!res) reader_awake = false; diff --git a/src/zmq.cpp b/src/zmq.cpp index 21895c10..76a7c649 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -153,8 +153,8 @@ int zmq_ctx_term (void *ctx_) return -1; } - int rc = (static_cast (ctx_))->terminate (); - int en = errno; + const int rc = (static_cast (ctx_))->terminate (); + const int en = errno; // Shut down only if termination was not interrupted by a signal. if (!rc || en != EINTR) { @@ -358,7 +358,7 @@ static inline int s_sendmsg (zmq::socket_base_t *s_, zmq_msg_t *msg_, int flags_) { size_t sz = zmq_msg_size (msg_); - int rc = s_->send (reinterpret_cast (msg_), flags_); + const int rc = s_->send (reinterpret_cast (msg_), flags_); if (unlikely (rc < 0)) return -1; @@ -390,10 +390,10 @@ int zmq_send (void *s_, const void *buf_, size_t len_, int flags_) assert (buf_); memcpy (zmq_msg_data (&msg), buf_, len_); } - int rc = s_sendmsg (s, &msg, flags_); + const int rc = s_sendmsg (s, &msg, flags_); if (unlikely (rc < 0)) { - int err = errno; - int rc2 = zmq_msg_close (&msg); + const int err = errno; + const int rc2 = zmq_msg_close (&msg); errno_assert (rc2 == 0); errno = err; return -1; @@ -416,8 +416,8 @@ int zmq_send_const (void *s_, const void *buf_, size_t len_, int flags_) rc = s_sendmsg (s, &msg, flags_); if (unlikely (rc < 0)) { - int err = errno; - int rc2 = zmq_msg_close (&msg); + const int err = errno; + const int rc2 = zmq_msg_close (&msg); errno_assert (rc2 == 0); errno = err; return -1; @@ -459,8 +459,8 @@ int zmq_sendiov (void *s_, iovec *a_, size_t count_, int flags_) flags_ = flags_ & ~ZMQ_SNDMORE; rc = s_sendmsg (s, &msg, flags_); if (unlikely (rc < 0)) { - int err = errno; - int rc2 = zmq_msg_close (&msg); + const int err = errno; + const int rc2 = zmq_msg_close (&msg); errno_assert (rc2 == 0); errno = err; rc = -1; @@ -474,12 +474,12 @@ int zmq_sendiov (void *s_, iovec *a_, size_t count_, int flags_) static int s_recvmsg (zmq::socket_base_t *s_, zmq_msg_t *msg_, int flags_) { - int rc = s_->recv (reinterpret_cast (msg_), flags_); + const int rc = s_->recv (reinterpret_cast (msg_), flags_); if (unlikely (rc < 0)) return -1; // Truncate returned size to INT_MAX to avoid overflow to negative values - size_t sz = zmq_msg_size (msg_); + const size_t sz = zmq_msg_size (msg_); return static_cast (sz < INT_MAX ? sz : INT_MAX); } @@ -499,9 +499,9 @@ int zmq_recv (void *s_, void *buf_, size_t len_, int flags_) int rc = zmq_msg_init (&msg); errno_assert (rc == 0); - int nbytes = s_recvmsg (s, &msg, flags_); + const int nbytes = s_recvmsg (s, &msg, flags_); if (unlikely (nbytes < 0)) { - int err = errno; + const int err = errno; rc = zmq_msg_close (&msg); errno_assert (rc == 0); errno = err; @@ -509,7 +509,7 @@ int zmq_recv (void *s_, void *buf_, size_t len_, int flags_) } // An oversized message is silently truncated. - size_t to_copy = size_t (nbytes) < len_ ? size_t (nbytes) : len_; + const size_t to_copy = size_t (nbytes) < len_ ? size_t (nbytes) : len_; // We explicitly allow a null buffer argument if len is zero if (to_copy) { @@ -548,7 +548,7 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_) return -1; } - size_t count = *count_; + const size_t count = *count_; int nread = 0; bool recvmore = true; @@ -559,9 +559,9 @@ int zmq_recviov (void *s_, iovec *a_, size_t *count_, int flags_) int rc = zmq_msg_init (&msg); errno_assert (rc == 0); - int nbytes = s_recvmsg (s, &msg, flags_); + const int nbytes = s_recvmsg (s, &msg, flags_); if (unlikely (nbytes < 0)) { - int err = errno; + const int err = errno; rc = zmq_msg_close (&msg); errno_assert (rc == 0); errno = err; @@ -949,12 +949,12 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_) #if defined ZMQ_POLL_BASED_ON_POLL // Compute the timeout for the subsequent poll. - zmq::timeout_t timeout = + const zmq::timeout_t timeout = zmq::compute_timeout (first_pass, timeout_, now, end); // Wait for events. { - int rc = poll (&pollfds[0], nitems_, timeout); + const int rc = poll (&pollfds[0], nitems_, timeout); if (rc == -1 && errno == EINTR) { return -1; } @@ -1263,7 +1263,7 @@ int zmq_poller_remove_fd (void *poller_, zmq::fd_t fd_) int zmq_poller_wait (void *poller_, zmq_poller_event_t *event_, long timeout_) { - int rc = zmq_poller_wait_all (poller_, event_, 1, timeout_); + const int rc = zmq_poller_wait_all (poller_, event_, 1, timeout_); if (rc < 0 && event_) { // TODO this is not portable... zmq_poller_event_t contains pointers, @@ -1291,7 +1291,7 @@ int zmq_poller_wait_all (void *poller_, return -1; } - int rc = + const int rc = (static_cast (poller_)) ->wait (reinterpret_cast (events_), n_events_, timeout_); diff --git a/src/zmq_utils.cpp b/src/zmq_utils.cpp index b2ac669a..74cad47e 100644 --- a/src/zmq_utils.cpp +++ b/src/zmq_utils.cpp @@ -68,14 +68,14 @@ void *zmq_stopwatch_start () unsigned long zmq_stopwatch_intermediate (void *watch_) { - uint64_t end = zmq::clock_t::now_us (); - uint64_t start = *static_cast (watch_); + const uint64_t end = zmq::clock_t::now_us (); + const uint64_t start = *static_cast (watch_); return static_cast (end - start); } unsigned long zmq_stopwatch_stop (void *watch_) { - unsigned long res = zmq_stopwatch_intermediate (watch_); + const unsigned long res = zmq_stopwatch_intermediate (watch_); free (watch_); return res; } @@ -173,12 +173,12 @@ uint8_t *zmq_z85_decode (uint8_t *dest_, const char *string_) goto error_inval; } value *= 85; - uint8_t index = string_[char_nbr++] - 32; + const uint8_t index = string_[char_nbr++] - 32; if (index >= sizeof (decoder)) { // Invalid z85 encoding, character outside range goto error_inval; } - uint32_t summand = decoder[index]; + const uint32_t summand = decoder[index]; if (summand == 0xFF || summand > (UINT32_MAX - value)) { // Invalid z85 encoding, invalid character or represented value exceeds 0xffffffff goto error_inval; @@ -223,7 +223,7 @@ int zmq_curve_keypair (char *z85_public_key_, char *z85_secret_key_) zmq::random_open (); - int res = crypto_box_keypair (public_key, secret_key); + const int res = crypto_box_keypair (public_key, secret_key); zmq_z85_encode (z85_public_key_, public_key, 32); zmq_z85_encode (z85_secret_key_, secret_key, 32); diff --git a/src/zmtp_engine.cpp b/src/zmtp_engine.cpp index 7892038e..9b452002 100644 --- a/src/zmtp_engine.cpp +++ b/src/zmtp_engine.cpp @@ -92,7 +92,7 @@ zmq::zmtp_engine_t::zmtp_engine_t ( zmq::zmtp_engine_t::~zmtp_engine_t () { - int rc = _routing_id_msg.close (); + const int rc = _routing_id_msg.close (); errno_assert (rc == 0); } @@ -410,7 +410,7 @@ bool zmq::zmtp_engine_t::handshake_v3_0 () int zmq::zmtp_engine_t::routing_id_msg (msg_t *msg_) { - int rc = msg_->init_size (_options.routing_id_size); + const int rc = msg_->init_size (_options.routing_id_size); errno_assert (rc == 0); if (_options.routing_id_size > 0) memcpy (msg_->data (), _options.routing_id, _options.routing_id_size); @@ -422,7 +422,7 @@ int zmq::zmtp_engine_t::process_routing_id_msg (msg_t *msg_) { if (_options.recv_routing_id) { msg_->set_flags (msg_t::routing_id); - int rc = session ()->push_msg (msg_); + const int rc = session ()->push_msg (msg_); errno_assert (rc == 0); } else { int rc = msg_->close (); From 78961eeab7c7762f0c27248a7099d52a87cad576 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 25 Dec 2019 15:51:26 +0100 Subject: [PATCH 5/6] Problem: non-modifying member functions not marked as const/static Solution: add const/static --- src/array.hpp | 4 ++-- src/ctx.cpp | 4 ++-- src/ctx.hpp | 7 ++++--- src/curve_client_tools.hpp | 2 +- src/dist.hpp | 2 +- src/io_thread.cpp | 4 ++-- src/io_thread.hpp | 4 ++-- src/mechanism.cpp | 2 +- src/mechanism.hpp | 9 ++++++--- src/mechanism_base.cpp | 2 +- src/mechanism_base.hpp | 2 +- src/msg.cpp | 4 ++-- src/msg.hpp | 4 ++-- src/object.cpp | 8 ++++---- src/object.hpp | 8 ++++---- src/own.cpp | 2 +- src/own.hpp | 2 +- src/plain_server.cpp | 2 +- src/plain_server.hpp | 2 +- src/poller_base.cpp | 2 +- src/poller_base.hpp | 2 +- src/session_base.cpp | 4 ++-- src/session_base.hpp | 4 ++-- src/signaler.cpp | 2 +- src/signaler.hpp | 2 +- src/socket_poller.cpp | 4 ++-- src/socket_poller.hpp | 22 +++++++++++----------- src/socks_connecter.cpp | 2 +- src/socks_connecter.hpp | 14 +++++++------- src/timers.cpp | 2 +- src/timers.hpp | 2 +- src/udp_engine.hpp | 10 +++++----- src/yqueue.hpp | 2 +- 33 files changed, 76 insertions(+), 72 deletions(-) diff --git a/src/array.hpp b/src/array.hpp index b141a082..4e4869e7 100644 --- a/src/array.hpp +++ b/src/array.hpp @@ -61,7 +61,7 @@ template class array_item_t inline void set_array_index (int index_) { _array_index = index_; } - inline int get_array_index () { return _array_index; } + inline int get_array_index () const { return _array_index; } private: int _array_index; @@ -118,7 +118,7 @@ template class array_t inline void clear () { _items.clear (); } - inline size_type index (T *item_) + static inline size_type index (T *item_) { return (size_type) ((item_t *) item_)->get_array_index (); } diff --git a/src/ctx.cpp b/src/ctx.cpp index b4185f3f..56fbd4ae 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -105,7 +105,7 @@ zmq::ctx_t::ctx_t () : #endif } -bool zmq::ctx_t::check_tag () +bool zmq::ctx_t::check_tag () const { return _tag == ZMQ_CTX_TAG_VALUE_GOOD; } @@ -534,7 +534,7 @@ void zmq::ctx_t::destroy_socket (class socket_base_t *socket_) _reaper->stop (); } -zmq::object_t *zmq::ctx_t::get_reaper () +zmq::object_t *zmq::ctx_t::get_reaper () const { return _reaper; } diff --git a/src/ctx.hpp b/src/ctx.hpp index e1315c6f..0ccd68fa 100644 --- a/src/ctx.hpp +++ b/src/ctx.hpp @@ -97,7 +97,7 @@ class ctx_t ZMQ_FINAL : public thread_ctx_t ctx_t (); // Returns false if object is not a context. - bool check_tag (); + bool check_tag () const; // This function is called when user invokes zmq_ctx_term. If there are // no more sockets open it'll cause all the infrastructure to be shut @@ -132,7 +132,7 @@ class ctx_t ZMQ_FINAL : public thread_ctx_t zmq::io_thread_t *choose_io_thread (uint64_t affinity_); // Returns reaper thread object. - zmq::object_t *get_reaper (); + zmq::object_t *get_reaper () const; // Management of inproc endpoints. int register_endpoint (const char *addr_, const endpoint_t &endpoint_); @@ -253,7 +253,8 @@ class ctx_t ZMQ_FINAL : public thread_ctx_t connect_side, bind_side }; - void + + static void connect_inproc_sockets (zmq::socket_base_t *bind_socket_, const options_t &bind_options_, const pending_connection_t &pending_connection_, diff --git a/src/curve_client_tools.hpp b/src/curve_client_tools.hpp index 4ee12570..f047b379 100644 --- a/src/curve_client_tools.hpp +++ b/src/curve_client_tools.hpp @@ -268,7 +268,7 @@ struct curve_client_tools_t size_t size_, const uint64_t cn_nonce_, const uint8_t *metadata_plaintext_, - const size_t metadata_length_) + const size_t metadata_length_) const { return produce_initiate (data_, size_, cn_nonce_, server_key, public_key, secret_key, cn_public, cn_secret, diff --git a/src/dist.hpp b/src/dist.hpp index 15691ab5..f772a716 100644 --- a/src/dist.hpp +++ b/src/dist.hpp @@ -73,7 +73,7 @@ class dist_t // Send the message to all the outbound pipes. int send_to_all (zmq::msg_t *msg_); - bool has_out (); + static bool has_out (); // check HWM of all pipes matching bool check_hwm (); diff --git a/src/io_thread.cpp b/src/io_thread.cpp index a95fa274..a2ca950a 100644 --- a/src/io_thread.cpp +++ b/src/io_thread.cpp @@ -73,7 +73,7 @@ zmq::mailbox_t *zmq::io_thread_t::get_mailbox () return &_mailbox; } -int zmq::io_thread_t::get_load () +int zmq::io_thread_t::get_load () const { return _poller->get_load (); } @@ -107,7 +107,7 @@ void zmq::io_thread_t::timer_event (int) zmq_assert (false); } -zmq::poller_t *zmq::io_thread_t::get_poller () +zmq::poller_t *zmq::io_thread_t::get_poller () const { zmq_assert (_poller); return _poller; diff --git a/src/io_thread.hpp b/src/io_thread.hpp index 98552e15..e06c0252 100644 --- a/src/io_thread.hpp +++ b/src/io_thread.hpp @@ -67,13 +67,13 @@ class io_thread_t ZMQ_FINAL : public object_t, public i_poll_events void timer_event (int id_) ZMQ_FINAL; // Used by io_objects to retrieve the associated poller object. - poller_t *get_poller (); + poller_t *get_poller () const; // Command handlers. void process_stop () ZMQ_FINAL; // Returns load experienced by the I/O thread. - int get_load (); + int get_load () const; private: // I/O thread accesses incoming commands via this mailbox. diff --git a/src/mechanism.cpp b/src/mechanism.cpp index ad5959bc..7bac643b 100644 --- a/src/mechanism.cpp +++ b/src/mechanism.cpp @@ -95,7 +95,7 @@ const char socket_type_scatter[] = "SCATTER"; const char socket_type_dgram[] = "DGRAM"; #endif -const char *zmq::mechanism_t::socket_type_string (int socket_type_) const +const char *zmq::mechanism_t::socket_type_string (int socket_type_) { // TODO the order must of the names must correspond to the values resp. order of ZMQ_* socket type definitions in zmq.h! static const char *names[] = { diff --git a/src/mechanism.hpp b/src/mechanism.hpp index edd58a8f..13f0ffbe 100644 --- a/src/mechanism.hpp +++ b/src/mechanism.hpp @@ -81,17 +81,20 @@ class mechanism_t const blob_t &get_user_id () const; - const metadata_t::dict_t &get_zmtp_properties () + const metadata_t::dict_t &get_zmtp_properties () const { return _zmtp_properties; } - const metadata_t::dict_t &get_zap_properties () { return _zap_properties; } + const metadata_t::dict_t &get_zap_properties () const + { + return _zap_properties; + } protected: // Only used to identify the socket for the Socket-Type // property in the wire protocol. - const char *socket_type_string (int socket_type_) const; + static const char *socket_type_string (int socket_type_); static size_t add_property (unsigned char *ptr_, size_t ptr_capacity_, diff --git a/src/mechanism_base.cpp b/src/mechanism_base.cpp index 325af77b..d51b3695 100644 --- a/src/mechanism_base.cpp +++ b/src/mechanism_base.cpp @@ -39,7 +39,7 @@ zmq::mechanism_base_t::mechanism_base_t (session_base_t *const session_, { } -int zmq::mechanism_base_t::check_basic_command_structure (msg_t *msg_) +int zmq::mechanism_base_t::check_basic_command_structure (msg_t *msg_) const { if (msg_->size () <= 1 || msg_->size () <= (static_cast (msg_->data ()))[0]) { diff --git a/src/mechanism_base.hpp b/src/mechanism_base.hpp index 11422c5e..454f8e8d 100644 --- a/src/mechanism_base.hpp +++ b/src/mechanism_base.hpp @@ -44,7 +44,7 @@ class mechanism_base_t : public mechanism_t session_base_t *const session; - int check_basic_command_structure (msg_t *msg_); + int check_basic_command_structure (msg_t *msg_) const; void handle_error_reason (const char *error_reason_, size_t error_reason_len_); diff --git a/src/msg.cpp b/src/msg.cpp index 0690a4ca..7822a548 100644 --- a/src/msg.cpp +++ b/src/msg.cpp @@ -553,7 +553,7 @@ bool zmq::msg_t::rm_refs (int refs_) return true; } -uint32_t zmq::msg_t::get_routing_id () +uint32_t zmq::msg_t::get_routing_id () const { return _u.base.routing_id; } @@ -574,7 +574,7 @@ int zmq::msg_t::reset_routing_id () return 0; } -const char *zmq::msg_t::group () +const char *zmq::msg_t::group () const { return _u.base.group; } diff --git a/src/msg.hpp b/src/msg.hpp index 7673d894..a75be068 100644 --- a/src/msg.hpp +++ b/src/msg.hpp @@ -146,10 +146,10 @@ class msg_t bool is_cmsg () const; bool is_lmsg () const; bool is_zcmsg () const; - uint32_t get_routing_id (); + uint32_t get_routing_id () const; int set_routing_id (uint32_t routing_id_); int reset_routing_id (); - const char *group (); + const char *group () const; int set_group (const char *group_); int set_group (const char *, size_t length_); diff --git a/src/object.cpp b/src/object.cpp index 97a91ac2..6b829cf2 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -53,7 +53,7 @@ zmq::object_t::~object_t () { } -uint32_t zmq::object_t::get_tid () +uint32_t zmq::object_t::get_tid () const { return _tid; } @@ -63,7 +63,7 @@ void zmq::object_t::set_tid (uint32_t id_) _tid = id_; } -zmq::ctx_t *zmq::object_t::get_ctx () +zmq::ctx_t *zmq::object_t::get_ctx () const { return _ctx; } @@ -184,7 +184,7 @@ void zmq::object_t::unregister_endpoints (socket_base_t *socket_) return _ctx->unregister_endpoints (socket_); } -zmq::endpoint_t zmq::object_t::find_endpoint (const char *addr_) +zmq::endpoint_t zmq::object_t::find_endpoint (const char *addr_) const { return _ctx->find_endpoint (addr_); } @@ -207,7 +207,7 @@ void zmq::object_t::destroy_socket (socket_base_t *socket_) _ctx->destroy_socket (socket_); } -zmq::io_thread_t *zmq::object_t::choose_io_thread (uint64_t affinity_) +zmq::io_thread_t *zmq::object_t::choose_io_thread (uint64_t affinity_) const { return _ctx->choose_io_thread (affinity_); } diff --git a/src/object.hpp b/src/object.hpp index 19836339..dc1566bd 100644 --- a/src/object.hpp +++ b/src/object.hpp @@ -59,9 +59,9 @@ class object_t object_t (object_t *parent_); virtual ~object_t (); - uint32_t get_tid (); + uint32_t get_tid () const; void set_tid (uint32_t id_); - ctx_t *get_ctx (); + ctx_t *get_ctx () const; void process_command (const zmq::command_t &cmd_); void send_inproc_connected (zmq::socket_base_t *socket_); void send_bind (zmq::own_t *destination_, @@ -74,7 +74,7 @@ class object_t int register_endpoint (const char *addr_, const zmq::endpoint_t &endpoint_); int unregister_endpoint (const std::string &addr_, socket_base_t *socket_); void unregister_endpoints (zmq::socket_base_t *socket_); - zmq::endpoint_t find_endpoint (const char *addr_); + zmq::endpoint_t find_endpoint (const char *addr_) const; void pend_connection (const std::string &addr_, const endpoint_t &endpoint_, pipe_t **pipes_); @@ -86,7 +86,7 @@ class object_t void log (const char *format_, ...); // Chooses least loaded I/O thread. - zmq::io_thread_t *choose_io_thread (uint64_t affinity_); + zmq::io_thread_t *choose_io_thread (uint64_t affinity_) const; // Derived object can use these functions to send commands // to other objects. diff --git a/src/own.cpp b/src/own.cpp index 7588dd07..f74824bb 100644 --- a/src/own.cpp +++ b/src/own.cpp @@ -147,7 +147,7 @@ void zmq::own_t::terminate () send_term_req (_owner, this); } -bool zmq::own_t::is_terminating () +bool zmq::own_t::is_terminating () const { return _terminating; } diff --git a/src/own.hpp b/src/own.hpp index 25fe5a6d..21463fe3 100644 --- a/src/own.hpp +++ b/src/own.hpp @@ -84,7 +84,7 @@ class own_t : public object_t void terminate (); // Returns true if the object is in process of termination. - bool is_terminating (); + bool is_terminating () const; // Derived object destroys own_t. There's no point in allowing // others to invoke the destructor. At the same time, it has to be diff --git a/src/plain_server.cpp b/src/plain_server.cpp index ff6eff3d..694c925e 100644 --- a/src/plain_server.cpp +++ b/src/plain_server.cpp @@ -192,7 +192,7 @@ int zmq::plain_server_t::process_hello (msg_t *msg_) return receive_and_process_zap_reply () == -1 ? -1 : 0; } -void zmq::plain_server_t::produce_welcome (msg_t *msg_) const +void zmq::plain_server_t::produce_welcome (msg_t *msg_) { const int rc = msg_->init_size (welcome_prefix_len); errno_assert (rc == 0); diff --git a/src/plain_server.hpp b/src/plain_server.hpp index 19d3c827..9aa64ced 100644 --- a/src/plain_server.hpp +++ b/src/plain_server.hpp @@ -51,7 +51,7 @@ class plain_server_t ZMQ_FINAL : public zap_client_common_handshake_t int process_handshake_command (msg_t *msg_) ZMQ_FINAL; private: - void produce_welcome (msg_t *msg_) const; + static void produce_welcome (msg_t *msg_); void produce_ready (msg_t *msg_) const; void produce_error (msg_t *msg_) const; diff --git a/src/poller_base.cpp b/src/poller_base.cpp index b81bd6c5..014b2779 100644 --- a/src/poller_base.cpp +++ b/src/poller_base.cpp @@ -123,7 +123,7 @@ void zmq::worker_poller_base_t::start (const char *name_) _ctx.start_thread (_worker, worker_routine, this, name_); } -void zmq::worker_poller_base_t::check_thread () +void zmq::worker_poller_base_t::check_thread () const { #ifdef _DEBUG zmq_assert (!_worker.get_started () || _worker.is_current_thread ()); diff --git a/src/poller_base.hpp b/src/poller_base.hpp index d167d797..b39f2a41 100644 --- a/src/poller_base.hpp +++ b/src/poller_base.hpp @@ -172,7 +172,7 @@ class worker_poller_base_t : public poller_base_t // via an assertion. // Should be called by the add_fd, removed_fd, set_*, reset_* functions // to ensure correct usage. - void check_thread (); + void check_thread () const; // Stops the worker thread. Should be called from the destructor of the // leaf class. diff --git a/src/session_base.cpp b/src/session_base.cpp index bc0eb248..f4f68400 100644 --- a/src/session_base.cpp +++ b/src/session_base.cpp @@ -325,7 +325,7 @@ void zmq::session_base_t::hiccuped (pipe_t *) zmq_assert (false); } -zmq::socket_base_t *zmq::session_base_t::get_socket () +zmq::socket_base_t *zmq::session_base_t::get_socket () const { return _socket; } @@ -385,7 +385,7 @@ int zmq::session_base_t::zap_connect () return 0; } -bool zmq::session_base_t::zap_enabled () +bool zmq::session_base_t::zap_enabled () const { return (options.mechanism != ZMQ_NULL || !options.zap_domain.empty ()); } diff --git a/src/session_base.hpp b/src/session_base.hpp index dfe909b8..ed63910d 100644 --- a/src/session_base.hpp +++ b/src/session_base.hpp @@ -75,7 +75,7 @@ class session_base_t : public own_t, public io_object_t, public i_pipe_events virtual int push_msg (msg_t *msg_); int zap_connect (); - bool zap_enabled (); + bool zap_enabled () const; // Fetches a message. Returns 0 if successful; -1 otherwise. // The caller is responsible for freeing the message when no @@ -92,7 +92,7 @@ class session_base_t : public own_t, public io_object_t, public i_pipe_events // The function takes ownership of the message. int write_zap_msg (msg_t *msg_); - socket_base_t *get_socket (); + socket_base_t *get_socket () const; const endpoint_uri_pair_t &get_endpoint () const; protected: diff --git a/src/signaler.cpp b/src/signaler.cpp index e55360dc..93fb248e 100644 --- a/src/signaler.cpp +++ b/src/signaler.cpp @@ -227,7 +227,7 @@ void zmq::signaler_t::send () #endif } -int zmq::signaler_t::wait (int timeout_) +int zmq::signaler_t::wait (int timeout_) const { #ifdef HAVE_FORK if (unlikely (pid != getpid ())) { diff --git a/src/signaler.hpp b/src/signaler.hpp index 795fb650..49fac1ba 100644 --- a/src/signaler.hpp +++ b/src/signaler.hpp @@ -54,7 +54,7 @@ class signaler_t // May return retired_fd if the signaler could not be initialized. fd_t get_fd () const; void send (); - int wait (int timeout_); + int wait (int timeout_) const; void recv (); int recv_failable (); diff --git a/src/socket_poller.cpp b/src/socket_poller.cpp index 81afce5a..c761646e 100644 --- a/src/socket_poller.cpp +++ b/src/socket_poller.cpp @@ -81,12 +81,12 @@ zmq::socket_poller_t::~socket_poller_t () #endif } -bool zmq::socket_poller_t::check_tag () +bool zmq::socket_poller_t::check_tag () const { return _tag == 0xCAFEBABE; } -int zmq::socket_poller_t::signaler_fd (fd_t *fd_) +int zmq::socket_poller_t::signaler_fd (fd_t *fd_) const { if (_signaler) { *fd_ = _signaler->get_fd (); diff --git a/src/socket_poller.hpp b/src/socket_poller.hpp index c850b64a..3e29f065 100644 --- a/src/socket_poller.hpp +++ b/src/socket_poller.hpp @@ -76,19 +76,19 @@ class socket_poller_t int modify_fd (fd_t fd_, short events_); int remove_fd (fd_t fd_); // Returns the signaler's fd if there is one, otherwise errors. - int signaler_fd (fd_t *fd_); + int signaler_fd (fd_t *fd_) const; int wait (event_t *events_, int n_events_, long timeout_); - inline int size () { return static_cast (_items.size ()); }; + inline int size () const { return static_cast (_items.size ()); }; // Return false if object is not a socket. - bool check_tag (); + bool check_tag () const; private: - void zero_trail_events (zmq::socket_poller_t::event_t *events_, - int n_events_, - int found_); + static void zero_trail_events (zmq::socket_poller_t::event_t *events_, + int n_events_, + int found_); #if defined ZMQ_POLL_BASED_ON_POLL int check_events (zmq::socket_poller_t::event_t *events_, int n_events_); #elif defined ZMQ_POLL_BASED_ON_SELECT @@ -98,11 +98,11 @@ class socket_poller_t fd_set &outset_, fd_set &errset_); #endif - int adjust_timeout (zmq::clock_t &clock_, - long timeout_, - uint64_t &now_, - uint64_t &end_, - bool &first_pass_); + static int adjust_timeout (zmq::clock_t &clock_, + long timeout_, + uint64_t &now_, + uint64_t &end_, + bool &first_pass_); int rebuild (); // Used to check whether the object is a socket_poller. diff --git a/src/socks_connecter.cpp b/src/socks_connecter.cpp index 2a426637..b2931605 100644 --- a/src/socks_connecter.cpp +++ b/src/socks_connecter.cpp @@ -344,7 +344,7 @@ int zmq::socks_connecter_t::connect_to_proxy () return -1; } -zmq::fd_t zmq::socks_connecter_t::check_proxy_connection () +zmq::fd_t zmq::socks_connecter_t::check_proxy_connection () const { // Async connect has finished. Check whether an error occurred int err = 0; diff --git a/src/socks_connecter.hpp b/src/socks_connecter.hpp index 3e17a2e1..ea008f8c 100644 --- a/src/socks_connecter.hpp +++ b/src/socks_connecter.hpp @@ -88,13 +88,13 @@ class socks_connecter_t ZMQ_FINAL : public stream_connecter_base_t // Internal function to start the actual connection establishment. void start_connecting () ZMQ_FINAL; - int process_server_response (const socks_choice_t &response_); - int process_server_response (const socks_response_t &response_); - int process_server_response (const socks_auth_response_t &response_); + static int process_server_response (const socks_choice_t &response_); + static int process_server_response (const socks_response_t &response_); + static int process_server_response (const socks_auth_response_t &response_); - int parse_address (const std::string &address_, - std::string &hostname_, - uint16_t &port_); + static int parse_address (const std::string &address_, + std::string &hostname_, + uint16_t &port_); int connect_to_proxy (); @@ -107,7 +107,7 @@ class socks_connecter_t ZMQ_FINAL : public stream_connecter_base_t // Get the file descriptor of newly created connection. Returns // retired_fd if the connection was unsuccessful. - zmq::fd_t check_proxy_connection (); + zmq::fd_t check_proxy_connection () const; socks_greeting_encoder_t _greeting_encoder; socks_choice_decoder_t _choice_decoder; diff --git a/src/timers.cpp b/src/timers.cpp index 74c1b716..e9b516e0 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -43,7 +43,7 @@ zmq::timers_t::~timers_t () _tag = 0xdeadbeef; } -bool zmq::timers_t::check_tag () +bool zmq::timers_t::check_tag () const { return _tag == 0xCAFEDADA; } diff --git a/src/timers.hpp b/src/timers.hpp index 3e950061..384d5e3f 100644 --- a/src/timers.hpp +++ b/src/timers.hpp @@ -74,7 +74,7 @@ class timers_t int execute (); // Return false if object is not a timers class. - bool check_tag (); + bool check_tag () const; private: // Used to check whether the object is a timers class. diff --git a/src/udp_engine.hpp b/src/udp_engine.hpp index a81da2d5..922995d1 100644 --- a/src/udp_engine.hpp +++ b/src/udp_engine.hpp @@ -48,14 +48,14 @@ class udp_engine_t ZMQ_FINAL : public io_object_t, public i_engine private: int resolve_raw_address (const char *name_, size_t length_); - void sockaddr_to_msg (zmq::msg_t *msg_, const sockaddr_in *addr_); + static void sockaddr_to_msg (zmq::msg_t *msg_, const sockaddr_in *addr_); - int set_udp_reuse_address (fd_t s_, bool on_); - int set_udp_reuse_port (fd_t s_, bool on_); + static int set_udp_reuse_address (fd_t s_, bool on_); + static int set_udp_reuse_port (fd_t s_, bool on_); // Indicate, if the multicast data being sent should be looped back - int set_udp_multicast_loop (fd_t s_, bool is_ipv6_, bool loop_); + static int set_udp_multicast_loop (fd_t s_, bool is_ipv6_, bool loop_); // Set multicast TTL - int set_udp_multicast_ttl (fd_t s_, bool is_ipv6_, int hops_); + static int set_udp_multicast_ttl (fd_t s_, bool is_ipv6_, int hops_); // Set multicast address/interface int set_udp_multicast_iface (fd_t s_, bool is_ipv6_, diff --git a/src/yqueue.hpp b/src/yqueue.hpp index 5f6365d2..4a950521 100644 --- a/src/yqueue.hpp +++ b/src/yqueue.hpp @@ -179,7 +179,7 @@ template class yqueue_t chunk_t *next; }; - inline chunk_t *allocate_chunk () + static inline chunk_t *allocate_chunk () { #ifdef HAVE_POSIX_MEMALIGN void *pv; From 406c423c9ae57a73b0d127b554a8e7eaec851dfc Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 25 Dec 2019 16:01:40 +0100 Subject: [PATCH 6/6] Problem: C-style casts used Solution: use static_cast instead --- src/array.hpp | 18 ++++++++++++------ src/ip_resolver.cpp | 2 +- src/mechanism.cpp | 3 ++- src/thread.cpp | 2 +- src/v2_decoder.cpp | 4 ++-- src/ws_decoder.cpp | 4 ++-- src/xpub.cpp | 2 +- src/yqueue.hpp | 2 +- src/zmq.cpp | 2 +- src/zmq_utils.cpp | 2 +- 10 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/array.hpp b/src/array.hpp index 4e4869e7..e1b55349 100644 --- a/src/array.hpp +++ b/src/array.hpp @@ -89,20 +89,23 @@ template class array_t inline void push_back (T *item_) { if (item_) - ((item_t *) item_)->set_array_index ((int) _items.size ()); + static_cast (item_)->set_array_index ( + static_cast (_items.size ())); _items.push_back (item_); } inline void erase (T *item_) { - erase (((item_t *) item_)->get_array_index ()); + erase (static_cast (item_)->get_array_index ()); } inline void erase (size_type index_) { if (_items.empty ()) return; - ((item_t *) _items.back ())->set_array_index ((int) index_); + static_cast (_items.back ()) + ->set_array_index (static_cast (index_)); + _items[index_] = _items.back (); _items.pop_back (); } @@ -110,9 +113,11 @@ template class array_t inline void swap (size_type index1_, size_type index2_) { if (_items[index1_]) - ((item_t *) _items[index1_])->set_array_index ((int) index2_); + static_cast (_items[index1_]) + ->set_array_index (static_cast (index2_)); if (_items[index2_]) - ((item_t *) _items[index2_])->set_array_index ((int) index1_); + static_cast (_items[index2_]) + ->set_array_index (static_cast (index1_)); std::swap (_items[index1_], _items[index2_]); } @@ -120,7 +125,8 @@ template class array_t static inline size_type index (T *item_) { - return (size_type) ((item_t *) item_)->get_array_index (); + return static_cast ( + static_cast (item_)->get_array_index ()); } private: diff --git a/src/ip_resolver.cpp b/src/ip_resolver.cpp index c0bb25b3..dcf7ea0c 100644 --- a/src/ip_resolver.cpp +++ b/src/ip_resolver.cpp @@ -388,7 +388,7 @@ int zmq::ip_resolver_t::resolve_getaddrinfo (ip_addr_t *ip_addr_, // Use the first result. zmq_assert (res != NULL); - zmq_assert ((size_t) res->ai_addrlen <= sizeof (*ip_addr_)); + zmq_assert (static_cast (res->ai_addrlen) <= sizeof (*ip_addr_)); memcpy (ip_addr_, res->ai_addr, res->ai_addrlen); // Cleanup getaddrinfo after copying the possibly referenced result. diff --git a/src/mechanism.cpp b/src/mechanism.cpp index 7bac643b..93945a33 100644 --- a/src/mechanism.cpp +++ b/src/mechanism.cpp @@ -110,7 +110,8 @@ const char *zmq::mechanism_t::socket_type_string (int socket_type_) #endif }; static const size_t names_count = sizeof (names) / sizeof (names[0]); - zmq_assert (socket_type_ >= 0 && socket_type_ < (int) names_count); + zmq_assert (socket_type_ >= 0 + && socket_type_ < static_cast (names_count)); return names[socket_type_]; } diff --git a/src/thread.cpp b/src/thread.cpp index c40e3061..539622b9 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -50,7 +50,7 @@ static DWORD thread_routine (LPVOID arg_) static unsigned int __stdcall thread_routine (void *arg_) #endif { - zmq::thread_t *self = (zmq::thread_t *) arg_; + zmq::thread_t *self = static_cast (arg_); self->applyThreadName (); self->_tfn (self->_arg); return 0; diff --git a/src/v2_decoder.cpp b/src/v2_decoder.cpp index 92e37fce..5848d6a0 100644 --- a/src/v2_decoder.cpp +++ b/src/v2_decoder.cpp @@ -115,8 +115,8 @@ int zmq::v2_decoder_t::size_ready (uint64_t msg_size_, shared_message_memory_allocator &allocator = get_allocator (); if (unlikely (!_zero_copy - || msg_size_ > (size_t) (allocator.data () + allocator.size () - - read_pos_))) { + || msg_size_ > static_cast ( + allocator.data () + allocator.size () - read_pos_))) { // a new message has started, but the size would exceed the pre-allocated arena // this happens every time when a message does not fit completely into the buffer rc = _in_progress.init_size (static_cast (msg_size_)); diff --git a/src/ws_decoder.cpp b/src/ws_decoder.cpp index 68c2e955..9fc4e2e2 100644 --- a/src/ws_decoder.cpp +++ b/src/ws_decoder.cpp @@ -213,8 +213,8 @@ int zmq::ws_decoder_t::size_ready (unsigned char const *read_pos_) shared_message_memory_allocator &allocator = get_allocator (); if (unlikely (!_zero_copy - || _size > (size_t) (allocator.data () + allocator.size () - - read_pos_))) { + || _size > static_cast ( + allocator.data () + allocator.size () - read_pos_))) { // a new message has started, but the size would exceed the pre-allocated arena // this happens every time when a message does not fit completely into the buffer rc = _in_progress.init_size (static_cast (_size)); diff --git a/src/xpub.cpp b/src/xpub.cpp index 0c81b413..36748e13 100644 --- a/src/xpub.cpp +++ b/src/xpub.cpp @@ -270,7 +270,7 @@ void zmq::xpub_t::xpipe_terminated (pipe_t *pipe_) // Remove pipe without actually sending the message as it was taken // care of by the manual call above. subscriptions is the real mtrie, // so the pipe must be removed from there or it will be left over. - _subscriptions.rm (pipe_, stub, (void *) NULL, false); + _subscriptions.rm (pipe_, stub, static_cast (NULL), false); } else { // Remove the pipe from the trie. If there are topics that nobody // is interested in anymore, send corresponding unsubscriptions diff --git a/src/yqueue.hpp b/src/yqueue.hpp index 4a950521..6ba634a3 100644 --- a/src/yqueue.hpp +++ b/src/yqueue.hpp @@ -187,7 +187,7 @@ template class yqueue_t return (chunk_t *) pv; return NULL; #else - return (chunk_t *) malloc (sizeof (chunk_t)); + return static_cast (malloc (sizeof (chunk_t))); #endif } diff --git a/src/zmq.cpp b/src/zmq.cpp index 76a7c649..372ba707 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -259,7 +259,7 @@ void *zmq_socket (void *ctx_, int type_) } zmq::ctx_t *ctx = static_cast (ctx_); zmq::socket_base_t *s = ctx->create_socket (type_); - return (void *) s; + return static_cast (s); } int zmq_close (void *s_) diff --git a/src/zmq_utils.cpp b/src/zmq_utils.cpp index 74cad47e..a42d732a 100644 --- a/src/zmq_utils.cpp +++ b/src/zmq_utils.cpp @@ -63,7 +63,7 @@ void *zmq_stopwatch_start () uint64_t *watch = static_cast (malloc (sizeof (uint64_t))); alloc_assert (watch); *watch = zmq::clock_t::now_us (); - return (void *) watch; + return static_cast (watch); } unsigned long zmq_stopwatch_intermediate (void *watch_)