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/sp/nonblock_test.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/sp') diff --git a/src/sp/nonblock_test.c b/src/sp/nonblock_test.c index 7b2251c4..c06fa64d 100644 --- a/src/sp/nonblock_test.c +++ b/src/sp/nonblock_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -46,8 +46,7 @@ repthr(void *arg) for (;;) { fd_set fset; struct timeval tmo; - char *msgbuf; - size_t msglen; + nng_msg *msg; FD_ZERO(&fset); FD_SET(fd, &fset); @@ -59,14 +58,13 @@ repthr(void *arg) for (;;) { int rv; - rv = nng_recv(rep, &msgbuf, &msglen, - NNG_FLAG_NONBLOCK | NNG_FLAG_ALLOC); + rv = nng_recvmsg(rep, &msg, NNG_FLAG_NONBLOCK); if (rv != 0) { return; } - nng_free(msgbuf, msglen); - int ok = 0; - rv = nng_send(rep, &ok, 4, NNG_FLAG_NONBLOCK); + nng_msg_clear(msg); + nng_msg_append_u32(msg, 0); + rv = nng_sendmsg(rep, msg, NNG_FLAG_NONBLOCK); if (rv == NNG_ECLOSED) { return; } -- cgit v1.2.3-70-g09d2