diff options
Diffstat (limited to 'src/sp/protocol')
27 files changed, 187 insertions, 123 deletions
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); } |
