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