sub.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "precompiled.hpp"
4 #include "sub.hpp"
5 #include "msg.hpp"
6 
7 zmq::sub_t::sub_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
8  xsub_t (parent_, tid_, sid_)
9 {
10  options.type = ZMQ_SUB;
11 
12  // Switch filtering messages on (as opposed to XSUB which where the
13  // filtering is off).
14  options.filter = true;
15 }
16 
17 zmq::sub_t::~sub_t ()
18 {
19 }
20 
21 int zmq::sub_t::xsetsockopt (int option_,
22  const void *optval_,
23  size_t optvallen_)
24 {
25  if (option_ != ZMQ_SUBSCRIBE && option_ != ZMQ_UNSUBSCRIBE) {
26  errno = EINVAL;
27  return -1;
28  }
29 
30  // Create the subscription message.
31  msg_t msg;
32  int rc;
33  const unsigned char *data = static_cast<const unsigned char *> (optval_);
34  if (option_ == ZMQ_SUBSCRIBE) {
35  rc = msg.init_subscribe (optvallen_, data);
36  } else {
37  rc = msg.init_cancel (optvallen_, data);
38  }
39  errno_assert (rc == 0);
40 
41  // Pass it further on in the stack.
42  rc = xsub_t::xsend (&msg);
43  return close_and_return (&msg, rc);
44 }
45 
46 int zmq::sub_t::xsend (msg_t *)
47 {
48  // Override the XSUB's send.
49  errno = ENOTSUP;
50  return -1;
51 }
52 
53 bool zmq::sub_t::xhas_out ()
54 {
55  // Override the XSUB's send.
56  return false;
57 }
ENOTSUP
#define ENOTSUP
Definition: zmq.h:104
options
Message * options
Definition: src/google/protobuf/descriptor.cc:3119
EINVAL
#define EINVAL
Definition: errno.hpp:25
precompiled.hpp
errno
int errno
ZMQ_SUBSCRIBE
#define ZMQ_SUBSCRIBE
Definition: zmq.h:278
ZMQ_SUB
#define ZMQ_SUB
Definition: zmq.h:260
errno_assert
#define errno_assert(x)
Definition: err.hpp:113
sub.hpp
zmq::close_and_return
int close_and_return(zmq::msg_t *msg_, int echo_)
Definition: msg.hpp:300
msg.hpp
ZMQ_UNSUBSCRIBE
#define ZMQ_UNSUBSCRIBE
Definition: zmq.h:279
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: glcorearb.h:2879


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