pair.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 "pair.hpp"
6 #include "err.hpp"
7 #include "pipe.hpp"
8 #include "msg.hpp"
9 
10 zmq::pair_t::pair_t (class ctx_t *parent_, uint32_t tid_, int sid_) :
11  socket_base_t (parent_, tid_, sid_), _pipe (NULL)
12 {
13  options.type = ZMQ_PAIR;
14 }
15 
16 zmq::pair_t::~pair_t ()
17 {
18  zmq_assert (!_pipe);
19 }
20 
21 void zmq::pair_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_ != NULL);
29 
30  // ZMQ_PAIR socket can only be connected to a single peer.
31  // The socket rejects any further connection requests.
32  if (_pipe == NULL)
33  _pipe = pipe_;
34  else
35  pipe_->terminate (false);
36 }
37 
38 void zmq::pair_t::xpipe_terminated (pipe_t *pipe_)
39 {
40  if (pipe_ == _pipe) {
41  _pipe = NULL;
42  }
43 }
44 
45 void zmq::pair_t::xread_activated (pipe_t *)
46 {
47  // There's just one pipe. No lists of active and inactive pipes.
48  // There's nothing to do here.
49 }
50 
51 void zmq::pair_t::xwrite_activated (pipe_t *)
52 {
53  // There's just one pipe. No lists of active and inactive pipes.
54  // There's nothing to do here.
55 }
56 
57 int zmq::pair_t::xsend (msg_t *msg_)
58 {
59  if (!_pipe || !_pipe->write (msg_)) {
60  errno = EAGAIN;
61  return -1;
62  }
63 
64  if (!(msg_->flags () & msg_t::more))
65  _pipe->flush ();
66 
67  // Detach the original message from the data buffer.
68  const int rc = msg_->init ();
69  errno_assert (rc == 0);
70 
71  return 0;
72 }
73 
74 int zmq::pair_t::xrecv (msg_t *msg_)
75 {
76  // Deallocate old content of the message.
77  int rc = msg_->close ();
78  errno_assert (rc == 0);
79 
80  if (!_pipe || !_pipe->read (msg_)) {
81  // Initialise the output parameter to be a 0-byte message.
82  rc = msg_->init ();
83  errno_assert (rc == 0);
84 
85  errno = EAGAIN;
86  return -1;
87  }
88  return 0;
89 }
90 
91 bool zmq::pair_t::xhas_in ()
92 {
93  if (!_pipe)
94  return false;
95 
96  return _pipe->check_read ();
97 }
98 
99 bool zmq::pair_t::xhas_out ()
100 {
101  if (!_pipe)
102  return false;
103 
104  return _pipe->check_write ();
105 }
NULL
NULL
Definition: test_security_zap.cpp:405
options
Message * options
Definition: src/google/protobuf/descriptor.cc:3119
EAGAIN
#define EAGAIN
Definition: errno.hpp:14
precompiled.hpp
zmq_assert
#define zmq_assert(x)
Definition: err.hpp:102
errno
int errno
errno_assert
#define errno_assert(x)
Definition: err.hpp:113
macros.hpp
LIBZMQ_UNUSED
#define LIBZMQ_UNUSED(object)
Definition: macros.hpp:6
pipe.hpp
msg.hpp
ZMQ_PAIR
#define ZMQ_PAIR
Definition: zmq.h:258
err.hpp
pair.hpp


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