LIBNNG(3)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

πŸ’– LIBNNG(3) β€” nanomsg next generation library πŸ’–

libnng β€” the manual page, bestie edition. Yes it's nng, the nanomsg next generation library, and yes she is that girl. πŸŽ€


✨ NAME ✨

libnng β€” nanomsg next generation library πŸ¦‹


✨ SYNOPSIS ✨

cc [flags] files -lnng [libraries]

like. that's it. that's the whole build line. you compile your stuff, you link -lnng, you go live your life. πŸ’…


✨ DESCRIPTION ✨

okay so picture this: distributed applications have a LOT of communication problems and they're all kind of the same problems over and over again. NNG is a common messaging framework built specifically to solve those common communication problems. no cap. 🫢

and the way you talk to it is through a C language API. that's the whole vibe.


🌸 Common Functions

these are the little everyday helpers that live in libnng. the utility squad. the ones you call constantly and never think about:

  • nng_alloc β€” allocate memory 🧚
  • nng_free β€” free memory (yes, the sequel)
  • nng_strdup β€” duplicate string
  • nng_strerror β€” return an error description
  • nng_strfree β€” free string
  • nng_version β€” report library version πŸ‘‘

ngl nng_strerror is lowkey doing the most for you every single time something explodes. thank her.


🌈 Socket Functions

and these ones? these operate on sockets. this is where the main character energy lives:

  • nng_close β€” close socket
  • nng_dial β€” create and start dialer
  • nng_getopt β€” get socket option
  • nng_listen β€” create and start listener
  • nng_recv β€” receive data
  • nng_send β€” send data (the iconique counterpart)
  • nng_setopt β€” set socket option (DEPRECATED)
  • nng_socket_get β€” get socket option
  • nng_socket_id β€” get numeric socket identifier
  • nng_socket_raw β€” is the socket raw
  • nng_socket_proto_id β€” get the socket protocol identifier
  • nng_socket_proto_name β€” get the socket protocol name
  • nng_socket_set β€” set socket option
  • nng_sub_subscribe β€” manage subscriptions
🚨 bestie listen. nng_setopt is marked DEPRECATED. she still exists, she still works, but she is NOT the moment anymore. do not build your new thing on her. periodt. πŸ’€

and that's part 1, we are literally just getting started β€” more pages are coming so don't go anywhere bestie πŸ’œ

πŸ’– Connection Management πŸ’–

okay so these functions are used with either listeners, or dialers. Listeners accept incoming connection requests, and dialers make them. That's the whole dynamic, bestie β€” listeners are the ones saying "come thru," dialers are the ones making the first move. πŸ’Œ

  • nng_dial β€” create and start dialer
  • nng_dialer_close β€” close dialer
  • nng_dialer_create β€” create dialer
  • nng_dialer_get β€” get dialer option
  • nng_dialer_getopt β€” get dialer option (DEPRECATED)
  • nng_dialer_id β€” get numeric dialer identifier
  • nng_dialer_set β€” set dialer option
  • nng_dialer_setopt β€” set dialer option (DEPRECATED)
  • nng_dialer_start β€” start dialer
  • nng_listen β€” create and start listener
  • nng_listener_close β€” close listener
  • nng_listener_create β€” create listener
  • nng_listener_get β€” get listener option
  • nng_listener_getopt β€” get listener option (DEPRECATED)
  • nng_listener_id β€” get numeric listener identifier
  • nng_listener_set β€” set listener option
  • nng_listener_setopt β€” set listener option (DEPRECATED)
  • nng_listener_start β€” start listener
  • nng_pipe_close β€” close pipe
  • nng_pipe_dialer β€” return dialer that created pipe
  • nng_pipe_get β€” get pipe option
  • nng_pipe_getopt β€” get pipe option (DEPRECATED)
  • nng_pipe_id β€” get numeric pipe identifier
  • nng_pipe_listener β€” return listener that created pipe
  • nng_pipe_notify β€” register pipe notification callback
  • nng_pipe_socket β€” return owning socket for pipe

πŸ¦‹ Message Handling Functions πŸ¦‹

If your app wants the richest part of libnng, you're gonna want the message API β€” a message structure gets passed between functions. This API provides the most powerful support for zero-copy. πŸ’…βœ¨

Okay so here's the whole roster of message functions β€” the header is one thing, the body is another, and almost everyone only ever touches the body. The body carries your user payload; the header carries protocol-specific header info. Cute, right?

  • nng_msg_alloc β€” allocate a message
  • nng_msg_append β€” append to message body
  • nng_msg_body β€” return message body
  • nng_msg_capacity β€” return capacity allocated for message body
  • nng_msg_chop β€” remove data from end of message body
  • nng_msg_clear β€” clear message body
  • nng_msg_dup β€” duplicate a message
  • nng_msg_free β€” free a message
  • nng_msg_get_pipe β€” get pipe for message
  • nng_msg_insert β€” prepend to message body
  • nng_msg_len β€” return the message body length
  • nng_msg_realloc β€” reallocate a message
  • nng_msg_reserve β€” reserve storage for message body
  • nng_msg_set_pipe β€” set pipe for message
  • nng_msg_trim β€” remove data from start of message body
  • nng_recvmsg β€” receive a message
  • nng_sendmsg β€” send a message

πŸ¦‹ Message Header Handling πŸ¦‹

Tip β€” bestie, most apps will never need these. Message headers only carry protocol-specific content, periodt. But if you're living that raw mode life, you may need to poke at the header of messages. iykyk.
  • nng_msg_header β€” return message header
  • nng_msg_header_append β€” append to message header
  • nng_msg_header_chop β€” remove data from end of message header
  • nng_msg_header_clear β€” clear message header
  • nng_msg_header_insert β€” prepend to message header
  • nng_msg_header_len β€” return the message header length
  • nng_msg_header_trim β€” remove data from start of message header

✨ Asynchronous Operations ✨

So most apps interact with NNG synchronously, meaning functions like nng_send will lowkey hold the calling thread hostage until the operation has completed. Like, block and wait, bestie. πŸ’…

Note β€” not me telling you that synchronous operations which send messages may return before the message has actually been received, or even transmitted. Fr fr: these functions return as soon as the message was successfully queued for delivery. That's it. That's the whole story. πŸ™ˆ

Asynchronous operations? Completely different vibe. The calling thread kicks the operation off, but control returns to the calling thread immediately. Then, when the operation is subsequently completed β€” successful or not, no judgment, both are valid β€” a user-supplied function gets executed. Callback era. πŸŽ€

A context structure, an nng_aio, is allocated and associated with each asynchronous operation. And here's the rule: only a single asynchronous operation may be associated with an nng_aio at any time. One. Singular. Don't be messy about it. πŸ‘‘


✨ the asynchronous model girlies ✨

okay so these are all the functions you'll be living in when you're doing stuff asynchronously β€” like, nothing waits around blocking your thread, everything's giving "i'll text you back later" energy πŸ’…

  • nng_aio_abort β€” abort asynchronous I/O operation
  • nng_aio_alloc β€” allocate asynchronous I/O handle
  • nng_aio_begin β€” begin asynchronous I/O operation
  • nng_aio_busy β€” test if asynchronous I/O is busy
  • nng_aio_cancel β€” cancel asynchronous I/O operation
  • nng_aio_count β€” return number of bytes transferred
  • nng_aio_defer β€” defer asynchronous I/O operation
  • nng_aio_finish β€” finish asynchronous I/O operation
  • nng_aio_free β€” free asynchronous I/O handle
  • nng_aio_get_input β€” return input parameter
  • nng_aio_get_msg β€” get message from an asynchronous receive
  • nng_aio_get_output β€” return output result
  • nng_aio_reap β€” reap asynchronous I/O handle
  • nng_aio_result β€” return result of asynchronous operation
  • nng_aio_set_input β€” set input parameter
  • nng_aio_set_iov β€” set scatter/gather vector
  • nng_aio_set_msg β€” set message for an asynchronous send
  • nng_aio_set_output β€” set output result
  • nng_aio_set_timeout β€” set asynchronous I/O timeout
  • nng_aio_stop β€” stop asynchronous I/O operation
  • nng_aio_wait β€” wait for asynchronous I/O operation
  • nng_recv_aio β€” receive message asynchronously
  • nng_send_aio β€” send message asynchronously
  • nng_sleep_aio β€” sleep asynchronously

πŸŽ€ Protocols πŸŽ€

and these bad boys? they're how you build yourself a socket that's committed to one specific protocol. pick your fighter, bestie ✨

  • nng_bus_open β€” open a bus socket
  • nng_pair_open β€” open a pair socket
  • nng_pub_open β€” open a pub socket
  • nng_pull_open β€” open a pull socket
  • nng_push_open β€” open a push socket
  • nng_rep_open β€” open a rep socket
  • nng_req_open β€” open a req socket
  • nng_respondent_open β€” open a respondent socket
  • nng_sub_open β€” open a sub socket
  • nng_surveyor_open β€” open a surveyor socket

πŸ¦‹ that's the whole roster, no cap πŸ¦‹

πŸ’« Transports πŸ’«

okay so these functions register a transport for use, right? but bestie. plot twist β€” this is no longer necessary, and applications should not call these functions anymore. that's not me being dramatic, that's the manpage. periodt. πŸ™…β€β™€οΈ

so like, they're still documented (we don't gatekeep the lore) but every single one of them is DEPRECATED. read them for the history lesson, not for your new project. πŸ’…

  • nng_inproc_register β€” register inproc transport (DEPRECATED)
  • nng_ipc_register β€” register IPC transport (DEPRECATED)
  • nng_tcp_register β€” register TCP transport (DEPRECATED)
  • nng_tls_register β€” register TLS transport (DEPRECATED)
  • nng_ws_register β€” register WebSocket transport (DEPRECATED)
  • nng_wss_register β€” register WebSocket Secure transport (DEPRECATED)
  • nng_zt_register β€” register ZeroTier transport (DEPRECATED)
fr fr whisper: if you're out here calling these in 2024+ code, we need to talk. they're deprecated. the library handles this now.

πŸ§ πŸ’… Protocol Contexts πŸ’…πŸ§ 

now THIS is the good stuff. these functions let you pull the protocol processing out of a socket object and into a whole separate context. why do we care? because it means you can spin up multiple contexts on a single socket for concurrent applications. one socket, many main characters. that's range. πŸ‘‘

  • nng_ctx_close β€” close context
  • nng_ctx_get β€” get context option
  • nng_ctx_getopt β€” get context option (DEPRECATED)
  • nng_ctx_id β€” get numeric context identifier
  • nng_ctx_open β€” create context
  • nng_ctx_recv β€” receive message using context asynchronously
  • nng_ctx_recvmsg β€” receive a message using context
  • nng_ctx_send β€” send message using context asynchronously
  • nng_ctx_sendmsg β€” send a message using context
  • nng_ctx_set β€” set context option
  • nng_ctx_setopt β€” set context option (DEPRECATED)
heads up bestie: see how nng_ctx_getopt and nng_ctx_setopt are tagged DEPRECATED? yeah. they're the old way. nng_ctx_get and nng_ctx_set are the ones you actually want. the vibe check said "evolve." πŸ¦‹

πŸ”€ Devices, Relays πŸ”€

last lil family in this part, and honestly? iconic behaviour. this one is a whole function family (okay it's one function, but the concept is a family) for building forwarders or relayers β€” the lil guys that take messages from one socket and route them on over to another socket. message traffic controller energy. 🚦✨

  • nng_device β€” message forwarding device

so that's your relayer. route it, forward it, slay it. 🫢

πŸ’– Statistics πŸ’–

okay bestie, so these functions are the whole stats vibe β€” they give you access to statistics that can be used to observe program behaviors and as an aid in troubleshooting. It’s giving β€œI know what my code is doing” energy, fr fr. πŸ”βœ¨

  • nng_stat_bool β€” get statistic Boolean value
  • nng_stat_child β€” get child statistic
  • nng_stat_name β€” get statistic description
  • nng_stat_find β€” find statistic by name
  • nng_stat_find_dialer β€” find dialer statistics
  • nng_stat_find_listener β€” find listener statistics
  • nng_stat_find_socket β€” find socket statistics
  • nng_stat_name β€” get statistic name
  • nng_stat_next β€” get next statistic
  • nng_stat_string β€” get statistic string value
  • nng_stat_timestamp β€” get statistic timestamp
  • nng_stat_type β€” get statistic type
  • nng_stat_unit β€” get statistic unit
  • nng_stat_value β€” get statistic numeric value
  • nng_stats_free β€” free statistics
  • nng_stats_get β€” get statistics

🌐 URL Object 🌐

Common functionality is supplied for parsing and handling universal resource locators (URLS). Yes, URLS with the S, we are not taking questions at this time πŸ’…

  • nng_url_clone β€” clone URL structure
  • nng_url_free β€” free URL structure
  • nng_url_parse β€” create URL structure from string

πŸ“ Logging Support πŸ“

Common functionality for message logging. Because sometimes you need receipts, bestie. πŸ§ΎπŸ’–

  • nng_log β€” log a message
  • nng_log_set_facility β€” set log facility
  • nng_log_set_level β€” set log level
  • nng_log_set_logger β€” set logging handler

✨ Supplemental API ✨

Okay bestie, so these supplemental functions? They're not like intrinsic to building network applications with NNG β€” they're not the main character of the networking story πŸ’…. But they're here anyway, as a convenience, to help you out when you're trying to make portable applications. Think of them as the little besties that carry your bags while you do the big networking stuff 🫢

Here's the full squad, no gatekeeping:

  • nng_clock β€” get time ⏰
  • nng_cv_alloc β€” allocate condition variable
  • nng_cv_free β€” free condition variable
  • nng_cv_until β€” wait for condition or timeout ⏳
  • nng_cv_wait β€” wait for condition
  • nng_cv_wake β€” wake all waiters
  • nng_cv_wake1 β€” wake one waiter
  • nng_id_map β€” identifier based mapping table πŸ—ΊοΈ
  • nng_msleep β€” sleep for milliseconds 😴
  • nng_mtx_alloc β€” allocate mutex
  • nng_mtx_free β€” free mutex
  • nng_mtx_lock β€” lock mutex πŸ”’
  • nng_mtx_unlock β€” unlock mutex πŸ”“
  • nng_opts_parse β€” parse command line options
  • nng_random β€” get random number 🎲
  • nng_socket_pair β€” create connected pair of BSD sockets
  • nng_thread_create β€” create thread 🧡
  • nng_thread_destroy β€” reap thread
  • nng_thread_set_name β€” set thread name 🏷️

🌊 Byte Streams 🌊

And these functions? They're the ones you can use with byte streams πŸ’§. Fr fr, they're considered low-level β€” like, you reach for them when the higher level functions that use Scalability Protocols are just not it for whatever you're doing πŸ™ˆ. Not inappropriate in a bad way, just inappropriate for the vibe.

So like β€” byte streams, bestie, are what you get when you want a raw connection: an actual TCP connection, a named pipe, that kind of thing 🫢 Each one is wrapped up in an nng_stream object, and you never just ✨materialize✨ one out of thin air. They come from either nng_stream_dialer or nng_stream_listener objects. The dialer slides out and makes the connection happen; the listener sits there all cute until somebody shows up. πŸŽ€

Here's the whole squad of byte stream functions, every single one, no skips:

  • nng_stream_close β€” close byte stream πŸ’…
  • nng_stream_dialer_alloc β€” allocate byte stream dialer ✨
  • nng_stream_dialer_close β€” close byte stream dialer
  • nng_stream_dialer_dial β€” initiate outgoing byte stream πŸ”₯
  • nng_stream_dialer_free β€” free byte stream dialer
  • nng_stream_dialer_get β€” get option from byte stream dialer
  • nng_stream_dialer_set β€” set option on byte stream dialer
  • nng_stream_free β€” free byte stream
  • nng_stream_get β€” get option from byte stream
  • nng_stream_listener_accept β€” accept incoming byte stream 🫢
  • nng_stream_listener_alloc β€” allocate byte stream listener
  • nng_stream_listener_close β€” close byte stream listener
  • nng_stream_listener_free β€” free byte stream listener
  • nng_stream_listener_get β€” get option from byte stream listener
  • nng_stream_listener_listen β€” bind byte stream listener to address 🌈
  • nng_stream_listener_set β€” set option on byte stream listener
  • nng_stream_recv β€” receive from byte stream πŸ’œ
  • nng_stream_send β€” send to byte stream πŸ’Œ
  • nng_stream_set β€” set option on byte stream

πŸ¦‹ HTTP Support πŸ¦‹

Okay so this one depends on how your library was built, and that's the tea: the library may be configured with support for HTTP πŸ’… β€” and the rule is that this will be the case if WebSocket support is configured as well. So no WebSocket, no HTTP party. Periodt.

When you do have it, though? You get access to functionality to support the creation of HTTP servers and clients, and, if TLS support is present, HTTP/S ones too. both flavors, iconically πŸ‘‘

✨ Common HTTP Functions ✨

Okay bestie, these are the little guys you'll be texting all day long β€” the functions that handle HTTP requests, responses, and connections. Every single one, in order, no skips, let's go 🫢

  • nng_http_conn_close β€” closes down that HTTP connection, bye bye πŸ‘‹
  • nng_http_conn_read β€” reads from an HTTP connection πŸ“–
  • nng_http_conn_read_all β€” reads everything from an HTTP connection, no crumbs left πŸͺ
  • nng_http_conn_read_req β€” reads an HTTP request πŸ“¨
  • nng_http_conn_read_res β€” reads an HTTP response πŸ“¬
  • nng_http_conn_write β€” writes to an HTTP connection ✍️
  • nng_http_conn_write_all β€” writes all of it to an HTTP connection, commitment issues = none πŸ’…
  • nng_http_conn_write_req β€” writes an HTTP request πŸ“€
  • nng_http_conn_write_res β€” writes an HTTP response πŸ“₯
  • nng_http_req_add_header β€” adds an HTTP request header βž•
  • nng_http_req_alloc β€” allocates an HTTP request structure πŸ—οΈ
  • nng_http_req_copy_data β€” copies the HTTP request body πŸ“‹
  • nng_http_req_del_header β€” deletes an HTTP request header πŸ—‘οΈ
  • nng_http_req_free β€” frees that HTTP request structure, so it stops living rent free 🏠
  • nng_http_req_get_data β€” gets the HTTP request body πŸ”
  • nng_http_req_get_header β€” returns an HTTP request header πŸ”™
  • nng_http_req_get_method β€” returns the HTTP request method (the verb energy fr) 🏷️
  • nng_http_req_get_uri β€” returns the HTTP request URI 🌐
  • nng_http_req_get_version β€” returns the HTTP request protocol version πŸ”’

  • nng_http_req_reset β€” resets the HTTP request structure, starting fresh, main character rebirth arc πŸ¦‹
  • nng_http_req_set_data β€” sets the HTTP request body 🩹
  • nng_http_req_set_header β€” sets an HTTP request header πŸŽ€
  • nng_http_req_set_method β€” sets the HTTP request method βš™οΈ
  • nng_http_req_set_uri β€” sets the HTTP request URI 🧭
  • nng_http_req_set_version β€” sets the HTTP request protocol version πŸ”§
  • nng_http_res_add_header β€” adds an HTTP response header βž•
  • nng_http_res_alloc β€” allocates an HTTP response structure πŸ—οΈ
  • nng_http_res_alloc_error β€” allocates an HTTP error response, for when things are giving chaos 😭
  • nng_http_res_copy_data β€” copies the HTTP response body πŸ“‹
  • nng_http_res_del_header β€” deletes an HTTP response header πŸ—‘οΈ
  • nng_http_res_free β€” frees the HTTP response structure 🏠
  • nng_http_res_get_data β€” gets the HTTP response body πŸ”
  • nng_http_res_get_header β€” returns an HTTP response header πŸ”™
  • nng_http_res_get_reason β€” returns the HTTP response reason πŸ’¬

…and the rest of the response girlies, finishing up the roster πŸ’…

  • nng_http_res_get_status β€” hands you back the HTTP response status ✨
  • nng_http_res_get_version β€” hands you back the HTTP response protocol version 🌸
  • nng_http_res_reset β€” wipes the HTTP response structure back to a clean slate 🧼
  • nng_http_res_set_data β€” sets the HTTP response body πŸ“
  • nng_http_res_set_header β€” sets an HTTP response header πŸ“¨
  • nng_http_res_set_reason β€” sets the HTTP response reason πŸ’¬
  • nng_http_res_set_status β€” sets the HTTP response status πŸ”’
  • nng_http_res_set_version β€” sets the HTTP response protocol version 🏷️

πŸ‘‘ HTTP Client Functions πŸ‘‘

These functions are intended for use with HTTP client applications. Like, if you're the one making the requests, this is your section bestie 🫢

  • nng_http_client_alloc β€” allocates an HTTP client 🌱
  • nng_http_client_connect β€” establishes the HTTP client connection πŸ”Œ
  • nng_http_client_free β€” frees the HTTP client πŸ’€ (the good kind of free, don't panic)
  • nng_http_client_get_tls β€” gets the HTTP client TLS configuration πŸ”
  • nng_http_client_set_tls β€” sets the HTTP client TLS configuration πŸ”’
  • nng_http_client_transact β€” performs one HTTP transaction ✨
  • nng_http_conn_transact β€” performs one HTTP transaction on a connection 🌈

HTTP Server Functions 🌐✨

These ones are for when you're building an HTTP server app, like actually serving requests to people. Bestie, this is where the main character energy lives fr fr πŸ’…

  • nng_http_handler_alloc β€” allocate HTTP server handler
  • nng_http_handler_collect_body β€” set HTTP handler to collect request body
  • nng_http_handler_free β€” free HTTP server handler
  • nng_http_handler_get_data β€” return extra data for HTTP handler
  • nng_http_handler_set_data β€” set extra data for HTTP handler
  • nng_http_handler_set_host β€” set host for HTTP handler
  • nng_http_handler_set_method β€” set HTTP handler method
  • nng_http_handler_set_tree β€” set HTTP handler to match trees
  • nng_http_hijack β€” hijack HTTP server connection
  • nng_http_server_add_handler β€” add HTTP server handler
  • nng_http_server_del_handler β€” delete HTTP server handler
  • nng_http_server_get_addr β€” get HTTP server address
  • nng_http_server_get_tls β€” get HTTP server TLS configuration
  • nng_http_server_hold β€” get and hold HTTP server instance
  • nng_http_server_release β€” release HTTP server instance
  • nng_http_server_set_error_file β€” set custom HTTP error file
  • nng_http_server_set_error_page β€” set custom HTTP error page
  • nng_http_server_set_tls β€” set HTTP server TLS configuration
  • nng_http_server_res_error β€” use HTTP server error page
  • nng_http_server_start β€” start HTTP server
  • nng_http_server_stop β€” stop HTTP server

TLS Configuration Objects πŸ”πŸ¦‹

The following functions are used to manipulate transport layer security (TLS) configuration objects. The way that most of these functions are so niche that even actual TLS applications won't touch them… yeah, that's the vibe 😭 Most of y'all will never call these, and that's totally okay bestie, no cap.

Note

These functions will only be present if the library has been built with TLS support. like, if your build didn't have TLS turned on, these just… don't exist bestie πŸ’€ don't come for me, that's just how it is.

  • nng_tls_config_alloc β€” allocate a TLS configuration ✨
  • nng_tls_config_auth_mode β€” set the authentication mode πŸ”
  • nng_tls_config_ca_chain β€” set the certificate authority chain πŸŽ€
  • nng_tls_config_ca_file β€” load the certificate authority from a file πŸ“‚
  • nng_tls_config_cert_key_file β€” load your own certificate and key from a file πŸ—οΈ
  • nng_tls_config_psk β€” set the pre-shared key and identity 🀝
  • nng_tls_config_own_cert β€” set your own certificate and key πŸ‘‘
  • nng_tls_config_free β€” free the TLS configuration 🧹
  • nng_tls_config_server_name β€” set the remote server name πŸ›°οΈ

🌈 SEE ALSO 🌈

okay so if you wanna keep vibing through the docs, these are the ones to tap next:

and that's the whole page, babe 🫢

this was LIBNNG(3), dated 2026-06-30 πŸ’… tagged and dated, archived, iconic, periodt. go forth and configure your TLS like the main character you are βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from