From 2ddaecdadb8a931188b3f3e6b8ad43b9cba45d0f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 12 Jan 2025 14:43:31 -0800 Subject: api: extend usage of nng_err This replaces the int, and we will expand this further, as this makes it clear that the int is actually an error code and helps in debuggers that can provide symbolic values. --- tests/cplusplus_pair.cc | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/cplusplus_pair.cc b/tests/cplusplus_pair.cc index 1148aaae..4481a4d7 100644 --- a/tests/cplusplus_pair.cc +++ b/tests/cplusplus_pair.cc @@ -7,10 +7,11 @@ // found online at https://opensource.org/licenses/MIT. // -#include "nng/nng.h" - #include #include +#include + +#include #define SOCKET_ADDRESS "inproc://c++" @@ -22,58 +23,58 @@ main(int argc, char **argv) nng_socket s1; nng_socket s2; - int rv; + nng_err rv; size_t sz; char buf[8]; (void) argc; (void) argv; nng_init(NULL); - if ((rv = nng_pair1_open(&s1)) != 0) { + if ((rv = (nng_err) nng_pair1_open(&s1)) != 0) { throw nng_strerror(rv); } - if ((rv = nng_pair1_open(&s2)) != 0) { + if ((rv = (nng_err) nng_pair1_open(&s2)) != 0) { throw nng_strerror(rv); } - if ((rv = nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) { + if ((rv = (nng_err) nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) { throw nng_strerror(rv); } - if ((rv = nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) { + if ((rv = (nng_err) nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) { throw nng_strerror(rv); } - if ((rv = nng_send(s2, (void *) "ABC", 4, 0)) != 0) { + if ((rv = (nng_err) nng_send(s2, (void *) "ABC", 4, 0)) != 0) { throw nng_strerror(rv); } sz = sizeof(buf); - if ((rv = nng_recv(s1, buf, &sz, 0)) != 0) { + if ((rv = (nng_err) nng_recv(s1, buf, &sz, 0)) != 0) { throw nng_strerror(rv); } - if ((sz != 4) || (memcmp(buf, "ABC", 4) != 0)) { + if ((sz != 4) || (std::strcmp(buf, "ABC") != 0)) { throw "Contents did not match"; } - if ((rv = nng_send(s1, (void *) "DEF", 4, 0)) != 0) { + if ((rv = (nng_err) nng_send(s1, (void *) "DEF", 4, 0)) != 0) { throw nng_strerror(rv); } sz = sizeof(buf); - if ((rv = nng_recv(s2, buf, &sz, 0)) != 0) { + if ((rv = (nng_err) nng_recv(s2, buf, &sz, 0)) != 0) { throw nng_strerror(rv); } - if ((sz != 4) || (memcmp(buf, "DEF", 4) != 0)) { + if ((sz != 4) || (std::strcmp(buf, "DEF") != 0)) { throw "Contents did not match"; } - if ((rv = nng_socket_close(s1)) != 0) { + if ((rv = (nng_err) nng_socket_close(s1)) != 0) { throw nng_strerror(rv); } - if ((rv = nng_socket_close(s2)) != 0) { + if ((rv = (nng_err) nng_socket_close(s2)) != 0) { throw nng_strerror(rv); } - printf("Pass.\n"); + std::cout << "Pass." << std::endl; nng_fini(); #else (void) argc; (void) argv; - printf("Skipped (protocol unconfigured).\n"); + std::cout << "Skipped (protocol unconfigured)." << std::endl; #endif return (0); -- cgit v1.2.3-70-g09d2