zmq_proxy_steerable.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. zmq_proxy_steerable(3)
  2. ======================
  3. NAME
  4. ----
  5. zmq_proxy_steerable - built-in 0MQ proxy with control flow
  6. SYNOPSIS
  7. --------
  8. *int zmq_proxy_steerable (const void '*frontend', const void '*backend',
  9. const void '*capture', const void '*control');*
  10. DESCRIPTION
  11. -----------
  12. The _zmq_proxy_steerable()_ function starts the built-in 0MQ proxy in the
  13. current application thread, as _zmq_proxy()_ do. Please, refer to this function
  14. for the general description and usage. We describe here only the additional
  15. control flow provided by the socket passed as the fourth argument "control".
  16. If the control socket is not NULL, the proxy supports control flow. If
  17. 'PAUSE' is received on this socket, the proxy suspends its activities. If
  18. 'RESUME' is received, it goes on. If 'TERMINATE' is received, it terminates
  19. smoothly. If 'STATISTICS' is received, the proxy will reply on the control socket
  20. sending a multipart message with 8 frames, each with an unsigned integer 64-bit
  21. wide that provide in the following order:
  22. - number of messages received by the frontend socket
  23. - number of bytes received by the frontend socket
  24. - number of messages sent out the frontend socket
  25. - number of bytes sent out the frontend socket
  26. - number of messages received by the backend socket
  27. - number of bytes received by the backend socket
  28. - number of messages sent out the backend socket
  29. - number of bytes sent out the backend socket
  30. At start, the proxy runs normally as if zmq_proxy was used.
  31. If the control socket is NULL, the function behave exactly as if linkzmq:zmq_proxy[3]
  32. had been called.
  33. Refer to linkzmq:zmq_socket[3] for a description of the available socket types.
  34. Refer to linkzmq:zmq_proxy[3] for a description of the zmq_proxy.
  35. EXAMPLE USAGE
  36. -------------
  37. cf zmq_proxy
  38. RETURN VALUE
  39. ------------
  40. The _zmq_proxy_steerable()_ function returns 0 if TERMINATE is sent to its
  41. control socket. Otherwise, it returns `-1` and 'errno' set to *ETERM* or
  42. *EINTR* (the 0MQ 'context' associated with either of the specified sockets was
  43. terminated).
  44. EXAMPLE
  45. -------
  46. .Creating a shared queue proxy
  47. ----
  48. // Create frontend, backend and control sockets
  49. void *frontend = zmq_socket (context, ZMQ_ROUTER);
  50. assert (backend);
  51. void *backend = zmq_socket (context, ZMQ_DEALER);
  52. assert (frontend);
  53. void *control = zmq_socket (context, ZMQ_SUB);
  54. assert (control);
  55. // Bind sockets to TCP ports
  56. assert (zmq_bind (frontend, "tcp://*:5555") == 0);
  57. assert (zmq_bind (backend, "tcp://*:5556") == 0);
  58. assert (zmq_connect (control, "tcp://*:5557") == 0);
  59. // Subscribe to the control socket since we have chosen SUB here
  60. assert (zmq_setsockopt (control, ZMQ_SUBSCRIBE, "", 0));
  61. // Start the queue proxy, which runs until ETERM or "TERMINATE"
  62. // received on the control socket
  63. zmq_proxy_steerable (frontend, backend, NULL, control);
  64. ----
  65. .Set up a controller in another node, process or whatever
  66. ----
  67. void *control = zmq_socket (context, ZMQ_PUB);
  68. assert (control);
  69. assert (zmq_bind (control, "tcp://*:5557") == 0);
  70. // pause the proxy
  71. assert (zmq_send (control, "PAUSE", 5, 0) == 0);
  72. // resume the proxy
  73. assert (zmq_send (control, "RESUME", 6, 0) == 0);
  74. // terminate the proxy
  75. assert (zmq_send (control, "TERMINATE", 9, 0) == 0);
  76. // check statistics
  77. assert (zmq_send (control, "STATISTICS", 10, 0) == 0);
  78. zmq_msg_t stats_msg;
  79. while (1) {
  80. assert (zmq_msg_init (&stats_msg) == 0);
  81. assert (zmq_recvmsg (control, &stats_msg, 0) == sizeof (uint64_t));
  82. assert (rc == sizeof (uint64_t));
  83. printf ("Stat: %lu\n", *(unsigned long int *)zmq_msg_data (&stats_msg));
  84. if (!zmq_msg_get (&stats_msg, ZMQ_MORE))
  85. break;
  86. assert (zmq_msg_close (&stats_msg) == 0);
  87. }
  88. assert (zmq_msg_close (&stats_msg) == 0);
  89. ---
  90. SEE ALSO
  91. --------
  92. linkzmq:zmq_proxy[3]
  93. linkzmq:zmq_bind[3]
  94. linkzmq:zmq_connect[3]
  95. linkzmq:zmq_socket[3]
  96. linkzmq:zmq[7]
  97. AUTHORS
  98. -------
  99. This page was written by the 0MQ community. To make a change please
  100. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.