pgm_sender.hpp 3.5 KB

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