Unverified Commit bb9135da authored by Luca Boccassi's avatar Luca Boccassi Committed by GitHub

Merge pull request #3847 from JSYoo5B/protocol-literals-refactor

Refactor protocol literals into constants
parents 0c7ee438 38fd1fdc
...@@ -62,6 +62,13 @@ namespace protocol_name ...@@ -62,6 +62,13 @@ namespace protocol_name
static const char inproc[] = "inproc"; static const char inproc[] = "inproc";
static const char tcp[] = "tcp"; static const char tcp[] = "tcp";
static const char udp[] = "udp"; static const char udp[] = "udp";
#ifdef ZMQ_HAVE_OPENPGM
static const char pgm[] = "pgm";
static const char epgm[] = "epgm";
#endif
#ifdef ZMQ_HAVE_NORM
static const char norm[] = "norm";
#endif
#ifdef ZMQ_HAVE_WS #ifdef ZMQ_HAVE_WS
static const char ws[] = "ws"; static const char ws[] = "ws";
#endif #endif
......
...@@ -534,8 +534,14 @@ void zmq::session_base_t::reconnect () ...@@ -534,8 +534,14 @@ void zmq::session_base_t::reconnect ()
{ {
// For delayed connect situations, terminate the pipe // For delayed connect situations, terminate the pipe
// and reestablish later on // and reestablish later on
if (_pipe && options.immediate == 1 && _addr->protocol != "pgm" if (_pipe && options.immediate == 1
&& _addr->protocol != "epgm" && _addr->protocol != "norm" #ifdef ZMQ_HAVE_OPENPGM
&& _addr->protocol != protocol_name::pgm
&& _addr->protocol != protocol_name::epgm
#endif
#ifdef ZMQ_HAVE_NORM
&& _addr->protocol != protocol_name::norm
#endif
&& _addr->protocol != protocol_name::udp) { && _addr->protocol != protocol_name::udp) {
_pipe->hiccup (); _pipe->hiccup ();
_pipe->terminate (false); _pipe->terminate (false);
...@@ -604,13 +610,13 @@ zmq::session_base_t::start_connecting_entry_t ...@@ -604,13 +610,13 @@ zmq::session_base_t::start_connecting_entry_t
start_connecting_entry_t (protocol_name::udp, start_connecting_entry_t (protocol_name::udp,
&zmq::session_base_t::start_connecting_udp), &zmq::session_base_t::start_connecting_udp),
#if defined ZMQ_HAVE_OPENPGM #if defined ZMQ_HAVE_OPENPGM
start_connecting_entry_t ("pgm", start_connecting_entry_t (protocol_name::pgm,
&zmq::session_base_t::start_connecting_pgm), &zmq::session_base_t::start_connecting_pgm),
start_connecting_entry_t ("epgm", start_connecting_entry_t (protocol_name::epgm,
&zmq::session_base_t::start_connecting_pgm), &zmq::session_base_t::start_connecting_pgm),
#endif #endif
#if defined ZMQ_HAVE_NORM #if defined ZMQ_HAVE_NORM
start_connecting_entry_t ("norm", start_connecting_entry_t (protocol_name::norm,
&zmq::session_base_t::start_connecting_norm), &zmq::session_base_t::start_connecting_norm),
#endif #endif
}; };
...@@ -724,7 +730,7 @@ void zmq::session_base_t::start_connecting_pgm (io_thread_t *io_thread_) ...@@ -724,7 +730,7 @@ void zmq::session_base_t::start_connecting_pgm (io_thread_t *io_thread_)
|| options.type == ZMQ_SUB || options.type == ZMQ_XSUB); || options.type == ZMQ_SUB || options.type == ZMQ_XSUB);
// For EPGM transport with UDP encapsulation of PGM is used. // For EPGM transport with UDP encapsulation of PGM is used.
bool const udp_encapsulation = _addr->protocol == "epgm"; bool const udp_encapsulation = _addr->protocol == protocol_name::epgm;
// At this point we'll create message pipes to the session straight // At this point we'll create message pipes to the session straight
// away. There's no point in delaying it as no concept of 'connect' // away. There's no point in delaying it as no concept of 'connect'
......
...@@ -347,15 +347,15 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_) const ...@@ -347,15 +347,15 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_) const
#endif #endif
#if defined ZMQ_HAVE_OPENPGM #if defined ZMQ_HAVE_OPENPGM
// pgm/epgm transports only available if 0MQ is compiled with OpenPGM. // pgm/epgm transports only available if 0MQ is compiled with OpenPGM.
&& protocol_ != "pgm" && protocol_ != protocol_name::pgm
&& protocol_ != "epgm" && protocol_ != protocol_name::epgm
#endif #endif
#if defined ZMQ_HAVE_TIPC #if defined ZMQ_HAVE_TIPC
// TIPC transport is only available on Linux. // TIPC transport is only available on Linux.
&& protocol_ != protocol_name::tipc && protocol_ != protocol_name::tipc
#endif #endif
#if defined ZMQ_HAVE_NORM #if defined ZMQ_HAVE_NORM
&& protocol_ != "norm" && protocol_ != protocol_name::norm
#endif #endif
#if defined ZMQ_HAVE_VMCI #if defined ZMQ_HAVE_VMCI
&& protocol_ != protocol_name::vmci && protocol_ != protocol_name::vmci
...@@ -369,7 +369,14 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_) const ...@@ -369,7 +369,14 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_) const
// Specifically, multicast protocols can't be combined with // Specifically, multicast protocols can't be combined with
// bi-directional messaging patterns (socket types). // bi-directional messaging patterns (socket types).
#if defined ZMQ_HAVE_OPENPGM || defined ZMQ_HAVE_NORM #if defined ZMQ_HAVE_OPENPGM || defined ZMQ_HAVE_NORM
if ((protocol_ == "pgm" || protocol_ == "epgm" || protocol_ == "norm") #if defined ZMQ_HAVE_OPENPGM && defined ZMQ_HAVE_NORM
if ((protocol_ == protocol_name::pgm || protocol_ == protocol_name::epgm
|| protocol_ == protocol_name::norm)
#elif defined ZMQ_HAVE_OPENPGM
if ((protocol_ == protocol_name::pgm || protocol_ == protocol_name::epgm)
#else // defined ZMQ_HAVE_NORM
if (protocol_ == protocol_name::norm
#endif
&& options.type != ZMQ_PUB && options.type != ZMQ_SUB && options.type != ZMQ_PUB && options.type != ZMQ_SUB
&& options.type != ZMQ_XPUB && options.type != ZMQ_XSUB) { && options.type != ZMQ_XPUB && options.type != ZMQ_XSUB) {
errno = ENOCOMPATPROTO; errno = ENOCOMPATPROTO;
...@@ -546,7 +553,15 @@ int zmq::socket_base_t::bind (const char *endpoint_uri_) ...@@ -546,7 +553,15 @@ int zmq::socket_base_t::bind (const char *endpoint_uri_)
return rc; return rc;
} }
if (protocol == "pgm" || protocol == "epgm" || protocol == "norm") { #if defined ZMQ_HAVE_OPENPGM || defined ZMQ_HAVE_NORM
#if defined ZMQ_HAVE_OPENPGM && defined ZMQ_HAVE_NORM
if (protocol == protocol_name::pgm || protocol == protocol_name::epgm
|| protocol == protocol_name::norm) {
#elif defined ZMQ_HAVE_OPENPGM
if (protocol == protocol_name::pgm || protocol == protocol_name::epgm) {
#else // defined ZMQ_HAVE_NORM
if (protocol == protocol_name::norm) {
#endif
// For convenience's sake, bind can be used interchangeable with // For convenience's sake, bind can be used interchangeable with
// connect for PGM, EPGM, NORM transports. // connect for PGM, EPGM, NORM transports.
rc = connect (endpoint_uri_); rc = connect (endpoint_uri_);
...@@ -554,6 +569,7 @@ int zmq::socket_base_t::bind (const char *endpoint_uri_) ...@@ -554,6 +569,7 @@ int zmq::socket_base_t::bind (const char *endpoint_uri_)
options.connected = true; options.connected = true;
return rc; return rc;
} }
#endif
if (protocol == protocol_name::udp) { if (protocol == protocol_name::udp) {
if (!(options.type == ZMQ_DGRAM || options.type == ZMQ_DISH)) { if (!(options.type == ZMQ_DGRAM || options.type == ZMQ_DISH)) {
...@@ -968,7 +984,7 @@ int zmq::socket_base_t::connect_internal (const char *endpoint_uri_) ...@@ -968,7 +984,7 @@ int zmq::socket_base_t::connect_internal (const char *endpoint_uri_)
// TBD - Should we check address for ZMQ_HAVE_NORM??? // TBD - Should we check address for ZMQ_HAVE_NORM???
#ifdef ZMQ_HAVE_OPENPGM #ifdef ZMQ_HAVE_OPENPGM
if (protocol == "pgm" || protocol == "epgm") { if (protocol == protocol_name::pgm || protocol == protocol_name::epgm) {
struct pgm_addrinfo_t *res = NULL; struct pgm_addrinfo_t *res = NULL;
uint16_t port_number = 0; uint16_t port_number = 0;
int rc = int rc =
...@@ -1021,9 +1037,20 @@ int zmq::socket_base_t::connect_internal (const char *endpoint_uri_) ...@@ -1021,9 +1037,20 @@ int zmq::socket_base_t::connect_internal (const char *endpoint_uri_)
// PGM does not support subscription forwarding; ask for all data to be // PGM does not support subscription forwarding; ask for all data to be
// sent to this pipe. (same for NORM, currently?) // sent to this pipe. (same for NORM, currently?)
const bool subscribe_to_all = protocol == "pgm" || protocol == "epgm" #if defined ZMQ_HAVE_OPENPGM && defined ZMQ_HAVE_NORM
|| protocol == "norm" const bool subscribe_to_all =
protocol == protocol_name::pgm || protocol == protocol_name::epgm
|| protocol == protocol_name::norm || protocol == protocol_name::udp;
#elif defined ZMQ_HAVE_OPENPGM
const bool subscribe_to_all = protocol == protocol_name::pgm
|| protocol == protocol_name::epgm
|| protocol == protocol_name::udp; || protocol == protocol_name::udp;
#elif defined ZMQ_HAVE_NORM
const bool subscribe_to_all =
protocol == protocol_name::norm || protocol == protocol_name::udp;
#else
const bool subscribe_to_all = protocol == protocol_name::udp;
#endif
pipe_t *newpipe = NULL; pipe_t *newpipe = NULL;
if (options.immediate != 1 || subscribe_to_all) { if (options.immediate != 1 || subscribe_to_all) {
......
...@@ -1477,7 +1477,7 @@ int zmq_has (const char *capability_) ...@@ -1477,7 +1477,7 @@ int zmq_has (const char *capability_)
return true; return true;
#endif #endif
#if defined(ZMQ_HAVE_OPENPGM) #if defined(ZMQ_HAVE_OPENPGM)
if (strcmp (capability_, "pgm") == 0) if (strcmp (capability_, zmq::protocol_name::pgm) == 0)
return true; return true;
#endif #endif
#if defined(ZMQ_HAVE_TIPC) #if defined(ZMQ_HAVE_TIPC)
...@@ -1485,7 +1485,7 @@ int zmq_has (const char *capability_) ...@@ -1485,7 +1485,7 @@ int zmq_has (const char *capability_)
return true; return true;
#endif #endif
#if defined(ZMQ_HAVE_NORM) #if defined(ZMQ_HAVE_NORM)
if (strcmp (capability_, "norm") == 0) if (strcmp (capability_, zmq::protocol_name::norm) == 0)
return true; return true;
#endif #endif
#if defined(ZMQ_HAVE_CURVE) #if defined(ZMQ_HAVE_CURVE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment