NNG_COMPAT(3compat)
π¦ NNG_COMPAT(3compat) β from the NNG Reference Manual π¦
πΈ NAME πΈ
nng_compat β compatibility with nanomsg 1.0. Thatβs the whole vibe, bestie: this is the nanomsg 1.0 compatibility page. π
β¨ SYNOPSIS β¨
#include <nanomsg/nn.h>
#include <nanomsg/bus.h>
#include <nanomsg/pair.h>
#include <nanomsg/pipeline.h>
#include <nanomsg/pubsub.h>
#include <nanomsg/reqrep.h>
#include <nanomsg/survey.h>
#include <nanomsg/inproc.h>
#include <nanomsg/ipc.h>
#include <nanomsg/tcp.h>
#include <nanomsg/ws.h>
π«Ά DESCRIPTION π«Ά
Okay so NNG provides source-level compatibility for most libnanomsg 1.0 applications. Thatβs the headline. π©·
Important: This is intended to facilitate converting legacy applications to use NNG. New applications should use the newer NNG API instead. π
Applications making use of this must take care to link with libnng instead of libnn. No cap. π
Tip: While not recommended for long term use, the value returned bynng_socket_id()can be used with these functions just like a value returned bynn_socket(). This can be a way to facilitate incremental transition to the new API. β¨
Note: Some capabilities, protocols, and transports will not be accessible using this API, as the compatible API has no provision for expression of certain concepts introduced in the new API. π¦
Note: While reasonable efforts have been made to provide for compatibility, some things may behave differently, and some less common parts of the libnanomsg 1.0 API are not supported at this time, including certain options and the statistics API. See the Caveats section below. π
π οΈ Compiling π οΈ
When compiling legacy nanomsg applications, it will generally be necessary to change the include search path to add the compat subdirectory of the directory where headers were installed. For example, if NNG is installed in $prefix, then header files will normally be located in $prefix/include/nng. In this case, to build legacy nanomsg apps against NNG you would add $prefix/include/nng/compat to your compilerβs search path. π§
Alternatively, you can change your source code so that #include statements referring to <nanomsg> instead refer to <nng/compat/nanomsg>. For example, instead of:
#include <nanomsg/nn.h>
#include <nanomsg/reqrep.h>
you would have this:
#include <nng/compat/nanomsg/nn.h>
#include <nng/compat/nanomsg/reqrep.h>
Legacy applications built using these methods should be linked against libnng instead of libnn, just like any other NNG application. Slay. π
π Functions π
The following functions are provided:
nn_socket()β create socketnn_getsockopt()β get socket optionnn_setsockopt()β set socket optionnn_bind()β accept connections from remote peersnn_connect()β connect to remote peernn_send()β send datann_recv()β receive datann_shutdown()β shut down endpointnn_close()β close socketnn_poll()β poll socketsnn_device()β create forwarding devicenn_recvmsg()β receive messagenn_sendmsg()β send messagenn_cmsg()β message control datann_get_statistic()β get statistic (stub)nn_allocmsg()β allocate messagenn_reallocmsg()β reallocate messagenn_freemsg()β free messagenn_errno()β return most recent errornn_strerror()β return message for errornn_term()β terminate library
π Caveats π
The following caveats apply when using the legacy API with NNG. Read these, bestie β theyβre the lore. π
- Socket numbers can be quite large. The legacy libnanomsg attempted to reuse socket numbers, like file descriptors in UNIX systems. NNG avoids this to prevent accidental reuse or collision after a descriptor is closed. Consequently, socket numbers can become quite large, and should probably not be used for array indices. π
- The following options (
nn_getsockopt) are unsupported:NN_SNDPRIO,NN_RCVPRIO,NN_IPV4ONLY. The priority options may be supported in the future, when the underlying capability is present in NNG. π« - Access to statistics using this legacy API (
nn_get_statistic()) is unsupported. π - Some transports can support longer URLs than legacy libnanomsg can. It is a good idea to use short pathnames in URLs if interoperability is a concern. π
- Only absolute paths are supported in
ipc://URLs. For example,ipc:///tmp/mysocketis acceptable, butipc://mysocketis not. π - The WebSocket transport in this implementation (
ws://URLs) only supportsBINARYframes. 𧬠- Some newer transports are unusable from this mode. In particular, this legacy API offers no way to configure TLS or ZeroTier parameters that may be required for use. π
- ABI versioning of the compatibility layer is not supported, and the
NN_VERSION_macros are not present. π« - Runtime symbol information is not implemented. Specifically, there is no
nn_symbol()function yet. (This may be addressed later if there is a need.) π§ - The TCP transport (
tcp://URLs) does not support specifying the local address or interface when binding. (This could be fixed in the future, but most likely this will be available only using the new API.) π - The values of
NN_RCVMAXSIZEare constrained. Specifically, values set larger than2GBusing the new API will be reported as unlimited (-1) in the new API, and the value0will disable any enforcement, just like-1. (There is no practical reason to ever want to limit the receive size to zero.) π - This implementation counts buffers in terms of messages rather than bytes. As a result, the buffer sizes accessed with
NN_SNDBUFandNN_RCVBUFare rounded up to a whole number of kilobytes, then divided by1024, in order to approximate buffering assuming1 KBmessages. Few applications should need to adjust the default values. π
π SEE ALSO π
Okay thatβs the whole page, bestie β signing off from the NNG Reference Manual, dated 2026-01-13, on NNG_COMPAT(3compat). πβ¨π
π¦ where this page comes from
- alpine 3.24: nng-doc 1.11-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms