Miscellaneous
This chapter discusses some interfaces that don’t really fit anywhere else.
Get Random Number
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, and is obtained using platform-specific cryptographically strong random
number facilities when available.
Create Socket Pair
int nng_socket_pair(int fds[2]);
The nng_socket_pair
function creates a pair of connected file descriptors.
These file descriptors, which are returned in the fds array, are suitable for
use with the Socket transport.
On POSIX platforms, this is a thin wrapper around the standard socketpair
function,
using the AF_UNIX
family and the SOCK_STREAM
socket type.
1
This will return zero on success, or an error number. On platforms that lack this
capability, such as Windows, it will return NNG_ENOTSUP
.
tip
This function may be useful for creating a shared connection between a parent process and a child process on UNIX platforms, without requiring the processes use a shared filesystem or TCP connection.
Report Library Version
const char * nng_version(void);
The nng_version
function returns a human readable version number
for NNG, formatted as a NUL
-terminated string.
Additionally, compile time version information is available via some predefined macros:
NNG_MAJOR_VERSION
: Major version number.NNG_MINOR_VERSION
: Minor version number.NNG_PATCH_VERSION
: Patch version number.
NNG is developed and released using Semantic Versioning 2.0, and the version numbers reported refer to both the API and the library itself. (The ABI – application binary interface – between the library and the application is controlled in a similar, but different manner depending upon the link options and how the library is built.)
1: At present only POSIX platforms implementing socketpair
support this function.