From 08400bd437149c4fb31af9b2abece2ae44041283 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 11 May 2025 21:11:09 -0700 Subject: Add new nng_sockaddr_equal and nng_sockaddr_hash functions. These are intended for new transports. Right now they are not documented, but that will be addressed soon. --- include/nng/nng.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/nng/nng.h b/include/nng/nng.h index 89fae345..32605e3c 100644 --- a/include/nng/nng.h +++ b/include/nng/nng.h @@ -317,7 +317,20 @@ NNG_DECL const char *nng_str_sockaddr( // Obtain a port number (for NNG_AF_INET and NNG_AF_INET6this will be 16 bits // maximum, but other address familiies may have larger port numbers.) For // address that don't have the concept of port numbers, zero will be returned. -uint32_t nng_sockaddr_port(const nng_sockaddr *sa); +NNG_DECL uint32_t nng_sockaddr_port(const nng_sockaddr *sa); + +// Compare two socket addresses. Returns true if they are equal, false +// otherwise. +NNG_DECL bool nng_sockaddr_equal( + const nng_sockaddr *sa1, const nng_sockaddr *sa2); + +// Generate a quick non-zero 64-bit value for the sockaddr. +// This should usually be unique, but collisions are possible. +// The resulting hash is not portable between systems, and may not +// be portable from one version of NNG to the next. +// +// The intended use is to allow creation of an index for use with id maps. +NNG_DECL uint64_t nng_sockaddr_hash(const nng_sockaddr *sa); // Arguably the pipe callback functions could be handled as an option, // but with the need to specify an argument, we find it best to unify -- cgit v1.2.3-70-g09d2