zmtp_engine.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_ZMTP_ENGINE_HPP_INCLUDED__
4 #define __ZMQ_ZMTP_ENGINE_HPP_INCLUDED__
5 
6 #include <stddef.h>
7 
8 #include "fd.hpp"
9 #include "i_engine.hpp"
10 #include "io_object.hpp"
11 #include "i_encoder.hpp"
12 #include "i_decoder.hpp"
13 #include "options.hpp"
14 #include "socket_base.hpp"
15 #include "metadata.hpp"
16 #include "msg.hpp"
17 #include "stream_engine_base.hpp"
18 
19 namespace zmq
20 {
21 // Protocol revisions
22 enum
23 {
24  ZMTP_1_0 = 0,
25  ZMTP_2_0 = 1,
27 };
28 
29 class io_thread_t;
30 class session_base_t;
31 class mechanism_t;
32 
33 // This engine handles any socket with SOCK_STREAM semantics,
34 // e.g. TCP socket or an UNIX domain socket.
35 
36 class zmtp_engine_t ZMQ_FINAL : public stream_engine_base_t
37 {
38  public:
39  zmtp_engine_t (fd_t fd_,
40  const options_t &options_,
41  const endpoint_uri_pair_t &endpoint_uri_pair_);
42  ~zmtp_engine_t ();
43 
44  protected:
45  // Detects the protocol used by the peer.
46  bool handshake ();
47 
48  void plug_internal ();
49 
50  int process_command_message (msg_t *msg_);
51  int produce_ping_message (msg_t *msg_);
52  int process_heartbeat_message (msg_t *msg_);
53  int produce_pong_message (msg_t *msg_);
54 
55  private:
56  // Receive the greeting from the peer.
57  int receive_greeting ();
58  void receive_greeting_versioned ();
59 
60  typedef bool (zmtp_engine_t::*handshake_fun_t) ();
61  static handshake_fun_t select_handshake_fun (bool unversioned,
62  unsigned char revision,
63  unsigned char minor);
64 
65  bool handshake_v1_0_unversioned ();
66  bool handshake_v1_0 ();
67  bool handshake_v2_0 ();
68  bool handshake_v3_x (bool downgrade_sub);
69  bool handshake_v3_0 ();
70  bool handshake_v3_1 ();
71 
72  int routing_id_msg (msg_t *msg_);
73  int process_routing_id_msg (msg_t *msg_);
74 
76 
77  // Need to store PING payload for PONG
79 
80  static const size_t signature_size = 10;
81 
82  // Size of ZMTP/1.0 and ZMTP/2.0 greeting message
83  static const size_t v2_greeting_size = 12;
84 
85  // Size of ZMTP/3.0 greeting message
86  static const size_t v3_greeting_size = 64;
87 
88  // Expected greeting size.
90 
91  // Greeting received from, and sent to peer
92  unsigned char _greeting_recv[v3_greeting_size];
93  unsigned char _greeting_send[v3_greeting_size];
94 
95  // Size of greeting received so far
96  unsigned int _greeting_bytes_read;
97 
98  // Indicates whether the engine is to inject a phantom
99  // subscription message into the incoming stream.
100  // Needed to support old peers.
102 
104 
105  ZMQ_NON_COPYABLE_NOR_MOVABLE (zmtp_engine_t)
106 };
107 }
108 
109 #endif
stream_engine_base.hpp
zmq::ZMQ_FINAL::_heartbeat_timeout
int _heartbeat_timeout
Definition: zmtp_engine.hpp:103
zmq::ZMTP_2_0
@ ZMTP_2_0
Definition: zmtp_engine.hpp:25
zmq::ZMTP_3_x
@ ZMTP_3_x
Definition: zmtp_engine.hpp:26
zmq::ZMQ_FINAL::_pong_msg
msg_t _pong_msg
Definition: zmtp_engine.hpp:78
zmq
Definition: zmq.hpp:229
zmq::ZMQ_FINAL::_subscription_required
bool _subscription_required
Definition: zmtp_engine.hpp:101
ZMQ_NON_COPYABLE_NOR_MOVABLE
#define ZMQ_NON_COPYABLE_NOR_MOVABLE(classname)
Definition: macros.hpp:58
zmq::ZMQ_FINAL::_greeting_bytes_read
unsigned int _greeting_bytes_read
Definition: zmtp_engine.hpp:96
fd.hpp
minor
int minor
Definition: gl3w.c:93
msg.hpp
metadata.hpp
zmq::ZMQ_FINAL::_routing_id_msg
msg_t _routing_id_msg
Definition: zmtp_engine.hpp:75
options.hpp
socket_base.hpp
zmq::ZMQ_FINAL::_greeting_size
size_t _greeting_size
Definition: zmtp_engine.hpp:89
io_object.hpp
fd_t
zmq_fd_t fd_t
Definition: libzmq/tests/testutil.hpp:98
zmq::ZMTP_1_0
@ ZMTP_1_0
Definition: zmtp_engine.hpp:24
i_engine.hpp
ZMQ_FINAL
Definition: unittest_ip_resolver.cpp:26
i_decoder.hpp
zmq::msg_t
Definition: msg.hpp:33
i_encoder.hpp
options_
DebugStringOptions options_
Definition: src/google/protobuf/descriptor.cc:2410


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