NNG_CTX_GET(3)
π NNG_CTX_GET(3) π
okay bestie, so this is the NNG Reference Manual page for nng_ctx_get β aka the "get a context option" girlies. pull up a chair, we're doing this together π«Ά
β¨ NAME β¨
nng_ctx_get β get context option. that's it, that's the mission π
β¨ SYNOPSIS β¨
#include <nng/nng.h>
int nng_ctx_get(nng_ctx ctx, const char *opt, void *val, size_t *valszp);
int nng_ctx_get_bool(nng_ctx ctx, const char *opt, bool *bvalp);
int nng_ctx_get_int(nng_ctx ctx, const char *opt, int *ivalp);
int nng_ctx_get_ms(nng_ctx ctx, const char *opt, nng_duration *durp);
int nng_ctx_get_size(nng_ctx ctx, const char *opt, size_t *zp);
int nng_ctx_get_string(nng_ctx ctx, const char *opt, char **strp);
int nng_ctx_get_uint64(nng_ctx ctx, const char *opt, uint64_t *u64p);
look at all these little guys π₯Ή seven whole functions. it's giving overachiever and honestly? we love that for them.
β¨ DESCRIPTION β¨
so the nng_ctx_get() family is how you retrieve option values off of a context, ctx. and likeβ¦ which options you can actually get this way? varies, bestie. a whole bunch of them are documented over in nng_options(5) if you wanna go read π
Note π Context options are protocol specific. The details will be documented with the protocol. so don't come for me, come for your protocol's docs, iykyk π€·ββοΈ
πΈ Forms πΈ
in literally all of these forms, the option opt gets retrieved from the context ctx. the forms only differ based on the type of the option they take β like different flavors of the same slay β¨
the details of the type, the size, and the semantics of the option depend on the actual option itself, and will be documented with the option itself. no cap, that's just how it is.
π nng_ctx_get()
this one is the untyped queen π β you can use it to retrieve the value of any option.
here's the tea: the caller has to store a pointer to a buffer to 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 had been enough room β is stored at the location referenced by valszp. and okay bestie listen: if your buffer is not large enough to hold the entire object, then the copy is truncated π so you should check for truncation by verifying that the returned size in valszp does not exceed the original buffer size. pls pls pls check it.
also, it is acceptable to pass NULL for val if the value in valszp is zero. this is the little trick you can use to figure out the size of the buffer you need to receive the object. iconic behavior honestly π
Tip β¨ It may be easier to use one of the typed forms of this function. just saying. the typed ones are holding your hand and that's cute.
π nng_ctx_get_bool()
for options that take a Boolean (bool). the value will be stored at ivalp.
π nng_ctx_get_int()
for options that take an integer (int). the value will be stored at ivalp.
π nng_ctx_get_ms()
this one retrieves time durations (think: timeouts) and stores them in durp as a number of milliseconds. and the special value NNG_DURATION_INFINITE means an infinite amount of time π while the special value NNG_DURATION_DEFAULT means a context-specific default. two little celebrities, love them π
π nng_ctx_get_size()
retrieves a size into the pointer zp β typically for buffer sizes, message maximum sizes, and similar options. very measurements-coded π
π nng_ctx_get_string()
retrieves a string into strp. heads up bestie: this string is created from the source using nng_strdup() and consequently must be freed by the caller using nng_strfree() when it is no longer needed. don't forget. don't ghost it. free your strings π
π nng_ctx_get_uint64()
retrieves a 64-bit unsigned value into the value referenced by u64p. typically used for options related to identifiers, network numbers, and similar. big number energy, truly π₯
β¨ RETURN VALUES β¨
these functions return 0 on success, and non-zero otherwise. simple. elegant. β¨
β¨ ERRORS β¨
NNG_EBADTYPEβ Incorrect type for option. mismatch era, we hate to see it πNNG_ECLOSEDβ Parametersdoes not refer to an open socket.NNG_EINVALβ Size of destinationvaltoo small for object. buffer said "not today" πNNG_ENOMEMβ Insufficient memory exists. we are broke (in RAM)NNG_ENOTSUPβ The optionoptis not supported. it's not you, it's the option πNNG_EWRITEONLYβ The optionoptis write-only. you can set it, you just can't get it. boundaries, respect them π
β¨ SEE ALSO β¨
nng_ctx_set(3), nng_strdup(3), nng_strerror(3), nng_strfree(3), nng_duration(5), nng_ctx(5), nng_options(5), nng(7)
go read those too, they're in the same friend group π¦
and that's the page, bestie!! this was the NNG Reference Manual, dated 2026-06-30 πΈ ily, go set some options, and remember: typed getters are your besties, truncation is not πβ¨π
π¦ 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