zmq_unbind.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. zmq_unbind(3)
  2. ==============
  3. NAME
  4. ----
  5. zmq_unbind - Stop accepting connections on a socket
  6. SYNOPSIS
  7. --------
  8. int zmq_unbind (void '*socket', const char '*endpoint');
  9. DESCRIPTION
  10. -----------
  11. The _zmq_unbind()_ function shall unbind a socket specified
  12. by the 'socket' argument from the endpoint specified by the 'endpoint'
  13. argument.
  14. Addionally the incoming message queue associated with the endpoint will be
  15. discarded. This means that after unbinding an endpoint it is possible to
  16. received messages originating from that same endpoint if they were already
  17. present in the incoming message queue before unbinding.
  18. The 'endpoint' argument is as described in linkzmq:zmq_bind[3]
  19. Unbinding wild-card address from a socket
  20. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. When wild-card `*` 'endpoint' (described in linkzmq:zmq_tcp[7],
  22. linkzmq:zmq_ipc[7], linkzmq:zmq_udp[7] and linkzmq:zmq_vmci[7]) was used in
  23. _zmq_bind()_, the caller should use real 'endpoint' obtained from the
  24. ZMQ_LAST_ENDPOINT socket option to unbind this 'endpoint' from a socket.
  25. RETURN VALUE
  26. ------------
  27. The _zmq_unbind()_ function shall return zero if successful. Otherwise it
  28. shall return `-1` and set 'errno' to one of the values defined below.
  29. ERRORS
  30. ------
  31. *EINVAL*::
  32. The endpoint supplied is invalid.
  33. *ETERM*::
  34. The 0MQ 'context' associated with the specified 'socket' was terminated.
  35. *ENOTSOCK*::
  36. The provided 'socket' was invalid.
  37. *ENOENT*::
  38. The endpoint supplied was not previously bound.
  39. EXAMPLES
  40. --------
  41. .Unbind a subscriber socket from a TCP transport
  42. ----
  43. /* Create a ZMQ_SUB socket */
  44. void *socket = zmq_socket (context, ZMQ_SUB);
  45. assert (socket);
  46. /* Connect it to the host server001, port 5555 using a TCP transport */
  47. rc = zmq_bind (socket, "tcp://127.0.0.1:5555");
  48. assert (rc == 0);
  49. /* Disconnect from the previously connected endpoint */
  50. rc = zmq_unbind (socket, "tcp://127.0.0.1:5555");
  51. assert (rc == 0);
  52. ----
  53. .Unbind wild-card `*` binded socket
  54. ----
  55. /* Create a ZMQ_SUB socket */
  56. void *socket = zmq_socket (context, ZMQ_SUB);
  57. assert (socket);
  58. /* Bind it to the system-assigned ephemeral port using a TCP transport */
  59. rc = zmq_bind (socket, "tcp://127.0.0.1:*");
  60. assert (rc == 0);
  61. /* Obtain real endpoint */
  62. const size_t buf_size = 32;
  63. char buf[buf_size];
  64. rc = zmq_getsockopt (socket, ZMQ_LAST_ENDPOINT, buf, (size_t *)&buf_size);
  65. assert (rc == 0);
  66. /* Unbind socket by real endpoint */
  67. rc = zmq_unbind (socket, buf);
  68. assert (rc == 0);
  69. ----
  70. NOTE
  71. ----
  72. Note that while the implementation is similar to _zmq_disconnect()_, the
  73. semantics are different and the two functions should not be used
  74. interchangeably. Bound sockets should be unbound, and connected sockets should
  75. be disconnected.
  76. SEE ALSO
  77. --------
  78. linkzmq:zmq_bind[3]
  79. linkzmq:zmq_socket[3]
  80. linkzmq:zmq[7]
  81. AUTHORS
  82. -------
  83. This page was written by the 0MQ community. To make a change please
  84. read the 0MQ Contribution Policy at <http://www.zeromq.org/docs:contributing>.