dealer.cpp
Go to the documentation of this file.
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  socket_base_t (parent_, tid_, sid_), _probe_router (false)
11 {
15 }
16 
18 {
19 }
20 
21 void zmq::dealer_t::xattach_pipe (pipe_t *pipe_,
22  bool subscribe_to_all_,
23  bool locally_initiated_)
24 {
25  LIBZMQ_UNUSED (subscribe_to_all_);
26  LIBZMQ_UNUSED (locally_initiated_);
27 
28  zmq_assert (pipe_);
29 
30  if (_probe_router) {
31  msg_t probe_msg;
32  int rc = probe_msg.init ();
33  errno_assert (rc == 0);
34 
35  rc = pipe_->write (&probe_msg);
36  // zmq_assert (rc) is not applicable here, since it is not a bug.
37  LIBZMQ_UNUSED (rc);
38 
39  pipe_->flush ();
40 
41  rc = probe_msg.close ();
42  errno_assert (rc == 0);
43  }
44 
45  _fq.attach (pipe_);
46  _lb.attach (pipe_);
47 }
48 
49 int zmq::dealer_t::xsetsockopt (int option_,
50  const void *optval_,
51  size_t optvallen_)
52 {
53  const bool is_int = (optvallen_ == sizeof (int));
54  int value = 0;
55  if (is_int)
56  memcpy (&value, optval_, sizeof (int));
57 
58  switch (option_) {
59  case ZMQ_PROBE_ROUTER:
60  if (is_int && value >= 0) {
61  _probe_router = (value != 0);
62  return 0;
63  }
64  break;
65 
66  default:
67  break;
68  }
69 
70  errno = EINVAL;
71  return -1;
72 }
73 
75 {
76  return sendpipe (msg_, NULL);
77 }
78 
80 {
81  return recvpipe (msg_, NULL);
82 }
83 
85 {
86  return _fq.has_in ();
87 }
88 
90 {
91  return _lb.has_out ();
92 }
93 
94 void zmq::dealer_t::xread_activated (pipe_t *pipe_)
95 {
96  _fq.activated (pipe_);
97 }
98 
99 void zmq::dealer_t::xwrite_activated (pipe_t *pipe_)
100 {
101  _lb.activated (pipe_);
102 }
103 
105 {
106  _fq.pipe_terminated (pipe_);
107  _lb.pipe_terminated (pipe_);
108 }
109 
110 int zmq::dealer_t::sendpipe (msg_t *msg_, pipe_t **pipe_)
111 {
112  return _lb.sendpipe (msg_, pipe_);
113 }
114 
115 int zmq::dealer_t::recvpipe (msg_t *msg_, pipe_t **pipe_)
116 {
117  return _fq.recvpipe (msg_, pipe_);
118 }
NULL
NULL
Definition: test_security_zap.cpp:405
EINVAL
#define EINVAL
Definition: errno.hpp:25
zmq::dealer_t::xattach_pipe
void xattach_pipe(zmq::pipe_t *pipe_, bool subscribe_to_all_, bool locally_initiated_) ZMQ_FINAL
Definition: dealer.cpp:21
zmq::dealer_t::xhas_out
bool xhas_out() ZMQ_OVERRIDE
Definition: dealer.cpp:89
precompiled.hpp
zmq_assert
#define zmq_assert(x)
Definition: err.hpp:102
errno
int errno
zmq::socket_base_t
Definition: socket_base.hpp:31
zmq::dealer_t::xhas_in
bool xhas_in() ZMQ_OVERRIDE
Definition: dealer.cpp:84
zmq::dealer_t::xrecv
int xrecv(zmq::msg_t *msg_) ZMQ_OVERRIDE
Definition: dealer.cpp:79
zmq::dealer_t::xwrite_activated
void xwrite_activated(zmq::pipe_t *pipe_) ZMQ_FINAL
Definition: dealer.cpp:99
zmq::options_t::can_send_hello_msg
bool can_send_hello_msg
Definition: options.hpp:279
ZMQ_DEALER
#define ZMQ_DEALER
Definition: zmq.h:263
errno_assert
#define errno_assert(x)
Definition: err.hpp:113
zmq::dealer_t::sendpipe
int sendpipe(zmq::msg_t *msg_, zmq::pipe_t **pipe_)
Definition: dealer.cpp:110
macros.hpp
LIBZMQ_UNUSED
#define LIBZMQ_UNUSED(object)
Definition: macros.hpp:6
zmq::msg_t::close
int close()
Definition: msg.cpp:242
zmq::options_t::can_recv_hiccup_msg
bool can_recv_hiccup_msg
Definition: options.hpp:287
zmq::dealer_t::xsend
int xsend(zmq::msg_t *msg_) ZMQ_OVERRIDE
Definition: dealer.cpp:74
zmq::own_t::options
options_t options
Definition: own.hpp:78
zmq::msg_t::init
int init()
Definition: msg.cpp:50
msg.hpp
zmq::dealer_t::xpipe_terminated
void xpipe_terminated(zmq::pipe_t *pipe_) ZMQ_OVERRIDE
Definition: dealer.cpp:104
zmq::dealer_t::xsetsockopt
int xsetsockopt(int option_, const void *optval_, size_t optvallen_) ZMQ_OVERRIDE
Definition: dealer.cpp:49
zmq::dealer_t::~dealer_t
~dealer_t() ZMQ_OVERRIDE
Definition: dealer.cpp:17
ZMQ_PROBE_ROUTER
#define ZMQ_PROBE_ROUTER
Definition: zmq.h:316
zmq::dealer_t::xread_activated
void xread_activated(zmq::pipe_t *pipe_) ZMQ_FINAL
Definition: dealer.cpp:94
dealer.hpp
err.hpp
zmq::dealer_t::dealer_t
dealer_t(zmq::ctx_t *parent_, uint32_t tid_, int sid_)
Definition: dealer.cpp:9
value
GLsizei const GLfloat * value
Definition: glcorearb.h:3093
zmq::options_t::type
int8_t type
Definition: options.hpp:80
false
#define false
Definition: cJSON.c:70
zmq::msg_t
Definition: msg.hpp:33
zmq::dealer_t::recvpipe
int recvpipe(zmq::msg_t *msg_, zmq::pipe_t **pipe_)
Definition: dealer.cpp:115


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:49