NNG_CTX_GETOPT(3)
πΈ NNG_CTX_GETOPT(3) πΈ
hey bestie!! welcome back to the NNG Reference Manual, section 3 π today's reading is nng_ctx_getopt, and yes, we know, it's the deprecated one β but we're still gonna learn it properly because that's just the kind of student you are π€π
β¨ NAME β¨
nng_ctx_getopt β get a context option, bestie π
β¨ SYNOPSIS β¨
#include <nng/nng.h>
int nng_ctx_getopt(nng_ctx ctx, const char *opt, void *val, size_t *valszp);
int nng_ctx_getopt_bool(nng_ctx ctx, const char *opt, bool *bvalp);
int nng_ctx_getopt_int(nng_ctx ctx, const char *opt, int *ivalp);
int nng_ctx_getopt_ms(nng_ctx ctx, const char *opt, nng_duration *durp);
int nng_ctx_getopt_size(nng_ctx ctx, const char *opt, size_t *zp);
int nng_ctx_getopt_string(nng_ctx ctx, const char *opt, char **strp);
int nng_ctx_getopt_uint64(nng_ctx ctx, const char *opt, uint64_t *u64p);
β¨ DESCRIPTION β¨
Important β these functions are deprecated, babe π no cap. Please go look atnng_ctx_getinstead. And lowkey they might not even exist if the library was built withNNG_ELIDE_DEPRECATEDπ
The nng_ctx_getopt() functions are how you retrieve option values for the context ctx. Which options you can actually pull this way? varies, bestie π A whole bunch of them are documented over in nng_options(5).
Note β context options are protocol specific β¨ the deets get documented with the protocol itself, so go read those.
π« Forms π«
In all of these forms, the option opt is retrieved from the context ctx. The forms just vary based on the type of the option they take.
The deets of the type, the size, and the semantics of the option all depend on the actual option, and get documented with the option itself. okay? okay π«Ά
nng_ctx_getopt()β the untyped one, and she can retrieve the value of any option, periodt π
You, the caller, must store a pointer to a buffer to receive the value in val, and the size of the 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 sufficient space were present β is stored at the location referenced by valszp. If your buffer isn't large enough to hold the entire object, then the copy gets truncated π So the caller should check for truncation by verifying that the returned size in valszp does not exceed the original buffer size. fr fr, check it.
It is acceptable to pass NULL for val if the value in valszp is zero β¨ This can be used to determine the size of the buffer needed to receive the object. it's giving "tell me how much room I need before I commit" π
Tip β it may be easier to use one of the typed forms of this function, just saying π
nng_ctx_getopt_bool()β this function is for options which take a Boolean (bool). The value will be stored ativalp.nng_ctx_getopt_int()β this function is for options which take an integer (int). The value will be stored ativalp.nng_ctx_getopt_ms()β this one retrieves time durations (like 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.) iconic β¨nng_ctx_getopt_size()β this one retrieves a size into the pointerzp, typically for buffer sizes, message maximum sizes, and similar options π¦nng_ctx_getopt_string()β this one 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 is no longer needed. don't forget to free her π€nng_ctx_getopt_uint64()β this one retrieves a 64-bit unsigned value into the value referenced byu64p. This is typically used for options related to identifiers, network numbers, and similar π
β¨ RETURN VALUES β¨
These functions return 0 on success, and non-zero otherwise. that's it, that's the vibe π
β¨ ERRORS β¨
NNG_EBADTYPEβ incorrect type for option.NNG_ECLOSEDβ parametersdoes not refer to an open socket.NNG_EINVALβ size of destinationvaltoo small for object.NNG_ENOMEMβ insufficient memory exists.NNG_ENOTSUPβ the optionoptis not supported.NNG_EWRITEONLYβ the optionoptis write-only. yeah bestie, some of them only take, they don't give π
β¨ SEE ALSO β¨
nng_ctx_setopt(3)nng_strdup(3)nng_strerror(3)nng_strfree(3)nng_duration(5)nng_ctx(5)nng_options(5)nng(7)
okay that's the whole page, you ate that fr fr π go forth and get those context options, and go use nng_ctx_get instead we BEG π«Ά
NNG Reference Manual Β· dated 2026-06-30 Β· bye bestie, drink some water ππ·
π¦ 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