#include <nng/protocol/bus0/bus.h>
-
-int nng_bus0_open(nng_socket *s);
+#include <nng/protocol/bus0/bus.h>
From b08d7a398d68c9ebe4781e5c4cb5cc8b945f9653 Mon Sep 17 00:00:00 2001
From: Garrett D'Amore
close socket
close context
get context option
create context
receive message using context asynchronously
send message using context asynchronously
set context option
send message
sleep asynchronously
duplicate string
return an error description
free memory
create sub socket
This section documents supplemental functions that are available. +These functions are not intrinsic to building applications with +this library, but their presence may facilitate writing portable applications.
+| + | get time |
+
| + | allocate condition variable |
+
| + | free condition variable |
+
| + | wait for condition or timeout |
+
| + | wait for condition |
+
| + | wake all waiters |
+
| + | wake one waiter |
+
| + | sleep milliseconds |
+
| + | allocate mutex |
+
| + | free mutex |
+
| + | lock mutex |
+
| + | lock mutex |
+
| + | parse command line options |
+
| + | get random number |
+
| + | create thread |
+
| + | reap thread |
+
asynchronous I/O handle
protocol context
dialer
free memory
duplicate string
return an error description
free string
report library version
The following functions are useful to separate the protocol processing +from a socket object, into a separate context. +This can allow multiple contexts to be created on a single socket for +concurrent applications.
+| + | close context |
+
| + | get context option |
+
| + | create context |
+
| + | receive message using context asynchronously |
+
| + | send message using context asynchronously |
+
| + | set context option |
+
Common functionality is supplied for parsing and handling @@ -1077,6 +1128,86 @@ universal resource locators (URLS).
These supplemental functions are not intrinsic to building +network applications with NNG, but they are made available +as a convenience to aid in creating portable applications.
+| + | get time |
+
| + | allocate condition variable |
+
| + | free condition variable |
+
| + | wait for condition or timeout |
+
| + | wait for condition |
+
| + | wake all waiters |
+
| + | wake one waiter |
+
| + | sleep for milliseconds |
+
| + | allocate mutex |
+
| + | free mutex |
+
| + | lock mutex |
+
| + | unlock mutex |
+
| + | parse command line options |
+
| + | get random number |
+
| + | create thread |
+
| + | reap thread |
+
The library may be configured with support for HTTP, and this will diff --git a/man/tip/nng.7.html b/man/tip/nng.7.html index f412f39f..c3685bac 100644 --- a/man/tip/nng.7.html +++ b/man/tip/nng.7.html @@ -646,53 +646,94 @@ other languages please check the website.
nng presents a socket view of networking. The sockets are constructed -using protocol-specific functions, as a given socket implements precisely -one nng protocol.
+nng presents a socket view of networking. +The sockets are constructed using protocol-specific functions, as a given +socket implements precisely one nng protocol.
Each socket can be used to send and receive messages (if the protocol) -supports it, and implements the appropriate protocol semantics. For -example, nng_sub(7) sockets automatically filter incoming +supports it, and implements the appropriate protocol semantics. +For example, sub sockets automatically filter incoming messages to discard those for topics that have not been subscribed.
nng sockets are message oriented, so that messages are either delivered -wholly, or not at all. Partial delivery is not possible. Furthermore, -nng does not provide any other delivery or ordering guarantees; -messages may be dropped or reordered. (Some protocols, such as -nng_req(7) may offer stronger guarantees by -performing their own retry and validation schemes.)
+wholly, or not at all. Partial delivery is not possible. +Furthermore, nng does not provide any other delivery or ordering guarantees; +messages may be dropped or reordered +(Some protocols, such as req may offer stronger +guarantees by performing their own retry and validation schemes.)Each socket can have zero, one, or many "endpoints", which are either -listeners or dialers. (A given socket may freely choose whether it uses -listeners, dialers, or both.) These "endpoints" provide access to -underlying transports, such as TCP, etc.
+listeners or dialers. +(A given socket may freely choose whether it uses listeners, dialers, or both.) +These "endpoints" provide access to underlying transports, such as TCP, etc.Each endpoint is associated with a URL, which is a service address. For -dialers, this will be the service address that will be contacted, whereas -for listeners this is where the listener will bind and watch for new -connections.
+Each endpoint is associated with a URL, which is a service address. +For dialers, this will be the service address that will be contacted, whereas +for listeners this is where the listener will accept new connections.
Endpoints do not themselves transport data. They are instead responsible -for the creation of pipes, which can be thought of as message-oriented, -connected, streams. Pipes frequently correspond to a single underlying -byte stream — for example both IPC and TCP transports implement their -pipes using a 1:1 relationship with a connected socket.
+Endpoints do not themselves transport data. +They are instead responsible for the creation of pipes, which can be +thought of as message-oriented connected streams. +Pipes frequently correspond to a single underlying byte stream. +For example both IPC and TCP transports implement their +pipes using a 1:1 relationship with a connected operating system socket.
Endpoints create pipes as needed. Listeners will create them when a new -client connection request arrives, and dialers will generally create one, -then wait for it to disconnect before reconnecting.
+Endpoints create pipes as needed. +Listeners will create them when a new client connection request arrives, +and dialers will generally create one, then wait for it to disconnect before +reconnecting.
Most applications should not have to worry about endpoints or pipes at all; the socket abstraction should provide all the functionality needed other than in a few specific circumstances.
+Most applications will use nng sockets in “cooked” mode. +This mode provides the full semantics of the protocol. +For example, req sockets will automatically +match a reply to a request, and resend requests periodically if no reply +was received.
+There are situations, such as with proxies, +where it is desirable to bypass these semantics and simply pass messages +to and from the socket with no extra semantic handling. +This is possible using “raw” mode sockets.
+Raw mode sockets are generally constructed with a different function,
+such as nng_req0_open_raw().
+Using these sockets, the application can simply send and receive messages,
+and is responsible for supplying any additional socket semantics.
+Typically this means that the application will need to inspect message
+headers on incoming messages, and supply them on outgoing messages.
| + + | +
+The nng_device() function only works with raw mode
+sockets, but as it only forwards the messages, no additional application
+processing is needed.
+ |
+
/) separators are removed from the path.
them is believed to improve both the usability and security of nng
applications, without violating RFC 3986 itself.
| + + | ++Port numbers may be service names in some instances, but it is recommended +that numeric port numbers be used when known. +If service names are used, it is recommended that they follow the naming +conventions for C identifiers, and not be longer than 32 characters in length. +This will maximize compatibility across systems and minimize opportunities for +confusion when they are parsed on different systems. + | +
NNG_ECANCELED, and th
for it to complete or to be completely aborted.
This is logically the equivalent of nng_aio_cancel()
-followed by nng_aio_wait(), except that the asynchronous
-I/O handle may not be used for any further operations.
If an operation is in progress when this function is called, that operation +is canceled and the callback function is not allowed to run.
+If the callback function is already running when this function is called, +then it is allowed to complete before returning to the caller.
+No new operations will be started on this aio.
+| + + | ++Calling this function means that the operation may be aborted without +completing its callback function. + | +
| - + |
Do not use the system free() function to release this memory.
@@ -566,20 +566,17 @@ to a crash or other undesirable and unpredictable behavior.
RETURN VALUES
-
This function returns 0 on success, and non-zero otherwise. +This function returns a pointer to the allocated memory on success,
+and ERRORS
-
diff --git a/man/tip/nng_bus.7.html b/man/tip/nng_bus.7.html
index 54adf490..4c4342d3 100644
--- a/man/tip/nng_bus.7.html
+++ b/man/tip/nng_bus.7.html
@@ -530,9 +530,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
-
+
No errors are returned, but a
-
+
Socket Operations
-
diff --git a/man/tip/nng_bus_open.3.html b/man/tip/nng_bus_open.3.html
index 09b02fe8..e8aee826 100644
--- a/man/tip/nng_bus_open.3.html
+++ b/man/tip/nng_bus_open.3.html
@@ -528,7 +528,9 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
The The
+int nng_bus0_open(nng_socket *s);
+
+int nng_bus0_open_raw(nng_socket *s);
The
+
The RETURN VALUES
-
This function returns 0 on success, and non-zero otherwise. +These functions return 0 on success, and non-zero otherwise.
+
+nng_clock(3supp) Manual Page+
+
+Table of Contents
+
+NAME+
+
+nng_clock - get time +
+
+
+
diff --git a/man/tip/nng_ctx.5.html b/man/tip/nng_ctx.5.html
new file mode 100644
index 00000000..a218059e
--- /dev/null
+++ b/man/tip/nng_ctx.5.html
@@ -0,0 +1,731 @@
+---
+version: tip
+layout: refman
+---
+
+
+
+
+
+
+
+
+
+SYNOPSIS+
+
+
+
+
+
+
+
+
+DESCRIPTION+
+
+
+
+The
+
+
+
+
+
+RETURN VALUES+
+
+
+
+Milliseconds since reference time. +
+
+ERRORS+
+
+
+
+None. +
+
+SEE ALSO+
+
+
+
+
+nng_ctx(5) Manual Page+
+
+Table of Contents
+
NAME+
+
+nng_ctx - protocol context +
+
+
+
diff --git a/man/tip/nng_ctx_close.3.html b/man/tip/nng_ctx_close.3.html
new file mode 100644
index 00000000..6f486e0a
--- /dev/null
+++ b/man/tip/nng_ctx_close.3.html
@@ -0,0 +1,599 @@
+---
+version: tip
+layout: refman
+---
+
+
+
+
+
+
+
+
+
+SYNOPSIS+
+
+
+
+
+
+
+
+
+DESCRIPTION+
+
+
+
+An
+
+For example, a req context will contain the request ID +of any sent request, a timer to retry the request on failure, and so forth. +A separate context on the same socket can have similar data, but corresponding +to a completely different request. +
+
+All contexts share the same socket, and so some options, as well as the +underlying transport details, will be common to all contexts on that socket. +
+
+
+
+Protocols that make use of contexts will also have a “default” context +that is used when the socket global operations are used. +Operations using the global context will generally not interfere with +any other contexts, except that certain socket options may affect socket +global behavior. +
+
++Historically, applications wanting to use a stateful protocol concurrently +would have to resort to raw mode sockets, which bypasses +much of the various protocol handling, leaving it to up to the application +to do so. +Contexts make it possible to still benefit from advanced protocol handling, +including timeouts, retries, and matching requests to responses, while doing so +concurrently. +
+
+
+
+
+
+
+
+EXAMPLE+
+
+
+
+The following program fragment demonstrates the use of contexts to implement +a concurrent rep service that simply echos messages back +to the sender. +
+
+
+
+
+
+
+Given the above fragment, the following example shows setting up the
+service. It assumes that the socket has already been
+created and any transports set up as well with functions such as
+
+
+
+
+
+
+
+SEE ALSO+ +
+
+nng_ctx_close(3) Manual Page+
+
+Table of Contents
+
+NAME+
+
+nng_ctx_close - close context +
+
+
+
diff --git a/man/tip/nng_ctx_getopt.3.html b/man/tip/nng_ctx_getopt.3.html
new file mode 100644
index 00000000..3ad0bad2
--- /dev/null
+++ b/man/tip/nng_ctx_getopt.3.html
@@ -0,0 +1,728 @@
+---
+version: tip
+layout: refman
+---
+
+
+
+
+
+
+
+
+
+SYNOPSIS+
+
+
+
+
+
+
+
+
+DESCRIPTION+
+
+
+
+The
+
+Further attempts to use the context after this call returns will result
+in
+
+
+
+RETURN VALUES+
+
+
+
+This function returns 0 on success, and non-zero otherwise. +
+
+ERRORS+
+
+
+
+
+
+SEE ALSO+
+
+
+
+
+
+
+nng_ctx_getopt(3) Manual Page+
+
+Table of Contents
+
NAME+
+
+nng_ctx_getopt - get context option +
+
+
+
diff --git a/man/tip/nng_ctx_open.3.html b/man/tip/nng_ctx_open.3.html
new file mode 100644
index 00000000..20b582cd
--- /dev/null
+++ b/man/tip/nng_ctx_open.3.html
@@ -0,0 +1,629 @@
+---
+version: tip
+layout: refman
+---
+
+
+
+
+
+
+
+
+
+SYNOPSIS+
+
+
+
+
+
+
+
+
+DESCRIPTION+
+
+
+
+
+The
+
+
+
+Forms+
+
+In all of these forms, the option opt is retrieved from the context ctx. +The forms vary based on the type of the option they take. +
+
+The details of the type, size, and semantics of the option will depend +on the actual option, and will be documented with the option itself. +
+
+
+
+
+ |
| + + | ++Not every protocol supports creation of separate contexts. + | +
Contexts allow the independent and concurrent use of stateful operations +using the same socket. +For example, two different contexts created on a rep +socket can each receive requests, and send replies to them, without any +regard to or interference with each other.
++TIP: Using contexts is an excellent way to write simpler concurrent +applications, while retaining the benefits of the protocol-specific +advanced processing, avoiding the need to bypass that with +raw mode sockets.
+| + + | ++Use of contexts with raw mode sockets is +nonsensical, and not supported. + | +
This function returns 0 on success, and non-zero otherwise.
+NNG_ENOMEMInsufficient memory is available.
+NNG_ENOTSUPThe protocol does not support separate contexts, or the socket was opened in raw mode.
+nng_ctx_recv - receive message using context asynchronously
+#include <nng/nng.h>
+
+void nng_ctx_recv(nng_ctx ctx, nng_aio *aio);
+When a message is successfully received by the context, it is
+stored in the aio by an internal call equivalent to
+nng_aio_set_msg(), then the completion
+callback on the aio is executed.
+In this case, nng_aio_result() will
+return zero.
+The callback function is responsible for retrieving the message
+and disposing of it appropriately.
| + + | ++Failing to accept and dispose of messages in this +case can lead to memory leaks. + | +
If for some reason the asynchronous receive cannot be completed
+successfully (including by being canceled or timing out), then
+the callback will still be executed,
+but nng_aio_result() will be non-zero.
| + + | ++The semantics of what receiving a message means varies from protocol to +protocol, so examination of the protocol documentation is encouraged. + | +
None. (The operation completes asynchronously.)
+NNG_ECANCELEDThe operation was aborted.
+NNG_ECLOSEDThe context ctx is not open.
+NNG_ENOMEMInsufficient memory is available.
+NNG_ENOTSUPThe protocol for context ctx does not support receiving.
+NNG_ESTATEThe context ctx cannot receive data in this state.
+NNG_ETIMEDOUTThe receive timeout expired.
+nng_ctx_send - send message using context asynchronously
+#include <nng/nng.h>
+
+void nng_ctx_send(nng_ctx ctx, nng_aio *aio);
+The message to send must have previously been set on the aio
+using the nng_aio_set_msg() function.
+The function assumes “ownership” of the message.
If the message was successfully queued for delivery to the socket,
+then the aio will be completed, and nng_aio_result()
+will return zero.
+In this case the socket will dispose of the message when it is finished with it.
| + + | ++The operation will be “completed”, and the callback associated +with the aio executed, as soon as the socket accepts the message +for sending. +This does not indicate that the message was actually delivered, as it +may still be buffered in the sending socket, buffered in the receiving +socket, or in flight over physical media. + | +
If the operation fails for any reason (including cancellation or timeout),
+then the aio callback will be executed and nng_aio_result()
+will return a non-zero error status.
+In this case, the callback has a responsibity to retrieve the message from
+the aio with nng_aio_get_msg() and dispose of
+it appropriately.
+(This may include retrying the send operation on the same or a different
+socket, or deallocating the message with nng_msg_free().)
| + + | ++The semantics of what sending a message means varies from protocol to +protocol, so examination of the protocol documentation is encouraged. + | +
| + + | +
+Context send operations are asynchronous.
+If a synchronous operation is needed, one can be constructed by using a
+NULL callback on the aio and then waiting for the operation using
+nng_aio_wait().
+ |
+
None. (The operation completes asynchronously.)
+NNG_ECANCELEDThe operation was aborted.
+NNG_ECLOSEDThe context ctx is not open.
+NNG_EMSGSIZEThe message is too large.
+NNG_ENOMEMInsufficient memory is available.
+NNG_ENOTSUPThe protocol for context ctx does not support sending.
+NNG_ESTATEThe context ctx cannot send data in this state.
+NNG_ETIMEDOUTThe send timeout expired.
+nng_ctx_setopt - set context option
+#include <nng/nng.h>
+
+int nng_ctx_setopt(nng_ctx ctx, const char *opt, const void *val, size_t valsz);
+
+int nng_ctx_setopt_bool(nng_ctx ctx, const char *opt, int bval);
+
+int nng_ctx_setopt_int(nng_ctx ctx, const char *opt, int ival);
+
+int nng_ctx_setopt_ms(nng_ctx ctx, const char *opt, nng_duration dur);
+
+int nng_ctx_setopt_size(nng_ctx ctx, const char *opt, size_t z);
+
+int nng_ctx_setopt_string(nng_ctx ctx, const char *opt, const char *str);
+
+int nng_ctx_setopt_uint64(nng_ctx ctx, const char *opt, uint64_t u64);
+
+The nng_ctx_setopt() functions are used to configure options for
+the context ctx.
+The actual options that may be configured in this way vary, and are
+specified by opt.
| + + | ++Context options are protocol specific. +The details will be documented with the protocol. + | +
The details of the type, size, and semantics of the option will depend +on the actual option, and will be documented with the option itself.
+| + + | ++Generally, it will be easier to use one of the typed versions +of this function. + | +
nng_ctx_setopt()This function is untyped, and can be used to configure any arbitrary data. +The val pointer addresses the data to copy, and valsz is the +size of the objected located at val.
+nng_ctx_setopt_bool()This function is for options which take a boolean (bool).
+The bval is passed to the option.
nng_ctx_setopt_int()This function is for options which take an integer (int).
+The ival is passed to the option.
nng_ctx_setopt_ms()This function is used to configure time durations (such as timeouts) using
+type nng_duration.
+The duration dur is an integer number of milliseconds.
nng_ctx_setopt_size()This function is used to configure a size, z, typically for buffer sizes, +message maximum sizes, and similar options.
+nng_ctx_setopt_string()This function is used to pass configure a string, str.
+Strings passed this way must be legal UTF-8 or ASCII strings, terminated
+with a NUL (\0) byte.
+(Other constraints may apply as well, see the documentation for each option
+for details.)
nng_ctx_setopt_uint64()This function is used to configure a 64-bit unsigned value, u64. +This is typically used for options related to identifiers, network numbers, +and similar.
+These functions return 0 on success, and non-zero otherwise.
+NNG_ECLOSEDParameter s does not refer to an open socket.
+NNG_EINVALThe value being passed is invalid.
+NNG_ENOTSUPThe option opt is not supported.
+NNG_EREADONLYThe option opt is read-only.
+NNG_ESTATEThe socket is in an inappropriate state for setting this option.
+nng_cv_alloc - allocate condition variable
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+typedef struct nng_cv nng_cv;
+
+int nng_cv_alloc(nng_cv **cvp, nng_mtx *mtx);
+The nng_cv_alloc() function allocates a condition variable, using
+the mutex mtx, and returns it in cvp.
Every condition variable is associated with a mutex, which must be
+owned when a thread waits for the condition using
+nng_cv_wait() or
+nng_cv_until().
+The mutex must also be owned when signaling the condition using the
+nng_cv_wake() or
+nng_cv_wake1() functions.
This function returns 0 on success, and non-zero otherwise.
+NNG_ENOMEMInsufficient free memory exists.
+nng_cv_free - free condition variable
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_cv_free(nng_cv *cv);
+The nng_cv_free() function frees the condition variable cv.
None.
+None.
+nng_cv_until - wait for condition or timeout
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+int nng_cv_wait(nng_cv *cv, nng_time when);
+The nng_cv_until() waits until either the condition variable cv is signaled
+by another thread calling either nng_cv_wake() or
+nng_cv_wake1(), or the system clock (as tracked
+by nng_clock()) reaches when.
The caller must have have ownership of the mutex that was used when +cv was allocated. +This function will drop the ownership of that mutex, and reacquire it +atomically just before returning to the caller. +(The waiting is done without holding the mutex.)
+| + + | ++Any condition may be used or checked, but the condition must be +checked, as it is possible for this function to wake up “spuriously”. +The best way to do this is inside a loop that repeats until the condition +tests for true. + | +
The following example demonstrates use of this function:
+
+ nng_mtx_lock(m); // assume cv was allocated using m
+ while (!condition_true) {
+ if (nng_cv_wait(cv) == NNG_ETIMEDOUT) {
+ printf("Time out reached!\n");
+ break;
+ }
+ }
+ // condition_true is true
+ nng_mtx_unlock(m);
+ nng_mtx_lock(m);
+ condition_true = true;
+ cv_wake(cv);
+ nng_mtx_unlock(m);
+None.
+None.
+nng_cv_wait - wait for condition
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_cv_wait(nng_cv *cv);
+The nng_cv_wait() waits for the condition variable cv to be signaled
+by another thread calling either nng_cv_wake() or
+nng_cv_wake1().
The caller must have have ownership of the mutex that was used when +cv was allocated. +This function will drop the ownership of that mutex, and reacquire it +atomically just before returning to the caller. +(The waiting is done without holding the mutex.)
+| + + | ++Any condition may be used or checked, but the condition must be +checked, as it is possible for this function to wake up “spuriously”. +The best way to do this is inside a loop that repeats until the condition +tests for true. + | +
The following example demonstrates use of this function:
+
+ nng_mtx_lock(m); // assume cv was allocated using m
+ while (!condition_true) {
+ nng_cv_wait(cv);
+ }
+ // condition_true is true
+ nng_mtx_unlock(m);
+ nng_mtx_lock(m);
+ condition_true = true;
+ cv_wake(cv);
+ nng_mtx_unlock(m);
+None.
+None.
+nng_cv_wake - wake all waiters
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_cv_wake(nng_cv *cv);
+The nng_cv_wake() wakes any threads waiting for the condition variable cv
+to be signaled in the nng_cv_wait() or
+nng_cv_until() functions.
The caller must have have ownership of the mutex that was used when +cv was allocated.
+| + + | ++The caller should already have set the condition that the waiters +will check, while holding the mutex. + | +
| + + | +
+This function wakes all threads, which is generally safer but can
+lead to a problem known as the “thundering herd” when there are many
+waiters, as they are all woken simultaneously.
+See nng_cv_wake1() for a solution to this problem.
+ |
+
None.
+None.
+nng_cv_wake1 - wake one waiter
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_cv_wake1(nng_cv *cv);
+The nng_cv_wake1() wakes at most one thread waiting for the condition
+variable cv
+to be signaled in the nng_cv_wait() or
+nng_cv_until() functions.
The caller must have have ownership of the mutex that was used when +cv was allocated.
+| + + | ++The caller should already have set the condition that the waiters +will check, while holding the mutex. + | +
| + + | +
+While this function avoids the “thundering herd” problem, the
+caller cannot predict which waiter will be woken, and so the design must
+ensure that it is sufficient that any waiter be woken.
+When in doubt, it is safer to use nng_cv_wake().
+ |
+
None.
+None.
+Only raw mode sockets may be used with this
+function.
+These can be created using _raw forms of the various socket constructors,
+such as nng_req0_open_raw().
The nng_device() function does not return until one of the sockets
is closed.
This nng_device() function puts each socket into raw mode
-(see NNG_OPT_RAW), and then moves messages
-between them.
-When a protocol has a backtrace style header, routing information is
-added as the message crosses the forwarder, allowing replies to be
+
The nng_device() function moves messages between the provided sockets.
When a protocol has a backtrace style header, routing information +is present in the header of received messages, and is copied to the +header of the output bound message. +The underlying raw mode protocols supply the necessary header +adjustments to add or remove routing headers as needed. +This allows replies to be returned to requestors, and responses to be routed back to surveyors.
In all of these forms, the option opt is retrieved from the dialer d. The forms vary based on the type of the option they take.
The details of the type, size, and semantics of the option will depend +on the actual option, and will be documented with the option itself.
+| - - | --No validation that the option is actually of the associated type is -performed, so the caller must take care to use the correct typed form. - | -
The details of the type, size, and semantics of the option will depend -on the actual option, and will be documented with the option itself.
-nng_dialer_getopt()nng_dialer_getopt_bool()This function is for options which take a boolean (bool).
-The value will be stored at ivalp.
nng_dialer_getopt_sockaddr()This function is used to retrieve an nng_sockaddr
+into the value referenced by sap.
nng_dialer_getopt_string()This function is used to retrieve a string into strp.
+This string is created from the source using nng_strdup()
+and consequently must be freed by the caller using
+nng_strfree() when it is no longer needed.
nng_dialer_getopt_uint64()This function is used to retrieve a 64-bit unsigned value into the value @@ -685,10 +692,22 @@ numbers, and similar.
NNG_EBADTYPEIncorrect type for option.
+NNG_ECLOSEDParameter d does not refer to an open dialer.
NNG_EINVALSize of destination val too small for object.
+NNG_ENOMEMInsufficient memory exists.
+NNG_ENOTSUPThe option opt is not supported.
@@ -707,10 +726,13 @@ numbers, and similar.| - - | --No validation that the option is actually of the associated -type is performed, so the caller must take care to use the correct typed form. - | -
nng_dialer_setopt()NNG_EBADTYPEIncorrect type for option.
+NNG_ECLOSEDParameter d does not refer to an open dialer.
diff --git a/man/tip/nng_free.3.html b/man/tip/nng_free.3.html index c56fc914..6bfc9d67 100644 --- a/man/tip/nng_free.3.html +++ b/man/tip/nng_free.3.html @@ -540,11 +540,11 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b that was previously allocated bynng_alloc() or
nng_recv() with the NNG_FLAG_ALLOC flag.
| - + | It is very important that size match the allocation size @@ -553,11 +553,11 @@ used to allocate the memory. |
| - + |
Do not attempt to use this function to deallocate memory
diff --git a/man/tip/nng_getopt.3.html b/man/tip/nng_getopt.3.html
index 889881bc..ffaa72fe 100644
--- a/man/tip/nng_getopt.3.html
+++ b/man/tip/nng_getopt.3.html
@@ -543,6 +543,8 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
int nng_getopt_size(nng_socket s, const char *opt, size_t *zp);
+int nng_getopt_string(nng_socket s, const char *opt, char **strp);
+
int nng_getopt_uint64(nng_socket s, const char *opt, uint64_t *u64p);
@@ -568,6 +570,10 @@ documented with the transports and protocols themselves.
In all of these forms, the option opt is retrieved from the socket s. The forms vary based on the type of the option they take. +
+
The details of the type, size, and semantics of the option will depend +on the actual option, and will be documented with the option itself. +
-
-
-
The details of the type, size, and semantics of the option will depend -on the actual option, and will be documented with the option itself. -
|
| - - | --No validation that the option is actually of the associated type is -performed, so the caller must take care to use the correct typed form. - | -
The details of the type, size, and semantics of the option will depend -on the actual option, and will be documented with the option itself.
-nng_listener_getopt()nng_listener_getopt_bool()This function is for options which take a boolean (bool).
-The value will be stored at ivalp.
nng_listener_getopt_ms()This function is used to retrieve time durations
-(such as timeouts), stored in durp as a number of milliseconds.
-(The special value NNG_DUR_INFINITE means an infinite amount of time, and
-the special value NNG_DUR_DEFAULT means a context-specific default.)
nng_listener_getopt_sockaddr()This function is used to retrieve an nng_sockaddr
+into the value referenced by sap.
nng_listener_getopt_string()This function is used to retrieve a string into strp.
+This string is created from the source using nng_strdup()
+and consequently must be freed by the caller using
+nng_strfree() when it is no longer needed.
nng_listener_getopt_uint64()This function is used to retrieve a 64-bit unsigned value into the value @@ -686,10 +690,22 @@ numbers, and similar.
NNG_EBADTYPEIncorrect type for option.
+NNG_ECLOSEDParameter l does not refer to an open listener.
NNG_EINVALSize of destination val too small for object.
+NNG_ENOMEMInsufficient memory exists.
+NNG_ENOTSUPThe option opt is not supported.
@@ -710,7 +726,13 @@ numbers, and similar. nng_listener_create(3) nng_listener_setopt(3) nng_getopt(3), +nng_strdup(3), nng_strerror(3), +nng_strfree(3), +nng_duration(5), +nng_listener(5), +nng_options(5), +nng_sockaddr(5), nng(7)| - - | --No validation that the option is actually of the associated -type is performed, so the caller must take care to use the correct typed form. - | -
nng_listener_setopt()NNG_EBADTYPEIncorrect type for option.
+NNG_ECLOSEDParameter l does not refer to an open listener.
@@ -726,6 +717,7 @@ and similar. nng_listener_getopt(3) nng_setopt(3), nng_strerror(3), +nng_duration(5), nng_listener(5), nng_options(5), nng(7) diff --git a/man/tip/nng_msleep.3supp.html b/man/tip/nng_msleep.3supp.html new file mode 100644 index 00000000..8658c615 --- /dev/null +++ b/man/tip/nng_msleep.3supp.html @@ -0,0 +1,588 @@ +--- +version: tip +layout: refman +--- + + + + + + + +nng_msleep - sleep milliseconds
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_msleep(nng_duration msec);
+The nng_msleep() blocks the caller for at least msec milliseconds.
| + + | ++This function may block for longer than requested. +The actual wait time is determined by the capabilities of the +underlying system. + | +
None.
+None.
+nng_mtx_alloc - allocate mutex
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+typedef struct nng_mtx nng_mtx;
+
+int nng_mtx_alloc(nng_mtx **mtxp);
+The nng_mtx_alloc() function allocates mutex and returns it in mtxp.
The mutex objects created by this function are suitable only for +simple lock and unlock operations, and are not recursive. +Every effort has been made to use light-weight underlying primitives when available.
+Mutex (mutual exclusion) objects can be thought of as binary semaphores, +where only a single thread of execution is permitted to “own” the semaphore.
+Furthermore, a mutex can only be unlocked by the thread that locked it.
+This function returns 0 on success, and non-zero otherwise.
+NNG_ENOMEMInsufficient free memory exists.
+nng_mtx_free - free mutex
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_mtx_free(nng_mtx *mtx);
+The nng_mtx_free() function frees the mutex mtx.
+The mutex must not be locked when this function is called.
None.
+None.
+nng_mtx_lock - lock mutex
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_mtx_lock(nng_mtx *mtx);
+The nng_mtx_lock() acquires exclusive ownership of the mutex mtx.
+If the lock is already owned, this function will wait until the current
+owner releases it with nng_mtx_unlock().
If multiple threads are waiting for the lock, the order of acquisition +is not specified.
+| + + | ++A mutex can only be unlocked by the thread that locked it. + | +
| + + | ++Mutex locks are not recursive; attempts to reacquire the +same mutex may result in deadlock or aborting the current program. +It is a programming error for the owner of a mutex to attempt to +reacquire it. + | +
None.
+None.
+nng_mtx_lock - lock mutex
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_mtx_unlock(nng_mtx *mtx);
+The nng_mtx_unlock() reqlinquishes ownership of the mutex mtx that
+was previously acquired via nng_mtx_lock().
| + + | ++A mutex can only be unlocked by the thread that locked it. +Attempting to unlock a mutex that is not owned by the caller will result +in undefined behavior. + | +
None.
+None.
+
(bool)
-This option determines whether the socket is in “raw” mode.
+This read-only option indicates whether the socket is in “raw” mode.
If true, the socket is in “raw” mode, and if false the socket is
in “cooked” mode.
Raw mode sockets generally do not have any protocol-specific semantics applied
to them; instead the application is expected to perform such semantics itself.
(For example, in “cooked” mode a rep socket would
automatically copy message headers from a received message to the corresponding
-reply, whereas in “raw” mode this is not done.)
nng_opts_parse - parse command line options
+#include <nng/nng.h>
+#include <nng/supplemental/util/options.h>
+
+typedef struct nng_optspec {
+ const char *o_name; // Long style name (may be NULL for short only)
+ int o_short; // Short option (no clustering!)
+ int o_val; // Value stored on a good parse (>0)
+ bool o_arg; // Option takes an argument if true
+} nng_optspec;
+
+int nng_opts_parse(int argc, const char **argv, const nng_optspec *spec, int *val, const char **arg, int *idx);
+The nng_opts_parse() is function is a supplemental funtion intened to
+facilitate parsing command line arguments.
+This function exists largely to stand in for getopt() from POSIX
+systems, but it is available everywhere that NNG is, and it includes
+some capabilities missing from getopt().
The function parses arguments from main() (using argc and argv),
+starting at the index referenced by idx.
+(New invocations typically set the value pointed to by idx to 1.)
Options are parsed as specified by spec (see Option Specification.) +The value of the parsed option will be stored at the address indicated by +val, and the value of idx will be incremented to reflect the next +option to parse.
+| + + | ++For using this to parse command-line like strings that do not include +the command name itself, set the value referenced by idx to zero +instead of one. + | +
If the option had an argument, a pointer to that is returned at the address +referenced by arg.
+This function should be called repeatedly, until it returns either -1 +(indicating the end of options is reached) or a non-zero error code is +returned.
+The calling program must first create an array of nng_optspec structures
+describing the options to be supported.
+This structure has the following members:
o_nameThe long style name for the option, such as "verbose".
+This will be parsed on the command line when it is prefixed with two dashes.
+It may be NULL if only a short option is to be supported.
o_shortThis is a single letter (at present only ASCII letters are supported). +These options appear as just a single letter, and are prefixed with a single dash on the command line. +The use of a slash in lieu of the dash is not supported, in order to avoid confusion with path name arguments. +This value may be set to 0 if no short option is needed.
+o_valThis is a numeric value that is unique to this option.
+This value is assigned by the application program, and must be non-zero
+for a valid option.
+If this is zero, then it indicates the end of the specifications, and the
+rest of this structure is ignored.
+The value will be returned to the caller in val by nng_opts_parse() when
+this option is parsed from the command line.
o_argThis value should be set to true if the option should take an argument.
Long options are parsed from the argv array, and are indicated when
+the element being scanned starts with two dashes.
+For example, the "verbose" option would be specified as --verbose on
+the command line.
+If a long option takes an argument, it can either immediately follow
+the option as the next element in argv, or it can be appended to
+the option, separated from the option by an equals sign (=) or a
+colon (:).
Short options appear by themselves in an argv element, prefixed by a
+dash (-).
+If the short option takes an argument, it can either be appended in the
+same element of argv, or may appear in the next argv element.
| + + | ++Option clustering, where multiple options can be crammed together in +a single argv element, is not supported by this function (yet). + | +
When using long options, the parser will match if it is equal to a prefix
+of the o_name member of a option specification, provided that it do so
+unambiguously (meaning it must not match any other option specification.)
The following program fragment demonstrates this function.
+ enum { OPT_LOGFILE, OPT_VERBOSE };
+ char *logfile; // options to be set
+ bool verbose;
+
+ static nng_optspec specs[] = {
+ {
+ .o_name = "logfile",
+ .o_short = 'D',
+ .o_val = OPT_LOGFILE,
+ .o_arg = true,
+ }, {
+ .o_name = "verbose",
+ .o_short = 'V',
+ .o_val = OPT_VERBOSE,
+ .o_arg = false,
+ }, {
+ .o_val = 0; // Terminate array
+ }
+ };
+
+ for (int idx = 1;;) {
+ int rv, opt;
+ char *arg;
+ rv = nng_opts_parse(argc, argv, specs, &opt, &arg, &idx);
+ if (rv != 0) {
+ break;
+ }
+ switch (opt) {
+ case OPT_LOGFILE:
+ logfile = arg;
+ break;
+ case OPT_VERBOSE:
+ verbose = true;
+ break;
+ }
+ }
+ if (rv != -1) {
+ printf("Options error: %s\n", nng_strerror(rv));
+ exit(1);
+ }
+This function returns 0 if an option parsed correctly, -1 if +no more options are available to be parsed, or an error number otherwise.
+NNG_EAMBIGUOUSParsed option matches more than one specification.
+NNG_ENOARGOption requires an argument, but one is not present.
+NNG_EINVALAn invalid (unknown) argument is present.
+#include <nng/protocol/pair0/pair.h>
-
-int nng_pair0_open(nng_socket *s);
+#include <nng/protocol/pair0/pair.h>
#include <nng/protocol/pair1/pair.h>
-
-int nng_pair1_open(nng_socket *s);
+#include <nng/protocol/pair1/pair.h>
The nng_pair_open() call creates a pair socket. Normally, this
-pattern will block when attempting to send a message, if no peer is
-able to receive the message.
The nng_pair_open() functions create pair socket.
Normally, this pattern will block when attempting to send a message if +no peer is able to receive the message.
| Generally, it will be easier to use one of the typed forms instead. -Note however that no validation that the option is actually of the associated -type is performed, so the caller must take care to use the correct typed form. |
nng_pipe_getopt_sockaddr()This function is used to retrieve an nng_sockaddr
+into sap.
nng_pipe_getopt_string()This function is used to retrieve a string into strp.
+This string is created from the source using nng_strdup()
+and consequently must be freed by the caller using
+nng_strfree() when it is no longer needed.
nng_pipe_getopt_uint64()This function is used to retriev a 64-bit unsigned value into the value @@ -689,6 +707,10 @@ related to identifiers, network numbers, and similar.
NNG_EBADTYPEIncorrect type for option.
+NNG_ECLOSEDParameter p does not refer to an open pipe.
@@ -697,6 +719,14 @@ related to identifiers, network numbers, and similar.The option opt is not supported.
NNG_ENOMEMInsufficient memory exists.
+NNG_EINVALSize of destination val too small for object.
+NNG_EWRITEONLYThe option opt is write-only.
@@ -713,8 +743,13 @@ related to identifiers, network numbers, and similar. nng_getopt(3), nng_listener_setopt(3) nng_msg_get_pipe(3) +nng_strdup(3), nng_strerror(3), +nng_strfree(3), +nng_duration(5), nng_options(5), +nng_pipe(5), +nng_sockaddr(5), nng(7)#include <nng/protocol/pubsub0/pub.h>
-
-int nng_pub0_open(nng_socket *s);
+#include <nng/protocol/pubsub0/pub.h>
The nng_pub0_open() call creates a publisher socket.
+
The nng_pub0_open() functions create a publisher socket.
This socket may be used to send messages, but is unable to receive them.
Attempts to receive messages will result in NNG_ENOTSUP.
#include <nng/nng.h>
#include <nng/protocol/pubsub0/pub.h>
-int nng_pub0_open(nng_socket *s);
+int nng_pub0_open(nng_socket *s);
+
+int nng_pub0_open_raw(nng_socket *s);
The nng_pub0_open() function creates a pub version 0
socket and returns it at the location pointed to by s.
This function returns 0 on success, and non-zero otherwise.
+These functions return 0 on success, and non-zero otherwise.
#include <nng/protocol/pipeline0/pull.h>
-
-int nng_pull0_open(nng_socket *s);
+#include <nng/protocol/pipeline0/pull.h>
The nng_pull0_open() call creates a puller socket.
+
The nng_pull0_open() functions create a puller socket.
This socket may be used to receive messages, but is unable to send them.
Attempts to send messages will result in NNG_ENOTSUP.
#include <nng/nng.h>
#include <nng/protocol/pipeline0/pull.h>
-int nng_pull0_open(nng_socket *s);
+int nng_pull0_open(nng_socket *s);
+
+int nng_pull0_open_raw(nng_socket *s);
The nng_pull0_open() function creates a pull version 0
socket and returns it at the location pointed to by s.
This function returns 0 on success, and non-zero otherwise.
+These functions return 0 on success, and non-zero otherwise.
#include <nng/protocol/pipeline0/push.h>
-
-int nng_push0_open(nng_socket *s);
+#include <nng/protocol/pipeline0/push.h>
#include <nng/nng.h>
#include <nng/protocol/pipeline0/push.h>
-int nng_push0_open(nng_socket *s);
+int nng_push0_open(nng_socket *s);
+
+int nng_push0_open_raw(nng_socket *s);
@@ -540,13 +542,18 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
The nng_push0_open() function creates a push version 0
socket and returns it at the location pointed to by s.
The nng_push0_open_raw() function creates a push version 0
+socket in
+raw mode and returns it at the location pointed to by s.
This function returns 0 on success, and non-zero otherwise.
+These functions return 0 on success, and non-zero otherwise.
nng_random - get random number
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+uint32_t nng_random(void);
+The nng_random() returns a random number.
+The value returned is suitable for use with cryptographic functions such as
+key generation.
+The value is obtained using platform specific cryptographically strong random
+number facilities when available.
Random number.
+None.
+#include <nng/protocol/reqrep0/rep.h>
-
-int nng_rep0_open(nng_socket *s);
+#include <nng/protocol/reqrep0/rep.h>
The nng_rep0_open() call creates a replier socket.
+
The nng_rep0_open() functions create a replier socket.
This socket may be used to receive messages (requests), and then to send
-replies.
-Generally a reply can only be sent after receiving a request.
-(Attempts to receive a message will result in NNG_ESTATE if there
-is no outstanding request.)
Attempts to send on a socket with no outstanding requests will result
-in NNG_ESTATE.
Generally a reply can only be sent after receiving a request.
Raw mode sockets (set with NNG_OPT_RAW)
-ignore all these restrictions.
Send operations will result in NNG_ESTATE if no corresponding request
+was previously received.
Likewise, only one receive operation may be pending at a time.
+Any additional concurrent receive operations will result in NNG_ESTATE.
Raw mode sockets ignore all these restrictions.
+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 from the others. +The restrictions for order of operations with sockets apply equally +well for contexts, except that each context will be treated as if it were +a separate socket.
The nng_rep0_open() function creates a rep version 0
socket and returns it at the location pointed to by s.
The nng_rep0_open_raw() function creates a rep version 0
+socket
+in raw mode and returns it at the location pointed to by s.
This function returns 0 on success, and non-zero otherwise.
+These functions return 0 on success, and non-zero otherwise.
#include <nng/protocol/reqrep0/req.h>
-
-int nng_req0_open(nng_socket *s);
+#include <nng/protocol/reqrep0/req.h>
The nng_req0_open() call creates a requester socket.
-This socket may be used to send messages (requests),
-and then to receive replies.
-Generally a reply can only be received after sending a request.
+
The nng_req0_open() functions create a requester socket.
+This socket may be used to send messages (requests), and then to receive replies.
Generally a reply can only be received after sending a request.
(Attempts to receive a message will result in NNG_ESTATE if there is no
outstanding request.)
Furthermore, only a single receive operation may be pending at a time.
+Attempts to post more receive operations concurrently will result in
+NNG_ESTATE.
Requests may be canceled by sending a different request. This will cause the requester to discard any reply from the earlier request, but it will not stop a replier @@ -619,12 +624,23 @@ from processing a request it has already received or terminate a request that has already been placed on the wire.
Attempts to receive on a socket with no outstanding requests will result
-in NNG_ESTATE.
Raw mode sockets ignore all these restrictions.
+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.
Raw mode sockets (set with NNG_OPT_RAW)
-ignore all these restrictions.
Each context may have at most one outstanding request, and operates +independently from the others. +The restrictions for order of operations with sockets apply equally +well for contexts, except that each context will be treated as if it were +a separate socket.
#include <nng/nng.h>
#include <nng/protocol/reqrep0/req.h>
-int nng_req0_open(nng_socket *s);
+int nng_req0_open(nng_socket *s);
+
+int nng_req0_open_raw(nng_socket *s);
The nng_req0_open() function creates a req version 0
socket and returns it at the location pointed to by s.
The nng_req0_open_raw() function creates a req version 0
+socket in
+raw mode
+and returns it at the location pointed to by s.
This function returns 0 on success, and non-zero otherwise.
+These functions return 0 on success, and non-zero otherwise.
nng_options(5), +nng_socket(5), nng_rep(7), nng_req(7), nng(7)
diff --git a/man/tip/nng_respondent.7.html b/man/tip/nng_respondent.7.html index 63000d52..b51fb28c 100644 --- a/man/tip/nng_respondent.7.html +++ b/man/tip/nng_respondent.7.html @@ -530,9 +530,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b#include <nng/protocol/survey0/respond.h>
-
-int nng_respondent0_open(nng_socket *s);
+#include <nng/protocol/survey0/respond.h>
The nng_respondent0_open() call creates a
+
The nng_respondent0_open() functions create a
respondent socket.
This socket may be used to receive messages, and then to send replies.
A reply can only be sent after receiving a survey, and generally the
diff --git a/man/tip/nng_respondent_open.3.html b/man/tip/nng_respondent_open.3.html
index b9f893b7..86c25a56 100644
--- a/man/tip/nng_respondent_open.3.html
+++ b/man/tip/nng_respondent_open.3.html
@@ -528,7 +528,9 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
#include <nng/nng.h>
#include <nng/protocol/survey0/respond.h>
-int nng_respondent0_open(nng_socket *s);
+int nng_respondent0_open(nng_socket *s);
+
+int nng_respondent0_open_raw(nng_socket *s);
The nng_respondent0_open_raw() function creates a
+respondent
+version 0 socket in
+raw mode and returns it at the location pointed to by s.
This function returns 0 on success, and non-zero otherwise.
+These functions return 0 on success, and non-zero otherwise.
| - - | --No validation that the option is actually of the associated -type is performed, so the caller must take care to use the correct typed form. - | -
nng_setopt()nng_strdup - duplicate string
+#include <nng/nng.h>
+
+char *nng_strdup(const char *src);
+The nng_strdup() duplicates the string src and returns it.
This is logically equiavlent to using nng_alloc()
+to allocate a region of memory of strlen(s) + 1 bytes, and then
+using strcpy() to copy the string into the destination before
+returning it.
The returned string should be deallocated with
+nng_strfree(), or may be deallocated using the
+nng_free() using the length of the returned string plus
+one (for the NUL terminating byte).
| + + | +
+Do not use the system free() or similar functions to deallocate
+the string, since those may use a different memory arena!
+ |
+
This function returns the new string on success, and NULL on failure.
No errors are returned, but a NULL return value should be
+treated the same as NNG_ENOMEM.
nng_free - free memory
+#include <nng/nng.h>
+
+void nng_strfree(char *str);
+The nng_strfree() function deallocates the string str.
+This is equivalent to using nng_free() with
+the length of str plus one (for the NUL terminating byte) as
+the size.
| + + | +
+This should only be used with strings that were allocated
+by nng_strdup() or
+nng_alloc().
+In all cases, the allocation size of the string must be the same
+as strlen(str) + 1.
+ |
+
| + + | +
+Consequently, if the a string created with
+nng_strdup() is modified to be shorter, then
+it is incorrect to call this function.
+(The nng_free() function can be used instead in that
+case, using the length of the original string plus one for the size.)
+ |
+
None.
+None.
+#include <nng/nng.h>
-#include <nng/protocol/pubsub0/sub.h>
-
-int nng_sub0_open(nng_socket *s);
+#include <nng/protocol/pubsub0/sub.h>
The nng_sub0_open() call creates a subscriber socket.
+
The nng_sub0_open() functions create a subscriber socket.
This socket may be used to receive messages, but is unable to send them.
Attempts to send messages will result in NNG_ENOTSUP.
#include <nng/nng.h>
#include <nng/protocol/pubsub0/sub.h>
-int nng_sub0_open(nng_socket *s);
+int nng_sub0_open(nng_socket *s);
+
+int nng_sub0_open_raw(nng_socket *s);
The nng_sub0_open() function creates a sub version 0
socket and returns it at the location pointed to by s.
This function returns 0 on success, and non-zero otherwise.
+These functions return 0 on success, and non-zero otherwise.
#include <nng/nng.h>
-#include <nng/protocol/survey0/survey.h>
-
-int nng_surveyor0_open(nng_socket *s);
+#include <nng/protocol/survey0/survey.h>
The nng_surveyor0_open()
-call creates a surveyor socket.
+functions create a surveyor socket.
This socket may be used to send messages (surveys), and then to receive replies.
A reply can only be received after sending a survey.
A surveyor can normally expect to receive at most one reply from each responder.
@@ -591,8 +589,7 @@ cancel the prior one, and any responses from respondents from the prior
survey that arrive after this will be discarded.
Raw mode sockets (set with NNG_OPT_RAW)
-ignore all these restrictions.
Raw mode sockets ignore all these restrictions.
#include <nng/nng.h>
#include <nng/protocol/survey0/survey.h>
-int nng_surveyor0_open(nng_socket *s);
+int nng_surveyor0_open(nng_socket *s);
+
+int nng_surveyor0_open_raw(nng_socket *s);
The nng_surveyor0_open_raw() function creates a surveyor
+version 0 socket in
+raw mode and returns it at the location pointed to by s.
This function returns 0 on success, and non-zero otherwise.
+These functions return 0 on success, and non-zero otherwise.
nng_thread_create - create thread
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+typedef struct nng_thread nng_thread;
+
+int nng_thread_create(nng_thread **thrp, void (*func)(void *), void *arg);
+The nng_thread_create() function creates a single thread of execution,
+running func with the argument arg.
+The thread is started immediately.
+A pointer to the thread object is returned in thrp.
The intention of this program is to facilitate writing parallel programs. +Threads created by this program will be based upon the underlying +threading mechanism of the system that NNG is running on. +This may include use of so-called “green threads” or coroutines.
+Using threads created by this function can make it easy to write +programs that use simple sequential execution, using functions in the +NNG suite that would otherwise normally “block”.
+When the thread is no longer needed, the
+nng_thread_destroy()
+function should be used to reap it.
+(This function will block waiting for func to return.)
| + + | +
+Thread objects created by this function may not be “real”
+threads capable of performing blocking I/O operations using normal blocking
+system calls.
+If use of blocking system calls is required (not including APIs provided
+by the NNG library itself of course), then real OS-specific threads
+should be created instead (such as with pthread_create() or similar
+functions.)
+ |
+
| + + | ++Thread objects created by this function cannot be passed +to any system threading functions. + | +
| + + | +
+The system may impose limits on the number of threads that can be
+created.
+Typically applications should not create more than a few dozen of these.
+If greater concurrency or scalability is needed, consider instead using
+an asynchronous model using nng_aio structures.
+ |
+
| + + | ++Threads can be synchronized using +mutexes and +condition variables. + | +
This function returns 0 on success, and non-zero otherwise.
+NNG_ENOMEMInsufficient free memory exists.
+nng_thread_destroy - reap thread
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+void nng_thread_destroy(nng_thread *thread);
+The nng_thread_destroy() function reaps the thread.
+It waits for the thread function to return, and then deallocates
+the resources for the thread.
| + + | ++Do not call this function from the thread function itself, +or a deadlock will occur. + | +
None.
+None.
+