Commit 3455be14 authored by Simon Giesecke's avatar Simon Giesecke

Problem: code duplication around sending of routing id

Solution: extract functionality into send_routing_id
parent 83f41526
......@@ -652,15 +652,7 @@ void zmq::ctx_t::connect_inproc_sockets (
// is open before sending.
if (pending_connection_.endpoint.options.recv_routing_id
&& pending_connection_.endpoint.socket->check_tag ()) {
msg_t routing_id;
const int rc = routing_id.init_size (bind_options_.routing_id_size);
errno_assert (rc == 0);
memcpy (routing_id.data (), bind_options_.routing_id,
bind_options_.routing_id_size);
routing_id.set_flags (msg_t::routing_id);
const bool written = pending_connection_.bind_pipe->write (&routing_id);
zmq_assert (written);
pending_connection_.bind_pipe->flush ();
send_routing_id (pending_connection_.bind_pipe, bind_options_);
}
}
......
......@@ -76,6 +76,18 @@ int zmq::pipepair (class object_t *parents_[2],
return 0;
}
void zmq::send_routing_id (pipe_t *pipe_, const options_t &options_)
{
zmq::msg_t id;
const int rc = id.init_size (options_.routing_id_size);
errno_assert (rc == 0);
memcpy (id.data (), options_.routing_id, options_.routing_id_size);
id.set_flags (zmq::msg_t::routing_id);
const bool written = pipe_->write (&id);
zmq_assert (written);
pipe_->flush ();
}
zmq::pipe_t::pipe_t (object_t *parent_,
upipe_t *inpipe_,
upipe_t *outpipe_,
......
......@@ -36,6 +36,7 @@
#include "stdint.hpp"
#include "array.hpp"
#include "blob.hpp"
#include "options.hpp"
namespace zmq
{
......@@ -247,6 +248,8 @@ class pipe_t : public object_t,
pipe_t (const pipe_t &);
const pipe_t &operator= (const pipe_t &);
};
void send_routing_id (pipe_t *pipe_, const options_t &options_);
}
#endif
......@@ -721,42 +721,19 @@ int zmq::socket_base_t::connect (const char *addr_)
// to send the routing id message or not. To resolve this,
// we always send our routing id and drop it later if
// the peer doesn't expect it.
msg_t id;
rc = id.init_size (options.routing_id_size);
errno_assert (rc == 0);
memcpy (id.data (), options.routing_id, options.routing_id_size);
id.set_flags (msg_t::routing_id);
const bool written = new_pipes[0]->write (&id);
zmq_assert (written);
new_pipes[0]->flush ();
send_routing_id (new_pipes[0], options);
const endpoint_t endpoint = {this, options};
pend_connection (std::string (addr_), endpoint, new_pipes);
} else {
// If required, send the routing id of the local socket to the peer.
if (peer.options.recv_routing_id) {
msg_t id;
rc = id.init_size (options.routing_id_size);
errno_assert (rc == 0);
memcpy (id.data (), options.routing_id,
options.routing_id_size);
id.set_flags (msg_t::routing_id);
const bool written = new_pipes[0]->write (&id);
zmq_assert (written);
new_pipes[0]->flush ();
send_routing_id (new_pipes[0], options);
}
// If required, send the routing id of the peer to the local socket.
if (options.recv_routing_id) {
msg_t id;
rc = id.init_size (peer.options.routing_id_size);
errno_assert (rc == 0);
memcpy (id.data (), peer.options.routing_id,
peer.options.routing_id_size);
id.set_flags (msg_t::routing_id);
const bool written = new_pipes[1]->write (&id);
zmq_assert (written);
new_pipes[1]->flush ();
send_routing_id (new_pipes[1], peer.options);
}
// Attach remote end of the pipe to the peer socket. Note that peer's
......
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