mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-12 09:06:26 +00:00
Added test and updated documentation for unbind wild-card * binded socket
This commit is contained in:
parent
09e7416ee9
commit
f47960e4bc
@ -20,6 +20,12 @@ argument.
|
|||||||
|
|
||||||
The 'endpoint' argument is as described in linkzmq:zmq_bind[3]
|
The 'endpoint' argument is as described in linkzmq:zmq_bind[3]
|
||||||
|
|
||||||
|
Unbinding wild-card addres from a socket
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
When wild-card `*` 'endpoint' (described in linkzmq:zmq_tcp[7] and
|
||||||
|
linkzmq:zmq_ipc[7]) was used in _zmq_bind()_, the caller should use
|
||||||
|
real 'endpoind' obtained from the ZMQ_LAST_ENDPOINT socket option
|
||||||
|
to unbind this 'endpoint' from a socket.
|
||||||
|
|
||||||
RETURN VALUE
|
RETURN VALUE
|
||||||
------------
|
------------
|
||||||
@ -36,8 +42,8 @@ The 0MQ 'context' associated with the specified 'socket' was terminated.
|
|||||||
The provided 'socket' was invalid.
|
The provided 'socket' was invalid.
|
||||||
|
|
||||||
|
|
||||||
EXAMPLE
|
EXAMPLES
|
||||||
-------
|
--------
|
||||||
.Unbind a subscriber socket from a TCP transport
|
.Unbind a subscriber socket from a TCP transport
|
||||||
----
|
----
|
||||||
/* Create a ZMQ_SUB socket */
|
/* Create a ZMQ_SUB socket */
|
||||||
@ -51,6 +57,23 @@ rc = zmq_unbind (socket, "tcp://127.0.0.1:5555");
|
|||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
----
|
----
|
||||||
|
|
||||||
|
.Unbind wild-card `*` binded socket
|
||||||
|
----
|
||||||
|
/* Create a ZMQ_SUB socket */
|
||||||
|
void *socket = zmq_socket (context, ZMQ_SUB);
|
||||||
|
assert (socket);
|
||||||
|
/* Bind it to the system-assigned ephemeral port using a TCP transport */
|
||||||
|
rc = zmq_bind (socket, "tcp://127.0.0.1:*");
|
||||||
|
assert (rc == 0);
|
||||||
|
/* Obtain real endpoint */
|
||||||
|
const size_t buf_size = 32;
|
||||||
|
char buf[buf_size];
|
||||||
|
rc = zmq_getsockopt (socket, ZMQ_LAST_ENDPOINT, buf, (size_t *)&buf_size);
|
||||||
|
assert (rc == 0);
|
||||||
|
/* Unbind socket by real endpoint */
|
||||||
|
rc = zmq_unbind (socket, buf);
|
||||||
|
assert (rc == 0);
|
||||||
|
----
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
|
@ -23,8 +23,11 @@ int main (void)
|
|||||||
{
|
{
|
||||||
setup_test_environment();
|
setup_test_environment();
|
||||||
int rc;
|
int rc;
|
||||||
char buf[32];
|
const size_t buf_size = 32;
|
||||||
|
char buf[buf_size];
|
||||||
const char *ep = "tcp://127.0.0.1:5560";
|
const char *ep = "tcp://127.0.0.1:5560";
|
||||||
|
const char *ep_wc_tcp = "tcp://127.0.0.1:*";
|
||||||
|
const char *ep_wc_ipc = "ipc://*";
|
||||||
|
|
||||||
// Create infrastructure.
|
// Create infrastructure.
|
||||||
void *ctx = zmq_ctx_new ();
|
void *ctx = zmq_ctx_new ();
|
||||||
@ -100,5 +103,45 @@ int main (void)
|
|||||||
rc = zmq_ctx_term (ctx);
|
rc = zmq_ctx_term (ctx);
|
||||||
assert (rc == 0);
|
assert (rc == 0);
|
||||||
|
|
||||||
|
// Create infrastructure (wild-card binding)
|
||||||
|
ctx = zmq_ctx_new ();
|
||||||
|
assert (ctx);
|
||||||
|
push = zmq_socket (ctx, ZMQ_PUSH);
|
||||||
|
assert (push);
|
||||||
|
rc = zmq_bind (push, ep_wc_tcp);
|
||||||
|
assert (rc == 0);
|
||||||
|
pull = zmq_socket (ctx, ZMQ_PULL);
|
||||||
|
assert (pull);
|
||||||
|
rc = zmq_bind (pull, ep_wc_ipc);
|
||||||
|
assert (rc == 0);
|
||||||
|
|
||||||
|
// Unbind sockets binded by wild-card address
|
||||||
|
rc = zmq_getsockopt (push, ZMQ_LAST_ENDPOINT, buf, (size_t *)&buf_size);
|
||||||
|
assert (rc == 0);
|
||||||
|
rc = zmq_unbind (push, buf);
|
||||||
|
assert (rc == 0);
|
||||||
|
rc = zmq_getsockopt (pull, ZMQ_LAST_ENDPOINT, buf, (size_t *)&buf_size);
|
||||||
|
assert (rc == 0);
|
||||||
|
rc = zmq_unbind (pull, buf);
|
||||||
|
assert (rc == 0);
|
||||||
|
|
||||||
|
// Create infrastructure (wild-card binding)
|
||||||
|
ctx = zmq_ctx_new ();
|
||||||
|
assert (ctx);
|
||||||
|
push = zmq_socket (ctx, ZMQ_PUSH);
|
||||||
|
assert (push);
|
||||||
|
rc = zmq_bind (push, ep_wc_tcp);
|
||||||
|
assert (rc == 0);
|
||||||
|
pull = zmq_socket (ctx, ZMQ_PULL);
|
||||||
|
assert (pull);
|
||||||
|
rc = zmq_bind (pull, ep_wc_ipc);
|
||||||
|
assert (rc == 0);
|
||||||
|
|
||||||
|
// Sockets binded by wild-card address can't be unbinded by wild-card address
|
||||||
|
rc = zmq_unbind (push, ep_wc_tcp);
|
||||||
|
assert (rc == -1 && zmq_errno () == ENOENT);
|
||||||
|
rc = zmq_unbind (pull, ep_wc_ipc);
|
||||||
|
assert (rc == -1 && zmq_errno () == ENOENT);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user