NNG_SETOPT(3)

๐Ÿ“ฆ
version 1.12.0 ยท 4 versions
, in ubuntu stonking

๐Ÿ’– 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 at nng_socket_set instead. also, they might not even be here if the library was built with NNG_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 โ€” parameter s does not refer to an open socket. she's closed, hun. ๐Ÿ˜ญ
  • NNG_EINVAL โ€” the value being passed is invalid. not the vibe. ๐Ÿ™ˆ
  • NNG_ENOTSUP โ€” the option opt is not supported. we don't do that here. ๐Ÿ’€
  • NNG_EREADONLY โ€” the option opt is 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 ๐ŸŒŸ


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