forked from zeromq/libzmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdealer.cpp
118 lines (95 loc) · 2.41 KB
/
dealer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* SPDX-License-Identifier: MPL-2.0 */
#include "precompiled.hpp"
#include "macros.hpp"
#include "dealer.hpp"
#include "err.hpp"
#include "msg.hpp"
zmq::dealer_t::dealer_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
socket_base_t (parent_, tid_, sid_), _probe_router (false)
{
options.type = ZMQ_DEALER;
options.can_send_hello_msg = true;
options.can_recv_hiccup_msg = true;
}
zmq::dealer_t::~dealer_t ()
{
}
void zmq::dealer_t::xattach_pipe (pipe_t *pipe_,
bool subscribe_to_all_,
bool locally_initiated_)
{
LIBZMQ_UNUSED (subscribe_to_all_);
LIBZMQ_UNUSED (locally_initiated_);
zmq_assert (pipe_);
if (_probe_router) {
msg_t probe_msg;
int rc = probe_msg.init ();
errno_assert (rc == 0);
rc = pipe_->write (&probe_msg);
// zmq_assert (rc) is not applicable here, since it is not a bug.
LIBZMQ_UNUSED (rc);
pipe_->flush ();
rc = probe_msg.close ();
errno_assert (rc == 0);
}
_fq.attach (pipe_);
_lb.attach (pipe_);
}
int zmq::dealer_t::xsetsockopt (int option_,
const void *optval_,
size_t optvallen_)
{
const bool is_int = (optvallen_ == sizeof (int));
int value = 0;
if (is_int)
memcpy (&value, optval_, sizeof (int));
switch (option_) {
case ZMQ_PROBE_ROUTER:
if (is_int && value >= 0) {
_probe_router = (value != 0);
return 0;
}
break;
default:
break;
}
errno = EINVAL;
return -1;
}
int zmq::dealer_t::xsend (msg_t *msg_)
{
return sendpipe (msg_, NULL);
}
int zmq::dealer_t::xrecv (msg_t *msg_)
{
return recvpipe (msg_, NULL);
}
bool zmq::dealer_t::xhas_in ()
{
return _fq.has_in ();
}
bool zmq::dealer_t::xhas_out ()
{
return _lb.has_out ();
}
void zmq::dealer_t::xread_activated (pipe_t *pipe_)
{
_fq.activated (pipe_);
}
void zmq::dealer_t::xwrite_activated (pipe_t *pipe_)
{
_lb.activated (pipe_);
}
void zmq::dealer_t::xpipe_terminated (pipe_t *pipe_)
{
_fq.pipe_terminated (pipe_);
_lb.pipe_terminated (pipe_);
}
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_);
}