udp_engine.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef __ZMQ_UDP_ENGINE_HPP_INCLUDED__
  2. #define __ZMQ_UDP_ENGINE_HPP_INCLUDED__
  3. #include "io_object.hpp"
  4. #include "i_engine.hpp"
  5. #include "address.hpp"
  6. #include "msg.hpp"
  7. #define MAX_UDP_MSG 8192
  8. namespace zmq
  9. {
  10. class io_thread_t;
  11. class session_base_t;
  12. class udp_engine_t ZMQ_FINAL : public io_object_t, public i_engine
  13. {
  14. public:
  15. udp_engine_t (const options_t &options_);
  16. ~udp_engine_t ();
  17. int init (address_t *address_, bool send_, bool recv_);
  18. bool has_handshake_stage () ZMQ_FINAL { return false; };
  19. // i_engine interface implementation.
  20. // Plug the engine to the session.
  21. void plug (zmq::io_thread_t *io_thread_, class session_base_t *session_);
  22. // Terminate and deallocate the engine. Note that 'detached'
  23. // events are not fired on termination.
  24. void terminate ();
  25. // This method is called by the session to signalise that more
  26. // messages can be written to the pipe.
  27. bool restart_input ();
  28. // This method is called by the session to signalise that there
  29. // are messages to send available.
  30. void restart_output ();
  31. void zap_msg_available (){};
  32. void in_event ();
  33. void out_event ();
  34. const endpoint_uri_pair_t &get_endpoint () const;
  35. private:
  36. int resolve_raw_address (const char *name_, size_t length_);
  37. static void sockaddr_to_msg (zmq::msg_t *msg_, const sockaddr_in *addr_);
  38. static int set_udp_reuse_address (fd_t s_, bool on_);
  39. static int set_udp_reuse_port (fd_t s_, bool on_);
  40. // Indicate, if the multicast data being sent should be looped back
  41. static int set_udp_multicast_loop (fd_t s_, bool is_ipv6_, bool loop_);
  42. // Set multicast TTL
  43. static int set_udp_multicast_ttl (fd_t s_, bool is_ipv6_, int hops_);
  44. // Set multicast address/interface
  45. int set_udp_multicast_iface (fd_t s_,
  46. bool is_ipv6_,
  47. const udp_address_t *addr_);
  48. // Join a multicast group
  49. int add_membership (fd_t s_, const udp_address_t *addr_);
  50. // Function to handle network issues.
  51. void error (error_reason_t reason_);
  52. const endpoint_uri_pair_t _empty_endpoint;
  53. bool _plugged;
  54. fd_t _fd;
  55. session_base_t *_session;
  56. handle_t _handle;
  57. address_t *_address;
  58. options_t _options;
  59. sockaddr_in _raw_address;
  60. const struct sockaddr *_out_address;
  61. zmq_socklen_t _out_address_len;
  62. char _out_buffer[MAX_UDP_MSG];
  63. char _in_buffer[MAX_UDP_MSG];
  64. bool _send_enabled;
  65. bool _recv_enabled;
  66. };
  67. }
  68. #endif