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

#ifndef __ZMQ_UDP_ENGINE_HPP_INCLUDED__
#define __ZMQ_UDP_ENGINE_HPP_INCLUDED__

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

#define MAX_UDP_MSG 8192

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

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

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

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

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

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

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

42
    void zap_msg_available (){};
43

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

47
    const char *get_endpoint () const;
48

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

53
    bool plugged;
54

55 56 57 58
    fd_t fd;
    session_base_t *session;
    handle_t handle;
    address_t *address;
59

60
    options_t options;
61

62 63 64
    sockaddr_in raw_address;
    const struct sockaddr *out_address;
    socklen_t out_addrlen;
65

66 67 68 69 70
    unsigned char out_buffer[MAX_UDP_MSG];
    unsigned char in_buffer[MAX_UDP_MSG];
    bool send_enabled;
    bool recv_enabled;
};
71 72 73
}

#endif