zmq_engine.hpp 2.15 KB
Newer Older
1
/*
2 3
    Copyright (c) 2007-2011 iMatix Corporation
    Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
4 5 6 7

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
8
    the terms of the GNU Lesser General Public License as published by
9 10 11 12 13 14
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU Lesser General Public License for more details.
16

17
    You should have received a copy of the GNU Lesser General Public License
18 19 20 21 22 23
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __ZMQ_ZMQ_ENGINE_HPP_INCLUDED__
#define __ZMQ_ZMQ_ENGINE_HPP_INCLUDED__

24 25
#include <stddef.h>

26 27
#include <string>

28
#include "i_engine.hpp"
29
#include "io_object.hpp"
30
#include "tcp_socket.hpp"
31 32
#include "encoder.hpp"
#include "decoder.hpp"
33
#include "options.hpp"
34 35 36 37

namespace zmq
{

38
    class zmq_engine_t : public io_object_t, public i_engine
39 40 41
    {
    public:

42
        zmq_engine_t (fd_t fd_, const options_t &options_);
43
        ~zmq_engine_t ();
44

45
        //  i_engine interface implementation.
46
        void plug (class io_thread_t *io_thread_, struct i_inout *inout_);
47
        void unplug ();
48
        void terminate ();
49 50
        void activate_in ();
        void activate_out ();
51 52 53 54

        //  i_poll_events interface implementation.
        void in_event ();
        void out_event ();
55 56 57

    private:

58 59 60 61 62 63
        //  Function to handle network disconnections.
        void error ();

        tcp_socket_t tcp_socket;
        handle_t handle;

64
        unsigned char *inpos;
65
        size_t insize;
66
        decoder_t decoder;
67

68
        unsigned char *outpos;
69
        size_t outsize;
70
        encoder_t encoder;
71 72

        i_inout *inout;
73

74 75 76
        //  Detached transient inout handler.
        i_inout *ephemeral_inout;

77 78
        options_t options;

79 80
        bool plugged;

81
        zmq_engine_t (const zmq_engine_t&);
82
        const zmq_engine_t &operator = (const zmq_engine_t&);
83 84 85 86 87
    };

}

#endif