2009-12-13 14:45:23 +01:00
|
|
|
/*
|
2013-03-12 13:17:00 +01:00
|
|
|
Copyright (c) 2007-2013 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 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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-22 11:36:19 -05:00
|
|
|
void zmq::dealer_t::xattach_pipe (pipe_t *pipe_, bool icanhasall_)
|
2009-12-13 14:45:23 +01:00
|
|
|
{
|
2012-08-27 16:05:51 -07:00
|
|
|
// icanhasall_ is unused
|
|
|
|
(void) icanhasall_;
|
|
|
|
|
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));
|
|
|
|
int value = is_int? *((int *) optval_): 0;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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_);
|
|
|
|
}
|