NNG_GETOPT(3)
π 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 atnng_socket_getinstead, fr fr. And lowkey they might not even exist if the library was built withNNG_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 inval, and the size of that buffer shall be stored at the location referenced byvalszp.
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 atbvalp. βnng_getopt_int()β for options that take an integer (int). The value lands ativalp. π’nng_getopt_ms()β used to retrieve time durations (think timeouts), stored indurpas a number of milliseconds. The special valueNNG_DURATION_INFINITEmeans an infinite amount of time, and the special valueNNG_DURATION_DEFAULTmeans a context-specific default. β°β¨nng_getopt_ptr()β used to retrieve a pointer,ptr, to structured data. The data thatptrreferences 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 pointerzp. Typically for buffer sizes, message maximum sizes, and similar vibes. πnng_getopt_string()β retrieves a string intostrp. This string is created from the source usingnng_strdup(), and consequently must be freed by the caller usingnng_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 byu64p. 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β parametersdoes not refer to an open socket.NNG_EINVALβ size of destinationvaltoo small for object. your buffer said "not today" πNNG_ENOMEMβ insufficient memory exists.NNG_ENOTSUPβ the optionoptis not supported.NNG_EWRITEONLYβ the optionoptis 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
- 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