NNG_GETOPT(3)

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

πŸ’– NAME πŸ’–

nng_getopt β€” get socket option (bestie edition, let's get you that value πŸ‘‘


✨ SYNOPSIS ✨

#include <nng/nng.h>

int nng_getopt(nng_socket s, const char *opt, void *val, size_t *valszp);

int nng_getopt_bool(nng_socket s, const char *opt, bool *bvalp);

int nng_getopt_int(nng_socket s, const char *opt, int *ivalp);

int nng_getopt_ms(nng_socket s, const char *opt, nng_duration *durp);

int nng_getopt_ptr(nng_socket s, const char *opt, void **ptr);

int nng_getopt_size(nng_socket s, const char *opt, size_t *zp);

int nng_getopt_string(nng_socket s, const char *opt, char **strp);

int nng_getopt_uint64(nng_socket s, const char *opt, uint64_t *u64p);

🌸 DESCRIPTION 🌸

Important, bestie, listen up: these functions are deprecated. Go look at nng_socket_get instead, fr fr. And lowkey they might not even exist if the library was built with NNG_ELIDE_DEPRECATED β€” so like, don't come for me if they ghost you. πŸ’€

The nng_getopt() functions are the way you pull option values out of the socket s. Which options you can actually retrieve this way? Depends. A bunch of them are documented over in nng_options(5).

Also, transport-specific options and protocol-specific options get documented alongside the transports and protocols themselves, so go check those pages for the deets. πŸ¦‹

πŸŽ€ Forms πŸŽ€

In every single one of these forms, you're grabbing the option opt from the socket s. The forms just differ based on what type of option they hand you back.

The type, size, and semantics of the option all depend on the actual option itself, and they'll be documented with that option. iykyk. πŸ’…

  • nng_getopt() β€” this one's the untyped legend. It can retrieve the value of literally any option. You (the caller) have to stash a pointer to a buffer that'll receive the value in val, and the size of that buffer shall be stored at the location referenced by valszp.

When the function returns, the actual size of the data copied β€” or the size that would have been copied if there'd been enough space β€” gets stored at the location referenced by valszp. If your buffer isn't big enough to hold the entire object, then the copy is truncated. So you gotta check for truncation yourself by verifying that the returned size in valszp doesn't exceed your original buffer size. No cap. πŸ‘€

It's totally acceptable to pass NULL for val if the value in valszp is zero. That's the move for figuring out how big a buffer you actually need to receive the object. iconic behavior honestly.

Tip: it may be way easier to just use one of the typed forms of this function. save yourself the struggle bestie 🫢
  • nng_getopt_bool() β€” for options that take a Boolean (bool). The value lands at bvalp. βœ…
  • nng_getopt_int() β€” for options that take an integer (int). The value lands at ivalp. πŸ”’
  • nng_getopt_ms() β€” used to retrieve time durations (think timeouts), stored in durp as a number of milliseconds. The special value NNG_DURATION_INFINITE means an infinite amount of time, and the special value NNG_DURATION_DEFAULT means a context-specific default. ⏰✨
  • nng_getopt_ptr() β€” used to retrieve a pointer, ptr, to structured data. The data that ptr references is generally managed using other functions. And ngl this form is a little special: the object is generally not copied β€” instead the pointer to the object is what gets copied. πŸ™ˆ
  • nng_getopt_size() β€” retrieves a size into the pointer zp. Typically for buffer sizes, message maximum sizes, and similar vibes. πŸ“
  • nng_getopt_string() β€” retrieves a string into strp. This string is created from the source using nng_strdup(), and consequently must be freed by the caller using nng_strfree() when it's no longer needed. Don't leak, that's not the vibe. πŸŽ€
  • nng_getopt_uint64() β€” retrieves a 64-bit unsigned value into the value referenced by u64p. Usually for options related to identifiers, network numbers, and similar. πŸ‘‘

🌈 RETURN VALUES 🌈

These functions return 0 on success, and non-zero otherwise. Simple as that. πŸ’–


πŸ”₯ ERRORS πŸ”₯

  • NNG_EBADTYPE β€” incorrect type for option. wrong vibe entirely.
  • NNG_ECLOSED β€” parameter s does not refer to an open socket.
  • NNG_EINVAL β€” size of destination val too small for object. your buffer said "not today" 😭
  • NNG_ENOMEM β€” insufficient memory exists.
  • NNG_ENOTSUP β€” the option opt is not supported.
  • NNG_EWRITEONLY β€” the option opt is write-only. you can look, you just can't read. πŸ’€

πŸ¦‹ SEE ALSO πŸ¦‹

nng_dialer_getopt(3), nng_listener_getopt(3), nng_pipe_getopt(3), nng_setopt(3), nng_strdup(3), nng_strerror(3), nng_strfree(3), nng_duration(5), nng_options(5), nng_socket(5), nng(7)


okay bestie that's the whole page, you ate that 🫢 this was the NNG Reference Manual, NNG_GETOPT(3), dated 2026-06-30 β€” go forth and get those options, periodt. πŸ’…βœ¨

πŸ“¦ where this page comes from