NNG_TLS_CONFIG_ALLOC(3tls)

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

πŸ’– NAME πŸ’–

nng_tls_config_alloc β€” bestie, we're allocating a TLS configuration object ✨

Okay so real quick, this is from the NNG Reference Manual, section 3tls, and it's literally the very first thing you do before you can talk TLS with anybody. Let's get into it πŸŽ€


🌸 SYNOPSIS 🌸

#include <nng/nng.h>
#include <nng/supplemental/tls/tls.h>

typedef enum nng_tls_mode {
    NNG_TLS_MODE_CLIENT,
    NNG_TLS_MODE_SERVER
} nng_tls_mode;

int nng_tls_config_alloc(nng_tls_config **cfgp, nng_tls_mode mode);

✨ DESCRIPTION ✨

So nng_tls_config_alloc() makes you a brand-new, freshly initialized Transport Layer Security (<https://tools.ietf.org/html/rfc5246>) configuration object, and it drops a pointer to that lil guy into the value that cfgp points at. It's giving "here's your blank canvas, go be a secure socket" πŸ¦‹

This object gets set up for use when you're acting as either a client (NNG_TLS_MODE_CLIENT) or as a server (NNG_TLS_MODE_SERVER) β€” depends on whatever you pass in mode, no cap.

Then you can keep customizing your TLS object with other functions that set the security keys used, peer certificates, protocol policies, and so forth. Sky's the limit, fr fr πŸ’…

A single TLS configuration object can absolutely be used with multiple TLS streams or services β€” it's not a one-stream-only situation. The underlying system runs on reference counting so that the object does not get inadvertently freed while it's still in use. Protection spell activated 🧚

A configuration object created with nng_tls_config_alloc() starts with a reference count of one. You can bump that count up with nng_tls_config_hold() and bring it back down with nng_tls_config_free().

⚠️ Also big one, bestie: a TLS configuration object becomes read-only after it's first used with a service. After this point, any attempts to apply further changes to the configuration will result in NNG_EBUSY. It's locked in, it's committed, it said "I'm not taking new suggestions" πŸ’€

πŸ”₯ RETURN VALUES πŸ”₯

This function returns 0 on success, and non-zero otherwise. Simple as that, periodt.


πŸ’€ ERRORS πŸ’€

  • NNG_ENOMEM β€” insufficient memory is available. The RAM said no πŸ™ˆ
  • NNG_EINVAL β€” an invalid mode was specified. Bestie what mode even is that 😭

πŸ‘‘ SEE ALSO πŸ‘‘


And that's the whole page, bestie!! This icon of a manpage was dropped on 2026-06-30 in the NNG Reference Manual, filed under NNG_TLS_CONFIG_ALLOC(3tls) β€” go forth and allocate your TLS configs responsibly, mwah πŸ’–πŸŒˆ

πŸ“¦ where this page comes from