diff options
| author | Garrett D'Amore <garrett@damore.org> | 2025-01-01 12:44:02 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2025-01-01 12:44:02 -0800 |
| commit | 0d23af92531b7c0dd6d7b74c73c1a8c4811c7d13 (patch) | |
| tree | 2dc9ded3dfc724df42a360a9f2de359f406e537f /src | |
| parent | f8a2abaf931557030fd6e6683617c6a7877eebf7 (diff) | |
| download | nng-0d23af92531b7c0dd6d7b74c73c1a8c4811c7d13.tar.gz nng-0d23af92531b7c0dd6d7b74c73c1a8c4811c7d13.tar.bz2 nng-0d23af92531b7c0dd6d7b74c73c1a8c4811c7d13.zip | |
protocols: move content from the protocols to nng.h
This should simplify things for developers. Just one header to include
in most cases now.
Diffstat (limited to 'src')
34 files changed, 220 insertions, 193 deletions
diff --git a/src/sp/pipe_test.c b/src/sp/pipe_test.c index c0219813..7a50c133 100644 --- a/src/sp/pipe_test.c +++ b/src/sp/pipe_test.c @@ -113,8 +113,8 @@ init_cases(char *addr, struct testcase *push, struct testcase *pull) NUTS_PASS(nng_mtx_alloc(&pull->lk)); NUTS_PASS(nng_cv_alloc(&pull->cv, pull->lk)); - NUTS_PASS(nng_push_open(&push->s)); - NUTS_PASS(nng_pull_open(&pull->s)); + NUTS_PASS(nng_push0_open(&push->s)); + NUTS_PASS(nng_pull0_open(&pull->s)); NUTS_PASS(nng_socket_set_ms(push->s, NNG_OPT_RECONNMINT, 10)); NUTS_PASS(nng_socket_set_ms(push->s, NNG_OPT_RECONNMAXT, 10)); diff --git a/src/sp/protocol/bus0/bus.c b/src/sp/protocol/bus0/bus.c index 4822ffd6..99c3a9bf 100644 --- a/src/sp/protocol/bus0/bus.c +++ b/src/sp/protocol/bus0/bus.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -12,7 +12,6 @@ #include <stdlib.h> #include "core/nng_impl.h" -#include "nng/protocol/bus0/bus.h" #include <stdio.h> // Bus protocol. The BUS protocol, each peer sends a message to its peers. diff --git a/src/sp/protocol/bus0/bus_test.c b/src/sp/protocol/bus0/bus_test.c index fd0116e7..55231770 100644 --- a/src/sp/protocol/bus0/bus_test.c +++ b/src/sp/protocol/bus0/bus_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -14,6 +14,11 @@ #define SECOND 1000 +#define BUS0_SELF 0x70 +#define BUS0_PEER 0x70 +#define BUS0_SELF_NAME "bus" +#define BUS0_PEER_NAME "bus" + void test_bus_identity(void) { @@ -23,13 +28,13 @@ test_bus_identity(void) NUTS_PASS(nng_bus0_open(&s)); NUTS_PASS(nng_socket_proto_id(s, &p)); - NUTS_TRUE(p == NNG_BUS0_SELF); + NUTS_TRUE(p == BUS0_SELF); NUTS_PASS(nng_socket_peer_id(s, &p)); - NUTS_TRUE(p == NNG_BUS0_PEER); // 49 + NUTS_TRUE(p == BUS0_PEER); // 49 NUTS_PASS(nng_socket_proto_name(s, &n)); - NUTS_MATCH(n, NNG_BUS0_SELF_NAME); + NUTS_MATCH(n, BUS0_SELF_NAME); NUTS_PASS(nng_socket_peer_name(s, &n)); - NUTS_MATCH(n, NNG_BUS0_PEER_NAME); + NUTS_MATCH(n, BUS0_PEER_NAME); NUTS_CLOSE(s); } diff --git a/src/sp/protocol/pair0/pair.c b/src/sp/protocol/pair0/pair.c index face19bc..e577738b 100644 --- a/src/sp/protocol/pair0/pair.c +++ b/src/sp/protocol/pair0/pair.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -12,7 +12,6 @@ #include "core/nng_impl.h" #include "core/pipe.h" -#include "nng/protocol/pair0/pair.h" // Pair protocol. The PAIR protocol is a simple 1:1 messaging pattern. // While a peer is connected to the server, all other peer connection diff --git a/src/sp/protocol/pair1/pair.c b/src/sp/protocol/pair1/pair.c index b7e40f9d..65ee66ad 100644 --- a/src/sp/protocol/pair1/pair.c +++ b/src/sp/protocol/pair1/pair.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,6 @@ #include <stdlib.h> #include "core/nng_impl.h" -#include "nng/protocol/pair1/pair.h" // Pair protocol. The PAIRv1 protocol is a simple 1:1 messaging pattern. @@ -21,6 +20,11 @@ #define BUMP_STAT(x) #endif +#define PAIR1_SELF_NAME "pair1" +#define PAIR1_PEER_NAME "pair1" +#define PAIR1_SELF 0x11 +#define PAIR1_PEER 0x11 + typedef struct pair1_pipe pair1_pipe; typedef struct pair1_sock pair1_sock; @@ -262,12 +266,12 @@ pair1_pipe_start(void *arg) pair1_pipe *p = arg; pair1_sock *s = p->pair; - if (nni_pipe_peer(p->pipe) != NNG_PAIR1_PEER) { + if (nni_pipe_peer(p->pipe) != PAIR1_PEER) { BUMP_STAT(&s->stat_reject_mismatch); // Peer protocol mismatch. nng_log_warn("NNG-PEER-MISMATCH", "Peer protocol mismatch: %d != %d, rejected.", - nni_pipe_peer(p->pipe), NNG_PAIR1_PEER); + nni_pipe_peer(p->pipe), PAIR1_PEER); return (NNG_EPROTO); } @@ -782,8 +786,8 @@ static nni_proto_sock_ops pair1_sock_ops = { static nni_proto pair1_proto = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_PAIR1_SELF, NNG_PAIR1_SELF_NAME }, - .proto_peer = { NNG_PAIR1_PEER, NNG_PAIR1_PEER_NAME }, + .proto_self = { PAIR1_SELF, PAIR1_SELF_NAME }, + .proto_peer = { PAIR1_PEER, PAIR1_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV, .proto_sock_ops = &pair1_sock_ops, .proto_pipe_ops = &pair1_pipe_ops, @@ -810,8 +814,8 @@ static nni_proto_sock_ops pair1_sock_ops_raw = { static nni_proto pair1_proto_raw = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_PAIR1_SELF, NNG_PAIR1_SELF_NAME }, - .proto_peer = { NNG_PAIR1_PEER, NNG_PAIR1_PEER_NAME }, + .proto_self = { PAIR1_SELF, PAIR1_SELF_NAME }, + .proto_peer = { PAIR1_PEER, PAIR1_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, .proto_sock_ops = &pair1_sock_ops_raw, .proto_pipe_ops = &pair1_pipe_ops, diff --git a/src/sp/protocol/pair1/pair1_poly.c b/src/sp/protocol/pair1/pair1_poly.c index 546d3138..0e8a93f3 100644 --- a/src/sp/protocol/pair1/pair1_poly.c +++ b/src/sp/protocol/pair1/pair1_poly.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,11 @@ #include <stdlib.h> #include "core/nng_impl.h" -#include "nng/protocol/pair1/pair.h" + +#define PAIR1_SELF_NAME "pair1" +#define PAIR1_PEER_NAME "pair1" +#define PAIR1_SELF 0x11 +#define PAIR1_PEER 0x11 // Pair1 poly-amorous mode. The PAIRv1 protocol is normally a simple 1:1 // messaging pattern, but this mode offers the ability to use a best-effort @@ -229,13 +233,13 @@ pair1poly_pipe_start(void *arg) int rv; nni_mtx_lock(&s->mtx); - if (nni_pipe_peer(p->pipe) != NNG_PAIR1_PEER) { + if (nni_pipe_peer(p->pipe) != PAIR1_PEER) { // Peer protocol mismatch. nni_mtx_unlock(&s->mtx); BUMP_STAT(&s->stat_reject_mismatch); nng_log_warn("NNG-PEER-MISMATCH", "Peer protocol mismatch: %d != %d, rejected.", - nni_pipe_peer(p->pipe), NNG_PAIR1_PEER); + nni_pipe_peer(p->pipe), PAIR1_PEER); return (NNG_EPROTO); } @@ -522,8 +526,8 @@ static nni_proto_sock_ops pair1poly_sock_ops = { static nni_proto pair1poly_proto = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_PAIR1_SELF, NNG_PAIR1_SELF_NAME }, - .proto_peer = { NNG_PAIR1_PEER, NNG_PAIR1_PEER_NAME }, + .proto_self = { PAIR1_SELF, PAIR1_SELF_NAME }, + .proto_peer = { PAIR1_PEER, PAIR1_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV, .proto_sock_ops = &pair1poly_sock_ops, .proto_pipe_ops = &pair1poly_pipe_ops, diff --git a/src/sp/protocol/pipeline0/pull.c b/src/sp/protocol/pipeline0/pull.c index 89981b29..64438304 100644 --- a/src/sp/protocol/pipeline0/pull.c +++ b/src/sp/protocol/pipeline0/pull.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,6 @@ #include <stdlib.h> #include "core/nng_impl.h" -#include "nng/protocol/pipeline0/pull.h" // Pull protocol. The PULL protocol is the "read" side of a pipeline. diff --git a/src/sp/protocol/pipeline0/push.c b/src/sp/protocol/pipeline0/push.c index bac3f984..4cf14a6e 100644 --- a/src/sp/protocol/pipeline0/push.c +++ b/src/sp/protocol/pipeline0/push.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,6 @@ #include <stdlib.h> #include "core/nng_impl.h" -#include "nng/protocol/pipeline0/push.h" // Push protocol. The PUSH protocol is the "write" side of a pipeline. // Push distributes fairly, or tries to, by giving messages in round-robin diff --git a/src/sp/protocol/pubsub0/pub.c b/src/sp/protocol/pubsub0/pub.c index 371782a0..db449cde 100644 --- a/src/sp/protocol/pubsub0/pub.c +++ b/src/sp/protocol/pubsub0/pub.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,6 @@ #include <string.h> #include "core/nng_impl.h" -#include "nng/protocol/pubsub0/pub.h" // Publish protocol. The PUB protocol simply sends messages out, as // a broadcast. It has nothing more sophisticated because it does not diff --git a/src/sp/protocol/pubsub0/sub.c b/src/sp/protocol/pubsub0/sub.c index a4778555..97324571 100644 --- a/src/sp/protocol/pubsub0/sub.c +++ b/src/sp/protocol/pubsub0/sub.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // Copyright 2019 Nathan Kent <nate@nkent.net> // @@ -13,8 +13,6 @@ #include <string.h> #include "core/nng_impl.h" -#include "core/socket.h" -#include "nng/protocol/pubsub0/sub.h" // Subscriber protocol. The SUB protocol receives messages sent to // it from publishers, and filters out those it is not interested in, diff --git a/src/sp/protocol/pubsub0/xsub.c b/src/sp/protocol/pubsub0/xsub.c index abcdf8c9..cb2a5362 100644 --- a/src/sp/protocol/pubsub0/xsub.c +++ b/src/sp/protocol/pubsub0/xsub.c @@ -11,7 +11,6 @@ #include <stdlib.h> #include "core/nng_impl.h" -#include "nng/protocol/pubsub0/sub.h" // Subscriber protocol. The SUB protocol receives messages sent to // it from publishers, and filters out those it is not interested in, diff --git a/src/sp/protocol/reqrep0/rep.c b/src/sp/protocol/reqrep0/rep.c index 7a29ee68..4a30e967 100644 --- a/src/sp/protocol/reqrep0/rep.c +++ b/src/sp/protocol/reqrep0/rep.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,6 @@ #include <string.h> #include "core/nng_impl.h" -#include "nng/protocol/reqrep0/rep.h" // Response protocol. The REP protocol is the "reply" side of a // request-reply pair. This is useful for building RPC servers, for @@ -21,6 +20,11 @@ typedef struct rep0_pipe rep0_pipe; typedef struct rep0_sock rep0_sock; typedef struct rep0_ctx rep0_ctx; +#define REP0_SELF 0x31 +#define REP0_PEER 0x30 +#define REP0_SELF_NAME "rep" +#define REP0_PEER_NAME "req" + static void rep0_pipe_send_cb(void *); static void rep0_pipe_recv_cb(void *); static void rep0_pipe_fini(void *); @@ -293,11 +297,11 @@ rep0_pipe_start(void *arg) rep0_sock *s = p->rep; int rv; - if (nni_pipe_peer(p->pipe) != NNG_REP0_PEER) { + if (nni_pipe_peer(p->pipe) != REP0_PEER) { // Peer protocol mismatch. nng_log_warn("NNG-PEER-MISMATCH", "Peer protocol mismatch: %d != %d, rejected.", - nni_pipe_peer(p->pipe), NNG_REP0_PEER); + nni_pipe_peer(p->pipe), REP0_PEER); return (NNG_EPROTO); } @@ -662,8 +666,8 @@ static nni_proto_sock_ops rep0_sock_ops = { static nni_proto rep0_proto = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_REP0_SELF, NNG_REP0_SELF_NAME }, - .proto_peer = { NNG_REP0_PEER, NNG_REP0_PEER_NAME }, + .proto_self = { REP0_SELF, REP0_SELF_NAME }, + .proto_peer = { REP0_PEER, REP0_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV, .proto_sock_ops = &rep0_sock_ops, .proto_pipe_ops = &rep0_pipe_ops, diff --git a/src/sp/protocol/reqrep0/rep_test.c b/src/sp/protocol/reqrep0/rep_test.c index 2a07ecbc..29c5ee4c 100644 --- a/src/sp/protocol/reqrep0/rep_test.c +++ b/src/sp/protocol/reqrep0/rep_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -10,6 +10,11 @@ #include "nng/nng.h" #include <nuts.h> +#define REP0_SELF 0x31 +#define REP0_PEER 0x30 +#define REP0_SELF_NAME "rep" +#define REP0_PEER_NAME "req" + static void test_rep_identity(void) { @@ -24,10 +29,10 @@ test_rep_identity(void) NUTS_PASS(nng_socket_proto_name(s, &n1)); NUTS_PASS(nng_socket_peer_name(s, &n2)); NUTS_CLOSE(s); - NUTS_TRUE(p1 == NNG_REP0_SELF); - NUTS_TRUE(p2 == NNG_REP0_PEER); - NUTS_MATCH(n1, NNG_REP0_SELF_NAME); - NUTS_MATCH(n2, NNG_REP0_PEER_NAME); + NUTS_TRUE(p1 == REP0_SELF); + NUTS_TRUE(p2 == REP0_PEER); + NUTS_MATCH(n1, REP0_SELF_NAME); + NUTS_MATCH(n2, REP0_PEER_NAME); } void @@ -179,8 +184,8 @@ test_rep_huge_send(void) nng_msg *d; nng_aio *aio; - NUTS_PASS(nng_rep_open(&rep)); - NUTS_PASS(nng_req_open(&req)); + NUTS_PASS(nng_rep0_open(&rep)); + NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_socket_set_ms(rep, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(req, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(rep, NNG_OPT_SENDTIMEO, 1000)); @@ -234,8 +239,8 @@ test_rep_huge_send_socket(void) nng_msg *d; nng_aio *aio; - NUTS_PASS(nng_rep_open(&rep)); - NUTS_PASS(nng_req_open(&req)); + NUTS_PASS(nng_rep0_open(&rep)); + NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_socket_set_ms(rep, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(req, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(rep, NNG_OPT_SENDTIMEO, 1000)); diff --git a/src/sp/protocol/reqrep0/req.c b/src/sp/protocol/reqrep0/req.c index 67407ff0..0a10462a 100644 --- a/src/sp/protocol/reqrep0/req.c +++ b/src/sp/protocol/reqrep0/req.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -10,11 +10,15 @@ #include <stdio.h> #include "core/nng_impl.h" -#include "nng/protocol/reqrep0/req.h" // Request protocol. The REQ protocol is the "request" side of a // request-reply pair. This is useful for building RPC clients, for example. +#define REQ0_SELF 0x30 +#define REQ0_PEER 0x31 +#define REQ0_SELF_NAME "req" +#define REQ0_PEER_NAME "rep" + typedef struct req0_pipe req0_pipe; typedef struct req0_sock req0_sock; typedef struct req0_ctx req0_ctx; @@ -196,10 +200,10 @@ req0_pipe_start(void *arg) req0_pipe *p = arg; req0_sock *s = p->req; - if (nni_pipe_peer(p->pipe) != NNG_REQ0_PEER) { + if (nni_pipe_peer(p->pipe) != REQ0_PEER) { nng_log_warn("NNG-PEER-MISMATCH", "Peer protocol mismatch: %d != %d, rejected.", - nni_pipe_peer(p->pipe), NNG_REQ0_PEER); + nni_pipe_peer(p->pipe), REQ0_PEER); return (NNG_EPROTO); } @@ -911,8 +915,8 @@ static nni_proto_sock_ops req0_sock_ops = { static nni_proto req0_proto = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_REQ0_SELF, NNG_REQ0_SELF_NAME }, - .proto_peer = { NNG_REQ0_PEER, NNG_REQ0_PEER_NAME }, + .proto_self = { REQ0_SELF, REQ0_SELF_NAME }, + .proto_peer = { REQ0_PEER, REQ0_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV, .proto_sock_ops = &req0_sock_ops, .proto_pipe_ops = &req0_pipe_ops, diff --git a/src/sp/protocol/reqrep0/req_test.c b/src/sp/protocol/reqrep0/req_test.c index d4dc8c27..13bab6ec 100644 --- a/src/sp/protocol/reqrep0/req_test.c +++ b/src/sp/protocol/reqrep0/req_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,6 +11,11 @@ #include "nng/nng.h" #include <nuts.h> +#define REQ0_SELF 0x30 +#define REQ0_PEER 0x31 +#define REQ0_SELF_NAME "req" +#define REQ0_PEER_NAME "rep" + static void test_req_identity(void) { @@ -20,13 +25,13 @@ test_req_identity(void) NUTS_PASS(nng_req0_open(&s)); NUTS_PASS(nng_socket_proto_id(s, &p)); - NUTS_TRUE(p == NNG_REQ0_SELF); + NUTS_TRUE(p == REQ0_SELF); NUTS_PASS(nng_socket_peer_id(s, &p)); - NUTS_TRUE(p == NNG_REQ0_PEER); // 49 + NUTS_TRUE(p == REQ0_PEER); // 49 NUTS_PASS(nng_socket_proto_name(s, &n)); - NUTS_MATCH(n, NNG_REQ0_SELF_NAME); + NUTS_MATCH(n, REQ0_SELF_NAME); NUTS_PASS(nng_socket_peer_name(s, &n)); - NUTS_MATCH(n, NNG_REQ0_PEER_NAME); + NUTS_MATCH(n, REQ0_PEER_NAME); NUTS_CLOSE(s); } @@ -354,8 +359,8 @@ test_req_cancel(void) nng_socket req; nng_socket rep; - NUTS_PASS(nng_rep_open(&rep)); - NUTS_PASS(nng_req_open(&req)); + NUTS_PASS(nng_rep0_open(&rep)); + NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_socket_set_ms(req, NNG_OPT_RECVTIMEO, SECOND)); NUTS_PASS(nng_socket_set_ms(rep, NNG_OPT_RECVTIMEO, SECOND)); @@ -408,8 +413,8 @@ test_req_cancel_abort_recv(void) nng_socket req; nng_socket rep; - NUTS_PASS(nng_rep_open(&rep)); - NUTS_PASS(nng_req_open(&req)); + NUTS_PASS(nng_rep0_open(&rep)); + NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); NUTS_PASS(nng_socket_set_ms(req, NNG_OPT_REQ_RESENDTIME, retry)); diff --git a/src/sp/protocol/reqrep0/reqstress_test.c b/src/sp/protocol/reqrep0/reqstress_test.c index fd964003..9c0861d8 100644 --- a/src/sp/protocol/reqrep0/reqstress_test.c +++ b/src/sp/protocol/reqrep0/reqstress_test.c @@ -13,9 +13,6 @@ #include <time.h> #include <nng/nng.h> -#include <nng/protocol/bus0/bus.h> -#include <nng/protocol/reqrep0/rep.h> -#include <nng/protocol/reqrep0/req.h> #include <nuts.h> diff --git a/src/sp/protocol/reqrep0/xrep.c b/src/sp/protocol/reqrep0/xrep.c index 7e259dfc..1a5f6e24 100644 --- a/src/sp/protocol/reqrep0/xrep.c +++ b/src/sp/protocol/reqrep0/xrep.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,11 @@ #include <string.h> #include "core/nng_impl.h" -#include "nng/protocol/reqrep0/rep.h" + +#define REP0_SELF 0x31 +#define REP0_PEER 0x30 +#define REP0_SELF_NAME "rep" +#define REP0_PEER_NAME "req" // Response protocol in raw mode. The REP protocol is the "reply" side of a // request-reply pair. This is useful for building RPC servers, for @@ -153,11 +157,11 @@ xrep0_pipe_start(void *arg) xrep0_sock *s = p->rep; int rv; - if (nni_pipe_peer(p->pipe) != NNG_REP0_PEER) { + if (nni_pipe_peer(p->pipe) != REP0_PEER) { // Peer protocol mismatch. nng_log_warn("NNG-PEER-MISMATCH", "Peer protocol mismatch: %d != %d, rejected.", - nni_pipe_peer(p->pipe), NNG_REP0_PEER); + nni_pipe_peer(p->pipe), REP0_PEER); return (NNG_EPROTO); } @@ -420,8 +424,8 @@ static nni_proto_sock_ops xrep0_sock_ops = { static nni_proto xrep0_proto = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_REP0_SELF, NNG_REP0_SELF_NAME }, - .proto_peer = { NNG_REP0_PEER, NNG_REP0_PEER_NAME }, + .proto_self = { REP0_SELF, REP0_SELF_NAME }, + .proto_peer = { REP0_PEER, REP0_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, .proto_sock_ops = &xrep0_sock_ops, .proto_pipe_ops = &xrep0_pipe_ops, diff --git a/src/sp/protocol/reqrep0/xrep_test.c b/src/sp/protocol/reqrep0/xrep_test.c index e3ba0f94..a00f78f7 100644 --- a/src/sp/protocol/reqrep0/xrep_test.c +++ b/src/sp/protocol/reqrep0/xrep_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -10,6 +10,11 @@ #include "nng/nng.h" #include <nuts.h> +#define REP0_SELF 0x31 +#define REP0_PEER 0x30 +#define REP0_SELF_NAME "rep" +#define REP0_PEER_NAME "req" + static void test_xrep_identity(void) { @@ -24,10 +29,10 @@ test_xrep_identity(void) NUTS_PASS(nng_socket_proto_name(s, &n1)); NUTS_PASS(nng_socket_peer_name(s, &n2)); NUTS_CLOSE(s); - NUTS_TRUE(p1 == NNG_REP0_SELF); - NUTS_TRUE(p2 == NNG_REP0_PEER); - NUTS_MATCH(n1, NNG_REP0_SELF_NAME); - NUTS_MATCH(n2, NNG_REP0_PEER_NAME); + NUTS_TRUE(p1 == REP0_SELF); + NUTS_TRUE(p2 == REP0_PEER); + NUTS_MATCH(n1, REP0_SELF_NAME); + NUTS_MATCH(n2, REP0_PEER_NAME); } static void diff --git a/src/sp/protocol/reqrep0/xreq.c b/src/sp/protocol/reqrep0/xreq.c index b0ff301b..2bf3b95e 100644 --- a/src/sp/protocol/reqrep0/xreq.c +++ b/src/sp/protocol/reqrep0/xreq.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,11 @@ #include <stdio.h> #include "core/nng_impl.h" -#include "nng/protocol/reqrep0/req.h" + +#define REQ0_SELF 0x30 +#define REQ0_PEER 0x31 +#define REQ0_SELF_NAME "req" +#define REQ0_PEER_NAME "rep" // Request protocol. The REQ protocol is the "request" side of a // request-reply pair. This is useful for building RPC clients, for example. @@ -114,10 +118,10 @@ xreq0_pipe_start(void *arg) xreq0_pipe *p = arg; xreq0_sock *s = p->req; - if (nni_pipe_peer(p->pipe) != NNG_REQ0_PEER) { + if (nni_pipe_peer(p->pipe) != REQ0_PEER) { nng_log_warn("NNG-PEER-MISMATCH", "Peer protocol mismatch: %d != %d, rejected.", - nni_pipe_peer(p->pipe), NNG_REQ0_PEER); + nni_pipe_peer(p->pipe), REQ0_PEER); return (NNG_EPROTO); } @@ -305,8 +309,8 @@ static nni_proto_sock_ops xreq0_sock_ops = { static nni_proto xreq0_proto = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_REQ0_SELF, NNG_REQ0_SELF_NAME }, - .proto_peer = { NNG_REQ0_PEER, NNG_REQ0_PEER_NAME }, + .proto_self = { REQ0_SELF, REQ0_SELF_NAME }, + .proto_peer = { REQ0_PEER, REQ0_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, .proto_sock_ops = &xreq0_sock_ops, .proto_pipe_ops = &xreq0_pipe_ops, diff --git a/src/sp/protocol/reqrep0/xreq_test.c b/src/sp/protocol/reqrep0/xreq_test.c index b51de556..28c79a26 100644 --- a/src/sp/protocol/reqrep0/xreq_test.c +++ b/src/sp/protocol/reqrep0/xreq_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -10,6 +10,11 @@ #include "nng/nng.h" #include <nuts.h> +#define REQ0_SELF 0x30 +#define REQ0_PEER 0x31 +#define REQ0_SELF_NAME "req" +#define REQ0_PEER_NAME "rep" + static void test_xreq_identity(void) { @@ -24,10 +29,10 @@ test_xreq_identity(void) NUTS_PASS(nng_socket_proto_name(s, &n1)); NUTS_PASS(nng_socket_peer_name(s, &n2)); NUTS_CLOSE(s); - NUTS_TRUE(p1 == NNG_REQ0_SELF); - NUTS_TRUE(p2 == NNG_REQ0_PEER); - NUTS_MATCH(n1, NNG_REQ0_SELF_NAME); - NUTS_MATCH(n2, NNG_REQ0_PEER_NAME); + NUTS_TRUE(p1 == REQ0_SELF); + NUTS_TRUE(p2 == REQ0_PEER); + NUTS_MATCH(n1, REQ0_SELF_NAME); + NUTS_MATCH(n2, REQ0_PEER_NAME); } static void diff --git a/src/sp/protocol/survey0/respond.c b/src/sp/protocol/survey0/respond.c index fd1c5601..a7cdf132 100644 --- a/src/sp/protocol/survey0/respond.c +++ b/src/sp/protocol/survey0/respond.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -12,7 +12,6 @@ #include <string.h> #include "core/nng_impl.h" -#include "nng/protocol/survey0/respond.h" // Respondent protocol. The RESPONDENT protocol is the "replier" side of // the surveyor pattern. This is useful for building service discovery, or diff --git a/src/sp/protocol/survey0/respond_test.c b/src/sp/protocol/survey0/respond_test.c index ad8f7e60..0725efb7 100644 --- a/src/sp/protocol/survey0/respond_test.c +++ b/src/sp/protocol/survey0/respond_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -10,6 +10,11 @@ #include "nng/nng.h" #include <nuts.h> +#define RESPONDENT0_SELF 0x63 +#define RESPONDENT0_PEER 0x62 +#define RESPONDENT0_SELF_NAME "respondent" +#define RESPONDENT0_PEER_NAME "surveyor" + void test_resp_identity(void) { @@ -19,13 +24,13 @@ test_resp_identity(void) NUTS_PASS(nng_respondent0_open(&s)); NUTS_PASS(nng_socket_proto_id(s, &p)); - NUTS_TRUE(p == NNG_RESPONDENT0_SELF); + NUTS_TRUE(p == RESPONDENT0_SELF); NUTS_TRUE(nng_socket_peer_id(s, &p) == 0); - NUTS_TRUE(p == NNG_RESPONDENT0_PEER); + NUTS_TRUE(p == RESPONDENT0_PEER); NUTS_TRUE(nng_socket_proto_name(s, &n) == 0); - NUTS_MATCH(n, NNG_RESPONDENT0_SELF_NAME); + NUTS_MATCH(n, RESPONDENT0_SELF_NAME); NUTS_TRUE(nng_socket_peer_name(s, &n) == 0); - NUTS_MATCH(n, NNG_RESPONDENT0_PEER_NAME); + NUTS_MATCH(n, RESPONDENT0_PEER_NAME); NUTS_CLOSE(s); } diff --git a/src/sp/protocol/survey0/survey.c b/src/sp/protocol/survey0/survey.c index 66fea985..6cf73e66 100644 --- a/src/sp/protocol/survey0/survey.c +++ b/src/sp/protocol/survey0/survey.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,6 @@ #include <stdlib.h> #include "core/nng_impl.h" -#include "nng/protocol/survey0/survey.h" // Surveyor protocol. The SURVEYOR protocol is the "survey" side of the // survey pattern. This is useful for building service discovery, voting, etc. @@ -19,6 +18,11 @@ // multiple use of queues for simplicity. Typically this is used in cases // where a few dozen extra microseconds does not matter. +#define SURVEYOR0_SELF 0x62 +#define SURVEYOR0_PEER 0x63 +#define SURVEYOR0_SELF_NAME "surveyor" +#define SURVEYOR0_PEER_NAME "respondent" + typedef struct surv0_pipe surv0_pipe; typedef struct surv0_sock surv0_sock; typedef struct surv0_ctx surv0_ctx; @@ -348,10 +352,10 @@ surv0_pipe_start(void *arg) surv0_pipe *p = arg; surv0_sock *s = p->sock; - if (nni_pipe_peer(p->pipe) != NNG_SURVEYOR0_PEER) { + if (nni_pipe_peer(p->pipe) != SURVEYOR0_PEER) { nng_log_warn("NNG-PEER-MISMATCH", "Peer protocol mismatch: %d != %d, rejected.", - nni_pipe_peer(p->pipe), NNG_SURVEYOR0_PEER); + nni_pipe_peer(p->pipe), SURVEYOR0_PEER); return (NNG_EPROTO); } @@ -598,8 +602,8 @@ static nni_proto_sock_ops surv0_sock_ops = { static nni_proto surv0_proto = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_SURVEYOR0_SELF, NNG_SURVEYOR0_SELF_NAME }, - .proto_peer = { NNG_SURVEYOR0_PEER, NNG_SURVEYOR0_PEER_NAME }, + .proto_self = { SURVEYOR0_SELF, SURVEYOR0_SELF_NAME }, + .proto_peer = { SURVEYOR0_PEER, SURVEYOR0_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV, .proto_sock_ops = &surv0_sock_ops, .proto_pipe_ops = &surv0_pipe_ops, diff --git a/src/sp/protocol/survey0/survey_test.c b/src/sp/protocol/survey0/survey_test.c index 0489bf9f..1be9dee4 100644 --- a/src/sp/protocol/survey0/survey_test.c +++ b/src/sp/protocol/survey0/survey_test.c @@ -11,6 +11,11 @@ #include "nng/nng.h" #include <nuts.h> +#define SURVEYOR0_SELF 0x62 +#define SURVEYOR0_PEER 0x63 +#define SURVEYOR0_SELF_NAME "surveyor" +#define SURVEYOR0_PEER_NAME "respondent" + static void test_surv_identity(void) { @@ -20,13 +25,13 @@ test_surv_identity(void) NUTS_PASS(nng_surveyor0_open(&s)); NUTS_PASS(nng_socket_proto_id(s, &p)); - NUTS_TRUE(p == NNG_SURVEYOR0_SELF); + NUTS_TRUE(p == SURVEYOR0_SELF); NUTS_PASS(nng_socket_peer_id(s, &p)); - NUTS_TRUE(p == NNG_SURVEYOR0_PEER); // 49 + NUTS_TRUE(p == SURVEYOR0_PEER); // 49 NUTS_PASS(nng_socket_proto_name(s, &n)); - NUTS_MATCH(n, NNG_SURVEYOR0_SELF_NAME); + NUTS_MATCH(n, SURVEYOR0_SELF_NAME); NUTS_PASS(nng_socket_peer_name(s, &n)); - NUTS_MATCH(n, NNG_SURVEYOR0_PEER_NAME); + NUTS_MATCH(n, SURVEYOR0_PEER_NAME); NUTS_CLOSE(s); } diff --git a/src/sp/protocol/survey0/xrespond.c b/src/sp/protocol/survey0/xrespond.c index c4d54594..ceddc118 100644 --- a/src/sp/protocol/survey0/xrespond.c +++ b/src/sp/protocol/survey0/xrespond.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,7 +11,6 @@ #include <stdlib.h> #include "core/nng_impl.h" -#include "nng/protocol/survey0/respond.h" // Respondent protocol. The RESPONDENT protocol is the "replier" side of // the surveyor pattern. This is useful for building service discovery, or diff --git a/src/sp/protocol/survey0/xrespond_test.c b/src/sp/protocol/survey0/xrespond_test.c index 579438ec..03ac5fc1 100644 --- a/src/sp/protocol/survey0/xrespond_test.c +++ b/src/sp/protocol/survey0/xrespond_test.c @@ -10,6 +10,11 @@ #include "nng/nng.h" #include <nuts.h> +#define RESPONDENT0_SELF 0x63 +#define RESPONDENT0_PEER 0x62 +#define RESPONDENT0_SELF_NAME "respondent" +#define RESPONDENT0_PEER_NAME "surveyor" + static void test_xresp_identity(void) { @@ -24,10 +29,10 @@ test_xresp_identity(void) NUTS_PASS(nng_socket_proto_name(s, &n1)); NUTS_PASS(nng_socket_peer_name(s, &n2)); NUTS_CLOSE(s); - NUTS_TRUE(p1 == NNG_RESPONDENT0_SELF); - NUTS_TRUE(p2 == NNG_RESPONDENT0_PEER); - NUTS_MATCH(n1, NNG_RESPONDENT0_SELF_NAME); - NUTS_MATCH(n2, NNG_RESPONDENT0_PEER_NAME); + NUTS_TRUE(p1 == RESPONDENT0_SELF); + NUTS_TRUE(p2 == RESPONDENT0_PEER); + NUTS_MATCH(n1, RESPONDENT0_SELF_NAME); + NUTS_MATCH(n2, RESPONDENT0_PEER_NAME); } static void @@ -187,7 +192,7 @@ test_xresp_close_pipe_during_send(void) nng_pipe p; nng_msg *m; - NUTS_PASS(nng_respondent_open_raw(&resp)); + NUTS_PASS(nng_respondent0_open_raw(&resp)); NUTS_PASS(nng_surveyor0_open_raw(&surv)); NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_SENDTIMEO, 200)); diff --git a/src/sp/protocol/survey0/xsurvey.c b/src/sp/protocol/survey0/xsurvey.c index 208db051..2891fba5 100644 --- a/src/sp/protocol/survey0/xsurvey.c +++ b/src/sp/protocol/survey0/xsurvey.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -9,11 +9,15 @@ // #include "core/nng_impl.h" -#include "nng/protocol/survey0/survey.h" // Surveyor protocol. The SURVEYOR protocol is the "survey" side of the // survey pattern. This is useful for building service discovery, voting, etc. +#define SURVEYOR0_SELF 0x62 +#define SURVEYOR0_PEER 0x63 +#define SURVEYOR0_SELF_NAME "surveyor" +#define SURVEYOR0_PEER_NAME "respondent" + typedef struct xsurv0_pipe xsurv0_pipe; typedef struct xsurv0_sock xsurv0_sock; @@ -141,10 +145,10 @@ xsurv0_pipe_start(void *arg) xsurv0_pipe *p = arg; xsurv0_sock *s = p->psock; - if (nni_pipe_peer(p->npipe) != NNG_SURVEYOR0_PEER) { + if (nni_pipe_peer(p->npipe) != SURVEYOR0_PEER) { nng_log_warn("NNG-PEER-MISMATCH", "Peer protocol mismatch: %d != %d, rejected.", - nni_pipe_peer(p->npipe), NNG_SURVEYOR0_PEER); + nni_pipe_peer(p->npipe), SURVEYOR0_PEER); return (NNG_EPROTO); } @@ -366,8 +370,8 @@ static nni_proto_sock_ops xsurv0_sock_ops = { static nni_proto xsurv0_proto = { .proto_version = NNI_PROTOCOL_VERSION, - .proto_self = { NNG_SURVEYOR0_SELF, NNG_SURVEYOR0_SELF_NAME }, - .proto_peer = { NNG_SURVEYOR0_PEER, NNG_SURVEYOR0_PEER_NAME }, + .proto_self = { SURVEYOR0_SELF, SURVEYOR0_SELF_NAME }, + .proto_peer = { SURVEYOR0_PEER, SURVEYOR0_PEER_NAME }, .proto_flags = NNI_PROTO_FLAG_SNDRCV | NNI_PROTO_FLAG_RAW, .proto_sock_ops = &xsurv0_sock_ops, .proto_pipe_ops = &xsurv0_pipe_ops, diff --git a/src/sp/protocol/survey0/xsurvey_test.c b/src/sp/protocol/survey0/xsurvey_test.c index b151f230..44b2c990 100644 --- a/src/sp/protocol/survey0/xsurvey_test.c +++ b/src/sp/protocol/survey0/xsurvey_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -10,6 +10,11 @@ #include "nng/nng.h" #include <nuts.h> +#define SURVEYOR0_SELF 0x62 +#define SURVEYOR0_PEER 0x63 +#define SURVEYOR0_SELF_NAME "surveyor" +#define SURVEYOR0_PEER_NAME "respondent" + static void test_xsurveyor_identity(void) { @@ -19,13 +24,13 @@ test_xsurveyor_identity(void) NUTS_PASS(nng_surveyor0_open_raw(&s)); NUTS_PASS(nng_socket_proto_id(s, &p)); - NUTS_TRUE(p == NNG_SURVEYOR0_SELF); // 0x62 + NUTS_TRUE(p == SURVEYOR0_SELF); // 0x62 NUTS_PASS(nng_socket_peer_id(s, &p)); - NUTS_TRUE(p == NNG_SURVEYOR0_PEER); // 0x62 + NUTS_TRUE(p == SURVEYOR0_PEER); // 0x62 NUTS_PASS(nng_socket_proto_name(s, &n)); - NUTS_MATCH(n, NNG_SURVEYOR0_SELF_NAME); + NUTS_MATCH(n, SURVEYOR0_SELF_NAME); NUTS_PASS(nng_socket_peer_name(s, &n)); - NUTS_MATCH(n, NNG_SURVEYOR0_PEER_NAME); + NUTS_MATCH(n, SURVEYOR0_PEER_NAME); NUTS_CLOSE(s); } diff --git a/src/sp/reconnect_stress_test.c b/src/sp/reconnect_stress_test.c index 578e34bd..685f8b98 100644 --- a/src/sp/reconnect_stress_test.c +++ b/src/sp/reconnect_stress_test.c @@ -1,4 +1,5 @@ // +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2024 Aleksei Solovev <solovalex@gmail.com> // // This software is supplied under the terms of the MIT License, a @@ -10,10 +11,6 @@ #include <assert.h> #include <core/nng_impl.h> #include <nng/nng.h> -#include <nng/protocol/reqrep0/rep.h> -#include <nng/protocol/reqrep0/req.h> -#include <nng/protocol/survey0/respond.h> -#include <nng/protocol/survey0/survey.h> #include <nuts.h> @@ -187,7 +184,7 @@ void surveyor_open(struct work *w) { w->start = ping_start; - NUTS_PASS(nng_surveyor_open(&w->socket)); + NUTS_PASS(nng_surveyor0_open(&w->socket)); NUTS_PASS(nng_socket_set_ms( w->socket, NNG_OPT_SURVEYOR_SURVEYTIME, SURVEY_TIMEOUT_MS)); NUTS_PASS(nng_aio_alloc(&w->aio, ping_cb, w)); @@ -198,7 +195,7 @@ void respondent_open(struct work *w) { w->start = echo_start; - NUTS_PASS(nng_respondent_open(&w->socket)); + NUTS_PASS(nng_respondent0_open(&w->socket)); NUTS_PASS(nng_aio_alloc(&w->aio, echo_cb, w)); nni_atomic_init(&w->received); } @@ -207,7 +204,7 @@ void req_open(struct work *w) { w->start = ping_start; - NUTS_PASS(nng_req_open(&w->socket)); + NUTS_PASS(nng_req0_open(&w->socket)); NUTS_PASS(nng_aio_alloc(&w->aio, ping_cb, w)); nni_atomic_init(&w->received); } @@ -216,7 +213,7 @@ void rep_open(struct work *w) { w->start = echo_start; - NUTS_PASS(nng_rep_open(&w->socket)); + NUTS_PASS(nng_rep0_open(&w->socket)); NUTS_PASS(nng_aio_alloc(&w->aio, echo_cb, w)); nni_atomic_init(&w->received); } diff --git a/src/sp/scalability_test.c b/src/sp/scalability_test.c index 7579fe7f..02ec01a9 100644 --- a/src/sp/scalability_test.c +++ b/src/sp/scalability_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,8 +11,6 @@ #include <string.h> #include <nng/nng.h> -#include <nng/protocol/reqrep0/rep.h> -#include <nng/protocol/reqrep0/req.h> #include <nuts.h> @@ -49,7 +47,7 @@ openclients(nng_socket *clients, int num) for (i = 0; i < num; i++) { t = 100; // 100ms nng_socket c; - NUTS_PASS(nng_req_open(&c)); + NUTS_PASS(nng_req0_open(&c)); NUTS_PASS(nng_socket_set_ms(c, NNG_OPT_RECVTIMEO, t)); NUTS_PASS(nng_socket_set_ms(c, NNG_OPT_SENDTIMEO, t)); NUTS_PASS(nng_dial(c, addr, NULL, 0)); @@ -89,7 +87,7 @@ test_scalability(void) clients = calloc(nclients, sizeof(nng_socket)); results = calloc(nclients, sizeof(int)); - NUTS_PASS(nng_rep_open(&rep)); + NUTS_PASS(nng_rep0_open(&rep)); NUTS_PASS(nng_socket_set_int(rep, NNG_OPT_RECVBUF, 256)); NUTS_PASS(nng_socket_set_int(rep, NNG_OPT_SENDBUF, 256)); NUTS_PASS(nng_listen(rep, addr, NULL, 0)); diff --git a/src/supplemental/websocket/websocket_test.c b/src/supplemental/websocket/websocket_test.c index f4cfc1b4..91e42601 100644 --- a/src/supplemental/websocket/websocket_test.c +++ b/src/supplemental/websocket/websocket_test.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -11,6 +11,8 @@ #include <nng/nng.h> +#include "../sha1/sha1.h" + #include <nuts.h> void diff --git a/src/supplemental/websocket/wssfile_test.c b/src/supplemental/websocket/wssfile_test.c index 7239a1c7..9f059dc6 100644 --- a/src/supplemental/websocket/wssfile_test.c +++ b/src/supplemental/websocket/wssfile_test.c @@ -77,8 +77,8 @@ test_invalid_verify(void) (void) snprintf(addr, sizeof(addr), "wss4://:0/test"); - NUTS_PASS(nng_pair_open(&s1)); - NUTS_PASS(nng_pair_open(&s2)); + NUTS_PASS(nng_pair1_open(&s1)); + NUTS_PASS(nng_pair1_open(&s2)); NUTS_PASS(nng_listener_create(&l, s1, addr)); init_listener_wss_file(l); NUTS_PASS(nng_listener_start(l, 0)); @@ -119,8 +119,8 @@ test_no_verify(void) int port; NUTS_ENABLE_LOG(NNG_LOG_DEBUG); - NUTS_PASS(nng_pair_open(&s1)); - NUTS_PASS(nng_pair_open(&s2)); + NUTS_PASS(nng_pair1_open(&s1)); + NUTS_PASS(nng_pair1_open(&s2)); NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_SENDTIMEO, 5000)); NUTS_PASS(nng_socket_set_ms(s2, NNG_OPT_RECVTIMEO, 5000)); @@ -170,8 +170,8 @@ test_verify_works(void) bool b; int port; - NUTS_PASS(nng_pair_open(&s1)); - NUTS_PASS(nng_pair_open(&s2)); + NUTS_PASS(nng_pair1_open(&s1)); + NUTS_PASS(nng_pair1_open(&s2)); NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_SENDTIMEO, 5000)); NUTS_PASS(nng_socket_set_ms(s2, NNG_OPT_RECVTIMEO, 5000)); port = nuts_next_port(); @@ -231,8 +231,8 @@ test_tls_config(void) (void) snprintf(addr, sizeof(addr), "wss4://:0/test"); - NUTS_PASS(nng_pair_open(&s1)); - NUTS_PASS(nng_pair_open(&s2)); + NUTS_PASS(nng_pair1_open(&s1)); + NUTS_PASS(nng_pair1_open(&s2)); NUTS_PASS(nng_listener_create(&l, s1, addr)); NUTS_PASS(nng_listener_get_tls(l, &cfg)); nng_tls_config_hold(cfg); diff --git a/src/testing/nuts.h b/src/testing/nuts.h index b0c30245..5f7ea513 100644 --- a/src/testing/nuts.h +++ b/src/testing/nuts.h @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2025 Staysail Systems, Inc. <info@staysail.tech> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -49,19 +49,7 @@ extern void nuts_logger( #include <string.h> // The following headers are provided for test code convenience. -#include <nng/protocol/bus0/bus.h> -#include <nng/protocol/pair0/pair.h> -#include <nng/protocol/pair1/pair.h> -#include <nng/protocol/pipeline0/pull.h> -#include <nng/protocol/pipeline0/push.h> -#include <nng/protocol/pubsub0/pub.h> -#include <nng/protocol/pubsub0/sub.h> -#include <nng/protocol/reqrep0/rep.h> -#include <nng/protocol/reqrep0/req.h> -#include <nng/protocol/survey0/respond.h> -#include <nng/protocol/survey0/survey.h> #include <nng/supplemental/tls/tls.h> -#include <supplemental/sha1/sha1.h> #ifdef __cplusplus extern "C" { diff --git a/src/tools/perf/perf.c b/src/tools/perf/perf.c index 1b985c1c..5ce99c04 100644 --- a/src/tools/perf/perf.c +++ b/src/tools/perf/perf.c @@ -32,61 +32,39 @@ typedef int (*open_func)(nng_socket *); static open_func open_server = no_open; static open_func open_client = no_open; -#if defined(NNG_HAVE_PAIR1) -#include <nng/protocol/pair1/pair.h> -#else +#if !defined(NNG_HAVE_PAIR1) #define nng_pair1_open no_open #endif -#if defined(NNG_HAVE_PAIR0) -#include <nng/protocol/pair0/pair.h> -#else +#if !defined(NNG_HAVE_PAIR0) #define nng_pair0_open no_open #endif -#if !defined(NNG_HAVE_PAIR0) && !defined(NNG_HAVE_PAIR1) -#define nng_pair_open no_open -#endif - -#if defined(NNG_HAVE_REQ0) -#include <nng/protocol/reqrep0/req.h> -#else +#if !defined(NNG_HAVE_REQ0) #define nng_req0_open no_open #endif -#if defined(NNG_HAVE_REP0) -#include <nng/protocol/reqrep0/rep.h> -#else +#if !defined(NNG_HAVE_REP0) #define nng_rep0_open no_open #endif -#if defined(NNG_HAVE_BUS0) -#include <nng/protocol/bus0/bus.h> -#else +#if !defined(NNG_HAVE_BUS0) #define nng_bus0_open no_open #endif -#if defined(NNG_HAVE_PULL0) -#include <nng/protocol/pipeline0/pull.h> -#else +#if !defined(NNG_HAVE_PULL0) #define nng_pull0_open no_open #endif -#if defined(NNG_HAVE_PUSH0) -#include <nng/protocol/pipeline0/push.h> -#else +#if !defined(NNG_HAVE_PUSH0) #define nng_push0_open no_open #endif -#if defined(NNG_HAVE_PUB0) -#include <nng/protocol/pubsub0/pub.h> -#else +#if !defined(NNG_HAVE_PUB0) #define nng_pub0_open no_open #endif -#if defined(NNG_HAVE_SUB0) -#include <nng/protocol/pubsub0/sub.h> -#else +#if !defined(NNG_HAVE_SUB0) #define nng_sub0_open no_open #endif @@ -561,7 +539,7 @@ throughput_server(const char *addr, size_t msgsize, int count) uint64_t start, end; float msgpersec, mbps, total; - if ((rv = nng_pair_open(&s)) != 0) { + if ((rv = nng_pair1_open(&s)) != 0) { die("nng_socket: %s", nng_strerror(rv)); } rv = nng_socket_set_int(s, NNG_OPT_RECVBUF, 128); @@ -620,7 +598,7 @@ throughput_client(const char *addr, size_t msgsize, int count) // We send one extra zero length message to start the timer. count++; - if ((rv = nng_pair_open(&s)) != 0) { + if ((rv = nng_pair1_open(&s)) != 0) { die("nng_socket: %s", nng_strerror(rv)); } |
