2009-12-13 14:45:23 +01:00
|
|
|
/*
|
2016-01-28 15:07:31 +01:00
|
|
|
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License, or
|
2009-12-13 14:45:23 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
As a special exception, the Contributors give you permission to link
|
|
|
|
this library with independent modules to produce an executable,
|
|
|
|
regardless of the license terms of these independent modules, and to
|
|
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the
|
|
|
|
terms and conditions of the license of that module. An independent
|
|
|
|
module is a module which is not derived from or based on this library.
|
|
|
|
If you modify this library, you must extend this exception to your
|
|
|
|
version of the library.
|
|
|
|
|
|
|
|
libzmq 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 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-02-18 10:56:52 -06:00
|
|
|
#include "precompiled.hpp"
|
2015-08-21 16:12:22 -07:00
|
|
|
#include "macros.hpp"
|
2012-03-22 11:36:19 -05:00
|
|
|
#include "dealer.hpp"
|
2009-12-13 14:45:23 +01:00
|
|
|
#include "err.hpp"
|
2011-04-21 22:27:48 +02:00
|
|
|
#include "msg.hpp"
|
2009-12-13 14:45:23 +01:00
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
zmq::dealer_t::dealer_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
|
2013-05-23 01:49:40 -07:00
|
|
|
socket_base_t (parent_, tid_, sid_),
|
2013-06-05 15:55:15 +02:00
|
|
|
probe_router (false)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-03-22 11:36:19 -05:00
|
|
|
options.type = ZMQ_DEALER;
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
zmq::dealer_t::~dealer_t ()
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-31 09:53:47 -04:00
|
|
|
void zmq::dealer_t::xattach_pipe (pipe_t *pipe_, bool subscribe_to_all_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2015-09-11 13:03:31 -04:00
|
|
|
LIBZMQ_UNUSED (subscribe_to_all_);
|
2012-08-27 16:05:51 -07:00
|
|
|
|
2011-05-22 17:26:53 +02:00
|
|
|
zmq_assert (pipe_);
|
2013-05-23 01:49:40 -07:00
|
|
|
|
2013-06-05 15:55:15 +02:00
|
|
|
if (probe_router) {
|
2013-05-23 01:49:40 -07:00
|
|
|
msg_t probe_msg_;
|
2013-06-05 15:55:15 +02:00
|
|
|
int rc = probe_msg_.init ();
|
2013-05-23 01:49:40 -07:00
|
|
|
errno_assert (rc == 0);
|
|
|
|
|
2013-06-10 02:31:00 -07:00
|
|
|
rc = pipe_->write (&probe_msg_);
|
|
|
|
// zmq_assert (rc) is not applicable here, since it is not a bug.
|
2013-05-23 01:49:40 -07:00
|
|
|
pipe_->flush ();
|
|
|
|
|
|
|
|
rc = probe_msg_.close ();
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
}
|
|
|
|
|
2011-05-22 17:26:53 +02:00
|
|
|
fq.attach (pipe_);
|
|
|
|
lb.attach (pipe_);
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2013-05-23 01:49:40 -07:00
|
|
|
int zmq::dealer_t::xsetsockopt (int option_, const void *optval_,
|
|
|
|
size_t optvallen_)
|
|
|
|
{
|
|
|
|
bool is_int = (optvallen_ == sizeof (int));
|
2016-02-06 22:20:42 -05:00
|
|
|
int value = 0;
|
|
|
|
if (is_int) memcpy(&value, optval_, sizeof (int));
|
2013-05-23 01:49:40 -07:00
|
|
|
|
|
|
|
switch (option_) {
|
2013-06-05 15:55:15 +02:00
|
|
|
case ZMQ_PROBE_ROUTER:
|
2013-05-23 01:49:40 -07:00
|
|
|
if (is_int && value >= 0) {
|
2013-08-23 17:14:03 -07:00
|
|
|
probe_router = (value != 0);
|
2013-05-23 01:49:40 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-09 17:08:03 +01:00
|
|
|
int zmq::dealer_t::xsend (msg_t *msg_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2013-07-02 20:05:20 +02:00
|
|
|
return sendpipe (msg_, NULL);
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-11-09 17:17:43 +01:00
|
|
|
int zmq::dealer_t::xrecv (msg_t *msg_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2013-07-02 20:05:20 +02:00
|
|
|
return recvpipe (msg_, NULL);
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
bool zmq::dealer_t::xhas_in ()
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-11-09 15:45:25 +01:00
|
|
|
return fq.has_in ();
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
bool zmq::dealer_t::xhas_out ()
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2010-07-30 16:49:06 +02:00
|
|
|
return lb.has_out ();
|
2009-12-13 14:45:23 +01:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:58:36 +01:00
|
|
|
zmq::blob_t zmq::dealer_t::get_credential () const
|
|
|
|
{
|
|
|
|
return fq.get_credential ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
void zmq::dealer_t::xread_activated (pipe_t *pipe_)
|
2011-05-22 17:26:53 +02:00
|
|
|
{
|
|
|
|
fq.activated (pipe_);
|
|
|
|
}
|
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
void zmq::dealer_t::xwrite_activated (pipe_t *pipe_)
|
2011-05-22 17:26:53 +02:00
|
|
|
{
|
|
|
|
lb.activated (pipe_);
|
|
|
|
}
|
|
|
|
|
2013-05-28 16:49:24 +02:00
|
|
|
void zmq::dealer_t::xpipe_terminated (pipe_t *pipe_)
|
2011-05-22 17:26:53 +02:00
|
|
|
{
|
2013-05-28 16:49:24 +02:00
|
|
|
fq.pipe_terminated (pipe_);
|
|
|
|
lb.pipe_terminated (pipe_);
|
2011-05-22 17:26:53 +02:00
|
|
|
}
|
2013-07-02 20:05:20 +02:00
|
|
|
|
|
|
|
int zmq::dealer_t::sendpipe (msg_t *msg_, pipe_t **pipe_)
|
|
|
|
{
|
|
|
|
return lb.sendpipe (msg_, pipe_);
|
|
|
|
}
|
|
|
|
|
|
|
|
int zmq::dealer_t::recvpipe (msg_t *msg_, pipe_t **pipe_)
|
|
|
|
{
|
|
|
|
return fq.recvpipe (msg_, pipe_);
|
|
|
|
}
|