aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-01-01 17:06:39 -0800
committerGarrett D'Amore <garrett@damore.org>2025-01-01 17:06:39 -0800
commitf7bf24f429cbc488b861ab1b1e4cf1983af56295 (patch)
tree2196361a906bd5db1148c0e177d69854a99b7b58 /src/core
parentee5c8437f8c2a811c0eaef9b00c149b93c095391 (diff)
downloadnng-f7bf24f429cbc488b861ab1b1e4cf1983af56295.tar.gz
nng-f7bf24f429cbc488b861ab1b1e4cf1983af56295.tar.bz2
nng-f7bf24f429cbc488b861ab1b1e4cf1983af56295.zip
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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/sock_test.c24
1 files changed, 11 insertions, 13 deletions
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);