From f7bf24f429cbc488b861ab1b1e4cf1983af56295 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 1 Jan 2025 17:06:39 -0800 Subject: api: Remove the NNG_FLAG_ALLOC This flag failed to provide real zero copy that it was intended for, and it also involved extra allocations. Further, the API for it was brittle and error prone. Modern code should just work directly with nng_msg structures. --- src/core/sock_test.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/core') diff --git a/src/core/sock_test.c b/src/core/sock_test.c index e311634d..f6f1bd7d 100644 --- a/src/core/sock_test.c +++ b/src/core/sock_test.c @@ -102,8 +102,8 @@ test_send_recv(void) int len; size_t sz; nng_duration to = 3000; // 3 seconds - char *buf; - char *a = "inproc://t1"; + char *a = "inproc://t1"; + char rxbuf[32]; NUTS_OPEN(s1); NUTS_OPEN(s2); @@ -124,11 +124,10 @@ test_send_recv(void) NUTS_PASS(nng_dial(s2, a, NULL, 0)); NUTS_PASS(nng_send(s1, "abc", 4, 0)); - NUTS_PASS(nng_recv(s2, &buf, &sz, NNG_FLAG_ALLOC)); - NUTS_TRUE(buf != NULL); + sz = sizeof(rxbuf); + NUTS_PASS(nng_recv(s2, rxbuf, &sz, 0)); NUTS_TRUE(sz == 4); - NUTS_TRUE(memcmp(buf, "abc", 4) == 0); - nng_free(buf, sz); + NUTS_TRUE(memcmp(rxbuf, "abc", 4) == 0); NUTS_CLOSE(s1); NUTS_CLOSE(s2); @@ -142,7 +141,7 @@ test_send_recv_zero_length(void) int len; size_t sz; nng_duration to = 3000; // 3 seconds - char *buf; + char buf[32]; char *a = "inproc://send-recv-zero-length"; NUTS_OPEN(s1); @@ -164,10 +163,9 @@ test_send_recv_zero_length(void) NUTS_PASS(nng_dial(s2, a, NULL, 0)); NUTS_PASS(nng_send(s1, "", 0, 0)); - NUTS_PASS(nng_recv(s2, &buf, &sz, NNG_FLAG_ALLOC)); - NUTS_TRUE(buf == NULL); + sz = sizeof(buf); + NUTS_PASS(nng_recv(s2, buf, &sz, 0)); NUTS_TRUE(sz == 0); - nng_free(buf, sz); NUTS_CLOSE(s1); NUTS_CLOSE(s2); @@ -186,7 +184,7 @@ test_connection_refused(void) void test_late_connection(void) { - char *buf; + char buf[32]; size_t sz; nng_socket s1; nng_socket s2; @@ -202,10 +200,10 @@ test_late_connection(void) NUTS_PASS(nng_listen(s2, a, NULL, 0)); nng_msleep(100); NUTS_PASS(nng_send(s1, "abc", 4, 0)); - NUTS_PASS(nng_recv(s2, &buf, &sz, NNG_FLAG_ALLOC)); + sz = sizeof(buf); + NUTS_PASS(nng_recv(s2, &buf, &sz, 0)); NUTS_TRUE(sz == 4); NUTS_TRUE(memcmp(buf, "abc", 4) == 0); - nng_free(buf, sz); NUTS_CLOSE(s1); NUTS_CLOSE(s2); -- cgit v1.2.3-70-g09d2