summaryrefslogtreecommitdiff
path: root/src/session_stub.hpp
blob: 4499e454905d1d16e49f1f7c7acf25818822430a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
    Copyright (c) 2007-2009 FastMQ Inc.

    This file is part of 0MQ.

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

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

#ifndef __ZMQ_SESSION_STUB_HPP_INCLUDED__
#define __ZMQ_SESSION_STUB_HPP_INCLUDED__

#include <string>

#include "i_session.hpp"

namespace zmq
{

    //  This class is used instead of regular session till the identity of
    //  incomming connection is established and connection is attached
    //  to corresponding session.

    class session_stub_t : public i_session
    {
    public:

        session_stub_t (class listener_t *listener_);

        //  i_session implementation.
        void set_engine (struct i_engine *engine_);
        void terminate ();
        void shutdown ();
        bool read (struct zmq_msg *msg_);
        bool write (struct zmq_msg *msg_);
        void flush ();

        //  Detaches engine from the stub. Returns it to the caller.
        struct i_engine *detach_engine ();

        //  Manipulate stubs's index in listener's array of stubs.
        void set_index (int index_);
        int get_index ();

    private:

        //  Clean-up.
        virtual ~session_stub_t ();

        enum {
            reading_identity,
            has_identity
        } state;

        //  Reference to the associated engine.
        i_engine *engine;

        //  Reference to the listener object that owns this stub.
        class listener_t *listener;

        //  Index of the stub in listener's array of stubs.
        int index;

        //  Identity of the connection.
        std::string identity;

        session_stub_t (const session_stub_t&);
        void operator = (const session_stub_t&);
    };

}

#endif