This section documents supplemental TCP functions that are available.
+
+
+
These functions are made available to facilitate using raw TCP connections
+with the NNG asynchronous I/O API.
+Most applications should never need to use these functions.
@@ -879,7 +880,7 @@ mode may need to access the header of messages.
Asynchronous Operations
Most applications will interact with nng synchronously; that is that
-functions such as nng_send() will block the calling
+functions such as nng_send() will block the calling
thread until the operation has completed.
@@ -905,7 +906,7 @@ of whether this was successful or not), then a user supplied function
(“callback”) is executed.
-
A context structure, an nng_aio, is allocated and
+
A context structure, an nng_aio, is allocated and
associated with each asynchronous operation.
Only a single asynchronous operation may be associated with an
nng_aio at any time.
@@ -1409,6 +1410,98 @@ Most applications won’t need to use these.
+
Supplemental IPC
+
+
These IPC functions are available for use with direct interprocess
+communication (IPC).
+Most applications won’t need to use these.
diff --git a/man/tip/nng.7.html b/man/tip/nng.7.html
index 42d014c0..5a1e763e 100644
--- a/man/tip/nng.7.html
+++ b/man/tip/nng.7.html
@@ -798,7 +798,7 @@ This is possible using “raw” mode sockets.
Raw mode sockets are generally constructed with a different function,
-such as nng_req0_open_raw().
+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
@@ -811,7 +811,7 @@ headers on incoming messages, and supply them on outgoing messages.
-The nng_device() function only works with raw mode
+The nng_device() function only works with raw mode
sockets, but as it only forwards the messages, no additional application
processing is needed.
(int)
-This write-only option may be applied to a listener to configure the
-permissions that are used on the UNIX domain socket created by that listener.
-This property is only supported on POSIX systems.
-The value is of type int, representing the normal permission bits
-on a file, such as 0600 (typically meaning read-write to the owner, and
-no permissions for anyone else.)
-The default is system-specific, most often 0644.
-
-
-
-
-
-
-
-
-
-
-Not all systems validate these permissions.
-In particular, illumos and Solaris are known to ignore these permission
-settings when connecting.
-
-
-
-
-
-
-
-
-
-
-
-Normally both read and write permission will be necessary for a
-peer dialer to connect.
-See your system documentation for UNIX domain sockets for more information.
-
-
-
-
-
-
-
-
-
-
-
-The umask of the process is not applied to these bits.
-
-
-
-
-
-
-
-
-
-
-
-The best practice for limiting access is to place the socket in a
-directory writable only by the server, and only readable and searchable
-by clients.
-All mainstream POSIX systems will fail to permit a client to connect
-to a socket located in a directory for which the client lacks search (execute)
-permission.
-
-
-
-
-
-
-
-
-
-
-
-Also consider using the NNG_OPT_IPC_PEER_UID property from within a
-a pipe notification callback (nng_pipe_notify())
-to validate peer credentials.
-
-
-
-
-
-
-
NNG_OPT_IPC_SECURITY_DESCRIPTOR
-
-
(PSECURITY_DESCRIPTOR)
-This write-only option may be used on listeners on Windows platforms to
-configure the SECURITY_DESCRIPTOR that is used when creating the underlying
-named pipe.
-The value is a pointer, PSECURITY_DESCRIPTOR, and may only be
-applied to listeners that have not been started yet.
-
-
NNG_OPT_IPC_PEER_UID
-
-
(uint64_t)
-This read-only option may be read from a pipe to determine the peer user id.
-This is the effective user id of the peer when either the underlying
-listen() or connect() calls were made, and is not forgeable.
-This option is generally only available on POSIX systems.
-
-
NNG_OPT_IPC_PEER_GID
-
-
(uint64_t)
-This read-only option may be read from a pipe to determine the peer primary
-group id.
-This is the effective group id of the peer when either the underlying
-listen() or connect() calls were made, and is not forgeable.
-This option is generally only available on POSIX systems.
-
-
NNG_OPT_IPC_PEER_PID
-
-
(uint64_t)
-This read-only option may be read from a pipe to determine the process id
-of the peer.
-This option is only available on Windows, Linux, and certain other systems.
-
-
-
-
-
-
-
-
-
-
-Applications should not assume that the process ID does not change,
-as it is possible (although unsupported!) for a nefarious process to pass a
-file descriptor between processes.
-However, it is not possible for a nefarious application to forge the identity
-of a well-behaved one using this method.
-
-
-
+
+
The following transport options are supported by this transport,
+where supported by the underlying platform.
-
-
-
NNG_OPT_IPC_PEER_ZONEID
-
-
(uint64_t)
-This read-only option may be read from a pipe to determine the zone id
-of the peer.
-Zones (and this option) are only supported on Solaris and illumos systems.
The nng_ipc_close() function closes the supplied IPC connection, conn.
+
+
+
If any operations are pending (such as nng_ipc_send()
+or nng_ipc_recv()) they will be terminated with
+an NNG_ECLOSED error condition.
+Also, any new operations will fail with NNG_ECLOSED after the connection
+is closed.
+
+
+
+
+
+
+
+
+Closing the connection while data is in transmission will likely
+lead to loss of that data.
+There is no automatic linger or flush to ensure that the socket send buffers
+have completely transmitted.
+
+
+
+
+
+
+
+
+
+
+
+Closing the connection does not free the resources associated with it.
+Once it is certain that no more operations are pending on the connection,
+it should be freed with nng_ipc_free().
+
+An nng_ipc_dialer is a handle to an IPC “dialer”, which is responsible for
+creating connections (nng_ipc objects) by connecting to
+remote systems.
+
+
+
+
+
+
+
+
+The nng_ipc_dialer object is used for raw IPC connections, and
+should not be confused with a dialer object created using the
+nng_ipc(7) transport.
+
+
+
+
+
+
+
+
+
+
+
+Most NNG applications should not use this, but instead use the
+nng_ipc(7) transport instead.
+
The nng_ipc_dialer_alloc() allocates an IPC dialer, which can be used
+to create outgoing connections over IPC, and stores a pointer to it
+it in the location referenced by dp.
+
+
+
+
+
RETURN VALUES
+
+
+
This function returns 0 on success, and non-zero otherwise.
The nng_ipc_dialer_close() function closes the supplied IPC dialer d,
+but does not free the underlying resources associated with it.
+
+
+
If any dial operations using d are
+in progress, they will be terminated with an NNG_ECLOSED error condition.
+
+
+
Furthermore any future accesses to the dialer d will also result in
+NNG_ECLOSED.
+
+
+
+
+
+
+
+
+This function does not release the memory for the dialer, so the
+application should still free the memory using
+nng_ipc_dialer_free(3ipc)
+once it is certain that nothing else is using it.
+
The nng_ipc_dialer_dial() attempts to establish an IPC connection to the
+remote peer identified by sa, using the dialer d.
+The operation is completed asynchronously, using aio.
+
+
+
The address sa must be in the NNG_AF_IPC family,
+and have a valid path for IPC.
+
+
+
If a connection is successfully established, the aio will have the
+resulting nng_ipc stored as its first output.
+(See nng_aio_get_output().)
The nng_ipc_dialer_getopt() is used to retrieve the value of the option name for the IPC dialerd.
+The size of the buffer located at data to receive the copy is passed by the
+caller at the location referenced by sizep.
+If this size is sufficient to hold the entire object, the object is copied into
+the buffer specified by data.
+In either event, the size of the source object (the amount of data copied,
+or that would have been copied if sufficient space were available) is stored
+at the location of sizep.
+
+
+
Options
+
+
There are no predefined options for IPC dialers at this time.
+
+
+
+
+
+
RETURN VALUES
+
+
+
This function returns 0 on success, and non-zero otherwise.
+
+
+
+
+
ERRORS
+
+
+
+
+
+NNG_ECLOSED
+
+
+
The dialer is closed.
+
+
+
+
+NNG_EINVAL
+
+
+
There was insufficient space to receive the object.
+The amount of data actually needed is returned in sizep.
The nng_ipc_dialer_setopt() is used to set the option name for the
+IPC dialerd.
+The value to set is copied from data, which should be size bytes
+in length.
+
+
+
Options
+
+
There are no predefined options for IPC dialers at this time.
+
+
+
+
+
+
RETURN VALUES
+
+
+
This function returns 0 on success, and non-zero otherwise.
The nng_ipc_free() function closes the supplied IPC connection, conn,
+and frees the underlying resources associated with it.
+
+
+
If any operations are pending (such as nng_ipc_send()
+or nng_ipc_recv()) they will be terminated with
+an NNG_ECLOSED error condition.
+
+
+
+
+
+
+
+
+It is important that the application ensure that no further accesses
+are made to conn, as the memory backing it will be reclaimed for other uses.
+
+
+
+
+
+
+
+
+
+
+
+Closing the connection while data is in transmission will likely
+lead to loss of that data.
+There is no automatic linger or flush to ensure that the socket send buffers
+have completely transmitted.
+
The nng_ipc_getopt() is used to retrieve the value of the option name for
+the IPC connectionconn.
+The size of the buffer located at data to receive the copy is passed by the
+caller at the location referenced by sizep.
+If this size is sufficient to hold the entire object, the object is copied into
+the buffer specified by data.
+In either event, the size of the source object (the amount of data copied,
+or that would have been copied if sufficient space were available) is stored
+at the location of sizep.
+
+
+
Options
+
+
The options specifically suppported for retrieval from IPC connections are:
+An nng_ipc_listener is a handle to an IPC “listener”, which is responsible
+for accepting connections (nng_ipc objects) from remote
+systems.
+
+
+
+
+
+
+
+
+The nng_ipc_listener object is used for raw IPC connections, and
+should not be confused with a listener object created using the
+nng_ipc(7) transport.
+
+
+
+
+
+
+
+
+
+
+
+Most NNG applications should not use this, but instead use the
+nng_ipc(7) transport instead.
+
The nng_ipc_listener_accept() attempts to accept an incoming IPC connection
+from a remote peer, using the listener l.
+The operation is completed asynchronously, using aio.
+
+
+
This operation can only be done after the listener is already bound to
+an IPC path and is listening.
+
+
+
If a connection is successfully established, the aio will have the
+resulting nng_ipc stored as its first output.
+(See nng_aio_get_output().)
The nng_ipc_listener_alloc() allocates an IPC listener, which can be used
+to accept incoming connections over IPC, and stores a pointer to it
+it in the location referenced by lp.
+
+
+
+
+
RETURN VALUES
+
+
+
This function returns 0 on success, and non-zero otherwise.
The nng_ipc_listener_close() function closes the supplied IPC listener l,
+but does not free the underlying resources associated with it.
+
+
+
If any accept operations using l
+are in progress, they will be terminated with an NNG_ECLOSED error condition.
+
+
+
Furthermore any future accesses to the listener l will also result in
+NNG_ECLOSED.
+
+
+
+
+
+
+
+
+This function does not release the memory for the listener, so the
+application should still free the memory using
+nng_ipc_listener_free()
+once it is certain that nothing else is using it.
+
The nng_ipc_listener_getopt() is used to retrieve the value of the option name for the IPC listenerl.
+The size of the buffer located at data to receive the copy is passed by the
+caller at the location referenced by sizep.
+If this size is sufficient to hold the entire object, the object is copied into
+the buffer specified by data.
+In either event, the size of the source object (the amount of data copied,
+or that would have been copied if sufficient space were available) is stored
+at the location of sizep.
+
+
+
Options
+
+
The only option specifically suppported for retrieval from IPC listeners is:
The nng_ipc_listener_listen() attempts to bind the listener l
+to the local address specified by sa, which must be in the
+NNG_AF_IPC address family and must have a valid IPC path.
+
+
+
+
+
RETURN VALUES
+
+
+
This function returns 0 on success, and non-zero otherwise.
+
+
+
+
+
ERRORS
+
+
+
+
+
+NNG_EADDRINUSE
+
+
+
The address specified by sa is already in use.
+
+
+
+
+NNG_EADDRINVAL
+
+
+
The address specified by sa is invalid or unavailable.
+
+
+
+
+NNG_ECLOSED
+
+
+
The listener l has been closed.
+
+
+
+
+NNG_EPERM
+
+
+
Insufficient permission to create the specified IPC path.
The nng_ipc_listener_setopt() is used to set the option name for the
+IPC listenerl.
+The value to set is copied from data, which should be size bytes
+in length.
+
+
+
Options
+
+
The options specifically suppported for modification on IPC listeners are:
This page documents the various standard options that can be set or
+retrieved on objects using IPC in the nng library.
+
+
+
The option names should always be used by their symbolic definitions.
+
+
+
In the following list of options, the name of the option is supplied,
+along with the data type of the underlying value.
+
+
+
Some options are only meaningful or supported in certain contexts, or may
+have other access restrictions.
+An attempt has been made to include details about such restrictions in the
+description of the option.
+
+
+
+
+
+
+
+
+The availability of any of the following options is platform-specific,
+as the implementations of IPC are quite different on Windows and POSIX systems.
+
+
+
+
+
+
IPC Options
+
+
+
NNG_OPT_IPC_PEER_GID
+
+
(uint64_t)
+This read-only option provides a connected peer’s primary
+group id.
+This is the effective group id of the peer when either the underlying
+listen() or connect() calls were made, and is not forgeable.
+This option is generally only available on POSIX systems.
+
+
NNG_OPT_IPC_PEER_PID
+
+
(uint64_t)
+This read-only option provides the the process id
+of the connected peer.
+This option is only available on Windows, Linux, and certain other systems.
+
+
+
+
+
+
+
+Applications should not assume that the process ID does not change,
+as it is possible (although unsupported!) for a nefarious process to pass a
+file descriptor between processes.
+However, it is not possible for a nefarious application to forge the identity
+of a well-behaved one using this method.
+
+
+
+
+
+
NNG_OPT_IPC_PEER_UID
+
+
(uint64_t)
+This read-only option provides a connected peer’s user id.
+This is the effective user id of the peer when either the underlying
+listen() or connect() calls were made, and is not forgeable.
+This option is generally only available on POSIX systems.
+
+
NNG_OPT_IPC_PEER_ZONEID
+
+
(uint64_t)
+This read-only option provides a connected peer’s the zone id.
+Zones (and this option) are only supported on Solaris and illumos systems.
+
+
NNG_OPT_IPC_PERMISSIONS
+
+
(int)
+This write-only option may be applied to a listener to configure the
+permissions that are used on the UNIX domain socket created by that listener.
+This property is only supported on POSIX systems.
+The value is of type int, representing the normal permission bits
+on a file, such as 0600 (typically meaning read-write to the owner, and
+no permissions for anyone else.)
+The default is system-specific, most often 0644.
+
+
+
+
+
+
+
+Not all systems validate these permissions.
+In particular, illumos and Solaris are known to ignore these permission
+settings when connecting.
+
+
+
+
+
+
+
+
+
+
+
+Normally both read and write permission will be necessary for a
+peer dialer to connect.
+See your system documentation for UNIX domain sockets for more information.
+
+
+
+
+
+
+
+
+
+
+
+The umask of the process is not applied to these bits.
+
+
+
+
+
+
+
+
+
+
+
+The best practice for limiting access is to place the socket in a
+directory writable only by the server, and only readable and searchable
+by clients.
+All mainstream POSIX systems will fail to permit a client to connect
+to a socket located in a directory for which the client lacks search (execute)
+permission.
+
+
+
+
+
+
NNG_OPT_IPC_SECURITY_DESCRIPTOR
+
+
(PSECURITY_DESCRIPTOR)
+This write-only option may be used on listeners on Windows platforms to
+configure the SECURITY_DESCRIPTOR that is used when creating the underlying
+named pipe.
+The value is a pointer, PSECURITY_DESCRIPTOR, and may only be
+applied to listeners that have not been started yet.
+
+
+
+
+
+
Inherited Options
+
+
Generally, the following option values are also available for TLS objects,
+when appropriate for the context:
The nng_ipc_recv() function starts an asynchronous receive from the
+IPC connection conn, into the scatter/gather vector located in the
+asynchronous I/O structure aio.
+
+
+
+
+
+
+
+
+The nng_aio_set_iov() function must have been
+called first, to set the scatter/gather vector for aio.
+
+
+
+
+
+
This function returns immediately, with no return value.
+Completion of the operation is signaled via the aio,
+and the final result may be obtained via
+nng_aio_result().
+That result will either be zero or an error code.
+
+
+
The I/O operation completes as soon as at least one byte has been
+received, or an error has occurred.
+Therefore, the number of bytes read may be less than requested.
+The actual number of bytes read can be determined with
+nng_aio_count().
+
+
+
+
+
RETURN VALUES
+
+
+
None.
+
+
+
+
+
ERRORS
+
+
+
+
+
+NNG_ECANCELED
+
+
+
The operation was canceled.
+
+
+
+
+NNG_ECLOSED
+
+
+
The connection was closed.
+
+
+
+
+NNG_ECONNRESET
+
+
+
The peer closed the connection.
+
+
+
+
+NNG_EINVAL
+
+
+
The aio does not contain a valid scatter/gather vector.
+
+
+
+
+NNG_ENOMEM
+
+
+
Insufficient free memory to perform the operation.
The nng_ipc_send() function starts an asynchronous send over the
+IPC connection conn from the scatter/gather vector located in the
+asynchronous I/O structure aio.
+
+
+
+
+
+
+
+
+The nng_aio_set_iov() function must have been
+called first, to set the scatter/gather vector for aio.
+
+
+
+
+
+
This function returns immediately, with no return value.
+Completion of the operation is signaled via the aio, and the final
+result may be obtained via nng_aio_result().
+That result will either be zero or an error code.
+
+
+
The I/O operation completes as soon as at least one byte has been
+sent, or an error has occurred.
+Therefore, the number of bytes sent may be less than requested.
+The actual number of bytes sent can be determined with
+nng_aio_count().
+
+
+
+
+
RETURN VALUES
+
+
+
None.
+
+
+
+
+
ERRORS
+
+
+
+
+
+NNG_ECANCELED
+
+
+
The operation was canceled.
+
+
+
+
+NNG_ECLOSED
+
+
+
The connection was closed.
+
+
+
+
+NNG_ECONNRESET
+
+
+
The peer closed the connection.
+
+
+
+
+NNG_EINVAL
+
+
+
The aio does not contain a valid scatter/gather vector.
+
+
+
+
+NNG_ENOMEM
+
+
+
Insufficient free memory to perform the operation.
The nng_ipc_setopt() is used to set the option name for the
+IPC connectionconn.
+The value to set is copied from data, which should be size bytes
+in length.
+
+
+
Options
+
+
There are no options defined for modification on IPC connections at this time.
+
+
+
+
+
+
RETURN VALUES
+
+
+
This function returns 0 on success, and non-zero otherwise.
This page documents the various standard options that can be set or
+retrieved on objects using TCP in the nng library.
+
+
+
The option names should always be used by their symbolic definitions.
+
+
+
In the following list of options, the name of the option is supplied,
+along with the data type of the underlying value.
+
+
+
Some options are only meaningful or supported in certain contexts, or may
+have other access restrictions.
+An attempt has been made to include details about such restrictions in the
+description of the option.
+
+
+
The following options are generally application to objects making use of
+TCP/IP communications.
+
+
+
TCP Options
+
+
+
NNG_OPT_TCP_NODELAY
+
+
(bool)
+This option is used to disable (or enable) the use of Nagle’s algorithm
+for TCP connections.
+
+
+
+
+
+
+
+This setting may apply to transports that are built on top of TCP.
+See the transport documentation for each transport for details.
+
+
+
+
+
+
When true (the default), messages are sent immediately by the underlying
+TCP stream without waiting to gather more data.
+
+
+
When false, Nagle’s algorithm is enabled, and the TCP stream may
+wait briefly in attempt to coalesce messages.
+Nagle’s algorithm is useful on low-bandwidth connections to reduce overhead,
+but it comes at a cost to latency.
+
+
+
When used on a dialer or a listener, the value affects how newly
+created connections will be configured.
+
+
+
+
+
+
+
NNG_OPT_TCP_KEEPALIVE
+
+
(bool)
+This option is used to enable the sending of keep-alive messages on
+the underlying TCP stream.
+This option is false by default.
+
+
+
+
+
+
+
+This setting may apply to transports that are built on top of TCP.
+See the transport documentation for each transport for details.
+
+
+
+
+
+
When enabled, if no messages are seen for a period of time, then
+a zero length TCP message is sent with the ACK flag set in an attempt
+to tickle some traffic from the peer.
+If none is still seen (after some platform-specific number of retries and
+timeouts), then the remote peer is presumed dead, and the connection is closed.
+
+
+
When used on a dialer or a listener, the value affects how newly
+created connections will be configured.
+
+
+
+
+
+
+
+
+This option has two purposes.
+First, it can be used to detect dead peers on an otherwise quiescent network.
+Second, it can be used to keep connection table entries in NAT and other
+middleware from being expiring due to lack of activity.
+
+
+
+
+
+
+
+
+
+
Inherited Options
+
+
Generally, the following option values are also available for TCP objects,
+when appropriate for the context: