1/*
2 Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3
4 This file is part of libzmq, the ZeroMQ core engine in C++.
5
6 libzmq is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 As a special exception, the Contributors give you permission to link
12 this library with independent modules to produce an executable,
13 regardless of the license terms of these independent modules, and to
14 copy and distribute the resulting executable under terms of your choice,
15 provided that you also meet, for each linked independent module, the
16 terms and conditions of the license of that module. An independent
17 module is a module which is not derived from or based on this library.
18 If you modify this library, you must extend this exception to your
19 version of the library.
20
21 libzmq is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24 License for more details.
25
26 You should have received a copy of the GNU Lesser General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
28*/
29
30#ifndef __ZMQ_PGM_SENDER_HPP_INCLUDED__
31#define __ZMQ_PGM_SENDER_HPP_INCLUDED__
32
33#if defined ZMQ_HAVE_OPENPGM
34
35#include "stdint.hpp"
36#include "io_object.hpp"
37#include "i_engine.hpp"
38#include "options.hpp"
39#include "pgm_socket.hpp"
40#include "v1_encoder.hpp"
41#include "msg.hpp"
42
43namespace zmq
44{
45class io_thread_t;
46class session_base_t;
47
48class pgm_sender_t : public io_object_t, public i_engine
49{
50 public:
51 pgm_sender_t (zmq::io_thread_t *parent_, const options_t &options_);
52 ~pgm_sender_t ();
53
54 int init (bool udp_encapsulation_, const char *network_);
55
56 // i_engine interface implementation.
57 void plug (zmq::io_thread_t *io_thread_, zmq::session_base_t *session_);
58 void terminate ();
59 bool restart_input ();
60 void restart_output ();
61 void zap_msg_available () {}
62 const endpoint_uri_pair_t &get_endpoint () const;
63
64 // i_poll_events interface implementation.
65 void in_event ();
66 void out_event ();
67 void timer_event (int token);
68
69 private:
70 // Unplug the engine from the session.
71 void unplug ();
72
73 // TX and RX timeout timer ID's.
74 enum
75 {
76 tx_timer_id = 0xa0,
77 rx_timer_id = 0xa1
78 };
79
80 const endpoint_uri_pair_t _empty_endpoint;
81
82 // Timers are running.
83 bool has_tx_timer;
84 bool has_rx_timer;
85
86 session_base_t *session;
87
88 // Message encoder.
89 v1_encoder_t encoder;
90
91 msg_t msg;
92
93 // Keeps track of message boundaries.
94 bool more_flag;
95
96 // PGM socket.
97 pgm_socket_t pgm_socket;
98
99 // Socket options.
100 options_t options;
101
102 // Poll handle associated with PGM socket.
103 handle_t handle;
104 handle_t uplink_handle;
105 handle_t rdata_notify_handle;
106 handle_t pending_notify_handle;
107
108 // Output buffer from pgm_socket.
109 unsigned char *out_buffer;
110
111 // Output buffer size.
112 size_t out_buffer_size;
113
114 // Number of bytes in the buffer to be written to the socket.
115 // If zero, there are no data to be sent.
116 size_t write_size;
117
118 ZMQ_NON_COPYABLE_NOR_MOVABLE (pgm_sender_t)
119};
120}
121#endif
122
123#endif
124