2009-12-13 14:45:23 +01:00
|
|
|
/*
|
2012-03-23 23:29:04 +01:00
|
|
|
Copyright (c) 2012 iMatix Corporation
|
2011-10-31 16:20:30 +01:00
|
|
|
Copyright (c) 2009-2011 250bpm s.r.o.
|
2011-11-01 13:39:54 +01:00
|
|
|
Copyright (c) 2011 VMware, Inc.
|
2011-03-02 16:30:40 +01:00
|
|
|
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
|
2009-12-13 14:45:23 +01:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
2010-10-30 15:08:28 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by
|
2009-12-13 14:45:23 +01:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
0MQ is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-10-30 15:08:28 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2010-10-30 15:08:28 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2009-12-13 14:45:23 +01:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
#include "router.hpp"
|
2010-02-16 18:30:38 +01:00
|
|
|
#include "pipe.hpp"
|
2011-06-22 11:02:16 +02:00
|
|
|
#include "wire.hpp"
|
|
|
|
#include "random.hpp"
|
2011-09-28 08:03:14 +02:00
|
|
|
#include "likely.hpp"
|
2011-04-21 22:27:48 +02:00
|
|
|
#include "err.hpp"
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
zmq::router_t::router_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
|
2012-03-20 01:41:20 +01:00
|
|
|
socket_base_t (parent_, tid_, sid_),
|
2012-04-02 19:51:37 +02:00
|
|
|
prefetched (false),
|
|
|
|
identity_sent (false),
|
2010-04-27 17:36:00 +02:00
|
|
|
more_in (false),
|
|
|
|
current_out (NULL),
|
2011-07-15 11:24:33 +02:00
|
|
|
more_out (false),
|
2012-03-15 12:57:38 +01:00
|
|
|
next_peer_id (generate_random ()),
|
2012-10-29 08:03:36 +01:00
|
|
|
mandatory(false),
|
|
|
|
raw_sock(false)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-03-22 17:36:19 +01:00
|
|
|
options.type = ZMQ_ROUTER;
|
2010-02-12 19:42:35 +01:00
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
// TODO: Uncomment the following line when ROUTER will become true ROUTER
|
2011-10-31 15:56:39 +01:00
|
|
|
// rather than generic router socket.
|
2011-06-23 07:57:47 +02:00
|
|
|
// If peer disconnect there's noone to send reply to anyway. We can drop
|
|
|
|
// all the outstanding requests from that peer.
|
2011-10-31 15:56:39 +01:00
|
|
|
// options.delay_on_disconnect = false;
|
2011-06-23 07:57:47 +02:00
|
|
|
|
2011-11-04 08:00:47 +01:00
|
|
|
options.recv_identity = true;
|
2012-10-29 08:03:36 +01:00
|
|
|
options.raw_sock = false;
|
2011-11-04 08:00:47 +01:00
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
prefetched_id.init ();
|
2011-06-22 16:51:40 +02:00
|
|
|
prefetched_msg.init ();
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
zmq::router_t::~router_t ()
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-04-02 19:51:37 +02:00
|
|
|
zmq_assert (anonymous_pipes.empty ());;
|
2010-08-06 17:49:37 +02:00
|
|
|
zmq_assert (outpipes.empty ());
|
2012-04-02 19:51:37 +02:00
|
|
|
prefetched_id.close ();
|
2011-06-22 16:51:40 +02:00
|
|
|
prefetched_msg.close ();
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
void zmq::router_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-08-28 01:05:51 +02:00
|
|
|
// icanhasall_ is unused
|
|
|
|
(void)icanhasall_;
|
|
|
|
|
2011-05-22 17:26:53 +02:00
|
|
|
zmq_assert (pipe_);
|
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
bool identity_ok = identify_peer (pipe_);
|
|
|
|
if (identity_ok)
|
|
|
|
fq.attach (pipe_);
|
|
|
|
else
|
|
|
|
anonymous_pipes.insert (pipe_);
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
int zmq::router_t::xsetsockopt (int option_, const void *optval_,
|
2012-03-15 12:57:38 +01:00
|
|
|
size_t optvallen_)
|
|
|
|
{
|
2012-10-30 12:18:13 +01:00
|
|
|
if (option_ != ZMQ_ROUTER_MANDATORY
|
|
|
|
&& option_ != ZMQ_ROUTER_RAW_SOCK) {
|
2012-03-15 12:57:38 +01:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2012-04-02 19:51:37 +02:00
|
|
|
if (optvallen_ != sizeof (int) || *static_cast <const int*> (optval_) < 0) {
|
2012-03-15 12:57:38 +01:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2012-10-30 12:18:13 +01:00
|
|
|
if (option_ == ZMQ_ROUTER_RAW_SOCK) {
|
|
|
|
raw_sock = *static_cast <const int*> (optval_);
|
|
|
|
if (raw_sock) {
|
2012-10-29 08:03:36 +01:00
|
|
|
options.recv_identity = false;
|
|
|
|
options.raw_sock = true;
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 12:18:13 +01:00
|
|
|
else
|
|
|
|
mandatory = *static_cast <const int*> (optval_);
|
2012-03-15 12:57:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
void zmq::router_t::xterminated (pipe_t *pipe_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-04-02 19:51:37 +02:00
|
|
|
std::set <pipe_t*>::iterator it = anonymous_pipes.find (pipe_);
|
|
|
|
if (it != anonymous_pipes.end ())
|
|
|
|
anonymous_pipes.erase (it);
|
|
|
|
else {
|
|
|
|
outpipes_t::iterator it = outpipes.find (pipe_->get_identity ());
|
|
|
|
zmq_assert (it != outpipes.end ());
|
|
|
|
outpipes.erase (it);
|
|
|
|
fq.terminated (pipe_);
|
|
|
|
if (pipe_ == current_out)
|
|
|
|
current_out = NULL;
|
2010-04-27 17:36:00 +02:00
|
|
|
}
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
void zmq::router_t::xread_activated (pipe_t *pipe_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-04-02 19:51:37 +02:00
|
|
|
std::set <pipe_t*>::iterator it = anonymous_pipes.find (pipe_);
|
|
|
|
if (it == anonymous_pipes.end ())
|
|
|
|
fq.activated (pipe_);
|
|
|
|
else {
|
|
|
|
bool identity_ok = identify_peer (pipe_);
|
2012-04-03 09:28:38 +02:00
|
|
|
if (identity_ok) {
|
2012-04-02 19:51:37 +02:00
|
|
|
anonymous_pipes.erase (it);
|
2012-04-03 09:28:38 +02:00
|
|
|
fq.attach (pipe_);
|
|
|
|
}
|
2012-04-02 19:51:37 +02:00
|
|
|
}
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
void zmq::router_t::xwrite_activated (pipe_t *pipe_)
|
2010-03-01 10:13:26 +01:00
|
|
|
{
|
2012-07-11 15:11:48 +02:00
|
|
|
outpipes_t::iterator it;
|
|
|
|
for (it = outpipes.begin (); it != outpipes.end (); ++it)
|
|
|
|
if (it->second.pipe == pipe_)
|
|
|
|
break;
|
|
|
|
|
|
|
|
zmq_assert (it != outpipes.end ());
|
|
|
|
zmq_assert (!it->second.active);
|
|
|
|
it->second.active = true;
|
2010-03-01 10:13:26 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
int zmq::router_t::xsend (msg_t *msg_, int flags_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-08-28 01:05:51 +02:00
|
|
|
// flags_ is unused
|
|
|
|
(void)flags_;
|
|
|
|
|
2011-06-22 11:02:16 +02:00
|
|
|
// If this is the first part of the message it's the ID of the
|
2010-04-27 17:36:00 +02:00
|
|
|
// peer to send the message to.
|
|
|
|
if (!more_out) {
|
|
|
|
zmq_assert (!current_out);
|
|
|
|
|
2010-08-11 17:05:19 +02:00
|
|
|
// If we have malformed message (prefix with no subsequent message)
|
2010-10-10 09:23:37 +02:00
|
|
|
// then just silently ignore it.
|
2011-06-20 11:33:54 +02:00
|
|
|
// TODO: The connections should be killed instead.
|
2011-11-01 13:39:54 +01:00
|
|
|
if (msg_->flags () & msg_t::more) {
|
2010-10-10 09:23:37 +02:00
|
|
|
|
|
|
|
more_out = true;
|
|
|
|
|
2011-11-04 08:00:47 +01:00
|
|
|
// Find the pipe associated with the identity stored in the prefix.
|
2012-03-15 12:57:38 +01:00
|
|
|
// If there's no such pipe just silently ignore the message, unless
|
2012-06-17 00:33:43 +02:00
|
|
|
// report_unreachable is set.
|
2011-11-04 08:00:47 +01:00
|
|
|
blob_t identity ((unsigned char*) msg_->data (), msg_->size ());
|
|
|
|
outpipes_t::iterator it = outpipes.find (identity);
|
|
|
|
|
|
|
|
if (it != outpipes.end ()) {
|
|
|
|
current_out = it->second.pipe;
|
2012-03-28 06:38:25 +02:00
|
|
|
if (!current_out->check_write ()) {
|
2011-11-04 08:00:47 +01:00
|
|
|
it->second.active = false;
|
|
|
|
current_out = NULL;
|
2011-03-03 12:37:11 +01:00
|
|
|
}
|
2012-10-30 12:18:13 +01:00
|
|
|
}
|
|
|
|
else
|
2012-10-08 09:36:35 +02:00
|
|
|
if (mandatory) {
|
2012-06-17 00:33:43 +02:00
|
|
|
more_out = false;
|
2012-10-19 08:09:52 +02:00
|
|
|
errno = EHOSTUNREACH;
|
2012-06-17 00:33:43 +02:00
|
|
|
return -1;
|
2011-03-03 12:37:11 +01:00
|
|
|
}
|
2010-10-10 09:23:37 +02:00
|
|
|
}
|
2010-04-27 17:36:00 +02:00
|
|
|
|
2011-04-21 22:27:48 +02:00
|
|
|
int rc = msg_->close ();
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
rc = msg_->init ();
|
|
|
|
errno_assert (rc == 0);
|
2012-06-17 00:33:43 +02:00
|
|
|
return 0;
|
2010-02-16 18:30:38 +01:00
|
|
|
}
|
|
|
|
|
2012-10-30 12:18:13 +01:00
|
|
|
// Ignore the MORE flag for raw-sock or assert?
|
|
|
|
if (options.raw_sock)
|
|
|
|
msg_->reset_flags (msg_t::more);
|
2012-10-29 08:03:36 +01:00
|
|
|
|
2010-04-27 17:36:00 +02:00
|
|
|
// Check whether this is the last part of the message.
|
2011-11-01 13:39:54 +01:00
|
|
|
more_out = msg_->flags () & msg_t::more ? true : false;
|
2010-03-02 12:41:33 +01:00
|
|
|
|
2010-04-27 17:36:00 +02:00
|
|
|
// Push the message into the pipe. If there's no out pipe, just drop it.
|
|
|
|
if (current_out) {
|
2012-10-29 08:03:36 +01:00
|
|
|
|
|
|
|
// Close the remote connection if user has asked to do so
|
|
|
|
// by sending zero length message.
|
|
|
|
// Pending messages in the pipe will be dropped (on receiving term- ack)
|
2012-10-30 12:18:13 +01:00
|
|
|
if (raw_sock && msg_->size() == 0) {
|
|
|
|
current_out->terminate (false);
|
2012-10-29 08:03:36 +01:00
|
|
|
int rc = msg_->close ();
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
current_out = NULL;
|
|
|
|
return 0;
|
2012-10-30 12:18:13 +01:00
|
|
|
}
|
2012-10-29 08:03:36 +01:00
|
|
|
|
2010-04-27 17:36:00 +02:00
|
|
|
bool ok = current_out->write (msg_);
|
2011-09-28 08:03:14 +02:00
|
|
|
if (unlikely (!ok))
|
|
|
|
current_out = NULL;
|
2012-10-24 02:18:52 +02:00
|
|
|
else
|
|
|
|
if (!more_out) {
|
2010-04-27 17:36:00 +02:00
|
|
|
current_out->flush ();
|
|
|
|
current_out = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-04-21 22:27:48 +02:00
|
|
|
int rc = msg_->close ();
|
|
|
|
errno_assert (rc == 0);
|
2010-04-27 17:36:00 +02:00
|
|
|
}
|
2010-02-16 18:30:38 +01:00
|
|
|
|
|
|
|
// Detach the message from the data buffer.
|
2011-04-21 22:27:48 +02:00
|
|
|
int rc = msg_->init ();
|
|
|
|
errno_assert (rc == 0);
|
2010-02-16 18:30:38 +01:00
|
|
|
|
|
|
|
return 0;
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
int zmq::router_t::xrecv (msg_t *msg_, int flags_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-08-28 01:05:51 +02:00
|
|
|
// flags_ is unused
|
|
|
|
(void)flags_;
|
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
if (prefetched) {
|
|
|
|
if (!identity_sent) {
|
|
|
|
int rc = msg_->move (prefetched_id);
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
identity_sent = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int rc = msg_->move (prefetched_msg);
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
prefetched = false;
|
|
|
|
}
|
2011-11-01 13:39:54 +01:00
|
|
|
more_in = msg_->flags () & msg_t::more ? true : false;
|
2010-07-06 22:47:07 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-13 10:33:49 +01:00
|
|
|
pipe_t *pipe = NULL;
|
2012-04-26 13:16:51 +02:00
|
|
|
int rc = fq.recvpipe (msg_, &pipe);
|
2012-07-31 16:31:41 +02:00
|
|
|
|
|
|
|
// It's possible that we receive peer's identity. That happens
|
|
|
|
// after reconnection. The current implementation assumes that
|
|
|
|
// the peer always uses the same identity.
|
|
|
|
// TODO: handle the situation when the peer changes its identity.
|
|
|
|
while (rc == 0 && msg_->is_identity ())
|
|
|
|
rc = fq.recvpipe (msg_, &pipe);
|
|
|
|
|
|
|
|
if (rc != 0)
|
2012-04-02 19:51:37 +02:00
|
|
|
return -1;
|
2011-11-04 08:00:47 +01:00
|
|
|
|
2012-05-27 15:31:59 +02:00
|
|
|
zmq_assert (pipe != NULL);
|
2012-04-02 19:51:37 +02:00
|
|
|
|
2011-06-22 16:51:40 +02:00
|
|
|
// If we are in the middle of reading a message, just return the next part.
|
2012-04-02 19:51:37 +02:00
|
|
|
if (more_in)
|
2011-11-01 13:39:54 +01:00
|
|
|
more_in = msg_->flags () & msg_t::more ? true : false;
|
2012-04-02 19:51:37 +02:00
|
|
|
else {
|
|
|
|
// We are at the beginning of a message.
|
|
|
|
// Keep the message part we have in the prefetch buffer
|
|
|
|
// and return the ID of the peer instead.
|
|
|
|
rc = prefetched_msg.move (*msg_);
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
prefetched = true;
|
|
|
|
|
|
|
|
blob_t identity = pipe->get_identity ();
|
|
|
|
rc = msg_->init_size (identity.size ());
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
memcpy (msg_->data (), identity.data (), identity.size ());
|
|
|
|
msg_->set_flags (msg_t::more);
|
|
|
|
identity_sent = true;
|
2010-04-27 17:36:00 +02:00
|
|
|
}
|
2011-11-04 08:00:47 +01:00
|
|
|
|
2011-06-22 16:51:40 +02:00
|
|
|
return 0;
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
int zmq::router_t::rollback (void)
|
2011-05-08 09:02:47 +02:00
|
|
|
{
|
|
|
|
if (current_out) {
|
|
|
|
current_out->rollback ();
|
|
|
|
current_out = NULL;
|
|
|
|
more_out = false;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
bool zmq::router_t::xhas_in ()
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-04-02 19:51:37 +02:00
|
|
|
// If we are in the middle of reading the messages, there are
|
2011-12-17 10:14:32 +01:00
|
|
|
// definitely more parts available.
|
|
|
|
if (more_in)
|
|
|
|
return true;
|
|
|
|
|
2011-11-13 10:33:49 +01:00
|
|
|
// We may already have a message pre-fetched.
|
2012-04-02 19:51:37 +02:00
|
|
|
if (prefetched)
|
2010-04-27 17:36:00 +02:00
|
|
|
return true;
|
2011-11-13 10:33:49 +01:00
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
// Try to read the next message.
|
|
|
|
// The message, if read, is kept in the pre-fetch buffer.
|
|
|
|
pipe_t *pipe = NULL;
|
2012-04-26 13:16:51 +02:00
|
|
|
int rc = fq.recvpipe (&prefetched_msg, &pipe);
|
2012-07-31 16:31:41 +02:00
|
|
|
|
|
|
|
// It's possible that we receive peer's identity. That happens
|
|
|
|
// after reconnection. The current implementation assumes that
|
|
|
|
// the peer always uses the same identity.
|
|
|
|
// TODO: handle the situation when the peer changes its identity.
|
|
|
|
while (rc == 0 && prefetched_msg.is_identity ())
|
|
|
|
rc = fq.recvpipe (&prefetched_msg, &pipe);
|
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
if (rc != 0)
|
2011-11-13 10:33:49 +01:00
|
|
|
return false;
|
2011-12-17 10:14:32 +01:00
|
|
|
|
2012-07-31 16:31:41 +02:00
|
|
|
zmq_assert (pipe != NULL);
|
2012-04-02 19:51:37 +02:00
|
|
|
|
|
|
|
blob_t identity = pipe->get_identity ();
|
|
|
|
rc = prefetched_id.init_size (identity.size ());
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
memcpy (prefetched_id.data (), identity.data (), identity.size ());
|
|
|
|
prefetched_id.set_flags (msg_t::more);
|
|
|
|
|
|
|
|
prefetched = true;
|
|
|
|
identity_sent = false;
|
2011-12-17 10:14:32 +01:00
|
|
|
|
2011-11-13 10:33:49 +01:00
|
|
|
return true;
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
bool zmq::router_t::xhas_out ()
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-03-22 17:36:19 +01:00
|
|
|
// In theory, ROUTER socket is always ready for writing. Whether actual
|
2010-02-16 18:30:38 +01:00
|
|
|
// attempt to write succeeds depends on whitch pipe the message is going
|
|
|
|
// to be routed to.
|
|
|
|
return true;
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-04-02 19:51:37 +02:00
|
|
|
bool zmq::router_t::identify_peer (pipe_t *pipe_)
|
|
|
|
{
|
|
|
|
msg_t msg;
|
|
|
|
blob_t identity;
|
2012-10-29 08:03:36 +01:00
|
|
|
bool ok;
|
2012-04-02 19:51:37 +02:00
|
|
|
|
2012-10-30 12:18:13 +01:00
|
|
|
if (options.raw_sock) { // Always assign identity for raw-socket
|
2012-04-02 19:51:37 +02:00
|
|
|
unsigned char buf [5];
|
|
|
|
buf [0] = 0;
|
|
|
|
put_uint32 (buf + 1, next_peer_id++);
|
|
|
|
identity = blob_t (buf, sizeof buf);
|
2012-10-30 12:18:13 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-10-29 08:03:36 +01:00
|
|
|
msg.init ();
|
|
|
|
ok = pipe_->read (&msg);
|
|
|
|
if (!ok)
|
2012-04-02 19:51:37 +02:00
|
|
|
return false;
|
2012-10-29 08:03:36 +01:00
|
|
|
|
|
|
|
if (msg.size () == 0) {
|
|
|
|
// Fall back on the auto-generation
|
|
|
|
unsigned char buf [5];
|
|
|
|
buf [0] = 0;
|
|
|
|
put_uint32 (buf + 1, next_peer_id++);
|
|
|
|
identity = blob_t (buf, sizeof buf);
|
|
|
|
msg.close ();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
identity = blob_t ((unsigned char*) msg.data (), msg.size ());
|
|
|
|
outpipes_t::iterator it = outpipes.find (identity);
|
|
|
|
msg.close ();
|
|
|
|
|
|
|
|
// Ignore peers with duplicate ID.
|
|
|
|
if (it != outpipes.end ())
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-02 19:51:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pipe_->set_identity (identity);
|
|
|
|
// Add the record into output pipes lookup table
|
|
|
|
outpipe_t outpipe = {pipe_, true};
|
|
|
|
ok = outpipes.insert (outpipes_t::value_type (identity, outpipe)).second;
|
|
|
|
zmq_assert (ok);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
zmq::router_session_t::router_session_t (io_thread_t *io_thread_, bool connect_,
|
2011-09-15 10:00:23 +02:00
|
|
|
socket_base_t *socket_, const options_t &options_,
|
2012-02-02 14:56:51 +01:00
|
|
|
const address_t *addr_) :
|
|
|
|
session_base_t (io_thread_, connect_, socket_, options_, addr_)
|
2011-09-15 10:00:23 +02:00
|
|
|
{
|
|
|
|
}
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2012-03-22 17:36:19 +01:00
|
|
|
zmq::router_session_t::~router_session_t ()
|
2011-09-15 10:00:23 +02:00
|
|
|
{
|
|
|
|
}
|
2011-05-23 20:30:01 +02:00
|
|
|
|