Merge pull request #3557 from bluca/docs

Clarify documentation for zmq_unbind/disconnect and new batch options
This commit is contained in:
Doron Somech 2019-06-27 21:07:59 +03:00 committed by GitHub
commit 4a855fba8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 94 additions and 65 deletions

View File

@ -25,27 +25,12 @@ associated with the endpoint will be discarded. However, if the socket's linger
period is non-zero, libzmq will still attempt to transmit these discarded messages, period is non-zero, libzmq will still attempt to transmit these discarded messages,
until the linger period expires. until the linger period expires.
Addionally, if the disconnected endpoint was previously connected to
(as opposed to bound), the incoming message queue associated with the
endpoint will be discarded. This means that after unbinding an endpoint
using `disconnect`, it is possible to received messages originating
from that same endpoint if they were already present in the incoming message
queue before unbinding. However, this is not the case when disconnecting
from a connected endpoint.
The 'endpoint' argument is as described in linkzmq:zmq_connect[3] The 'endpoint' argument is as described in linkzmq:zmq_connect[3]
NOTE: The default setting of _ZMQ_LINGER_ does not discard unsent messages; NOTE: The default setting of _ZMQ_LINGER_ does not discard unsent messages;
this behaviour may cause the application to block when calling _zmq_ctx_term()_. this behaviour may cause the application to block when calling _zmq_ctx_term()_.
For details refer to linkzmq:zmq_setsockopt[3] and linkzmq:zmq_ctx_term[3]. For details refer to linkzmq:zmq_setsockopt[3] and linkzmq:zmq_ctx_term[3].
Unbinding wild-card address from a socket
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When a wild-card `*` 'endpoint' (described in linkzmq:zmq_tcp[7],
linkzmq:zmq_ipc[7] and linkzmq:zmq_vmci[7]) was used in _zmq_bind()_, the caller
should use the real 'endpoint' obtained from the ZMQ_LAST_ENDPOINT socket option
to unbind this 'endpoint' from a socket.
RETURN VALUE RETURN VALUE
------------ ------------
The _zmq_disconnect()_ function shall return zero if successful. Otherwise it The _zmq_disconnect()_ function shall return zero if successful. Otherwise it
@ -78,37 +63,6 @@ rc = zmq_disconnect (socket, "tcp://server001:5555");
assert (rc == 0); assert (rc == 0);
---- ----
.Unbind a subscriber socket from a TCP transport
----
/* Create a ZMQ_SUB socket */
void *socket = zmq_socket (context, ZMQ_SUB);
assert (socket);
/* Connect it to the host server001, port 5555 using a TCP transport */
rc = zmq_bind (socket, "tcp://127.0.0.1:5555");
assert (rc == 0);
/* Disconnect from the previously connected endpoint */
rc = zmq_disconnect(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_disconnect (socket, buf);
assert (rc == 0);
----
SEE ALSO SEE ALSO
-------- --------
linkzmq:zmq_connect[3] linkzmq:zmq_connect[3]

View File

@ -924,9 +924,8 @@ Applicable socket types:: ZMQ_ROUTER
ZMQ_IN_BATCH_SIZE: Maximal receive batch size ZMQ_IN_BATCH_SIZE: Maximal receive batch size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets the maximal amount of messages that can be received in a single Gets the maximal amount of messages that can be received in a single
'recv' system call. This can be used to improved throughtput at the expense of 'recv' system call.
latency and vice-versa.
Cannot be zero. Cannot be zero.
@ -936,14 +935,13 @@ NOTE: in DRAFT state, not yet available in stable releases.
Option value type:: int Option value type:: int
Option value unit:: messages Option value unit:: messages
Default value:: 8192 Default value:: 8192
Applicable socket types:: All Applicable socket types:: All, when using TCP, IPC, PGM or NORM transport.
ZMQ_OUT_BATCH_SIZE: Maximal send batch size ZMQ_OUT_BATCH_SIZE: Maximal send batch size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets the maximal amount of messages that can be sent in a single Gets the maximal amount of messages that can be sent in a single
'send' system call. This can be used to improved throughtput at the expense of 'send' system call.
latency and vice-versa.
Cannot be zero. Cannot be zero.
@ -953,7 +951,7 @@ NOTE: in DRAFT state, not yet available in stable releases.
Option value type:: int Option value type:: int
Option value unit:: messages Option value unit:: messages
Default value:: 8192 Default value:: 8192
Applicable socket types:: All Applicable socket types:: All, when using TCP, IPC, PGM or NORM transport.

View File

@ -1363,10 +1363,12 @@ Applicable socket types:: ZMQ_ROUTER
ZMQ_IN_BATCH_SIZE: Maximal receive batch size ZMQ_IN_BATCH_SIZE: Maximal receive batch size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets the maximal amount of messages that can be received in a single Sets the maximal amount of messages that can be received in a single
'recv' system call. This can be used to improved throughtput at the expense of 'recv' system call. WARNING: this option should almost never be changed.
latency and vice-versa. The default has been chosen to offer the best compromise between latency and
throughtput. In the vast majority of cases, changing this option will result in
worst result if not outright breakages.
Cannot be zero. Cannot be zero.
@ -1376,14 +1378,16 @@ NOTE: in DRAFT state, not yet available in stable releases.
Option value type:: int Option value type:: int
Option value unit:: messages Option value unit:: messages
Default value:: 8192 Default value:: 8192
Applicable socket types:: All Applicable socket types:: All, when using TCP, IPC, PGM or NORM transport.
ZMQ_OUT_BATCH_SIZE: Maximal send batch size ZMQ_OUT_BATCH_SIZE: Maximal send batch size
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sets the maximal amount of messages that can be sent in a single Sets the maximal amount of messages that can be sent in a single
'send' system call. This can be used to improved throughtput at the expense of 'send' system call. WARNING: this option should almost never be changed.
latency and vice-versa. The default has been chosen to offer the best compromise between latency and
throughtput. In the vast majority of cases, changing this option will result in
worst result if not outright breakages.
Cannot be zero. Cannot be zero.
@ -1393,7 +1397,7 @@ NOTE: in DRAFT state, not yet available in stable releases.
Option value type:: int Option value type:: int
Option value unit:: messages Option value unit:: messages
Default value:: 8192 Default value:: 8192
Applicable socket types:: All Applicable socket types:: All, when using TCP, IPC, PGM or NORM transport.
RETURN VALUE RETURN VALUE

View File

@ -4,7 +4,7 @@ zmq_unbind(3)
NAME NAME
---- ----
zmq_unbind - Another name for zmq_disconnect zmq_unbind - Stop accepting connections on a socket
SYNOPSIS SYNOPSIS
@ -14,8 +14,81 @@ int zmq_unbind (void '*socket', const char '*endpoint');
DESCRIPTION DESCRIPTION
----------- -----------
The _zmq_unbind()_ has the same exact behavior as _zmq_disconnect()_. The _zmq_unbind()_ function shall unbind a socket specified
Refer to linkzmq:zmq_disconnect[3]. by the 'socket' argument from the endpoint specified by the 'endpoint'
argument.
Addionally the incoming message queue associated with the endpoint will be
discarded. This means that after unbinding an endpoint it is possible to
received messages originating from that same endpoint if they were already
present in the incoming message queue before unbinding.
The 'endpoint' argument is as described in linkzmq:zmq_bind[3]
Unbinding wild-card address from a socket
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When wild-card `*` 'endpoint' (described in linkzmq:zmq_tcp[7],
linkzmq:zmq_ipc[7] and linkzmq:zmq_vmci[7]) was used in _zmq_bind()_, the caller should use
real 'endpoint' obtained from the ZMQ_LAST_ENDPOINT socket option
to unbind this 'endpoint' from a socket.
RETURN VALUE
------------
The _zmq_unbind()_ function shall return zero if successful. Otherwise it
shall return `-1` and set 'errno' to one of the values defined below.
ERRORS
------
*EINVAL*::
The endpoint supplied is invalid.
*ETERM*::
The 0MQ 'context' associated with the specified 'socket' was terminated.
*ENOTSOCK*::
The provided 'socket' was invalid.
*ENOENT*::
The endpoint supplied was not previously bound.
EXAMPLES
--------
.Unbind a subscriber socket from a TCP transport
----
/* Create a ZMQ_SUB socket */
void *socket = zmq_socket (context, ZMQ_SUB);
assert (socket);
/* Connect it to the host server001, port 5555 using a TCP transport */
rc = zmq_bind (socket, "tcp://127.0.0.1:5555");
assert (rc == 0);
/* Disconnect from the previously connected endpoint */
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);
----
NOTE
----
Note that while the implementation is similar to _zmq_disconnect()_, the
semantics are different and the two functions should not be used
interchangeably. Bound sockets should be unbound, and connected sockets should
be disconnected.
SEE ALSO SEE ALSO
-------- --------