From 799fae44fe03cb566ae011c344fab9d2a22b4c4a Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 15 Aug 2018 13:19:59 +0200 Subject: [PATCH] Problem: magic literal used for inproc Solution: define and use named constant --- src/address.hpp | 1 + src/socket_base.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/address.hpp b/src/address.hpp index 1275278e..34ca5766 100644 --- a/src/address.hpp +++ b/src/address.hpp @@ -49,6 +49,7 @@ class vmci_address_t; namespace protocol_name { +static const char inproc[] = "inproc"; static const char tcp[] = "tcp"; static const char udp[] = "udp"; #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 42931913..b8525b36 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -326,7 +326,7 @@ int zmq::socket_base_t::parse_uri (const char *uri_, int zmq::socket_base_t::check_protocol (const std::string &protocol_) const { // First check out whether the protocol is something we are aware of. - if (protocol_ != "inproc" + if (protocol_ != protocol_name::inproc #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ && !defined ZMQ_HAVE_VXWORKS && protocol_ != protocol_name::ipc @@ -522,7 +522,7 @@ int zmq::socket_base_t::bind (const char *endpoint_uri_) return -1; } - if (protocol == "inproc") { + if (protocol == protocol_name::inproc) { const endpoint_t endpoint = {this, options}; rc = register_endpoint (endpoint_uri_, endpoint); if (rc == 0) { @@ -714,7 +714,7 @@ int zmq::socket_base_t::connect (const char *endpoint_uri_) return -1; } - if (protocol == "inproc") { + if (protocol == protocol_name::inproc) { // TODO: inproc connect is specific with respect to creating pipes // as there's no 'reconnect' functionality implemented. Once that // is in place we should follow generic pipe creation algorithm. @@ -1045,7 +1045,7 @@ int zmq::socket_base_t::term_endpoint (const char *endpoint_uri_) const std::string endpoint_uri_str = std::string (endpoint_uri_); // Disconnect an inproc socket - if (uri_protocol == "inproc") { + if (uri_protocol == protocol_name::inproc) { return unregister_endpoint (endpoint_uri_str, this) == 0 ? 0 : _inprocs.erase_pipes (endpoint_uri_str); @@ -1578,7 +1578,7 @@ int zmq::socket_base_t::monitor (const char *endpoint_, int events_) return -1; // Event notification only supported over inproc:// - if (protocol != "inproc") { + if (protocol != protocol_name::inproc) { errno = EPROTONOSUPPORT; return -1; }