command.hpp 4.43 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
2
    Copyright (c) 2007-2015 Contributors as noted in the AUTHORS file
Martin Sustrik's avatar
Martin Sustrik committed
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
Martin Sustrik's avatar
Martin Sustrik committed
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.
Martin Sustrik's avatar
Martin Sustrik committed
15

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

Martin Sustrik's avatar
Martin Sustrik committed
20 21
#ifndef __ZMQ_COMMAND_HPP_INCLUDED__
#define __ZMQ_COMMAND_HPP_INCLUDED__
Martin Sustrik's avatar
Martin Sustrik committed
22 23 24

#include "stdint.hpp"

Martin Sustrik's avatar
Martin Sustrik committed
25
namespace zmq
Martin Sustrik's avatar
Martin Sustrik committed
26 27
{

28 29 30 31 32 33
    class object_t;
    class own_t;
    struct i_engine;
    class pipe_t;
    class socket_base_t;

Martin Sustrik's avatar
Martin Sustrik committed
34 35
    //  This structure defines the commands that can be sent between threads.

36 37 38
#ifdef _MSC_VER
    __declspec(align(64)) struct command_t
#else
Martin Sustrik's avatar
Martin Sustrik committed
39
    struct command_t
40
#endif
Martin Sustrik's avatar
Martin Sustrik committed
41 42
    {
        //  Object to process the command.
43
        zmq::object_t *destination;
Martin Sustrik's avatar
Martin Sustrik committed
44 45 46 47

        enum type_t
        {
            stop,
48 49
            plug,
            own,
50
            attach,
Martin Sustrik's avatar
Martin Sustrik committed
51
            bind,
52 53
            activate_read,
            activate_write,
54
            hiccup,
Martin Sustrik's avatar
Martin Sustrik committed
55 56
            pipe_term,
            pipe_term_ack,
57 58
            term_req,
            term,
59 60
            term_ack,
            reap,
61
            reaped,
62
            inproc_connected,
63
            done
Martin Sustrik's avatar
Martin Sustrik committed
64 65
        } type;

66 67
        union args_t
        {
Martin Sustrik's avatar
Martin Sustrik committed
68

69 70
            //  Sent to I/O thread to let it know that it should
            //  terminate itself.
Martin Sustrik's avatar
Martin Sustrik committed
71 72 73
            struct {
            } stop;

74
            //  Sent to I/O object to make it register with its I/O thread.
Martin Sustrik's avatar
Martin Sustrik committed
75
            struct {
76
            } plug;
Martin Sustrik's avatar
Martin Sustrik committed
77

78
            //  Sent to socket to let it know about the newly created object.
Martin Sustrik's avatar
Martin Sustrik committed
79
            struct {
80
                zmq::own_t *object;
81
            } own;
Martin Sustrik's avatar
Martin Sustrik committed
82

83 84
            //  Attach the engine to the session. If engine is NULL, it informs
            //  session that the connection have failed.
85
            struct {
86
                struct i_engine *engine;
87 88
            } attach;

Martin Sustrik's avatar
Martin Sustrik committed
89
            //  Sent from session to socket to establish pipe(s) between them.
90
            //  Caller have used inc_seqnum beforehand sending the command.
Martin Sustrik's avatar
Martin Sustrik committed
91
            struct {
92
                zmq::pipe_t *pipe;
93
            } bind;
Martin Sustrik's avatar
Martin Sustrik committed
94

Martin Sustrik's avatar
Martin Sustrik committed
95 96 97
            //  Sent by pipe writer to inform dormant pipe reader that there
            //  are messages in the pipe.
            struct {
98
            } activate_read;
Martin Sustrik's avatar
Martin Sustrik committed
99

100 101
            //  Sent by pipe reader to inform pipe writer about how many
            //  messages it has read so far.
Martin Hurton's avatar
Martin Hurton committed
102 103
            struct {
                uint64_t msgs_read;
104
            } activate_write;
Martin Hurton's avatar
Martin Hurton committed
105

106 107 108 109 110 111 112
            //  Sent by pipe reader to writer after creating a new inpipe.
            //  The parameter is actually of type pipe_t::upipe_t, however,
            //  its definition is private so we'll have to do with void*.
            struct {
                void *pipe;
            } hiccup;

Martin Sustrik's avatar
Martin Sustrik committed
113 114 115 116 117 118 119 120 121
            //  Sent by pipe reader to pipe writer to ask it to terminate
            //  its end of the pipe.
            struct {
            } pipe_term;

            //  Pipe writer acknowledges pipe_term command.
            struct {
            } pipe_term_ack;

122 123
            //  Sent by I/O object ot the socket to request the shutdown of
            //  the I/O object.
Martin Sustrik's avatar
Martin Sustrik committed
124
            struct {
125
                zmq::own_t *object;
126
            } term_req;
Martin Sustrik's avatar
Martin Sustrik committed
127

128
            //  Sent by socket to I/O object to start its shutdown.
Martin Sustrik's avatar
Martin Sustrik committed
129
            struct {
130
                int linger;
131
            } term;
Martin Sustrik's avatar
Martin Sustrik committed
132

133 134
            //  Sent by I/O object to the socket to acknowledge it has
            //  shut down.
Martin Sustrik's avatar
Martin Sustrik committed
135
            struct {
136
            } term_ack;
Martin Sustrik's avatar
Martin Sustrik committed
137

138 139 140
            //  Transfers the ownership of the closed socket
            //  to the reaper thread.
            struct {
141
                zmq::socket_base_t *socket;
142 143
            } reap;

144 145 146 147
            //  Closed socket notifies the reaper that it's already deallocated.
            struct {
            } reaped;

148 149 150 151 152
            //  Sent by reaper thread to the term thread when all the sockets
            //  are successfully deallocated.
            struct {
            } done;

Martin Sustrik's avatar
Martin Sustrik committed
153
        } args;
154
#ifdef _MSC_VER
Martin Sustrik's avatar
Martin Sustrik committed
155
    };
156 157 158
#else
    } __attribute__((aligned(64)));
#endif
159
}
Martin Sustrik's avatar
Martin Sustrik committed
160 161

#endif