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/sp/protocol/reqrep0 | |
| 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/sp/protocol/reqrep0')
| -rw-r--r-- | src/sp/protocol/reqrep0/rep.c | 16 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/rep_test.c | 23 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/req.c | 16 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/req_test.c | 23 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/reqstress_test.c | 3 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/xrep.c | 16 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/xrep_test.c | 15 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/xreq.c | 16 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/xreq_test.c | 15 |
9 files changed, 88 insertions, 55 deletions
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 |
