command.hpp 5.8 KB

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