1 | /* |
2 | Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file |
3 | |
4 | This file is part of libzmq, the ZeroMQ core engine in C++. |
5 | |
6 | libzmq is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU Lesser General Public License (LGPL) as published |
8 | by the Free Software Foundation; either version 3 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | As a special exception, the Contributors give you permission to link |
12 | this library with independent modules to produce an executable, |
13 | regardless of the license terms of these independent modules, and to |
14 | copy and distribute the resulting executable under terms of your choice, |
15 | provided that you also meet, for each linked independent module, the |
16 | terms and conditions of the license of that module. An independent |
17 | module is a module which is not derived from or based on this library. |
18 | If you modify this library, you must extend this exception to your |
19 | version of the library. |
20 | |
21 | libzmq is distributed in the hope that it will be useful, but WITHOUT |
22 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
24 | License for more details. |
25 | |
26 | You should have received a copy of the GNU Lesser General Public License |
27 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
28 | */ |
29 | |
30 | #ifndef __ZMQ_COMMAND_HPP_INCLUDED__ |
31 | #define __ZMQ_COMMAND_HPP_INCLUDED__ |
32 | |
33 | #include <string> |
34 | #include "stdint.hpp" |
35 | #include "endpoint.hpp" |
36 | |
37 | namespace zmq |
38 | { |
39 | class object_t; |
40 | class own_t; |
41 | struct i_engine; |
42 | class pipe_t; |
43 | class socket_base_t; |
44 | |
45 | // This structure defines the commands that can be sent between threads. |
46 | |
47 | #ifdef _MSC_VER |
48 | #pragma warning(push) |
49 | #pragma warning(disable : 4324) // C4324: alignment padding warnings |
50 | __declspec(align (64)) |
51 | #endif |
52 | struct command_t |
53 | { |
54 | // Object to process the command. |
55 | zmq::object_t *destination; |
56 | |
57 | enum type_t |
58 | { |
59 | stop, |
60 | plug, |
61 | own, |
62 | attach, |
63 | bind, |
64 | activate_read, |
65 | activate_write, |
66 | hiccup, |
67 | pipe_term, |
68 | pipe_term_ack, |
69 | pipe_hwm, |
70 | term_req, |
71 | term, |
72 | term_ack, |
73 | term_endpoint, |
74 | reap, |
75 | reaped, |
76 | inproc_connected, |
77 | pipe_peer_stats, |
78 | pipe_stats_publish, |
79 | done |
80 | } type; |
81 | |
82 | union args_t |
83 | { |
84 | // Sent to I/O thread to let it know that it should |
85 | // terminate itself. |
86 | struct |
87 | { |
88 | } stop; |
89 | |
90 | // Sent to I/O object to make it register with its I/O thread. |
91 | struct |
92 | { |
93 | } plug; |
94 | |
95 | // Sent to socket to let it know about the newly created object. |
96 | struct |
97 | { |
98 | zmq::own_t *object; |
99 | } own; |
100 | |
101 | // Attach the engine to the session. If engine is NULL, it informs |
102 | // session that the connection have failed. |
103 | struct |
104 | { |
105 | struct i_engine *engine; |
106 | } attach; |
107 | |
108 | // Sent from session to socket to establish pipe(s) between them. |
109 | // Caller have used inc_seqnum beforehand sending the command. |
110 | struct |
111 | { |
112 | zmq::pipe_t *pipe; |
113 | } bind; |
114 | |
115 | // Sent by pipe writer to inform dormant pipe reader that there |
116 | // are messages in the pipe. |
117 | struct |
118 | { |
119 | } activate_read; |
120 | |
121 | // Sent by pipe reader to inform pipe writer about how many |
122 | // messages it has read so far. |
123 | struct |
124 | { |
125 | uint64_t msgs_read; |
126 | } activate_write; |
127 | |
128 | // Sent by pipe reader to writer after creating a new inpipe. |
129 | // The parameter is actually of type pipe_t::upipe_t, however, |
130 | // its definition is private so we'll have to do with void*. |
131 | struct |
132 | { |
133 | void *pipe; |
134 | } hiccup; |
135 | |
136 | // Sent by pipe reader to pipe writer to ask it to terminate |
137 | // its end of the pipe. |
138 | struct |
139 | { |
140 | } pipe_term; |
141 | |
142 | // Pipe writer acknowledges pipe_term command. |
143 | struct |
144 | { |
145 | } pipe_term_ack; |
146 | |
147 | // Sent by one of pipe to another part for modify hwm |
148 | struct |
149 | { |
150 | int inhwm; |
151 | int outhwm; |
152 | } pipe_hwm; |
153 | |
154 | // Sent by I/O object ot the socket to request the shutdown of |
155 | // the I/O object. |
156 | struct |
157 | { |
158 | zmq::own_t *object; |
159 | } term_req; |
160 | |
161 | // Sent by socket to I/O object to start its shutdown. |
162 | struct |
163 | { |
164 | int linger; |
165 | } term; |
166 | |
167 | // Sent by I/O object to the socket to acknowledge it has |
168 | // shut down. |
169 | struct |
170 | { |
171 | } term_ack; |
172 | |
173 | // Sent by session_base (I/O thread) to socket (application thread) |
174 | // to ask to disconnect the endpoint. |
175 | struct |
176 | { |
177 | std::string *endpoint; |
178 | } term_endpoint; |
179 | |
180 | // Transfers the ownership of the closed socket |
181 | // to the reaper thread. |
182 | struct |
183 | { |
184 | zmq::socket_base_t *socket; |
185 | } reap; |
186 | |
187 | // Closed socket notifies the reaper that it's already deallocated. |
188 | struct |
189 | { |
190 | } reaped; |
191 | |
192 | // Send application-side pipe count and ask to send monitor event |
193 | struct |
194 | { |
195 | uint64_t queue_count; |
196 | zmq::own_t *socket_base; |
197 | endpoint_uri_pair_t *endpoint_pair; |
198 | } pipe_peer_stats; |
199 | |
200 | // Collate application thread and I/O thread pipe counts and endpoints |
201 | // and send as event |
202 | struct |
203 | { |
204 | uint64_t outbound_queue_count; |
205 | uint64_t inbound_queue_count; |
206 | endpoint_uri_pair_t *endpoint_pair; |
207 | } pipe_stats_publish; |
208 | |
209 | // Sent by reaper thread to the term thread when all the sockets |
210 | // are successfully deallocated. |
211 | struct |
212 | { |
213 | } done; |
214 | |
215 | } args; |
216 | #ifdef _MSC_VER |
217 | }; |
218 | #pragma warning(pop) |
219 | #else |
220 | } __attribute__ ((aligned (64))); |
221 | #endif |
222 | } |
223 | |
224 | #endif |
225 | |