Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
f47960e4
Commit
f47960e4
authored
Oct 29, 2014
by
lysyloren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test and updated documentation for unbind wild-card * binded socket
parent
09e7416e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
3 deletions
+69
-3
zmq_unbind.txt
doc/zmq_unbind.txt
+25
-2
test_term_endpoint.cpp
tests/test_term_endpoint.cpp
+44
-1
No files found.
doc/zmq_unbind.txt
View file @
f47960e4
...
...
@@ -20,6 +20,12 @@ argument.
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
------------
...
...
@@ -36,8 +42,8 @@ The 0MQ 'context' associated with the specified 'socket' was terminated.
The provided 'socket' was invalid.
EXAMPLE
-------
EXAMPLE
S
-------
-
.Unbind a subscriber socket from a TCP transport
----
/* Create a ZMQ_SUB socket */
...
...
@@ -51,6 +57,23 @@ rc = zmq_unbind (socket, "tcp://127.0.0.1:5555");
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
--------
...
...
tests/test_term_endpoint.cpp
View file @
f47960e4
...
...
@@ -23,8 +23,11 @@ int main (void)
{
setup_test_environment
();
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_wc_tcp
=
"tcp://127.0.0.1:*"
;
const
char
*
ep_wc_ipc
=
"ipc://*"
;
// Create infrastructure.
void
*
ctx
=
zmq_ctx_new
();
...
...
@@ -100,5 +103,45 @@ int main (void)
rc
=
zmq_ctx_term
(
ctx
);
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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment