zmq: add support for TIPC transport

A ZeroMQ application can opt for TIPC based sockets
using the TIPC port name format:
zmq_bind(sb, "tipc://{type,lower,upper}");
zmq_connect(sc, "tipc://{type,inst}");

'type' is the service ID, and 'lower/upper' can be
used for service partitioning or basic load
balancing.

ZeroMQ TIPC transport requires a kernel >= 3.8
(nonblocking connect support for TIPC).

Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
This commit is contained in:
Erik Hugne
2013-11-01 09:09:54 +01:00
parent bc88b88804
commit eab85b5295
11 changed files with 914 additions and 3 deletions

View File

@@ -39,6 +39,7 @@
#include "socket_base.hpp"
#include "tcp_listener.hpp"
#include "ipc_listener.hpp"
#include "tipc_listener.hpp"
#include "tcp_connecter.hpp"
#include "io_thread.hpp"
#include "session_base.hpp"
@@ -52,6 +53,7 @@
#include "address.hpp"
#include "ipc_address.hpp"
#include "tcp_address.hpp"
#include "tipc_address.hpp"
#ifdef ZMQ_HAVE_OPENPGM
#include "pgm_socket.hpp"
#endif
@@ -184,7 +186,7 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_)
{
// First check out whether the protcol is something we are aware of.
if (protocol_ != "inproc" && protocol_ != "ipc" && protocol_ != "tcp" &&
protocol_ != "pgm" && protocol_ != "epgm") {
protocol_ != "pgm" && protocol_ != "epgm" && protocol_ != "tipc") {
errno = EPROTONOSUPPORT;
return -1;
}
@@ -207,6 +209,14 @@ int zmq::socket_base_t::check_protocol (const std::string &protocol_)
}
#endif
// TIPC transport is only available on Linux.
#if !defined ZMQ_HAVE_LINUX
if (protocol_ = "tipc") {
errno = EPROTONOSUPPORT;
return -1;
}
#endif
// Check whether socket type and transport protocol match.
// Specifically, multicast protocols can't be combined with
// bi-directional messaging patterns (socket types).
@@ -399,6 +409,25 @@ int zmq::socket_base_t::bind (const char *addr_)
return 0;
}
#endif
#if defined ZMQ_HAVE_LINUX
if (protocol == "tipc") {
tipc_listener_t *listener = new (std::nothrow) tipc_listener_t (
io_thread, this, options);
alloc_assert (listener);
int rc = listener->set_address (address.c_str ());
if (rc != 0) {
delete listener;
event_bind_failed (address, zmq_errno());
return -1;
}
// Save last endpoint URI
listener->get_address (last_endpoint);
add_endpoint (addr_, (own_t *) listener, NULL);
return 0;
}
#endif
zmq_assert (false);
return -1;
@@ -560,6 +589,19 @@ int zmq::socket_base_t::connect (const char *addr_)
return -1;
}
#endif
#if defined ZMQ_HAVE_LINUX
else
if (protocol == "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());
if (rc != 0) {
delete paddr;
return -1;
}
}
#endif
// Create session.
session_base_t *session = session_base_t::create (io_thread, true, this,
options, paddr);