udp_engine.hpp 1.62 KB
Newer Older
1 2 3 4 5 6 7

#ifndef __ZMQ_UDP_ENGINE_HPP_INCLUDED__
#define __ZMQ_UDP_ENGINE_HPP_INCLUDED__

#include "io_object.hpp"
#include "i_engine.hpp"
#include "address.hpp"
8
#include "msg.hpp"
9 10 11 12 13

#define MAX_UDP_MSG 8192

namespace zmq
{
14 15
class io_thread_t;
class session_base_t;
16

17 18 19 20 21
class udp_engine_t : public io_object_t, public i_engine
{
  public:
    udp_engine_t (const options_t &options_);
    ~udp_engine_t ();
22

23
    int init (address_t *address_, bool send_, bool recv_);
24

25 26 27
    //  i_engine interface implementation.
    //  Plug the engine to the session.
    void plug (zmq::io_thread_t *io_thread_, class session_base_t *session_);
28

29 30 31
    //  Terminate and deallocate the engine. Note that 'detached'
    //  events are not fired on termination.
    void terminate ();
32

33 34
    //  This method is called by the session to signalise that more
    //  messages can be written to the pipe.
35
    bool restart_input ();
36

37 38 39
    //  This method is called by the session to signalise that there
    //  are messages to send available.
    void restart_output ();
40

41
    void zap_msg_available (){};
42

43 44
    void in_event ();
    void out_event ();
45

46
    const char *get_endpoint () const;
47

48 49
  private:
    int resolve_raw_address (char *addr_, size_t length_);
50
    void sockaddr_to_msg (zmq::msg_t *msg_, sockaddr_in *addr_);
51

52
    bool _plugged;
53

54 55 56 57
    fd_t _fd;
    session_base_t *_session;
    handle_t _handle;
    address_t *_address;
58

59
    options_t _options;
60

61 62 63
    sockaddr_in _raw_address;
    const struct sockaddr *_out_address;
    socklen_t _out_address_len;
64

65 66
    char _out_buffer[MAX_UDP_MSG];
    char _in_buffer[MAX_UDP_MSG];
67 68
    bool _send_enabled;
    bool _recv_enabled;
69
};
70 71 72
}

#endif