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