raw_engine.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 
6 #include <limits.h>
7 #include <string.h>
8 
9 #ifndef ZMQ_HAVE_WINDOWS
10 #include <unistd.h>
11 #endif
12 
13 #include <new>
14 #include <sstream>
15 
16 #include "raw_engine.hpp"
17 #include "io_thread.hpp"
18 #include "session_base.hpp"
19 #include "v1_encoder.hpp"
20 #include "v1_decoder.hpp"
21 #include "v2_encoder.hpp"
22 #include "v2_decoder.hpp"
23 #include "null_mechanism.hpp"
24 #include "plain_client.hpp"
25 #include "plain_server.hpp"
26 #include "gssapi_client.hpp"
27 #include "gssapi_server.hpp"
28 #include "curve_client.hpp"
29 #include "curve_server.hpp"
30 #include "raw_decoder.hpp"
31 #include "raw_encoder.hpp"
32 #include "config.hpp"
33 #include "err.hpp"
34 #include "ip.hpp"
35 #include "tcp.hpp"
36 #include "likely.hpp"
37 #include "wire.hpp"
38 
39 zmq::raw_engine_t::raw_engine_t (
40  fd_t fd_,
41  const options_t &options_,
42  const endpoint_uri_pair_t &endpoint_uri_pair_) :
43  stream_engine_base_t (fd_, options_, endpoint_uri_pair_, false)
44 {
45 }
46 
47 zmq::raw_engine_t::~raw_engine_t ()
48 {
49 }
50 
51 void zmq::raw_engine_t::plug_internal ()
52 {
53  // no handshaking for raw sock, instantiate raw encoder and decoders
54  _encoder = new (std::nothrow) raw_encoder_t (_options.out_batch_size);
55  alloc_assert (_encoder);
56 
57  _decoder = new (std::nothrow) raw_decoder_t (_options.in_batch_size);
58  alloc_assert (_decoder);
59 
60  _next_msg = &raw_engine_t::pull_msg_from_session;
61  _process_msg = static_cast<int (stream_engine_base_t::*) (msg_t *)> (
62  &raw_engine_t::push_raw_msg_to_session);
63 
64  properties_t properties;
65  if (init_properties (properties)) {
66  // Compile metadata.
67  zmq_assert (_metadata == NULL);
68  _metadata = new (std::nothrow) metadata_t (properties);
69  alloc_assert (_metadata);
70  }
71 
72  if (_options.raw_notify) {
73  // For raw sockets, send an initial 0-length message to the
74  // application so that it knows a peer has connected.
75  msg_t connector;
76  connector.init ();
77  push_raw_msg_to_session (&connector);
78  connector.close ();
79  session ()->flush ();
80  }
81 
82  set_pollin ();
83  set_pollout ();
84  // Flush all the data that may have been already received downstream.
85  in_event ();
86 }
87 
88 bool zmq::raw_engine_t::handshake ()
89 {
90  return true;
91 }
92 
93 void zmq::raw_engine_t::error (error_reason_t reason_)
94 {
95  if (_options.raw_socket && _options.raw_notify) {
96  // For raw sockets, send a final 0-length message to the application
97  // so that it knows the peer has been disconnected.
98  msg_t terminator;
99  terminator.init ();
100  push_raw_msg_to_session (&terminator);
101  terminator.close ();
102  }
103  stream_engine_base_t::error (reason_);
104 }
105 
106 int zmq::raw_engine_t::push_raw_msg_to_session (msg_t *msg_)
107 {
108  if (_metadata && _metadata != msg_->metadata ())
109  msg_->set_metadata (_metadata);
110  return push_msg_to_session (msg_);
111 }
ip.hpp
NULL
NULL
Definition: test_security_zap.cpp:405
config.hpp
raw_encoder.hpp
gssapi_server.hpp
precompiled.hpp
zmq_assert
#define zmq_assert(x)
Definition: err.hpp:102
null_mechanism.hpp
raw_engine.hpp
wire.hpp
v2_encoder.hpp
alloc_assert
#define alloc_assert(x)
Definition: err.hpp:146
v1_encoder.hpp
v2_decoder.hpp
macros.hpp
v1_decoder.hpp
curve_server.hpp
gssapi_client.hpp
raw_decoder.hpp
plain_server.hpp
plain_client.hpp
io_thread.hpp
tcp.hpp
err.hpp
likely.hpp
fd_t
zmq_fd_t fd_t
Definition: libzmq/tests/testutil.hpp:98
zmq::stream_engine_base_t::error
virtual void error(error_reason_t reason_)
Definition: stream_engine_base.cpp:667
session_base.hpp
false
#define false
Definition: cJSON.c:70
curve_client.hpp
options_
DebugStringOptions options_
Definition: src/google/protobuf/descriptor.cc:2410


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