zmq_init.hpp 2.47 KB
Newer Older
1
/*
2
    Copyright (c) 2007-2010 iMatix Corporation
3 4 5 6

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
7
    the terms of the GNU Lesser General Public License as published by
8 9 10 11 12 13
    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
14
    GNU Lesser General Public License for more details.
15

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

20 21
#ifndef __ZMQ_ZMQ_INIT_HPP_INCLUDED__
#define __ZMQ_ZMQ_INIT_HPP_INCLUDED__
22 23

#include "i_inout.hpp"
24
#include "i_engine.hpp"
25
#include "own.hpp"
26
#include "fd.hpp"
27 28
#include "stdint.hpp"
#include "stdint.hpp"
29
#include "blob.hpp"
30 31 32 33

namespace zmq
{

34
    //  The class handles initialisation phase of 0MQ wire-level protocol.
35

36
    class zmq_init_t : public own_t, public i_inout
37 38 39
    {
    public:

40 41
        zmq_init_t (class io_thread_t *io_thread_, class socket_base_t *socket_,
            class session_t *session_, fd_t fd_, const options_t &options_);
42
        ~zmq_init_t ();
43 44 45

    private:

46
        void finalise_initialisation ();
47

48
        //  i_inout interface implementation.
49 50
        bool read (::zmq_msg_t *msg_);
        bool write (::zmq_msg_t *msg_);
51
        void flush ();
52
        void detach ();
53 54 55 56 57

        //  Handlers for incoming commands.
        void process_plug ();
        void process_unplug ();

58
        //  Associated wire-protocol engine.
59
        i_engine *engine;
60

61 62
        //  True if our own identity was already sent to the peer.
        bool sent;
63

64 65 66
        //  True if peer's identity was already received.
        bool received;

67 68 69 70 71 72 73 74
        //  Socket the object belongs to.
        class socket_base_t *socket;

        //  Reference to the session the init object belongs to.
        //  If the associated session is unknown and should be found
        //  depending on peer identity this value is NULL.
        class session_t *session;

75
        //  Identity of the peer socket.
76
        blob_t peer_identity;
Martin Sustrik's avatar
Martin Sustrik committed
77

78 79 80 81
        //  I/O thread the object is living in. It will be used to plug
        //  the engine into the same I/O thread.
        class io_thread_t *io_thread;

82 83
        zmq_init_t (const zmq_init_t&);
        void operator = (const zmq_init_t&);
84 85 86 87 88
    };

}

#endif