NNG_CTX_GETOPT(3)

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

🌸 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 at nng_ctx_get instead. And lowkey they might not even exist if the library was built with NNG_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 at ivalp.
  • nng_ctx_getopt_int() β€” this function is for options which take an integer (int). The value will be stored at ivalp.
  • nng_ctx_getopt_ms() β€” this one retrieves time durations (like 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.) iconic ✨
  • nng_ctx_getopt_size() β€” this one retrieves a size into the pointer zp, typically for buffer sizes, message maximum sizes, and similar options πŸ¦‹
  • nng_ctx_getopt_string() β€” this one 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 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 by u64p. 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 β€” parameter s does not refer to an open socket.
  • NNG_EINVAL β€” size of destination val too small for object.
  • NNG_ENOMEM β€” insufficient memory exists.
  • NNG_ENOTSUP β€” the option opt is not supported.
  • NNG_EWRITEONLY β€” the option opt is write-only. yeah bestie, some of them only take, they don't give πŸ’€

✨ SEE ALSO ✨


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