NNG_SOCKET_GET(3)
π NNG_SOCKET_GET(3) β the NNG Reference Manual, but make it cute π
okay bestie, sit down, hydrate, and let me tell you about nng_socket_get. this is the page for the whole get family for sockets, and yes there's like eight of them, and no, you don't have to use all of them. she's giving "one job, many outfits." π
β¨ NAME β¨
nng_socket_get β get socket option. that's it. that's the whole job. you wanna read something off a socket, this is your girl. π«Ά
β¨ SYNOPSIS β¨
#include <nng/nng.h>
int nng_socket_get(nng_socket s, const char *opt, void *val, size_t *valszp);
int nng_socket_get_bool(nng_socket s, const char *opt, bool *bvalp);
int nng_socket_get_int(nng_socket s, const char *opt, int *ivalp);
int nng_socket_get_size(nng_socket s, const char *opt, size_t *zp);
int nng_socket_get_uint64(nng_socket s, const char *opt, uint64_t *u64p);
int nng_socket_get_string(nng_socket s, const char *opt, char **strp);
int nng_socket_get_ptr(nng_socket s, const char *opt, void **ptr);
int nng_socket_get_ms(nng_socket s, const char *opt, nng_duration *durp);
like. look at them. a whole little squad. π
β¨ DESCRIPTION β¨
so the nng_socket_get() functions are how you retrieve option values for the socket s. and which options can you retrieve this way? bestie. it varies. a whole bunch of them are documented over in nng_options(5), so go read that when you're done here.
also, protocol-specific options are documented with the protocols themselves β each protocol does its own thing, iykyk.
Important π¨ Access to transport options via this function is deprecated, and it may be removed from a future release. so like, it still works but it's on thin ice. Applications should instead make use ofnng_dialer_getornng_listener_getfor specific dialers or listeners. do the new thing, bestie, not the deprecated thing. π
πΈ Forms πΈ
in literally all of these forms, the option opt is retrieved from the socket s. the forms differ based on the type of the option they take. the details of the type, the size, and the semantics of the option all depend on the actual option, and they get documented with the option itself. no shortcuts, sorry. β¨
nng_socket_get()β this one is untyped, and it can retrieve the value of any option, periodt. you, the caller, must store 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 β is stored at the location referenced by valszp. β οΈ and here's the tea: if your buffer isn't big enough to hold the entire object, then the copy gets truncated. so you should check for truncation by verifying that the returned size in valszp does not exceed the original buffer size. don't get caught slippin'.
it is acceptable to pass NULL for val if the value in valszp is zero. this is genuinely useful β you can use it to figure out the size of the buffer you need to receive the object. chef's kiss. π
Tip π‘ it may be easier to use one of the typed forms of this function. no shade to the untyped one, she's just doing a lot.
nng_socket_get_bool()β for options that take a Boolean (bool). the value gets stored atbvalp. true or false, pick a lane. πnng_socket_get_int()β for options that take an integer (int). the value gets stored ativalp.nng_socket_get_ms()β this one retrieves time durations (think timeouts), stored indurpas a number of milliseconds. and two special values came to the party: the special valueNNG_DURATION_INFINITEmeans an infinite amount of time (forever, bestie, literally forever), and the special valueNNG_DURATION_DEFAULTmeans a context-specific default. β³nng_socket_get_ptr()β retrieves a pointer,ptr, to structured data. the data referenced byptris 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 copied. so you're holding a reference, not a lil souvenir copy. π¦nng_socket_get_size()β retrieves a size into the pointerzp, typically for buffer sizes, message maximum sizes, and similar options. size matters, and this is the one that tells you the size. πnng_socket_get_string()β retrieves a string intostrp. and listen closely: this string is created from the source usingnng_strdup(), and consequently it must be freed by the caller usingnng_strfree()when it is no longer needed. it's yours now. you have to take care of it. no leaving it lying around. πnng_socket_get_uint64()β retrieves a 64-bit unsigned value into the value referenced byu64p. this is typically used for options related to identifiers, network numbers, and similar. big number energy. β¨
β¨ RETURN VALUES β¨
these functions return 0 on success, and non-zero otherwise. that's the whole deal. π
β¨ ERRORS β¨
here's the receipts, bestie β every way this can go sideways:
NNG_EBADTYPEβ Incorrect type for option. you asked for the wrong flavor. πNNG_ECLOSEDβ Parametersdoes not refer to an open socket. she's closed, babes.NNG_EINVALβ Size of destinationvaltoo small for object. your buffer said "not today."NNG_ENOMEMβ Insufficient memory exists. the RAM said no. πNNG_ENOTSUPβ The optionoptis not supported. not a thing here, sorry.NNG_EWRITEONLYβ The optionoptis write-only. write-only means you can set it but you cannot get it. look, don't touch. π
β¨ SEE ALSO β¨
go read these next, they're all in the family:
nng_dialer_get(3), nng_listener_get(3), nng_pipe_get(3), nng_socket_set(3), nng_strdup(3), nng_strerror(3), nng_strfree(3), nng_duration(5), nng_options(5), nng_socket(5), nng(7)
and that's the page!! π«Ά this was the NNG_SOCKET_GET(3) manual, straight out of the NNG Reference Manual, dated 2026-06-30. slay, go read your socket options, and remember to nng_strfree() your strings. mwah. πβ¨π
π¦ 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