Problem: non-modifying member functions not marked as const/static

Solution: add const/static
This commit is contained in:
Simon Giesecke 2019-12-25 15:51:26 +01:00
parent 41e3f14d6a
commit 78961eeab7
33 changed files with 76 additions and 72 deletions

View File

@ -61,7 +61,7 @@ template <int ID = 0> class array_item_t
inline void set_array_index (int index_) { _array_index = index_; } 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: private:
int _array_index; int _array_index;
@ -118,7 +118,7 @@ template <typename T, int ID = 0> class array_t
inline void clear () { _items.clear (); } 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 (); return (size_type) ((item_t *) item_)->get_array_index ();
} }

View File

@ -105,7 +105,7 @@ zmq::ctx_t::ctx_t () :
#endif #endif
} }
bool zmq::ctx_t::check_tag () bool zmq::ctx_t::check_tag () const
{ {
return _tag == ZMQ_CTX_TAG_VALUE_GOOD; return _tag == ZMQ_CTX_TAG_VALUE_GOOD;
} }
@ -534,7 +534,7 @@ void zmq::ctx_t::destroy_socket (class socket_base_t *socket_)
_reaper->stop (); _reaper->stop ();
} }
zmq::object_t *zmq::ctx_t::get_reaper () zmq::object_t *zmq::ctx_t::get_reaper () const
{ {
return _reaper; return _reaper;
} }

View File

@ -97,7 +97,7 @@ class ctx_t ZMQ_FINAL : public thread_ctx_t
ctx_t (); ctx_t ();
// Returns false if object is not a context. // 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 // 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 // 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_); zmq::io_thread_t *choose_io_thread (uint64_t affinity_);
// Returns reaper thread object. // Returns reaper thread object.
zmq::object_t *get_reaper (); zmq::object_t *get_reaper () const;
// Management of inproc endpoints. // Management of inproc endpoints.
int register_endpoint (const char *addr_, const endpoint_t &endpoint_); 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, connect_side,
bind_side bind_side
}; };
void
static void
connect_inproc_sockets (zmq::socket_base_t *bind_socket_, connect_inproc_sockets (zmq::socket_base_t *bind_socket_,
const options_t &bind_options_, const options_t &bind_options_,
const pending_connection_t &pending_connection_, const pending_connection_t &pending_connection_,

View File

@ -268,7 +268,7 @@ struct curve_client_tools_t
size_t size_, size_t size_,
const uint64_t cn_nonce_, const uint64_t cn_nonce_,
const uint8_t *metadata_plaintext_, 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, return produce_initiate (data_, size_, cn_nonce_, server_key,
public_key, secret_key, cn_public, cn_secret, public_key, secret_key, cn_public, cn_secret,

View File

@ -73,7 +73,7 @@ class dist_t
// Send the message to all the outbound pipes. // Send the message to all the outbound pipes.
int send_to_all (zmq::msg_t *msg_); int send_to_all (zmq::msg_t *msg_);
bool has_out (); static bool has_out ();
// check HWM of all pipes matching // check HWM of all pipes matching
bool check_hwm (); bool check_hwm ();

View File

@ -73,7 +73,7 @@ zmq::mailbox_t *zmq::io_thread_t::get_mailbox ()
return &_mailbox; return &_mailbox;
} }
int zmq::io_thread_t::get_load () int zmq::io_thread_t::get_load () const
{ {
return _poller->get_load (); return _poller->get_load ();
} }
@ -107,7 +107,7 @@ void zmq::io_thread_t::timer_event (int)
zmq_assert (false); 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); zmq_assert (_poller);
return _poller; return _poller;

View File

@ -67,13 +67,13 @@ class io_thread_t ZMQ_FINAL : public object_t, public i_poll_events
void timer_event (int id_) ZMQ_FINAL; void timer_event (int id_) ZMQ_FINAL;
// Used by io_objects to retrieve the associated poller object. // Used by io_objects to retrieve the associated poller object.
poller_t *get_poller (); poller_t *get_poller () const;
// Command handlers. // Command handlers.
void process_stop () ZMQ_FINAL; void process_stop () ZMQ_FINAL;
// Returns load experienced by the I/O thread. // Returns load experienced by the I/O thread.
int get_load (); int get_load () const;
private: private:
// I/O thread accesses incoming commands via this mailbox. // I/O thread accesses incoming commands via this mailbox.

View File

@ -95,7 +95,7 @@ const char socket_type_scatter[] = "SCATTER";
const char socket_type_dgram[] = "DGRAM"; const char socket_type_dgram[] = "DGRAM";
#endif #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! // 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[] = { static const char *names[] = {

View File

@ -81,17 +81,20 @@ class mechanism_t
const blob_t &get_user_id () const; 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; 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: protected:
// Only used to identify the socket for the Socket-Type // Only used to identify the socket for the Socket-Type
// property in the wire protocol. // 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_, static size_t add_property (unsigned char *ptr_,
size_t ptr_capacity_, size_t ptr_capacity_,

View File

@ -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 if (msg_->size () <= 1
|| msg_->size () <= (static_cast<uint8_t *> (msg_->data ()))[0]) { || msg_->size () <= (static_cast<uint8_t *> (msg_->data ()))[0]) {

View File

@ -44,7 +44,7 @@ class mechanism_base_t : public mechanism_t
session_base_t *const session; 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_, void handle_error_reason (const char *error_reason_,
size_t error_reason_len_); size_t error_reason_len_);

View File

@ -553,7 +553,7 @@ bool zmq::msg_t::rm_refs (int refs_)
return true; return true;
} }
uint32_t zmq::msg_t::get_routing_id () uint32_t zmq::msg_t::get_routing_id () const
{ {
return _u.base.routing_id; return _u.base.routing_id;
} }
@ -574,7 +574,7 @@ int zmq::msg_t::reset_routing_id ()
return 0; return 0;
} }
const char *zmq::msg_t::group () const char *zmq::msg_t::group () const
{ {
return _u.base.group; return _u.base.group;
} }

View File

@ -146,10 +146,10 @@ class msg_t
bool is_cmsg () const; bool is_cmsg () const;
bool is_lmsg () const; bool is_lmsg () const;
bool is_zcmsg () 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 set_routing_id (uint32_t routing_id_);
int reset_routing_id (); int reset_routing_id ();
const char *group (); const char *group () const;
int set_group (const char *group_); int set_group (const char *group_);
int set_group (const char *, size_t length_); int set_group (const char *, size_t length_);

View File

@ -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; return _tid;
} }
@ -63,7 +63,7 @@ void zmq::object_t::set_tid (uint32_t id_)
_tid = id_; _tid = id_;
} }
zmq::ctx_t *zmq::object_t::get_ctx () zmq::ctx_t *zmq::object_t::get_ctx () const
{ {
return _ctx; return _ctx;
} }
@ -184,7 +184,7 @@ void zmq::object_t::unregister_endpoints (socket_base_t *socket_)
return _ctx->unregister_endpoints (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_); return _ctx->find_endpoint (addr_);
} }
@ -207,7 +207,7 @@ void zmq::object_t::destroy_socket (socket_base_t *socket_)
_ctx->destroy_socket (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_); return _ctx->choose_io_thread (affinity_);
} }

View File

@ -59,9 +59,9 @@ class object_t
object_t (object_t *parent_); object_t (object_t *parent_);
virtual ~object_t (); virtual ~object_t ();
uint32_t get_tid (); uint32_t get_tid () const;
void set_tid (uint32_t id_); void set_tid (uint32_t id_);
ctx_t *get_ctx (); ctx_t *get_ctx () const;
void process_command (const zmq::command_t &cmd_); void process_command (const zmq::command_t &cmd_);
void send_inproc_connected (zmq::socket_base_t *socket_); void send_inproc_connected (zmq::socket_base_t *socket_);
void send_bind (zmq::own_t *destination_, 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 register_endpoint (const char *addr_, const zmq::endpoint_t &endpoint_);
int unregister_endpoint (const std::string &addr_, socket_base_t *socket_); int unregister_endpoint (const std::string &addr_, socket_base_t *socket_);
void unregister_endpoints (zmq::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_, void pend_connection (const std::string &addr_,
const endpoint_t &endpoint_, const endpoint_t &endpoint_,
pipe_t **pipes_); pipe_t **pipes_);
@ -86,7 +86,7 @@ class object_t
void log (const char *format_, ...); void log (const char *format_, ...);
// Chooses least loaded I/O thread. // 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 // Derived object can use these functions to send commands
// to other objects. // to other objects.

View File

@ -147,7 +147,7 @@ void zmq::own_t::terminate ()
send_term_req (_owner, this); send_term_req (_owner, this);
} }
bool zmq::own_t::is_terminating () bool zmq::own_t::is_terminating () const
{ {
return _terminating; return _terminating;
} }

View File

@ -84,7 +84,7 @@ class own_t : public object_t
void terminate (); void terminate ();
// Returns true if the object is in process of termination. // 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 // Derived object destroys own_t. There's no point in allowing
// others to invoke the destructor. At the same time, it has to be // others to invoke the destructor. At the same time, it has to be

View File

@ -192,7 +192,7 @@ int zmq::plain_server_t::process_hello (msg_t *msg_)
return receive_and_process_zap_reply () == -1 ? -1 : 0; 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); const int rc = msg_->init_size (welcome_prefix_len);
errno_assert (rc == 0); errno_assert (rc == 0);

View File

@ -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; int process_handshake_command (msg_t *msg_) ZMQ_FINAL;
private: private:
void produce_welcome (msg_t *msg_) const; static void produce_welcome (msg_t *msg_);
void produce_ready (msg_t *msg_) const; void produce_ready (msg_t *msg_) const;
void produce_error (msg_t *msg_) const; void produce_error (msg_t *msg_) const;

View File

@ -123,7 +123,7 @@ void zmq::worker_poller_base_t::start (const char *name_)
_ctx.start_thread (_worker, worker_routine, this, 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 #ifdef _DEBUG
zmq_assert (!_worker.get_started () || _worker.is_current_thread ()); zmq_assert (!_worker.get_started () || _worker.is_current_thread ());

View File

@ -172,7 +172,7 @@ class worker_poller_base_t : public poller_base_t
// via an assertion. // via an assertion.
// Should be called by the add_fd, removed_fd, set_*, reset_* functions // Should be called by the add_fd, removed_fd, set_*, reset_* functions
// to ensure correct usage. // to ensure correct usage.
void check_thread (); void check_thread () const;
// Stops the worker thread. Should be called from the destructor of the // Stops the worker thread. Should be called from the destructor of the
// leaf class. // leaf class.

View File

@ -325,7 +325,7 @@ void zmq::session_base_t::hiccuped (pipe_t *)
zmq_assert (false); 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; return _socket;
} }
@ -385,7 +385,7 @@ int zmq::session_base_t::zap_connect ()
return 0; 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 ()); return (options.mechanism != ZMQ_NULL || !options.zap_domain.empty ());
} }

View File

@ -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_); virtual int push_msg (msg_t *msg_);
int zap_connect (); int zap_connect ();
bool zap_enabled (); bool zap_enabled () const;
// Fetches a message. Returns 0 if successful; -1 otherwise. // Fetches a message. Returns 0 if successful; -1 otherwise.
// The caller is responsible for freeing the message when no // 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. // The function takes ownership of the message.
int write_zap_msg (msg_t *msg_); 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; const endpoint_uri_pair_t &get_endpoint () const;
protected: protected:

View File

@ -227,7 +227,7 @@ void zmq::signaler_t::send ()
#endif #endif
} }
int zmq::signaler_t::wait (int timeout_) int zmq::signaler_t::wait (int timeout_) const
{ {
#ifdef HAVE_FORK #ifdef HAVE_FORK
if (unlikely (pid != getpid ())) { if (unlikely (pid != getpid ())) {

View File

@ -54,7 +54,7 @@ class signaler_t
// May return retired_fd if the signaler could not be initialized. // May return retired_fd if the signaler could not be initialized.
fd_t get_fd () const; fd_t get_fd () const;
void send (); void send ();
int wait (int timeout_); int wait (int timeout_) const;
void recv (); void recv ();
int recv_failable (); int recv_failable ();

View File

@ -81,12 +81,12 @@ zmq::socket_poller_t::~socket_poller_t ()
#endif #endif
} }
bool zmq::socket_poller_t::check_tag () bool zmq::socket_poller_t::check_tag () const
{ {
return _tag == 0xCAFEBABE; 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) { if (_signaler) {
*fd_ = _signaler->get_fd (); *fd_ = _signaler->get_fd ();

View File

@ -76,17 +76,17 @@ class socket_poller_t
int modify_fd (fd_t fd_, short events_); int modify_fd (fd_t fd_, short events_);
int remove_fd (fd_t fd_); int remove_fd (fd_t fd_);
// Returns the signaler's fd if there is one, otherwise errors. // 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_); int wait (event_t *events_, int n_events_, long timeout_);
inline int size () { return static_cast<int> (_items.size ()); }; inline int size () const { return static_cast<int> (_items.size ()); };
// Return false if object is not a socket. // Return false if object is not a socket.
bool check_tag (); bool check_tag () const;
private: private:
void zero_trail_events (zmq::socket_poller_t::event_t *events_, static void zero_trail_events (zmq::socket_poller_t::event_t *events_,
int n_events_, int n_events_,
int found_); int found_);
#if defined ZMQ_POLL_BASED_ON_POLL #if defined ZMQ_POLL_BASED_ON_POLL
@ -98,7 +98,7 @@ class socket_poller_t
fd_set &outset_, fd_set &outset_,
fd_set &errset_); fd_set &errset_);
#endif #endif
int adjust_timeout (zmq::clock_t &clock_, static int adjust_timeout (zmq::clock_t &clock_,
long timeout_, long timeout_,
uint64_t &now_, uint64_t &now_,
uint64_t &end_, uint64_t &end_,

View File

@ -344,7 +344,7 @@ int zmq::socks_connecter_t::connect_to_proxy ()
return -1; 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 // Async connect has finished. Check whether an error occurred
int err = 0; int err = 0;

View File

@ -88,11 +88,11 @@ class socks_connecter_t ZMQ_FINAL : public stream_connecter_base_t
// Internal function to start the actual connection establishment. // Internal function to start the actual connection establishment.
void start_connecting () ZMQ_FINAL; void start_connecting () ZMQ_FINAL;
int process_server_response (const socks_choice_t &response_); static int process_server_response (const socks_choice_t &response_);
int process_server_response (const socks_response_t &response_); static 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_auth_response_t &response_);
int parse_address (const std::string &address_, static int parse_address (const std::string &address_,
std::string &hostname_, std::string &hostname_,
uint16_t &port_); uint16_t &port_);
@ -107,7 +107,7 @@ class socks_connecter_t ZMQ_FINAL : public stream_connecter_base_t
// Get the file descriptor of newly created connection. Returns // Get the file descriptor of newly created connection. Returns
// retired_fd if the connection was unsuccessful. // 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_greeting_encoder_t _greeting_encoder;
socks_choice_decoder_t _choice_decoder; socks_choice_decoder_t _choice_decoder;

View File

@ -43,7 +43,7 @@ zmq::timers_t::~timers_t ()
_tag = 0xdeadbeef; _tag = 0xdeadbeef;
} }
bool zmq::timers_t::check_tag () bool zmq::timers_t::check_tag () const
{ {
return _tag == 0xCAFEDADA; return _tag == 0xCAFEDADA;
} }

View File

@ -74,7 +74,7 @@ class timers_t
int execute (); int execute ();
// Return false if object is not a timers class. // Return false if object is not a timers class.
bool check_tag (); bool check_tag () const;
private: private:
// Used to check whether the object is a timers class. // Used to check whether the object is a timers class.

View File

@ -48,14 +48,14 @@ class udp_engine_t ZMQ_FINAL : public io_object_t, public i_engine
private: private:
int resolve_raw_address (const char *name_, size_t length_); 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_); static 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_port (fd_t s_, bool on_);
// Indicate, if the multicast data being sent should be looped back // 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 // 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 // Set multicast address/interface
int set_udp_multicast_iface (fd_t s_, int set_udp_multicast_iface (fd_t s_,
bool is_ipv6_, bool is_ipv6_,

View File

@ -179,7 +179,7 @@ template <typename T, int N> class yqueue_t
chunk_t *next; chunk_t *next;
}; };
inline chunk_t *allocate_chunk () static inline chunk_t *allocate_chunk ()
{ {
#ifdef HAVE_POSIX_MEMALIGN #ifdef HAVE_POSIX_MEMALIGN
void *pv; void *pv;