aboutsummaryrefslogtreecommitdiff
path: root/src/sp/protocol/survey0
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-11-02 13:57:53 -0700
committerGarrett D'Amore <garrett@damore.org>2024-11-02 14:47:50 -0700
commit279180c1d07fc2c4c0bfa8f5a418cb02c4b87863 (patch)
treeb451ac7f845062674d6ab45eb5d530628d3ff47c /src/sp/protocol/survey0
parent9b27984d0e2da430b78a975e59f55c96de5f6056 (diff)
downloadnng-279180c1d07fc2c4c0bfa8f5a418cb02c4b87863.tar.gz
nng-279180c1d07fc2c4c0bfa8f5a418cb02c4b87863.tar.bz2
nng-279180c1d07fc2c4c0bfa8f5a418cb02c4b87863.zip
NNG_OPT_RECVFD and NNG_OPT_SENDFD converted to functions.
These options are removed entirely, and their functionality is now available via special functions, `nng_socket_get_send_poll_fd` and `nng_socket_get_recv_poll_fd`, making these first class methods on the socket. This eliminates a bit of wasteful code, and provides type safety for these methods.
Diffstat (limited to 'src/sp/protocol/survey0')
-rw-r--r--src/sp/protocol/survey0/respond.c46
-rw-r--r--src/sp/protocol/survey0/respond_test.c21
-rw-r--r--src/sp/protocol/survey0/survey.c44
-rw-r--r--src/sp/protocol/survey0/survey_test.c21
-rw-r--r--src/sp/protocol/survey0/xrespond_test.c5
-rw-r--r--src/sp/protocol/survey0/xsurvey_test.c5
6 files changed, 40 insertions, 102 deletions
diff --git a/src/sp/protocol/survey0/respond.c b/src/sp/protocol/survey0/respond.c
index 8a8c134b..ad0732c1 100644
--- a/src/sp/protocol/survey0/respond.c
+++ b/src/sp/protocol/survey0/respond.c
@@ -585,29 +585,19 @@ resp0_sock_get_max_ttl(void *arg, void *buf, size_t *szp, nni_opt_type t)
}
static int
-resp0_sock_get_sendfd(void *arg, void *buf, size_t *szp, nni_opt_type t)
+resp0_sock_get_sendfd(void *arg, int *fdp)
{
resp0_sock *s = arg;
- int rv;
- int fd;
- if ((rv = nni_pollable_getfd(&s->writable, &fd)) != 0) {
- return (rv);
- }
- return (nni_copyout_int(fd, buf, szp, t));
+ return (nni_pollable_getfd(&s->writable, fdp));
}
static int
-resp0_sock_get_recvfd(void *arg, void *buf, size_t *szp, nni_opt_type t)
+resp0_sock_get_recvfd(void *arg, int *fdp)
{
resp0_sock *s = arg;
- int rv;
- int fd;
- if ((rv = nni_pollable_getfd(&s->readable, &fd)) != 0) {
- return (rv);
- }
- return (nni_copyout_int(fd, buf, szp, t));
+ return (nni_pollable_getfd(&s->readable, fdp));
}
static void
@@ -649,16 +639,6 @@ static nni_option resp0_sock_options[] = {
.o_get = resp0_sock_get_max_ttl,
.o_set = resp0_sock_set_max_ttl,
},
- {
- .o_name = NNG_OPT_RECVFD,
- .o_get = resp0_sock_get_recvfd,
- .o_set = NULL,
- },
- {
- .o_name = NNG_OPT_SENDFD,
- .o_get = resp0_sock_get_sendfd,
- .o_set = NULL,
- },
// terminate list
{
.o_name = NULL,
@@ -666,14 +646,16 @@ static nni_option resp0_sock_options[] = {
};
static nni_proto_sock_ops resp0_sock_ops = {
- .sock_size = sizeof(resp0_sock),
- .sock_init = resp0_sock_init,
- .sock_fini = resp0_sock_fini,
- .sock_open = resp0_sock_open,
- .sock_close = resp0_sock_close,
- .sock_send = resp0_sock_send,
- .sock_recv = resp0_sock_recv,
- .sock_options = resp0_sock_options,
+ .sock_size = sizeof(resp0_sock),
+ .sock_init = resp0_sock_init,
+ .sock_fini = resp0_sock_fini,
+ .sock_open = resp0_sock_open,
+ .sock_close = resp0_sock_close,
+ .sock_send = resp0_sock_send,
+ .sock_recv = resp0_sock_recv,
+ .sock_send_poll_fd = resp0_sock_get_sendfd,
+ .sock_recv_poll_fd = resp0_sock_get_recvfd,
+ .sock_options = resp0_sock_options,
};
static nni_proto resp0_proto = {
diff --git a/src/sp/protocol/survey0/respond_test.c b/src/sp/protocol/survey0/respond_test.c
index 92e9bf81..0dad2222 100644
--- a/src/sp/protocol/survey0/respond_test.c
+++ b/src/sp/protocol/survey0/respond_test.c
@@ -7,6 +7,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include "nng/nng.h"
#include <nuts.h>
void
@@ -52,7 +53,7 @@ test_resp_poll_writeable(void)
NUTS_PASS(nng_surveyor0_open(&surv));
NUTS_PASS(nng_respondent0_open(&resp));
- NUTS_PASS(nng_socket_get_int(resp, NNG_OPT_SENDFD, &fd));
+ NUTS_PASS(nng_socket_get_send_poll_fd(resp, &fd));
NUTS_TRUE(fd >= 0);
// Not writable before connect.
@@ -89,7 +90,7 @@ test_resp_poll_readable(void)
NUTS_PASS(nng_surveyor0_open(&surv));
NUTS_PASS(nng_respondent0_open(&resp));
- NUTS_PASS(nng_socket_get_int(resp, NNG_OPT_RECVFD, &fd));
+ NUTS_PASS(nng_socket_get_recv_poll_fd(resp, &fd));
NUTS_TRUE(fd >= 0);
// Not readable if not connected!
@@ -118,21 +119,6 @@ test_resp_poll_readable(void)
}
void
-test_resp_context_no_poll(void)
-{
- int fd;
- nng_socket resp;
- nng_ctx ctx;
-
- NUTS_PASS(nng_respondent0_open(&resp));
- NUTS_PASS(nng_ctx_open(&ctx, resp));
- NUTS_FAIL(nng_ctx_get_int(ctx, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP);
- NUTS_FAIL(nng_ctx_get_int(ctx, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP);
- NUTS_PASS(nng_ctx_close(ctx));
- NUTS_CLOSE(resp);
-}
-
-void
test_resp_validate_peer(void)
{
nng_socket s1, s2;
@@ -568,7 +554,6 @@ TEST_LIST = {
{ "respond send bad state", test_resp_send_bad_state },
{ "respond poll readable", test_resp_poll_readable },
{ "respond poll writable", test_resp_poll_writeable },
- { "respond context does not poll", test_resp_context_no_poll },
{ "respond validate peer", test_resp_validate_peer },
{ "respond double recv", test_resp_double_recv },
{ "respond close pipe before send", test_resp_close_pipe_before_send },
diff --git a/src/sp/protocol/survey0/survey.c b/src/sp/protocol/survey0/survey.c
index 3197f743..b89614bb 100644
--- a/src/sp/protocol/survey0/survey.c
+++ b/src/sp/protocol/survey0/survey.c
@@ -520,29 +520,19 @@ surv0_sock_get_survey_time(void *arg, void *buf, size_t *szp, nni_opt_type t)
}
static int
-surv0_sock_get_send_fd(void *arg, void *buf, size_t *szp, nni_opt_type t)
+surv0_sock_get_send_fd(void *arg, int *fdp)
{
surv0_sock *sock = arg;
- int rv;
- int fd;
- if ((rv = nni_pollable_getfd(&sock->writable, &fd)) != 0) {
- return (rv);
- }
- return (nni_copyout_int(fd, buf, szp, t));
+ return (nni_pollable_getfd(&sock->writable, fdp));
}
static int
-surv0_sock_get_recv_fd(void *arg, void *buf, size_t *szp, nni_opt_type t)
+surv0_sock_get_recv_fd(void *arg, int *fdp)
{
surv0_sock *sock = arg;
- int rv;
- int fd;
- if ((rv = nni_pollable_getfd(&sock->readable, &fd)) != 0) {
- return (rv);
- }
- return (nni_copyout_int(fd, buf, szp, t));
+ return (nni_pollable_getfd(&sock->readable, fdp));
}
static void
@@ -598,14 +588,6 @@ static nni_option surv0_sock_options[] = {
.o_get = surv0_sock_get_max_ttl,
.o_set = surv0_sock_set_max_ttl,
},
- {
- .o_name = NNG_OPT_RECVFD,
- .o_get = surv0_sock_get_recv_fd,
- },
- {
- .o_name = NNG_OPT_SENDFD,
- .o_get = surv0_sock_get_send_fd,
- },
// terminate list
{
.o_name = NULL,
@@ -613,14 +595,16 @@ static nni_option surv0_sock_options[] = {
};
static nni_proto_sock_ops surv0_sock_ops = {
- .sock_size = sizeof(surv0_sock),
- .sock_init = surv0_sock_init,
- .sock_fini = surv0_sock_fini,
- .sock_open = surv0_sock_open,
- .sock_close = surv0_sock_close,
- .sock_send = surv0_sock_send,
- .sock_recv = surv0_sock_recv,
- .sock_options = surv0_sock_options,
+ .sock_size = sizeof(surv0_sock),
+ .sock_init = surv0_sock_init,
+ .sock_fini = surv0_sock_fini,
+ .sock_open = surv0_sock_open,
+ .sock_close = surv0_sock_close,
+ .sock_send = surv0_sock_send,
+ .sock_recv = surv0_sock_recv,
+ .sock_send_poll_fd = surv0_sock_get_send_fd,
+ .sock_recv_poll_fd = surv0_sock_get_recv_fd,
+ .sock_options = surv0_sock_options,
};
static nni_proto surv0_proto = {
diff --git a/src/sp/protocol/survey0/survey_test.c b/src/sp/protocol/survey0/survey_test.c
index c5f699da..76fe138d 100644
--- a/src/sp/protocol/survey0/survey_test.c
+++ b/src/sp/protocol/survey0/survey_test.c
@@ -8,6 +8,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include "nng/nng.h"
#include <nuts.h>
static void
@@ -313,7 +314,7 @@ test_surv_poll_writeable(void)
NUTS_PASS(nng_surveyor0_open(&surv));
NUTS_PASS(nng_respondent0_open(&resp));
- NUTS_PASS(nng_socket_get_int(surv, NNG_OPT_SENDFD, &fd));
+ NUTS_PASS(nng_socket_get_send_poll_fd(surv, &fd));
NUTS_TRUE(fd >= 0);
// Survey is broadcast, so we can always write.
@@ -338,7 +339,7 @@ test_surv_poll_readable(void)
NUTS_PASS(nng_surveyor0_open(&surv));
NUTS_PASS(nng_respondent0_open(&resp));
- NUTS_PASS(nng_socket_get_int(surv, NNG_OPT_RECVFD, &fd));
+ NUTS_PASS(nng_socket_get_recv_poll_fd(surv, &fd));
NUTS_TRUE(fd >= 0);
// Not readable if not connected!
@@ -372,21 +373,6 @@ test_surv_poll_readable(void)
}
static void
-test_surv_ctx_no_poll(void)
-{
- int fd;
- nng_socket surv;
- nng_ctx ctx;
-
- NUTS_PASS(nng_surveyor0_open(&surv));
- NUTS_PASS(nng_ctx_open(&ctx, surv));
- NUTS_FAIL(nng_ctx_get_int(ctx, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP);
- NUTS_FAIL(nng_ctx_get_int(ctx, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP);
- NUTS_PASS(nng_ctx_close(ctx));
- NUTS_CLOSE(surv);
-}
-
-static void
test_surv_ctx_recv_nonblock(void)
{
nng_socket surv;
@@ -639,7 +625,6 @@ TEST_LIST = {
{ "survey cancel post recv", test_surv_cancel_post_recv },
{ "survey poll writable", test_surv_poll_writeable },
{ "survey poll readable", test_surv_poll_readable },
- { "survey context does not poll", test_surv_ctx_no_poll },
{ "survey context recv close socket",
test_surv_ctx_recv_close_socket },
{ "survey context recv nonblock", test_surv_ctx_recv_nonblock },
diff --git a/src/sp/protocol/survey0/xrespond_test.c b/src/sp/protocol/survey0/xrespond_test.c
index b8d29b9a..8b8787f9 100644
--- a/src/sp/protocol/survey0/xrespond_test.c
+++ b/src/sp/protocol/survey0/xrespond_test.c
@@ -7,6 +7,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include "nng/nng.h"
#include <nuts.h>
static void
@@ -63,7 +64,7 @@ test_xresp_poll_writeable(void)
NUTS_PASS(nng_respondent0_open_raw(&resp));
NUTS_PASS(nng_surveyor0_open(&surv));
- NUTS_PASS(nng_socket_get_int(resp, NNG_OPT_SENDFD, &fd));
+ NUTS_PASS(nng_socket_get_send_poll_fd(resp, &fd));
NUTS_TRUE(fd >= 0);
// We are always writeable, even before connect. This is so that
@@ -91,7 +92,7 @@ test_xresp_poll_readable(void)
NUTS_PASS(nng_surveyor0_open(&surv));
NUTS_PASS(nng_respondent0_open_raw(&resp));
- NUTS_PASS(nng_socket_get_int(resp, NNG_OPT_RECVFD, &fd));
+ NUTS_PASS(nng_socket_get_recv_poll_fd(resp, &fd));
NUTS_TRUE(fd >= 0);
// Not readable if not connected!
diff --git a/src/sp/protocol/survey0/xsurvey_test.c b/src/sp/protocol/survey0/xsurvey_test.c
index 3b874afe..efa54101 100644
--- a/src/sp/protocol/survey0/xsurvey_test.c
+++ b/src/sp/protocol/survey0/xsurvey_test.c
@@ -7,6 +7,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include "nng/nng.h"
#include <nuts.h>
static void
@@ -62,7 +63,7 @@ test_xsurvey_poll_writeable(void)
NUTS_PASS(nng_surveyor0_open_raw(&surv));
NUTS_PASS(nng_respondent0_open(&resp));
- NUTS_PASS(nng_socket_get_int(surv, NNG_OPT_SENDFD, &fd));
+ NUTS_PASS(nng_socket_get_send_poll_fd(surv, &fd));
NUTS_TRUE(fd >= 0);
// Survey is broadcast, so we can always write.
@@ -87,7 +88,7 @@ test_xsurvey_poll_readable(void)
NUTS_PASS(nng_surveyor0_open_raw(&surv));
NUTS_PASS(nng_respondent0_open(&resp));
- NUTS_PASS(nng_socket_get_int(surv, NNG_OPT_RECVFD, &fd));
+ NUTS_PASS(nng_socket_get_recv_poll_fd(surv, &fd));
NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_RECVTIMEO, 1000));
NUTS_PASS(nng_socket_set_ms(surv, NNG_OPT_RECVTIMEO, 1000));
NUTS_PASS(nng_socket_set_ms(resp, NNG_OPT_SENDTIMEO, 1000));