From 294a01aa69296a7402b0dbafc38b88040f9c5450 Mon Sep 17 00:00:00 2001
From: gdamore Contexts in Scalability Protocols provide for isolation of protocol-specific
state machines and associated data, allowing multiple concurrent state machines (or transactions)
-to coexist on a single socket.Contexts
For example, a REP server may wish to allow many requests to be serviced concurrently, even though some jobs may take significant time to process. Contexts provide for this ability.
Not all protocols have contexts, because many protocols simply have no state to manage. @@ -285,7 +285,7 @@ to ensure that it cannot be confused with a valid open context.
int nng_ctx_open(nng_ctx *ctxp, nng_socket s);
-The nng_ctx_open function creates a separate context to be used with the socket s,
+
The nng_ctx_open function creates a separate context to be used with the socket s,
and returns it at the location pointed by ctxp.
int nng_ctx_id(nng_ctx c);
@@ -452,7 +452,7 @@ echo(void *arg)
Given the above fragment, the following example shows setting up the service.
-It assumes that the socket has already been
+It assumes that the socket has already been
created and any transports set up as well with functions such as nng_dial or nng_listen.
#define CONCURRENCY 1024
diff --git a/ref/api/errors.html b/ref/api/errors.html
index 866ab01e..798e3ee9 100644
--- a/ref/api/errors.html
+++ b/ref/api/errors.html
@@ -289,7 +289,7 @@ as in diagnostic messages or log entries.
NNG_EBUSY4 Resource busy.
NNG_ETIMEDOUT5 Timed out. The operation took longer than the allotted time.
NNG_ECONNREFUSED6 Connection refused. Usually indicates the wrong address or a server is running.
-NNG_ECLOSED7 Object closed. Typically the socket is closed.
+NNG_ECLOSED7 Object closed. Typically the socket is closed.
NNG_EAGAIN8 Try again. Typcally for a non-blocking operation that might succeed later.
NNG_ENOTSUP9 Not supported. Perhaps the protocol or transport is not supported, or the operation is not not supported with the transport or protocol.
NNG_EADDRINUSE10 Address in use. The network address is already used by another process. Most often this is seen for listeners.
diff --git a/ref/api/pipe.html b/ref/api/pipe.html
index b70e4a11..f0cd5b23 100644
--- a/ref/api/pipe.html
+++ b/ref/api/pipe.html
@@ -313,7 +313,7 @@ nng_socket nng_pipe_socket(nng_pipe p);
-These functions return the socket, dialer, or listener that created or owns the pipe.
+These functions return the socket, dialer, or listener that created or owns the pipe.
If the pipe was does not have an associated dialer or listener, then the associated will
return [NNG_DIALER_INITIALIZER] or [NNG_LISTENER_INITIALIZER], as appropriate, and
either [nng_dialer_id] or [nng_listener_id] for the returned object will return -1.
diff --git a/ref/api/sock.html b/ref/api/sock.html
index e0b4bef9..16a0d422 100644
--- a/ref/api/sock.html
+++ b/ref/api/sock.html
@@ -335,7 +335,7 @@ the protocol specific processing must be performed by the application.
Most applications do not need to use raw sockets.
The notable exception is when using nng_device, which requires raw sockets.
-To obtain asynchronous behavior, consider using contexts instead.
+To obtain asynchronous behavior, consider using contexts instead.
The following functions open a socket in raw mode:
@@ -363,7 +363,7 @@ a result of NNG_ECLOSED
Closing a socket also invalidates any dialers, listeners,
-pipes, or contexts associated with it.
+pipes, or contexts associated with it.
@@ -533,7 +533,7 @@ are available, whether they can be read or written, and the appropriate type to
note
Socket options are are used to tune the behavior of the higher level protocol. To change the options
-for an underlying transport, the option should be set on the dialer or listener instead of the socket.
+for an underlying transport, the option should be set on the dialer or listener instead of the socket.
Common Options
The following options are available for many protocols, and always use the same types and semantics described below.
@@ -581,7 +581,7 @@ were available in previous versions of NNG.
note
-These functions are not compatible with contexts.
+These functions are not compatible with contexts.
diff --git a/ref/api/stats.html b/ref/api/stats.html
index 2f7a5534..9d7f8684 100644
--- a/ref/api/stats.html
+++ b/ref/api/stats.html
@@ -312,7 +312,7 @@ const nng_stat *nng_stat_find_listener(const nng_stat *stat, nng_dialer listener
const nng_stat *nng_stat_find_socket(const nng_stat *stat, nng_dialer socket);
Sometimes it is easiest to search for a specific statistic, matching by name,
-or possibly to find the tree of statistics associated with a specific socket,
+or possibly to find the tree of statistics associated with a specific socket,
dialer, or listener.
The nng_stat_find functions are provided for this purpose.
The nng_stat_find function returns the first statistic within the subtree of
diff --git a/ref/api/stream.html b/ref/api/stream.html
index e0ddb068..4b4362da 100644
--- a/ref/api/stream.html
+++ b/ref/api/stream.html
@@ -267,7 +267,7 @@ using these Streams APIs.
note
The nng_stream object is used for raw byte stream connections, and
-should not be confused with a pipe object created on a socket using
+should not be confused with a pipe object created on a socket using
the nng_listen, nng_dial or related functions.
Sending and Receiving Data
diff --git a/ref/indexing.html b/ref/indexing.html
index e1155479..261863b8 100644
--- a/ref/indexing.html
+++ b/ref/indexing.html
@@ -383,7 +383,7 @@ named pipes, 1
NNG_OPT_REQ_RESENDTICK, 1
NNG_OPT_REQ_RESENDTIME, 1
NNG_OPT_SOCKET_FD, 1
-NNG_OPT_SUB_PREFNEW, 1
+NNG_OPT_SUB_PREF_NEW, 1
NNG_OPT_SURVEYOR_SURVEYTIME, 1
nng_pair0_open, 1
nng_pair0_open_raw, 1
@@ -523,8 +523,12 @@ named pipes, 1
nng_stream_stop, 1
nng_strerror, 1
nng_strfree, 1
-nng_sub0_open, 1
-nng_sub0_open_raw, 1
+nng_sub0_ctx_subscribe, 1
+nng_sub0_ctx_unsubscribe, 1
+nng_sub0_open, 1, 2
+nng_sub0_open_raw, 1, 2
+nng_sub0_socket_subscribe, 1
+nng_sub0_socket_unsubscribe, 1
nng_surveyor0_open, 1
nng_surveyor0_open_raw, 1
nng_system_logger, 1
diff --git a/ref/migrate/nanomsg.html b/ref/migrate/nanomsg.html
index eabe1549..62cf684d 100644
--- a/ref/migrate/nanomsg.html
+++ b/ref/migrate/nanomsg.html
@@ -317,8 +317,8 @@ NNG approach to messages. Likewise there is no struct nn_cmsghdr eq
NN_IPV4ONLYNone Use URL such as tcp4:// to obtain this functionality.
NN_SOCKET_NAMENone Removed from NNG.
NN_MAXTTLNNG_OPT_MAXTTL
-NN_SUB_SUBSCRIBEnng_sub0_socket_subscribeNo longer an option, use a function call.
-NN_SUB_UNSUBSCRIBEnng_sub0_socket_unsubscribeNo longer an option, use a function call.
+NN_SUB_SUBSCRIBEnng_sub0_socket_subscribeNo longer an option, use a function call.
+NN_SUB_UNSUBSCRIBEnng_sub0_socket_unsubscribeNo longer an option, use a function call.
Error Codes
diff --git a/ref/migrate/nng1.html b/ref/migrate/nng1.html
index 54fece2f..58dd6b29 100644
--- a/ref/migrate/nng1.html
+++ b/ref/migrate/nng1.html
@@ -489,8 +489,8 @@ matching the actual wire protocol values, instead of int.
Applications should keep track of this information separately.
Subscriptions
The NNG_OPT_SUB_SUBSCRIBE and NNG_OPT_SUB_UNSUBSCRIBE options have been replaced by
-the following functions: nng_sub0_socket_subscribe, nng_sub0_socket_unsubscribe,
-nng_sub0_ctx_subscribe and nng_sub0_ctx_unsubscribe. These functions, like the options
+the following functions: nng_sub0_socket_subscribe, nng_sub0_socket_unsubscribe,
+nng_sub0_ctx_subscribe and nng_sub0_ctx_unsubscribe. These functions, like the options
they replace, are only applicable to SUB sockets.
Statistics Use Constified Pointers
A number of the statistics functions take, or return, const nng_stat * instead
diff --git a/ref/print.html b/ref/print.html
index 77ce4612..bc259730 100644
--- a/ref/print.html
+++ b/ref/print.html
@@ -1260,7 +1260,7 @@ the protocol specific processing must be performed by the application.
Most applications do not need to use raw sockets.
The notable exception is when using nng_device, which requires raw sockets.
-To obtain asynchronous behavior, consider using contexts instead.
+To obtain asynchronous behavior, consider using contexts instead.
The following functions open a socket in raw mode:
@@ -1288,7 +1288,7 @@ a result of NNG_ECLOSED
Closing a socket also invalidates any dialers, listeners,
-pipes, or contexts associated with it.
+pipes, or contexts associated with it.
@@ -1458,7 +1458,7 @@ are available, whether they can be read or written, and the appropriate type to
note
Socket options are are used to tune the behavior of the higher level protocol. To change the options
-for an underlying transport, the option should be set on the dialer or listener instead of the socket.
+for an underlying transport, the option should be set on the dialer or listener instead of the socket.
Common Options
The following options are available for many protocols, and always use the same types and semantics described below.
@@ -1506,7 +1506,7 @@ were available in previous versions of NNG.
note
-These functions are not compatible with contexts.
+These functions are not compatible with contexts.
@@ -1709,7 +1709,7 @@ int main(int argc, char **argv) {
Contexts
Contexts in Scalability Protocols provide for isolation of protocol-specific
state machines and associated data, allowing multiple concurrent state machines (or transactions)
-to coexist on a single socket.
+to coexist on a single socket.
For example, a REP server may wish to allow many requests to be serviced concurrently,
even though some jobs may take significant time to process. Contexts provide for this ability.
Not all protocols have contexts, because many protocols simply have no state to manage.
@@ -1748,7 +1748,7 @@ to ensure that it cannot be confused with a valid open context.
Creating a Context
int nng_ctx_open(nng_ctx *ctxp, nng_socket s);
-The nng_ctx_open function creates a separate context to be used with the socket s,
+
The nng_ctx_open function creates a separate context to be used with the socket s,
and returns it at the location pointed by ctxp.
Context Identity
int nng_ctx_id(nng_ctx c);
@@ -1915,7 +1915,7 @@ echo(void *arg)
Example 2: Starting the Echo Service
Given the above fragment, the following example shows setting up the service.
-It assumes that the socket has already been
+It assumes that the socket has already been
created and any transports set up as well with functions such as nng_dial or nng_listen.
#define CONCURRENCY 1024
@@ -2083,7 +2083,7 @@ nng_socket nng_pipe_socket(nng_pipe p);
-These functions return the socket, dialer, or listener that created or owns the pipe.
+These functions return the socket, dialer, or listener that created or owns the pipe.
If the pipe was does not have an associated dialer or listener, then the associated will
return [NNG_DIALER_INITIALIZER] or [NNG_LISTENER_INITIALIZER], as appropriate, and
either [nng_dialer_id] or [nng_listener_id] for the returned object will return -1.
@@ -3822,7 +3822,7 @@ const nng_stat *nng_stat_find_listener(const nng_stat *stat, nng_dialer listener
const nng_stat *nng_stat_find_socket(const nng_stat *stat, nng_dialer socket);
Sometimes it is easiest to search for a specific statistic, matching by name,
-or possibly to find the tree of statistics associated with a specific socket,
+or possibly to find the tree of statistics associated with a specific socket,
dialer, or listener.
The nng_stat_find functions are provided for this purpose.
The nng_stat_find function returns the first statistic within the subtree of
@@ -4051,7 +4051,7 @@ as in diagnostic messages or log entries.
NNG_EBUSY4 Resource busy.
NNG_ETIMEDOUT5 Timed out. The operation took longer than the allotted time.
NNG_ECONNREFUSED6 Connection refused. Usually indicates the wrong address or a server is running.
-NNG_ECLOSED7 Object closed. Typically the socket is closed.
+NNG_ECLOSED7 Object closed. Typically the socket is closed.
NNG_EAGAIN8 Try again. Typcally for a non-blocking operation that might succeed later.
NNG_ENOTSUP9 Not supported. Perhaps the protocol or transport is not supported, or the operation is not not supported with the transport or protocol.
NNG_EADDRINUSE10 Address in use. The network address is already used by another process. Most often this is seen for listeners.
@@ -4186,7 +4186,7 @@ using these Streams APIs.
note
The nng_stream object is used for raw byte stream connections, and
-should not be confused with a pipe object created on a socket using
+should not be confused with a pipe object created on a socket using
the nng_listen, nng_dial or related functions.
Sending and Receiving Data
@@ -6749,7 +6749,7 @@ was previously received.
Any additional concurrent receive operations will result in NNG_ESTATE.
Raw mode sockets ignore all these restrictions.
Context Operations
-This protocol supports the creation of contexts for concurrent
+
This protocol supports the creation of contexts for concurrent
use cases using nng_ctx_open.
Each context may have at most one outstanding request, and operates
independently of the others.
@@ -6897,7 +6897,7 @@ from processing a request it has already received or terminate a request
that has already been placed on the wire.
Raw mode sockets ignore all these restrictions.
Context Operations
-This protocol supports the creation of contexts for concurrent
+
This protocol supports the creation of contexts for concurrent
use cases using nng_ctx_open.
The NNG_OPT_REQ_RESENDTIME value may be configured differently
on contexts created this way.
@@ -7074,7 +7074,7 @@ reply will be sent to surveyor from whom the last survey was received.
Respondents may discard a survey by simply not replying to it.
Raw mode sockets ignore all these restrictions.
Context Operations
-This protocol supports the creation of contexts for concurrent
+
This protocol supports the creation of contexts for concurrent
use cases using nng_ctx_open.
Incoming surveys will be routed to and received by only one context.
Additional surveys may be received by other contexts in parallel.
@@ -7194,22 +7194,51 @@ reduce bandwidth consumption.
the message body.
Applications should construct their messages accordingly.
Socket Operations
-The nng_sub0_open functions create a SUB socket.
-This socket may be used to receive messages, but is unable to send them.
-Attempts to send messages will result in NNG_ENOTSUP.
+
int nng_sub0_open(nng_socket *);
+int nng_sub0_open_raw(nng_socket *);
+int nng_sub0_socket_subscribe(nng_socket id, const void *buf, size_t sz);
+int nng_sub0_socket_unsubscribe(nng_socket id, const void *buf, size_t sz);
+
+The nng_sub0_open and nng_sub0_open_raw functions create a SUB socket in
+either cooked or raw mode.
+The nng_sub0_socket_subscribe function is used to add a subscription topic to the socket.
+Messages that do not match any subscription topic will be filtered out, and unavailable
+for receiving.
+A message is deemed to match a subscription if it has at least sz bytes, and the first
+sz bytes are the same as buf.
+The nng_sub0_socket_unsubscribe function removes a subscription from the socket.
+
+
+
+ note
+
+A socket with no subscriptions cannot receive messages.
+
+
+
+
+ tip
+
+To receive all messages, simply subscribe to a zero length topic.
+
+Context Operations
+The SUB protocol supports contexts.
+int nng_sub0_ctx_subscribe(nng_ctx id, const void *buf, size_t sz);
+int nng_sub0_ctx_unsubscribe(nng_ctx id, const void *buf, size_t sz);
+
+The nng_sub0_ctx_subscribe and nng_sub0_ctx_unsubscribe functions
+perform manage subscriptions for the context in precisely the same way that
+nng_sub0_socket_subscribe and nng_sub0_socket_unsubscribe do.
+Each context maintains its own set of subscriptions, and these are also independent
+of socket level subscriptions.
+Protocol Options
+
Protocol Versions
Only version 0 of this protocol is supported.
(At the time of writing, no other versions of this protocol have been defined.)
-Protocol Options
-The following protocol-specific option is available.
-
-NNG_OPT_SUB_PREFNEW:
-(bool)
-
-This read/write option specifies the behavior of the subscriber when the queue is full.
-When true (the default), the subscriber will make room in the queue by removing the oldest message.
-When false, the subscriber will reject messages if the message queue does not have room.
-
Protocol Headers
The SUB protocol has no protocol-specific headers.