NNG_SETOPT(3)
๐ NNG_SETOPT(3) โ the nng_setopt girlies' guide ๐
okay so bestie, welcome to the NNG Reference Manual, nng_setopt edition. this is where you poke at a socket's settings and make it behave. sit down, grab a lil snack ๐, we're doing options today. โจ
๐ธ NAME ๐ธ
nng_setopt โ set socket option. that's it, that's the whole vibe. setting. socket. options. ๐
โจ SYNOPSIS โจ
#include <nng/nng.h>
int nng_setopt(nng_socket s, const char *opt, const void *val, size_t valsz);
int nng_setopt_bool(nng_socket s, const char *opt, bool bval);
int nng_setopt_int(nng_socket s, const char *opt, int ival);
int nng_setopt_ms(nng_socket s, const char *opt, nng_duration dur);
int nng_setopt_ptr(nng_socket s, const char *opt, void *ptr);
int nng_setopt_size(nng_socket s, const char *opt, size_t z);
int nng_setopt_string(nng_socket s, const char *opt, const char *str);
int nng_setopt_uint64(nng_socket s, const char *opt, uint64_t u64);
eight whole functions. a whole lil family. iconic honestly. ๐
๐ฆ DESCRIPTION ๐ฆ
Important, and I mean it bestie: these functions are deprecated. please please please go look atnng_socket_setinstead. also, they might not even be here if the library was built withNNG_ELIDE_DEPRECATED. so likeโฆ they could ghost you. ๐ญ
so the nng_setopt() functions are how you configure options for the socket s. which options can be configured this way? depends, babe โ that's what opt is for. a whole bunch of them are documented over in nng_options(5).
and also, some transport-specific and protocol-specific options get documented right alongside the transports and protocols themselves. so check there too. ๐ซถ
๐ Forms ๐
the actual type, size, and semantics of any given option depend on the option itself, and are documented with the option. so like, read the option's own docs. i'm not out here guessing for you, and neither should you. ๐
nng_setopt()
this one is untyped, which means it can configure literally any arbitrary data you throw at it. the val pointer addresses the data to copy, and valsz is the size of the object located at val.
Tip: lowkey it may be easier to use one of the typed forms of this function. just saying. ๐
nng_setopt_bool()
for options that take a Boolean (bool). bval gets passed to the option. true/false, binary, no in-between. โจ
nng_setopt_int()
for options that take an integer (int). ival gets passed to the option.
nng_setopt_ms()
this is the one for configuring time durations (like timeouts) using the type nng_duration. the duration dur is an integer number of milliseconds. so like, 500 means half a second. math queen. ๐งฎ
nng_setopt_ptr()
this one passes a pointer, ptr, to structured data. the data referenced by ptr is generally managed by other functions. for example, TLS configuration objects created with (nng_tls_config_alloc()) can be passed this way.
Note: this form is somewhat special โ the object is generally not copied, instead the pointer to the object is copied. so don't go freeing stuff out from under it, bestie. ๐
nng_setopt_size()
for configuring a size, z. typically for buffer sizes, message maximum sizes, and similar options. big sizes, small sizes, all valid. ๐
nng_setopt_string()
for configuring a string, str. strings passed this way must be legal UTF-8 or ASCII strings, terminated with a NUL (\0) byte. (other constraints may apply as well โ see the documentation for each option for details, iykyk.)
nng_setopt_uint64()
for configuring a 64-bit unsigned value, u64. typically used for options related to identifiers, network numbers, and similar. sixty-four bits of pure potential. โญ
๐ RETURN VALUES ๐
these functions return 0 on success, and non-zero otherwise. zero = slay. non-zero = something's up. ๐
๐ฅ ERRORS ๐ฅ
NNG_ECLOSEDโ parametersdoes not refer to an open socket. she's closed, hun. ๐ญNNG_EINVALโ the value being passed is invalid. not the vibe. ๐NNG_ENOTSUPโ the optionoptis not supported. we don't do that here. ๐NNG_EREADONLYโ the optionoptis read-only. look, don't touch. ๐ซNNG_ESTATEโ the socket is in an inappropriate state for setting this option. wrong place, wrong time, bestie. โฐ
๐ SEE ALSO ๐
nng_getopt(3)nng_dialer_setopt(3)nng_listener_setopt(3)nng_strerror(3)nng_options(5)nng_socket(5)nng(7)
and that's the whole page, periodt. ๐ซถ this came out of the NNG Reference Manual, dated 2026-06-30, and the whole thing is filed under NNG_SETOPT(3). now go set some options, main character. ๐โจ๐๐ฆ
๐ฆ where this page comes from
- ubuntu stonking: libnng-dev 1.12.0-1 ยท MIT OR Apache-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms