aboutsummaryrefslogtreecommitdiff
path: root/src/sp/protocol/survey0
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-01-01 12:44:02 -0800
committerGarrett D'Amore <garrett@damore.org>2025-01-01 12:44:02 -0800
commit0d23af92531b7c0dd6d7b74c73c1a8c4811c7d13 (patch)
tree2dc9ded3dfc724df42a360a9f2de359f406e537f /src/sp/protocol/survey0
parentf8a2abaf931557030fd6e6683617c6a7877eebf7 (diff)
downloadnng-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/survey0')
-rw-r--r--src/sp/protocol/survey0/respond.c3
-rw-r--r--src/sp/protocol/survey0/respond_test.c15
-rw-r--r--src/sp/protocol/survey0/survey.c16
-rw-r--r--src/sp/protocol/survey0/survey_test.c13
-rw-r--r--src/sp/protocol/survey0/xrespond.c3
-rw-r--r--src/sp/protocol/survey0/xrespond_test.c15
-rw-r--r--src/sp/protocol/survey0/xsurvey.c16
-rw-r--r--src/sp/protocol/survey0/xsurvey_test.c15
8 files changed, 61 insertions, 35 deletions
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);
}