NNG_SOCKET_SET(3)

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

πŸ’– nng_socket_set β€” set socket option πŸ’–

okay so bestie, welcome to the NNG Reference Manual, page nng_socket_set(3) β€” yes that's the one, we're doing this πŸŽ€


✨ SYNOPSIS ✨

#include <nng/nng.h>

int nng_socket_set(nng_socket s, const char *opt, const void *val, size_t valsz);

int nng_socket_set_bool(nng_socket s, const char *opt, bool bval);

int nng_socket_set_int(nng_socket s, const char *opt, int ival);

int nng_socket_set_ms(nng_socket s, const char *opt, nng_duration dur);

int nng_socket_set_ptr(nng_socket s, const char *opt, void *ptr);

int nng_socket_set_size(nng_socket s, const char *opt, size_t z);

int nng_socket_set_string(nng_socket s, const char *opt, const char *str);

int nng_socket_set_uint64(nng_socket s, const char *opt, uint64_t u64);

🌸 DESCRIPTION 🌸

The nng_socket_set() functions are how you configure options on the socket s, bestie. Which options you can actually set this way? Depends!! It's all decided by opt, and a whole bunch of them are documented over in nng_options(5) πŸ’…

Protocol-specific options get documented with the protocol in question, so check there for those ones.

Important 🚨 Access to transport options through this function is deprecated, and it may be removed from a future release. Instead, applications should use nng_dialer_get or nng_listener_get for specific dialers or listeners. So like… use the new ones, okay? 🫢

πŸ¦‹ Forms πŸ¦‹

The type, size, and semantics of the option all depend on the actual option you're setting, and they're documented with that option itself, so no guessing πŸ’€

  • nng_socket_set() β€” this one is untyped and can be used to configure literally any arbitrary data. The val pointer addresses the data to copy, and valsz is the size of the object located at val.
Tip ✨ It may be easier to use one of the typed forms of this function. fr fr.
  • nng_socket_set_bool() β€” for options that take a Boolean (bool). The bval is passed to the option.
  • nng_socket_set_int() β€” for options that take an integer (int). The ival is passed to the option.
  • nng_socket_set_ms() β€” this is the one for configuring time durations (timeouts and friends) using type nng_duration. The duration dur is an integer number of milliseconds, periodt.
  • nng_socket_set_ptr() β€” passes a pointer, ptr, to structured data. The data referenced by ptr is generally managed by other functions. Like, for example, TLS configuration objects created with (nng_tls_config_alloc()) can be passed this way πŸ‘‘
Note This form is kinda special β€” the object is generally not copied, instead the pointer to the object is copied. iykyk πŸ™ˆ
  • nng_socket_set_size() β€” configures a size, z. Typically for buffer sizes, message maximum sizes, and similar options πŸ“
  • nng_socket_set_string() β€” configures a string, str. Strings passed this way must be legal UTF-8 or ASCII strings, terminated with a NUL (\0) byte. (Other constraints may apply too β€” see the documentation for each option for details, bestie.)
  • nng_socket_set_uint64() β€” configures a 64-bit unsigned value, u64. Typically used for options related to identifiers, network numbers, and similar πŸ”’

πŸ’– RETURN VALUES πŸ’–

These functions return 0 on success, and non-zero otherwise. slay ✨


πŸ’… ERRORS πŸ’…

  • NNG_ECLOSED β€” parameter s does not refer to an open socket. πŸ’€
  • NNG_EINVAL β€” the value being passed is invalid.
  • NNG_ENOTSUP β€” the option opt is not supported.
  • NNG_EREADONLY β€” the option opt is read-only. sad 😭
  • NNG_ESTATE β€” the socket is in an inappropriate state for setting this option.

🫢 SEE ALSO 🫢

nng_socket_get(3), nng_dialer_set(3), nng_listener_set(3), nng_strerror(3), nng_options(5), nng_socket(5), nng(7)


okay that's the whole page bestie, you ate that πŸŽ€ this was NNG_SOCKET_SET(3) from the NNG Reference Manual, dated 2026-06-30 β€” go set some options, main character πŸŒˆβœ¨πŸ’œ

πŸ“¦ where this page comes from