diff --git a/src/address.cpp b/src/address.cpp index ed98cdca..80d9697b 100644 --- a/src/address.cpp +++ b/src/address.cpp @@ -56,33 +56,33 @@ zmq::address_t::address_t (const std::string &protocol_, zmq::address_t::~address_t () { - if (protocol == "tcp") { + if (protocol == protocol_name::tcp) { if (resolved.tcp_addr) { LIBZMQ_DELETE (resolved.tcp_addr); } } - if (protocol == "udp") { + if (protocol == protocol_name::udp) { if (resolved.udp_addr) { LIBZMQ_DELETE (resolved.udp_addr); } } #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ && !defined ZMQ_HAVE_VXWORKS - else if (protocol == "ipc") { + else if (protocol == protocol_name::ipc) { if (resolved.ipc_addr) { LIBZMQ_DELETE (resolved.ipc_addr); } } #endif #if defined ZMQ_HAVE_TIPC - else if (protocol == "tipc") { + else if (protocol == protocol_name::tipc) { if (resolved.tipc_addr) { LIBZMQ_DELETE (resolved.tipc_addr); } } #endif #if defined ZMQ_HAVE_VMCI - else if (protocol == "vmci") { + else if (protocol == protocol_name::vmci) { if (resolved.vmci_addr) { LIBZMQ_DELETE (resolved.vmci_addr); } @@ -92,29 +92,29 @@ zmq::address_t::~address_t () int zmq::address_t::to_string (std::string &addr_) const { - if (protocol == "tcp") { + if (protocol == protocol_name::tcp) { if (resolved.tcp_addr) return resolved.tcp_addr->to_string (addr_); } - if (protocol == "udp") { + if (protocol == protocol_name::udp) { if (resolved.udp_addr) return resolved.udp_addr->to_string (addr_); } #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ && !defined ZMQ_HAVE_VXWORKS - else if (protocol == "ipc") { + else if (protocol == protocol_name::ipc) { if (resolved.ipc_addr) return resolved.ipc_addr->to_string (addr_); } #endif #if defined ZMQ_HAVE_TIPC - else if (protocol == "tipc") { + else if (protocol == protocol_name::tipc) { if (resolved.tipc_addr) return resolved.tipc_addr->to_string (addr_); } #endif #if defined ZMQ_HAVE_VMCI - else if (protocol == "vmci") { + else if (protocol == protocol_name::vmci) { if (resolved.vmci_addr) return resolved.vmci_addr->to_string (addr_); } diff --git a/src/address.hpp b/src/address.hpp index 61b6d717..bcc5c549 100644 --- a/src/address.hpp +++ b/src/address.hpp @@ -46,6 +46,23 @@ class tipc_address_t; #if defined ZMQ_HAVE_VMCI class vmci_address_t; #endif + +namespace protocol_name +{ +static const char tcp[] = "tcp"; +static const char udp[] = "udp"; +#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ + && !defined ZMQ_HAVE_VXWORKS +static const char ipc[] = "ipc"; +#endif +#if defined ZMQ_HAVE_TIPC +static const char tipc[] = "tipc"; +#endif +#if defined ZMQ_HAVE_VMCI +static const char vmci[] = "vmci"; +#endif +} + struct address_t { address_t (const std::string &protocol_, diff --git a/src/ipc_connecter.cpp b/src/ipc_connecter.cpp index 7109caa2..9e472108 100644 --- a/src/ipc_connecter.cpp +++ b/src/ipc_connecter.cpp @@ -67,7 +67,7 @@ zmq::ipc_connecter_t::ipc_connecter_t (class io_thread_t *io_thread_, current_reconnect_ivl (options.reconnect_ivl) { zmq_assert (addr); - zmq_assert (addr->protocol == "ipc"); + zmq_assert (addr->protocol == protocol_name::ipc); addr->to_string (endpoint); socket = session->get_socket (); } diff --git a/src/session_base.cpp b/src/session_base.cpp index 8137dcb7..db899eab 100644 --- a/src/session_base.cpp +++ b/src/session_base.cpp @@ -515,7 +515,7 @@ void zmq::session_base_t::reconnect () // and reestablish later on if (_pipe && options.immediate == 1 && _addr->protocol != "pgm" && _addr->protocol != "epgm" && _addr->protocol != "norm" - && _addr->protocol != "udp") { + && _addr->protocol != protocol_name::udp) { _pipe->hiccup (); _pipe->terminate (false); _terminating_pipes.insert (_pipe); @@ -557,10 +557,11 @@ void zmq::session_base_t::start_connecting (bool wait_) // Create the connecter object. - if (_addr->protocol == "tcp") { + if (_addr->protocol == protocol_name::tcp) { if (!options.socks_proxy_address.empty ()) { address_t *proxy_address = new (std::nothrow) - address_t ("tcp", options.socks_proxy_address, this->get_ctx ()); + address_t (protocol_name::tcp, options.socks_proxy_address, + this->get_ctx ()); alloc_assert (proxy_address); socks_connecter_t *connecter = new (std::nothrow) socks_connecter_t (io_thread, this, options, _addr, proxy_address, @@ -578,7 +579,7 @@ void zmq::session_base_t::start_connecting (bool wait_) #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ && !defined ZMQ_HAVE_VXWORKS - if (_addr->protocol == "ipc") { + if (_addr->protocol == protocol_name::ipc) { ipc_connecter_t *connecter = new (std::nothrow) ipc_connecter_t (io_thread, this, options, _addr, wait_); alloc_assert (connecter); @@ -587,7 +588,7 @@ void zmq::session_base_t::start_connecting (bool wait_) } #endif #if defined ZMQ_HAVE_TIPC - if (_addr->protocol == "tipc") { + if (_addr->protocol == protocol_name::tipc) { tipc_connecter_t *connecter = new (std::nothrow) tipc_connecter_t (io_thread, this, options, _addr, wait_); alloc_assert (connecter); @@ -596,7 +597,7 @@ void zmq::session_base_t::start_connecting (bool wait_) } #endif - if (_addr->protocol == "udp") { + if (_addr->protocol == protocol_name::udp) { zmq_assert (options.type == ZMQ_DISH || options.type == ZMQ_RADIO || options.type == ZMQ_DGRAM); @@ -698,7 +699,7 @@ void zmq::session_base_t::start_connecting (bool wait_) #endif // ZMQ_HAVE_NORM #if defined ZMQ_HAVE_VMCI - if (_addr->protocol == "vmci") { + if (_addr->protocol == protocol_name::vmci) { vmci_connecter_t *connecter = new (std::nothrow) vmci_connecter_t (io_thread, this, options, _addr, wait_); alloc_assert (connecter); diff --git a/src/socket_base.cpp b/src/socket_base.cpp index f8657f33..a0884930 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -295,9 +295,9 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_) if (protocol_ != "inproc" #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ && !defined ZMQ_HAVE_VXWORKS - && protocol_ != "ipc" + && protocol_ != protocol_name::ipc #endif - && protocol_ != "tcp" + && protocol_ != protocol_name::tcp #if defined ZMQ_HAVE_OPENPGM // pgm/epgm transports only available if 0MQ is compiled with OpenPGM. && protocol_ != "pgm" @@ -305,15 +305,15 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_) #endif #if defined ZMQ_HAVE_TIPC // TIPC transport is only available on Linux. - && protocol_ != "tipc" + && protocol_ != protocol_name::tipc #endif #if defined ZMQ_HAVE_NORM && protocol_ != "norm" #endif #if defined ZMQ_HAVE_VMCI - && protocol_ != "vmci" + && protocol_ != protocol_name::vmci #endif - && protocol_ != "udp") { + && protocol_ != protocol_name::udp) { errno = EPROTONOSUPPORT; return -1; } @@ -330,7 +330,7 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_) } #endif - if (protocol_ == "udp" + if (protocol_ == protocol_name::udp && (options.type != ZMQ_DISH && options.type != ZMQ_RADIO && options.type != ZMQ_DGRAM)) { errno = ENOCOMPATPROTO; @@ -511,7 +511,7 @@ int zmq::socket_base_t::bind (const char *addr_) return rc; } - if (protocol == "udp") { + if (protocol == protocol_name::udp) { if (!(options.type == ZMQ_DGRAM || options.type == ZMQ_DISH)) { errno = ENOCOMPATPROTO; return -1; @@ -575,7 +575,7 @@ int zmq::socket_base_t::bind (const char *addr_) return -1; } - if (protocol == "tcp") { + if (protocol == protocol_name::tcp) { tcp_listener_t *listener = new (std::nothrow) tcp_listener_t (io_thread, this, options); alloc_assert (listener); @@ -596,7 +596,7 @@ int zmq::socket_base_t::bind (const char *addr_) #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ && !defined ZMQ_HAVE_VXWORKS - if (protocol == "ipc") { + if (protocol == protocol_name::ipc) { ipc_listener_t *listener = new (std::nothrow) ipc_listener_t (io_thread, this, options); alloc_assert (listener); @@ -616,7 +616,7 @@ int zmq::socket_base_t::bind (const char *addr_) } #endif #if defined ZMQ_HAVE_TIPC - if (protocol == "tipc") { + if (protocol == protocol_name::tipc) { tipc_listener_t *listener = new (std::nothrow) tipc_listener_t (io_thread, this, options); alloc_assert (listener); @@ -636,7 +636,7 @@ int zmq::socket_base_t::bind (const char *addr_) } #endif #if defined ZMQ_HAVE_VMCI - if (protocol == "vmci") { + if (protocol == protocol_name::vmci) { vmci_listener_t *listener = new (std::nothrow) vmci_listener_t (io_thread, this, options); alloc_assert (listener); @@ -809,7 +809,7 @@ int zmq::socket_base_t::connect (const char *addr_) alloc_assert (paddr); // Resolve address (if needed by the protocol) - if (protocol == "tcp") { + if (protocol == protocol_name::tcp) { // Do some basic sanity checks on tcp:// address syntax // - hostname starts with digit or letter, with embedded '-' or '.' // - IPv6 address may contain hex chars and colons. @@ -853,7 +853,7 @@ int zmq::socket_base_t::connect (const char *addr_) } #if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS \ && !defined ZMQ_HAVE_VXWORKS - else if (protocol == "ipc") { + else if (protocol == protocol_name::ipc) { paddr->resolved.ipc_addr = new (std::nothrow) ipc_address_t (); alloc_assert (paddr->resolved.ipc_addr); int rc = paddr->resolved.ipc_addr->resolve (address.c_str ()); @@ -864,7 +864,7 @@ int zmq::socket_base_t::connect (const char *addr_) } #endif - if (protocol == "udp") { + if (protocol == protocol_name::udp) { if (options.type != ZMQ_RADIO) { errno = ENOCOMPATPROTO; LIBZMQ_DELETE (paddr); @@ -897,7 +897,7 @@ int zmq::socket_base_t::connect (const char *addr_) } #endif #if defined ZMQ_HAVE_TIPC - else if (protocol == "tipc") { + else if (protocol == protocol_name::tipc) { paddr->resolved.tipc_addr = new (std::nothrow) tipc_address_t (); alloc_assert (paddr->resolved.tipc_addr); int rc = paddr->resolved.tipc_addr->resolve (address.c_str ()); @@ -917,7 +917,7 @@ int zmq::socket_base_t::connect (const char *addr_) } #endif #if defined ZMQ_HAVE_VMCI - else if (protocol == "vmci") { + else if (protocol == protocol_name::vmci) { paddr->resolved.vmci_addr = new (std::nothrow) vmci_address_t (this->get_ctx ()); alloc_assert (paddr->resolved.vmci_addr); @@ -937,7 +937,8 @@ int zmq::socket_base_t::connect (const char *addr_) // PGM does not support subscription forwarding; ask for all data to be // sent to this pipe. (same for NORM, currently?) bool subscribe_to_all = protocol == "pgm" || protocol == "epgm" - || protocol == "norm" || protocol == "udp"; + || protocol == "norm" + || protocol == protocol_name::udp; pipe_t *newpipe = NULL; if (options.immediate != 1 || subscribe_to_all) { @@ -1039,7 +1040,7 @@ int zmq::socket_base_t::term_endpoint (const char *addr_) // IPv4-in-IPv6 mapping (EG: tcp://[::ffff:127.0.0.1]:9999), so try to // resolve before giving up. Given at this stage we don't know whether a // socket is connected or bound, try with both. - if (protocol == "tcp") { + if (protocol == protocol_name::tcp) { if (_endpoints.find (resolved_addr) == _endpoints.end ()) { tcp_address_t *tcp_addr = new (std::nothrow) tcp_address_t (); alloc_assert (tcp_addr); diff --git a/src/socks_connecter.cpp b/src/socks_connecter.cpp index 91bcc423..99cbc3df 100644 --- a/src/socks_connecter.cpp +++ b/src/socks_connecter.cpp @@ -72,7 +72,7 @@ zmq::socks_connecter_t::socks_connecter_t (class io_thread_t *io_thread_, _current_reconnect_ivl (options.reconnect_ivl) { zmq_assert (_addr); - zmq_assert (_addr->protocol == "tcp"); + zmq_assert (_addr->protocol == protocol_name::tcp); _proxy_addr->to_string (_endpoint); _socket = _session->get_socket (); } diff --git a/src/tcp_connecter.cpp b/src/tcp_connecter.cpp index 8886a3d6..9ab5647f 100644 --- a/src/tcp_connecter.cpp +++ b/src/tcp_connecter.cpp @@ -82,7 +82,7 @@ zmq::tcp_connecter_t::tcp_connecter_t (class io_thread_t *io_thread_, _socket (_session->get_socket ()) { zmq_assert (_addr); - zmq_assert (_addr->protocol == "tcp"); + zmq_assert (_addr->protocol == protocol_name::tcp); _addr->to_string (_endpoint); // TODO the return value is unused! what if it fails? if this is impossible // or does not matter, change such that endpoint in initialized using an diff --git a/src/zmq.cpp b/src/zmq.cpp index 5e765f43..43423549 100644 --- a/src/zmq.cpp +++ b/src/zmq.cpp @@ -87,10 +87,10 @@ struct iovec #include "msg.hpp" #include "fd.hpp" #include "metadata.hpp" -#include "signaler.hpp" #include "socket_poller.hpp" #include "timers.hpp" #include "ip.hpp" +#include "address.hpp" #if defined ZMQ_HAVE_OPENPGM #define __PGM_WININT_H__ @@ -1489,7 +1489,7 @@ int zmq_device (int /* type */, void *frontend_, void *backend_) int zmq_has (const char *capability_) { #if !defined(ZMQ_HAVE_WINDOWS) && !defined(ZMQ_HAVE_OPENVMS) - if (strcmp (capability_, "ipc") == 0) + if (strcmp (capability_, zmq::protocol_name::ipc) == 0) return true; #endif #if defined(ZMQ_HAVE_OPENPGM) @@ -1497,7 +1497,7 @@ int zmq_has (const char *capability_) return true; #endif #if defined(ZMQ_HAVE_TIPC) - if (strcmp (capability_, "tipc") == 0) + if (strcmp (capability_, zmq::protocol_name::tipc) == 0) return true; #endif #if defined(ZMQ_HAVE_NORM) @@ -1513,7 +1513,7 @@ int zmq_has (const char *capability_) return true; #endif #if defined(ZMQ_HAVE_VMCI) - if (strcmp (capability_, "vmci") == 0) + if (strcmp (capability_, zmq::protocol_name::vmci) == 0) return true; #endif #if defined(ZMQ_BUILD_DRAFT_API)