/src/libzmq/src/client.cpp
Line | Count | Source |
1 | | /* SPDX-License-Identifier: MPL-2.0 */ |
2 | | |
3 | | #include "precompiled.hpp" |
4 | | #include "macros.hpp" |
5 | | #include "client.hpp" |
6 | | #include "err.hpp" |
7 | | #include "msg.hpp" |
8 | | |
9 | | zmq::client_t::client_t (class ctx_t *parent_, uint32_t tid_, int sid_) : |
10 | 0 | socket_base_t (parent_, tid_, sid_, true) |
11 | 0 | { |
12 | 0 | options.type = ZMQ_CLIENT; |
13 | 0 | options.can_send_hello_msg = true; |
14 | 0 | options.can_recv_hiccup_msg = true; |
15 | 0 | } |
16 | | |
17 | | zmq::client_t::~client_t () |
18 | 0 | { |
19 | 0 | } |
20 | | |
21 | | void zmq::client_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 | _fq.attach (pipe_); |
31 | 0 | _lb.attach (pipe_); |
32 | 0 | } |
33 | | |
34 | | int zmq::client_t::xsend (msg_t *msg_) |
35 | 0 | { |
36 | | // CLIENT sockets do not allow multipart data (ZMQ_SNDMORE) |
37 | 0 | if (msg_->flags () & msg_t::more) { |
38 | 0 | errno = EINVAL; |
39 | 0 | return -1; |
40 | 0 | } |
41 | 0 | return _lb.sendpipe (msg_, NULL); |
42 | 0 | } |
43 | | |
44 | | int zmq::client_t::xrecv (msg_t *msg_) |
45 | 0 | { |
46 | 0 | int rc = _fq.recvpipe (msg_, NULL); |
47 | | |
48 | | // Drop any messages with more flag |
49 | 0 | while (rc == 0 && msg_->flags () & msg_t::more) { |
50 | | // drop all frames of the current multi-frame message |
51 | 0 | rc = _fq.recvpipe (msg_, NULL); |
52 | |
|
53 | 0 | while (rc == 0 && msg_->flags () & msg_t::more) |
54 | 0 | rc = _fq.recvpipe (msg_, NULL); |
55 | | |
56 | | // get the new message |
57 | 0 | if (rc == 0) |
58 | 0 | rc = _fq.recvpipe (msg_, NULL); |
59 | 0 | } |
60 | |
|
61 | 0 | return rc; |
62 | 0 | } |
63 | | |
64 | | bool zmq::client_t::xhas_in () |
65 | 0 | { |
66 | 0 | return _fq.has_in (); |
67 | 0 | } |
68 | | |
69 | | bool zmq::client_t::xhas_out () |
70 | 0 | { |
71 | 0 | return _lb.has_out (); |
72 | 0 | } |
73 | | |
74 | | void zmq::client_t::xread_activated (pipe_t *pipe_) |
75 | 0 | { |
76 | 0 | _fq.activated (pipe_); |
77 | 0 | } |
78 | | |
79 | | void zmq::client_t::xwrite_activated (pipe_t *pipe_) |
80 | 0 | { |
81 | 0 | _lb.activated (pipe_); |
82 | 0 | } |
83 | | |
84 | | void zmq::client_t::xpipe_terminated (pipe_t *pipe_) |
85 | 0 | { |
86 | 0 | _fq.pipe_terminated (pipe_); |
87 | 0 | _lb.pipe_terminated (pipe_); |
88 | 0 | } |