From edd3b6bc34f211bd3d58642d0c69ce1b5bb9dc3b Mon Sep 17 00:00:00 2001
From: gdamore
Replace -lnanomsg with -lnng.
It may be necessary to include additional system libraries, such as -lpthread, depending on your system.
It is necessary to explicitly initialize the library, using the nng_init function.
+
It is necessary to explicitly initialize the library, using the nng_init function.
This must be called before any other function.
Sockets, dialers, and listeners in libnanomsg are simple integers. @@ -265,87 +265,87 @@ headers.
NNG approach to messages. Likewise there is nostruct nn_cmsghdr equivalent.
| Nanomsg API | NNG Equivalent | Notes |
|---|---|---|
nn_strerror | nng_strerror | |
nn_strerror | nng_strerror | |
nn_errno | None | Errors are returned directly rather than through errno. |
nn_socket | Various | Use the appropriate protocol constructor, such as nng_req0_open. |
nn_close | nng_socket_close | |
nn_bind | nng_listen, nng_listener_create | Allocating a listener with nng_lister_create and configuring it offers more capabilities. |
nn_connect | nng_dial, nng_dialer_create | Allocating a dialer with nng_dialer_create and configuring it offers more capabilities. |
nn_shutdown | nng_listener_close, nng_dialer_close | |
nn_allocmsg | nng_msg_alloc | There are significant semantic differences. |
nn_freemsg | nng_msg_free | |
nn_reallocmsg | nng_msg_realloc | |
nn_send | nng_send | |
nn_recv | nng_recv | |
nn_sendmsg | nng_sendmsg | |
nn_getsockopt | nng_socket_get | NNG has typed accessors for options, and also separate functions for dialers and listeners. |
nn_setsockopt | nng_socket_set | |
nn_device | nng_device | |
nn_close | nng_socket_close | |
nn_bind | nng_listen, nng_listener_create | Allocating a listener with nng_lister_create and configuring it offers more capabilities. |
nn_connect | nng_dial, nng_dialer_create | Allocating a dialer with nng_dialer_create and configuring it offers more capabilities. |
nn_shutdown | nng_listener_close, nng_dialer_close | |
nn_allocmsg | nng_msg_alloc | There are significant semantic differences. |
nn_freemsg | nng_msg_free | |
nn_reallocmsg | nng_msg_realloc | |
nn_send | nng_send | |
nn_recv | nng_recv | |
nn_sendmsg | nng_sendmsg | |
nn_getsockopt | nng_socket_get | NNG has typed accessors for options, and also separate functions for dialers and listeners. |
nn_setsockopt | nng_socket_set | |
nn_device | nng_device | |
nn_poll | None | Can be constructed using nng_aio. Few if any applications ever used this API. |
nn_term | nng_fini | The nng_fini API can do this, but is not recommended except when debugging memory leaks. |
nn_get_statistic | nng_stats_get | The statistics in NNG are completely different, with different semantics and no stability guarantees. |
nn_term | nng_fini | The nng_fini API can do this, but is not recommended except when debugging memory leaks. |
nn_get_statistic | nng_stats_get | The statistics in NNG are completely different, with different semantics and no stability guarantees. |
NN_POLLIN | None | Used only with nn_poll. |
NN_POLLOUT | None | Used only with nn_poll. |
NN_MSG | nng_sendmsg, nng_recvmsg | There are differences as a separate nng_msg structure is involved. |
NN_MSG | nng_sendmsg, nng_recvmsg | There are differences as a separate nng_msg structure is involved. |
NN_CMSG_ALIGN | None | |
NN_CMSG_FIRSTHDR | None | |
NN_CMSG_NXTHDR | None | |
NN_CMSG_DATA | None | |
NN_CMSG_LEN | None | |
NN_CMSG_SPACE | None | |
struct nn_iovec | nng_iov | |
struct nn_msghdr | nng_msg | |
struct nn_cmsghdr | nng_msg and nng_msg_header | |
struct nn_iovec | nng_iov | |
struct nn_msghdr | nng_msg | |
struct nn_cmsghdr | nng_msg and nng_msg_header |
The following options are changed.
| Nanomsg Option | NNG Eqvaivalent | Notes |
|---|---|---|
NN_LINGER | None | NNG does not support tuning this. |
NN_SNDBUF | NNG_OPT_SENDBUF | NNG value is given in messages, not bytes. |
NN_RCVBUF | NNG_OPT_RECVBUF | NNG value is given in messages, not bytes. |
NN_SNDTIMEO | NNG_OPT_SENDTIMEO | |
NN_RCVTIMEO | NNG_OPT_RECVTIMEO | |
NN_RECONNECT_IVL | NNG_OPT_RECONNMINT | |
NN_RECONNECT_IVL_MAX | NNG_OPT_RECONNMAXT | |
NN_SNDBUF | NNG_OPT_SENDBUF | NNG value is given in messages, not bytes. |
NN_RCVBUF | NNG_OPT_RECVBUF | NNG value is given in messages, not bytes. |
NN_SNDTIMEO | NNG_OPT_SENDTIMEO | |
NN_RCVTIMEO | NNG_OPT_RECVTIMEO | |
NN_RECONNECT_IVL | NNG_OPT_RECONNMINT | |
NN_RECONNECT_IVL_MAX | NNG_OPT_RECONNMAXT | |
NN_SNDPRIO | None | Not supported in NNG yet. |
NN_RCVPRIO | None | Not supported in NNG yet. |
NN_RCVFD | nng_socket_get_recv_poll_fd | No longer an option, use a function call. |
NN_SNDFD | nng_socket_get_send_poll_fd | No longer an option, use a function call. |
NN_RCVFD | nng_socket_get_recv_poll_fd | No longer an option, use a function call. |
NN_SNDFD | nng_socket_get_send_poll_fd | No longer an option, use a function call. |
NN_DOMAIN | None | NNG options are not divided by domain or protocol. |
NN_PROTOCOL | nng_socket_proto_id | No longer an option. See also nng_socket_proto_name. |
NN_PROTOCOL | nng_socket_proto_id | No longer an option. See also nng_socket_proto_name. |
NN_IPV4ONLY | None | Use URL such as tcp4:// to obtain this functionality. |
NN_SOCKET_NAME | None | Removed from NNG. |
NN_MAXTTL | NNG_OPT_MAXTTL | |
NN_SUB_SUBSCRIBE | nng_sub0_socket_subscribe | No longer an option, use a function call. |
NN_SUB_UNSUBSCRIBE | nng_sub0_socket_unsubscribe | No longer an option, use a function call. |
NN_MAXTTL | NNG_OPT_MAXTTL | |
NN_SUB_SUBSCRIBE | nng_sub0_socket_subscribe | No longer an option, use a function call. |
NN_SUB_UNSUBSCRIBE | nng_sub0_socket_unsubscribe | No longer an option, use a function call. |
Most of the error codes have similar names in NNG, just prefixed with NNG_.
There are some exceptions. Be aware that the numeric values are not the same.
| Nanomsg Error | NNG Error | Notes |
|---|---|---|
EINTR | NNG_EINTR | |
ENOMEM | NNG_ENOMEM | |
EINVAL | NNG_EINVAL, NNG_EADDRINVAL, NNG_EBADTYPE | NNG discrimates between different types of errors. |
EBUSY | NNG_EBUSY | |
ETIMEDOUT | NNG_ETIMEDOUT | |
ECONNREFUSED | NNG_ECONNREFUSED | |
EBADF | NNG_ECLOSED, NNG_ECANCELED | Canceling an operation returns differently than using an invalid or closed object. |
EAGAIN | NNG_EAGAIN | |
ENOTSUP | NNG_ENOTSUP | |
EADDRINUSE | NNG_EADDRINUSE | |
EFSM | NNG_ESTATE | Not a legal POSIX errno value. |
ENOENT | NNG_ENOENT | |
EPROTO | NNG_EPROTO | |
EHOSTUNREACH | NNG_EUNREACHABLE | |
EACCCES | NNG_EPERM, NNG_EWRITEONLY, NNG_EREADONLY, NNG_ECRYPTO, NNG_EPEERAUTH | NNG has more fine grained reasons for access failures. |
EMSGSIZE | NNG_EMSGSIZE | |
ECONNABORTED | NNG_ECONNABORTED | |
ECONNRESET | NNG_ECONNRESET | |
EEXIST | NNG_EEXIST | |
EMFILE | NNG_ENOFILES | |
ENOSPC | NNG_ENOSPC | |
EINTR | NNG_EINTR | |
ENOMEM | NNG_ENOMEM | |
EINVAL | NNG_EINVAL, NNG_EADDRINVAL, NNG_EBADTYPE | NNG discrimates between different types of errors. |
EBUSY | NNG_EBUSY | |
ETIMEDOUT | NNG_ETIMEDOUT | |
ECONNREFUSED | NNG_ECONNREFUSED | |
EBADF | NNG_ECLOSED, NNG_ECANCELED | Canceling an operation returns differently than using an invalid or closed object. |
EAGAIN | NNG_EAGAIN | |
ENOTSUP | NNG_ENOTSUP | |
EADDRINUSE | NNG_EADDRINUSE | |
EFSM | NNG_ESTATE | Not a legal POSIX errno value. |
ENOENT | NNG_ENOENT | |
EPROTO | NNG_EPROTO | |
EHOSTUNREACH | NNG_EUNREACHABLE | |
EACCCES | NNG_EPERM, NNG_EWRITEONLY, NNG_EREADONLY, NNG_ECRYPTO, NNG_EPEERAUTH | NNG has more fine grained reasons for access failures. |
EMSGSIZE | NNG_EMSGSIZE | |
ECONNABORTED | NNG_ECONNABORTED | |
ECONNRESET | NNG_ECONNRESET | |
EEXIST | NNG_EEXIST | |
EMFILE | NNG_ENOFILES | |
ENOSPC | NNG_ENOSPC |
It is now required for applications to initialize the library explicitly before using it.
-This is done using the nng_init function.
nng_init function.
The following header files are removed, and the declarations they provided are now provided by including <nng/nng.h>.
Simply remove any references to them.
The following functions have been renamed as described by the following table.
The old names are available by defining the macro NNG1_TRANSITION in your compilation environment.
| Old Name | New Name |
|---|---|
nng_close | nng_socket_close |
nng_recv_aio | nng_socket_recv |
nng_send_aio | nng_socket_send |
nng_close | nng_socket_close |
nng_recv_aio | nng_socket_recv |
nng_send_aio | nng_socket_send |
NNG1_TRANSITION i
Just add either 0 or 1 (in the case of PAIRv1) to get the protocol desired. (Forcing the version number to
be supplied should avoid surprises later as new versions of protocols are added.)
The NNG_FLAG_ALLOC flag that allowed a zero copy semantic with nng_send and nng_recv is removed.
+
The NNG_FLAG_ALLOC flag that allowed a zero copy semantic with nng_send and nng_recv is removed.
This was implemented mostly to aid legacy nanomsg applications, and it was both error prone and still a bit
suboptimal in terms of performance.
Modern code should use one of nng_sendmsg, nng_recvmsg, nng_socket_send, or nng_socket_recv to get the maximum performance benefit.
-Working directly with nng_msg structures gives more control, reduces copies, and reduces allocation activity.
Modern code should use one of nng_sendmsg, nng_recvmsg, nng_socket_send, or nng_socket_recv to get the maximum performance benefit.
+Working directly with nng_msg structures gives more control, reduces copies, and reduces allocation activity.
When an operation fails with NNG_ESTOPPED, it means that the associated [nni_aio] object has
+
When an operation fails with The API used for providers for asynchronous I/O operations has changed slightly.NNG_ESTOPPED, it means that the associated [nni_aio] object has
been permanently stopped and must not be reused. Applications must watch for this error code, and
not resubmit an operation that returns it. This is particularly important for callbacks that automatically
resubmit operations. Failure to observe this rule will lead to an infinite loop
@@ -331,9 +331,9 @@ as any further operations on the object will fail immediately with NNG_EST
AIO Provider API changes
-
nng_aio_begin function is removed. However a new nng_aio_reset function should be called
+nng_aio_begin function is removed. However a new nng_aio_reset function should be called
instead, before performing any other operations on an aio object. (This simply clears certain fields.)nng_aio_defer function is replaced, with a very nng_aio_start function. However, this function
+nng_aio_defer function is replaced, with a very nng_aio_start function. However, this function
has slightly different semantics. It will automatically call the callback if the operation cannot be
scheduled.NNG_ESTOPPED error code, for operations on a handle that is being torn down by
@@ -359,10 +359,10 @@ can be simply removed from your application:
NNG_OPT_TLS_SERVER_NAME, and similar has been removed.
Instead configuration must be performed by allocating
a nng_tls_config object, and then setting fields on it using the appropriate functions,
-after which it may be configured on a listener or dialer using the nng_listener_set_tls
-or nng_dialer_set_tls functions.
Likewise, when using the streams API, use the nng_stream_listener_set_tls or
-nng_stream_dialer_set_tls functions.
nng_listener_set_tls
+or nng_dialer_set_tls functions.
+Likewise, when using the streams API, use the nng_stream_listener_set_tls or
+nng_stream_dialer_set_tls functions.
Note that the declarations needed for TLS configuration are now available in <nng/nng.h>,
rather than the supplemental header.
NNG_TLS_1_0 and NNG_TLS_1_1 constants are
Applications should use NNG_TLS_1_2 or even NNG_TLS_1_3 instead.
The ability to configure multiple keys and certificates for a given TLS configuration object is removed.
-(The nng_tls_config_own_cert will return NNG_EBUSY if it has already been called for the configuration.)
+(The nng_tls_config_own_cert will return NNG_EBUSY if it has already been called for the configuration.)
The intended purpose was to support alternative cryptographic algorithms, but this is not necessary, was never
used, and was error prone.
NNG_OPT_LOCADDR on the dialer.
The types of NNG_OPT_PEER_GID, NNG_OPT_PEER_PID, NNG_OPT_PEER_UID, and NNG_OPT_PEER_ZONEID
+
The types of NNG_OPT_PEER_GID, NNG_OPT_PEER_PID, NNG_OPT_PEER_UID, and NNG_OPT_PEER_ZONEID
have changed from uint64_t to int. The underlying platforms all use 32-bit quantities for these.
The previously deprecated nng_pipe_getopt_xxx family of functions is removed.
@@ -459,7 +459,7 @@ or dialer that creates the stream instead.
A number of transport options can no longer be set on the socket. Instead these
options must be set on the endpoint (dialer or listener) using the appropriate
-nng_dialer_set or nng_listener_set option. This likely means that it is necessary
+nng_dialer_set or nng_listener_set option. This likely means that it is necessary
to allocate and configure the endpoint before attaching it to the socket. This will
also afford a much more fine-grained level of control over transport options.
The following options are copied from the socket when creating a dialer or listener, @@ -468,9 +468,9 @@ changes. It is recommended to set them properly on the socket before creating dialers or listeners, or set them explicitly on the dialer or listener directly:
NNG_OPT_RECONNMINTNNG_OPT_RECONNMAXTNNG_OPT_RECVMAXSZNNG_OPT_RECONNMINTNNG_OPT_RECONNMAXTNNG_OPT_RECVMAXSZThe latter option is a hint for transports and intended to facilitate early detection (and possibly avoidance of extra allocations) of oversize messages, @@ -478,22 +478,22 @@ before bringing them into the socket itself.
The NNG_OPT_PROTO, NNG_OPT_PROTONAME, NNG_OPT_PEER, and NNG_OPT_PEERNAME options
have been replaced by functions instead of options.
-Use nng_socket_proto_id, nng_socket_peer_id, nng_socket_proto_name, and nng_socket_peer_name instead.
+Use nng_socket_proto_id, nng_socket_peer_id, nng_socket_proto_name, and nng_socket_peer_name instead.
Note that the new functions provide a reference to a static string, and thus do not require
allocation, and the returned strings should not be freed. Also the IDs are provided as uint16_t,
matching the actual wire protocol values, instead of int.
The NNG_OPT_RAW option has also been replaced by a function, nng_socket_raw.
The NNG_OPT_RAW option has also been replaced by a function, nng_socket_raw.
The NNG_OPT_SENDFD and NNG_OPT_RECVFD options have been replaced by
-nng_socket_get_send_poll_fd and nng_socket_get_recv_poll_fd respectively.
nng_socket_get_send_poll_fd and nng_socket_get_recv_poll_fd respectively.
The NNG_OPT_SOCKNAME function is removed. This was provided for application use, and never used internally by NNG.
Applications should keep track of this information separately.
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.
A number of the statistics functions take, or return, const nng_stat * instead
+
A number of the statistics functions take, or return, const nng_stat * instead
of plain nng_stat *. The ABI has not changed, but it may be necessary to declare
certain methods variables const to avoid warnings about misuse of const.
* is RFC compliant.
The NNG_OPT_URL option has been removed.
-It is replaced by the type safe nng_dialer_get_url and
-nng_listener_get_url functions, which return an nng_url
+It is replaced by the type safe nng_dialer_get_url and
+nng_listener_get_url functions, which return an nng_url
structure instead of a string.
The details of nng_url have changed significantly, and direct
+
The details of nng_url have changed significantly, and direct
access of the structure is no longer permitted. Instead new
accessors functions are provided:
u_scheme is replaced by nng_url_scheme.u_port is replaced by nng_url_port, but this returns a uint16_t.u_hostname is replaced by nng_url_hostname.u_path is replaced by nng_url_path.u_query is replaced by nng_url_query.u_fragment is replaced by nng_url_fragment.u_userinfo is replaced by nng_url_userinfo.u_scheme is replaced by nng_url_scheme.u_port is replaced by nng_url_port, but this returns a uint16_t.u_hostname is replaced by nng_url_hostname.u_path is replaced by nng_url_path.u_query is replaced by nng_url_query.u_fragment is replaced by nng_url_fragment.u_userinfo is replaced by nng_url_userinfo.u_requri is removed - it can be easily formulated from the other fields.u_host is removed - use nng_url_hostname and nng_url_port to construct if neededu_rawurl is removed - a “cooked” URL can be obtained from the new nng_url_sprintf function.u_host is removed - use nng_url_hostname and nng_url_port to construct if neededu_rawurl is removed - a “cooked” URL can be obtained from the new nng_url_sprintf function.The entire HTTP API has been refactored and should be much simpler to use and more efficient. @@ -531,18 +531,18 @@ they may be silently truncated to the limit:
nng_http_handler_set_tree and matching a parent of the directory component.)nng_http_handler_set_tree and matching a parent of the directory component.)
The following API calls have changed so that they are void returns, and cannot fail.
They may silently truncate data.
nng_http_req_set_method]nng_http_res_set_status]nng_http_handler_collect_bodynng_http_handler_set_datanng_http_handler_set_hostnng_http_handler_set_methodnng_http_handler_set_treenng_http_handler_collect_bodynng_http_handler_set_datanng_http_handler_set_hostnng_http_handler_set_methodnng_http_handler_set_treeThe HTTP handler objects may not be modified once in use. Previously this would fail with NNG_EBUSY.
These checks are removed now, but debug builds will assert if an application tries to do so.
The supplemental function nng_opts_parse and supporting definitions have moved.
This functionality is now supplied by a header only library, available in nng/args.h.
-See nng_args_parse for more information.
nng_args_parse for more information.
The Layer 2 special ZeroTier transport has been removed. It is possible to use NNG with ZeroTier using TCP/IP, and a future update -- cgit v1.2.3-70-g09d2