From 279180c1d07fc2c4c0bfa8f5a418cb02c4b87863 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 2 Nov 2024 13:57:53 -0700 Subject: 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. --- src/sp/protocol/bus0/bus.c | 66 ++++++++++++--------------------- src/sp/protocol/bus0/bus_test.c | 7 ++-- src/sp/protocol/pair0/pair.c | 44 +++++++--------------- src/sp/protocol/pair0/pair0_test.c | 7 ++-- src/sp/protocol/pair1/pair.c | 62 ++++++++++++------------------- src/sp/protocol/pair1/pair1_test.c | 5 ++- src/sp/protocol/pipeline0/pull.c | 30 ++++++--------- src/sp/protocol/pipeline0/pull_test.c | 7 ++-- src/sp/protocol/pipeline0/push.c | 30 ++++++--------- src/sp/protocol/pipeline0/push_test.c | 9 +++-- src/sp/protocol/pubsub0/pub.c | 35 ++++++----------- src/sp/protocol/pubsub0/pub_test.c | 5 ++- src/sp/protocol/pubsub0/sub.c | 30 ++++++--------- src/sp/protocol/pubsub0/sub_test.c | 23 ++---------- src/sp/protocol/pubsub0/xsub_test.c | 7 ++-- src/sp/protocol/reqrep0/rep.c | 45 +++++++--------------- src/sp/protocol/reqrep0/rep_test.c | 20 +--------- src/sp/protocol/reqrep0/req.c | 45 +++++++--------------- src/sp/protocol/reqrep0/req_test.c | 25 +++---------- src/sp/protocol/reqrep0/xrep_test.c | 5 ++- src/sp/protocol/reqrep0/xreq_test.c | 5 ++- src/sp/protocol/survey0/respond.c | 46 +++++++---------------- src/sp/protocol/survey0/respond_test.c | 21 ++--------- src/sp/protocol/survey0/survey.c | 44 +++++++--------------- src/sp/protocol/survey0/survey_test.c | 21 ++--------- src/sp/protocol/survey0/xrespond_test.c | 5 ++- src/sp/protocol/survey0/xsurvey_test.c | 5 ++- 27 files changed, 219 insertions(+), 435 deletions(-) (limited to 'src/sp') diff --git a/src/sp/protocol/bus0/bus.c b/src/sp/protocol/bus0/bus.c index 692cb250..5c7249dd 100644 --- a/src/sp/protocol/bus0/bus.c +++ b/src/sp/protocol/bus0/bus.c @@ -363,34 +363,20 @@ again: } static int -bus0_sock_get_send_fd(void *arg, void *buf, size_t *szp, nni_type t) +bus0_sock_get_send_fd(void *arg, int *fdp) { bus0_sock *sock = arg; - int fd; - int rv; - nni_mtx_lock(&sock->mtx); // BUS sockets are *always* writable (best effort) nni_pollable_raise(&sock->can_send); - rv = nni_pollable_getfd(&sock->can_send, &fd); - nni_mtx_unlock(&sock->mtx); - - if (rv == 0) { - rv = nni_copyout_int(fd, buf, szp, t); - } - return (rv); + return (nni_pollable_getfd(&sock->can_send, fdp)); } static int -bus0_sock_get_recv_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +bus0_sock_get_recv_fd(void *arg, int *fdp) { bus0_sock *s = arg; - int rv; - int fd; - if ((rv = nni_pollable_getfd(&s->can_recv, &fd)) == 0) { - rv = nni_copyout_int(fd, buf, szp, t); - } - return (rv); + return (nni_pollable_getfd(&s->can_recv, fdp)); } static int @@ -474,14 +460,6 @@ static nni_proto_pipe_ops bus0_pipe_ops = { }; static nni_option bus0_sock_options[] = { - { - .o_name = NNG_OPT_SENDFD, - .o_get = bus0_sock_get_send_fd, - }, - { - .o_name = NNG_OPT_RECVFD, - .o_get = bus0_sock_get_recv_fd, - }, { .o_name = NNG_OPT_RECVBUF, .o_get = bus0_sock_get_recv_buf_len, @@ -499,25 +477,29 @@ static nni_option bus0_sock_options[] = { }; static nni_proto_sock_ops bus0_sock_ops = { - .sock_size = sizeof(bus0_sock), - .sock_init = bus0_sock_init, - .sock_fini = bus0_sock_fini, - .sock_open = bus0_sock_open, - .sock_close = bus0_sock_close, - .sock_send = bus0_sock_send, - .sock_recv = bus0_sock_recv, - .sock_options = bus0_sock_options, + .sock_size = sizeof(bus0_sock), + .sock_init = bus0_sock_init, + .sock_fini = bus0_sock_fini, + .sock_open = bus0_sock_open, + .sock_close = bus0_sock_close, + .sock_send = bus0_sock_send, + .sock_recv = bus0_sock_recv, + .sock_send_poll_fd = bus0_sock_get_send_fd, + .sock_recv_poll_fd = bus0_sock_get_recv_fd, + .sock_options = bus0_sock_options, }; static nni_proto_sock_ops bus0_sock_ops_raw = { - .sock_size = sizeof(bus0_sock), - .sock_init = bus0_sock_init_raw, - .sock_fini = bus0_sock_fini, - .sock_open = bus0_sock_open, - .sock_close = bus0_sock_close, - .sock_send = bus0_sock_send, - .sock_recv = bus0_sock_recv, - .sock_options = bus0_sock_options, + .sock_size = sizeof(bus0_sock), + .sock_init = bus0_sock_init_raw, + .sock_fini = bus0_sock_fini, + .sock_open = bus0_sock_open, + .sock_close = bus0_sock_close, + .sock_send = bus0_sock_send, + .sock_recv = bus0_sock_recv, + .sock_send_poll_fd = bus0_sock_get_send_fd, + .sock_recv_poll_fd = bus0_sock_get_recv_fd, + .sock_options = bus0_sock_options, }; static nni_proto bus0_proto = { diff --git a/src/sp/protocol/bus0/bus_test.c b/src/sp/protocol/bus0/bus_test.c index a832d9dd..7e049e34 100644 --- a/src/sp/protocol/bus0/bus_test.c +++ b/src/sp/protocol/bus0/bus_test.c @@ -7,6 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include #include @@ -244,7 +245,7 @@ test_bus_poll_readable(void) NUTS_PASS(nng_bus0_open(&s2)); NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(s2, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(s1, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(s1, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -277,10 +278,10 @@ test_bus_poll_writeable(void) NUTS_PASS(nng_bus0_open(&s1)); NUTS_PASS(nng_bus0_open(&s2)); NUTS_PASS(nng_socket_set_int(s2, NNG_OPT_SENDBUF, 1)); - NUTS_PASS(nng_socket_get_int(s2, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(s2, &fd)); NUTS_TRUE(fd >= 0); - // Pub is *always* writeable + // Bus is *always* writeable NUTS_TRUE(nuts_poll_fd(fd)); // Even after connect (no message yet) diff --git a/src/sp/protocol/pair0/pair.c b/src/sp/protocol/pair0/pair.c index 558a9e3b..254c2810 100644 --- a/src/sp/protocol/pair0/pair.c +++ b/src/sp/protocol/pair0/pair.c @@ -513,40 +513,22 @@ pair0_get_recv_buf_len(void *arg, void *buf, size_t *szp, nni_opt_type t) } static int -pair0_sock_get_recv_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +pair0_sock_get_recv_fd(void *arg, int *fdp) { pair0_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 int -pair0_sock_get_send_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +pair0_sock_get_send_fd(void *arg, int *fdp) { pair0_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 nni_option pair0_sock_options[] = { - { - .o_name = NNG_OPT_RECVFD, - .o_get = pair0_sock_get_recv_fd, - }, - { - .o_name = NNG_OPT_SENDFD, - .o_get = pair0_sock_get_send_fd, - }, { .o_name = NNG_OPT_SENDBUF, .o_get = pair0_get_send_buf_len, @@ -573,14 +555,16 @@ static nni_proto_pipe_ops pair0_pipe_ops = { }; static nni_proto_sock_ops pair0_sock_ops = { - .sock_size = sizeof(pair0_sock), - .sock_init = pair0_sock_init, - .sock_fini = pair0_sock_fini, - .sock_open = pair0_sock_open, - .sock_close = pair0_sock_close, - .sock_send = pair0_sock_send, - .sock_recv = pair0_sock_recv, - .sock_options = pair0_sock_options, + .sock_size = sizeof(pair0_sock), + .sock_init = pair0_sock_init, + .sock_fini = pair0_sock_fini, + .sock_open = pair0_sock_open, + .sock_close = pair0_sock_close, + .sock_send = pair0_sock_send, + .sock_recv = pair0_sock_recv, + .sock_recv_poll_fd = pair0_sock_get_recv_fd, + .sock_send_poll_fd = pair0_sock_get_send_fd, + .sock_options = pair0_sock_options, }; // Legacy protocol (v0) diff --git a/src/sp/protocol/pair0/pair0_test.c b/src/sp/protocol/pair0/pair0_test.c index 83d72c0c..e2196479 100644 --- a/src/sp/protocol/pair0/pair0_test.c +++ b/src/sp/protocol/pair0/pair0_test.c @@ -1,5 +1,5 @@ // -// Copyright 2021 Staysail Systems, Inc. +// Copyright 2024 Staysail Systems, Inc. // Copyright 2017 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -8,6 +8,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include #define SECOND 1000 @@ -340,7 +341,7 @@ test_pair0_poll_readable(void) NUTS_PASS(nng_pair0_open(&s2)); NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(s2, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(s1, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(s1, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -386,7 +387,7 @@ test_pair0_poll_writable(void) NUTS_PASS(nng_pair0_open(&s2)); NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(s2, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(s1, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(s1, &fd)); NUTS_TRUE(fd >= 0); // Not writable if not connected! diff --git a/src/sp/protocol/pair1/pair.c b/src/sp/protocol/pair1/pair.c index 1704d537..d7596fb9 100644 --- a/src/sp/protocol/pair1/pair.c +++ b/src/sp/protocol/pair1/pair.c @@ -724,29 +724,19 @@ pair1_get_recv_buf_len(void *arg, void *buf, size_t *szp, nni_opt_type t) } static int -pair1_sock_get_recv_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +pair1_sock_get_recv_fd(void *arg, int *fdp) { pair1_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 int -pair1_sock_get_send_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +pair1_sock_get_send_fd(void *arg, int *fdp) { pair1_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 nni_proto_pipe_ops pair1_pipe_ops = { @@ -764,14 +754,6 @@ static nni_option pair1_sock_options[] = { .o_get = pair1_sock_get_max_ttl, .o_set = pair1_sock_set_max_ttl, }, - { - .o_name = NNG_OPT_RECVFD, - .o_get = pair1_sock_get_recv_fd, - }, - { - .o_name = NNG_OPT_SENDFD, - .o_get = pair1_sock_get_send_fd, - }, { .o_name = NNG_OPT_SENDBUF, .o_get = pair1_get_send_buf_len, @@ -797,14 +779,16 @@ static nni_option pair1_sock_options[] = { }; static nni_proto_sock_ops pair1_sock_ops = { - .sock_size = sizeof(pair1_sock), - .sock_init = pair1_sock_init, - .sock_fini = pair1_sock_fini, - .sock_open = pair1_sock_open, - .sock_close = pair1_sock_close, - .sock_recv = pair1_sock_recv, - .sock_send = pair1_sock_send, - .sock_options = pair1_sock_options, + .sock_size = sizeof(pair1_sock), + .sock_init = pair1_sock_init, + .sock_fini = pair1_sock_fini, + .sock_open = pair1_sock_open, + .sock_close = pair1_sock_close, + .sock_recv = pair1_sock_recv, + .sock_send = pair1_sock_send, + .sock_recv_poll_fd = pair1_sock_get_recv_fd, + .sock_send_poll_fd = pair1_sock_get_send_fd, + .sock_options = pair1_sock_options, }; static nni_proto pair1_proto = { @@ -823,14 +807,16 @@ nng_pair1_open(nng_socket *sock) } static nni_proto_sock_ops pair1_sock_ops_raw = { - .sock_size = sizeof(pair1_sock), - .sock_init = pair1_sock_init_raw, - .sock_fini = pair1_sock_fini, - .sock_open = pair1_sock_open, - .sock_close = pair1_sock_close, - .sock_recv = pair1_sock_recv, - .sock_send = pair1_sock_send, - .sock_options = pair1_sock_options, + .sock_size = sizeof(pair1_sock), + .sock_init = pair1_sock_init_raw, + .sock_fini = pair1_sock_fini, + .sock_open = pair1_sock_open, + .sock_close = pair1_sock_close, + .sock_recv = pair1_sock_recv, + .sock_send = pair1_sock_send, + .sock_recv_poll_fd = pair1_sock_get_recv_fd, + .sock_send_poll_fd = pair1_sock_get_send_fd, + .sock_options = pair1_sock_options, }; static nni_proto pair1_proto_raw = { diff --git a/src/sp/protocol/pair1/pair1_test.c b/src/sp/protocol/pair1/pair1_test.c index ea80d80c..b6bbee1a 100644 --- a/src/sp/protocol/pair1/pair1_test.c +++ b/src/sp/protocol/pair1/pair1_test.c @@ -8,6 +8,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include #define SECOND 1000 @@ -524,7 +525,7 @@ test_pair1_poll_readable(void) NUTS_PASS(nng_pair1_open(&s2)); NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(s2, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(s1, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(s1, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -570,7 +571,7 @@ test_pair1_poll_writable(void) NUTS_PASS(nng_pair1_open(&s2)); NUTS_PASS(nng_socket_set_ms(s1, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(s2, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(s1, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(s1, &fd)); NUTS_TRUE(fd >= 0); // Not writable if not connected! diff --git a/src/sp/protocol/pipeline0/pull.c b/src/sp/protocol/pipeline0/pull.c index 40dd514c..bfd8f6ea 100644 --- a/src/sp/protocol/pipeline0/pull.c +++ b/src/sp/protocol/pipeline0/pull.c @@ -253,23 +253,14 @@ pull0_sock_recv(void *arg, nni_aio *aio) } static int -pull0_sock_get_recv_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +pull0_sock_get_recv_fd(void *arg, int *fdp) { pull0_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 nni_option pull0_sock_options[] = { - { - .o_name = NNG_OPT_RECVFD, - .o_get = pull0_sock_get_recv_fd, - }, // terminate list { .o_name = NULL, @@ -286,14 +277,15 @@ static nni_proto_pipe_ops pull0_pipe_ops = { }; static nni_proto_sock_ops pull0_sock_ops = { - .sock_size = sizeof(pull0_sock), - .sock_init = pull0_sock_init, - .sock_fini = pull0_sock_fini, - .sock_open = pull0_sock_open, - .sock_close = pull0_sock_close, - .sock_send = pull0_sock_send, - .sock_recv = pull0_sock_recv, - .sock_options = pull0_sock_options, + .sock_size = sizeof(pull0_sock), + .sock_init = pull0_sock_init, + .sock_fini = pull0_sock_fini, + .sock_open = pull0_sock_open, + .sock_close = pull0_sock_close, + .sock_send = pull0_sock_send, + .sock_recv = pull0_sock_recv, + .sock_recv_poll_fd = pull0_sock_get_recv_fd, + .sock_options = pull0_sock_options, }; static nni_proto pull0_proto = { diff --git a/src/sp/protocol/pipeline0/pull_test.c b/src/sp/protocol/pipeline0/pull_test.c index be11a42d..6be5c2f5 100644 --- a/src/sp/protocol/pipeline0/pull_test.c +++ b/src/sp/protocol/pipeline0/pull_test.c @@ -7,6 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include static void @@ -58,7 +59,7 @@ test_pull_not_writeable(void) nng_socket s; NUTS_PASS(nng_pull0_open(&s)); - NUTS_FAIL(nng_socket_get_int(s, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP); + NUTS_FAIL(nng_socket_get_send_poll_fd(s, &fd), NNG_ENOTSUP); NUTS_CLOSE(s); } @@ -73,7 +74,7 @@ test_pull_poll_readable(void) NUTS_PASS(nng_push0_open(&push)); NUTS_PASS(nng_socket_set_ms(pull, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(push, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(pull, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(pull, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -110,7 +111,7 @@ test_pull_close_pending(void) NUTS_PASS(nng_pull0_open(&pull)); NUTS_PASS(nng_push0_open(&push)); - NUTS_PASS(nng_socket_get_int(pull, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(pull, &fd)); NUTS_TRUE(fd >= 0); NUTS_MARRY_EX(pull, push, addr, &p1, &p2); diff --git a/src/sp/protocol/pipeline0/push.c b/src/sp/protocol/pipeline0/push.c index 0bd57d0a..f99dddc3 100644 --- a/src/sp/protocol/pipeline0/push.c +++ b/src/sp/protocol/pipeline0/push.c @@ -364,16 +364,11 @@ push0_get_send_buf_len(void *arg, void *buf, size_t *szp, nni_opt_type t) } static int -push0_sock_get_send_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +push0_sock_get_send_fd(void *arg, int *fdp) { push0_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 nni_proto_pipe_ops push0_pipe_ops = { @@ -386,10 +381,6 @@ static nni_proto_pipe_ops push0_pipe_ops = { }; static nni_option push0_sock_options[] = { - { - .o_name = NNG_OPT_SENDFD, - .o_get = push0_sock_get_send_fd, - }, { .o_name = NNG_OPT_SENDBUF, .o_get = push0_get_send_buf_len, @@ -402,14 +393,15 @@ static nni_option push0_sock_options[] = { }; static nni_proto_sock_ops push0_sock_ops = { - .sock_size = sizeof(push0_sock), - .sock_init = push0_sock_init, - .sock_fini = push0_sock_fini, - .sock_open = push0_sock_open, - .sock_close = push0_sock_close, - .sock_options = push0_sock_options, - .sock_send = push0_sock_send, - .sock_recv = push0_sock_recv, + .sock_size = sizeof(push0_sock), + .sock_init = push0_sock_init, + .sock_fini = push0_sock_fini, + .sock_open = push0_sock_open, + .sock_close = push0_sock_close, + .sock_options = push0_sock_options, + .sock_send = push0_sock_send, + .sock_recv = push0_sock_recv, + .sock_send_poll_fd = push0_sock_get_send_fd, }; static nni_proto push0_proto = { diff --git a/src/sp/protocol/pipeline0/push_test.c b/src/sp/protocol/pipeline0/push_test.c index 15574732..249c62a9 100644 --- a/src/sp/protocol/pipeline0/push_test.c +++ b/src/sp/protocol/pipeline0/push_test.c @@ -7,6 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include static void @@ -59,7 +60,7 @@ test_push_not_readable(void) nng_socket s; NUTS_PASS(nng_push0_open(&s)); - NUTS_FAIL(nng_socket_get_int(s, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP); + NUTS_FAIL(nng_socket_get_recv_poll_fd(s, &fd), NNG_ENOTSUP); NUTS_CLOSE(s); } @@ -74,7 +75,7 @@ test_push_poll_writable(void) NUTS_PASS(nng_push0_open(&push)); NUTS_PASS(nng_socket_set_ms(pull, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(push, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(push, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(push, &fd)); NUTS_TRUE(fd >= 0); // This tests unbuffered sockets for now. @@ -118,7 +119,7 @@ test_push_poll_buffered(void) NUTS_PASS(nng_socket_set_ms(pull, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(push, NNG_OPT_SENDTIMEO, 1000)); NUTS_PASS(nng_socket_set_int(push, NNG_OPT_SENDBUF, 2)); - NUTS_PASS(nng_socket_get_int(push, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(push, &fd)); NUTS_TRUE(fd >= 0); // We can write two message while unbuffered. @@ -168,7 +169,7 @@ test_push_poll_truncate(void) NUTS_PASS(nng_socket_set_ms(pull, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(push, NNG_OPT_SENDTIMEO, 1000)); NUTS_PASS(nng_socket_set_int(push, NNG_OPT_SENDBUF, 3)); - NUTS_PASS(nng_socket_get_int(push, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(push, &fd)); NUTS_TRUE(fd >= 0); // We can write two message while unbuffered. diff --git a/src/sp/protocol/pubsub0/pub.c b/src/sp/protocol/pubsub0/pub.c index 9539b851..c40725f7 100644 --- a/src/sp/protocol/pubsub0/pub.c +++ b/src/sp/protocol/pubsub0/pub.c @@ -253,21 +253,13 @@ pub0_sock_send(void *arg, nni_aio *aio) } static int -pub0_sock_get_sendfd(void *arg, void *buf, size_t *szp, nni_type t) +pub0_sock_get_sendfd(void *arg, int *fdp) { pub0_sock *sock = arg; - int fd; - int rv; - nni_mtx_lock(&sock->mtx); + // PUB sockets are *always* writable. nni_pollable_raise(&sock->sendable); - rv = nni_pollable_getfd(&sock->sendable, &fd); - nni_mtx_unlock(&sock->mtx); - - if (rv == 0) { - rv = nni_copyout_int(fd, buf, szp, t); - } - return (rv); + return (nni_pollable_getfd(&sock->sendable, fdp)); } static int @@ -320,10 +312,6 @@ static nni_proto_pipe_ops pub0_pipe_ops = { static nni_option pub0_sock_options[] = { // terminate list - { - .o_name = NNG_OPT_SENDFD, - .o_get = pub0_sock_get_sendfd, - }, { .o_name = NNG_OPT_SENDBUF, .o_get = pub0_sock_get_sendbuf, @@ -335,14 +323,15 @@ static nni_option pub0_sock_options[] = { }; static nni_proto_sock_ops pub0_sock_ops = { - .sock_size = sizeof(pub0_sock), - .sock_init = pub0_sock_init, - .sock_fini = pub0_sock_fini, - .sock_open = pub0_sock_open, - .sock_close = pub0_sock_close, - .sock_send = pub0_sock_send, - .sock_recv = pub0_sock_recv, - .sock_options = pub0_sock_options, + .sock_size = sizeof(pub0_sock), + .sock_init = pub0_sock_init, + .sock_fini = pub0_sock_fini, + .sock_open = pub0_sock_open, + .sock_close = pub0_sock_close, + .sock_send = pub0_sock_send, + .sock_recv = pub0_sock_recv, + .sock_send_poll_fd = pub0_sock_get_sendfd, + .sock_options = pub0_sock_options, }; static nni_proto pub0_proto = { diff --git a/src/sp/protocol/pubsub0/pub_test.c b/src/sp/protocol/pubsub0/pub_test.c index 462decd2..4be4b06f 100644 --- a/src/sp/protocol/pubsub0/pub_test.c +++ b/src/sp/protocol/pubsub0/pub_test.c @@ -7,6 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include static void @@ -58,7 +59,7 @@ test_pub_not_readable(void) nng_socket pub; NUTS_PASS(nng_pub0_open(&pub)); - NUTS_FAIL(nng_socket_get_int(pub, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP); + NUTS_FAIL(nng_socket_get_recv_poll_fd(pub, &fd), NNG_ENOTSUP); NUTS_CLOSE(pub); } @@ -71,7 +72,7 @@ test_pub_poll_writeable(void) NUTS_PASS(nng_sub0_open(&sub)); NUTS_PASS(nng_pub0_open(&pub)); - NUTS_PASS(nng_socket_get_int(pub, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(pub, &fd)); NUTS_TRUE(fd >= 0); // Pub is *always* writeable diff --git a/src/sp/protocol/pubsub0/sub.c b/src/sp/protocol/pubsub0/sub.c index ee911153..5d6a2a05 100644 --- a/src/sp/protocol/pubsub0/sub.c +++ b/src/sp/protocol/pubsub0/sub.c @@ -615,16 +615,11 @@ sub0_sock_recv(void *arg, nni_aio *aio) } static int -sub0_sock_get_recv_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +sub0_sock_get_recv_fd(void *arg, int *fdp) { sub0_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 int @@ -698,10 +693,6 @@ static nni_option sub0_sock_options[] = { .o_name = NNG_OPT_SUB_UNSUBSCRIBE, .o_set = sub0_sock_unsubscribe, }, - { - .o_name = NNG_OPT_RECVFD, - .o_get = sub0_sock_get_recv_fd, - }, { .o_name = NNG_OPT_RECVBUF, .o_get = sub0_sock_get_recv_buf_len, @@ -719,14 +710,15 @@ static nni_option sub0_sock_options[] = { }; static nni_proto_sock_ops sub0_sock_ops = { - .sock_size = sizeof(sub0_sock), - .sock_init = sub0_sock_init, - .sock_fini = sub0_sock_fini, - .sock_open = sub0_sock_open, - .sock_close = sub0_sock_close, - .sock_send = sub0_sock_send, - .sock_recv = sub0_sock_recv, - .sock_options = sub0_sock_options, + .sock_size = sizeof(sub0_sock), + .sock_init = sub0_sock_init, + .sock_fini = sub0_sock_fini, + .sock_open = sub0_sock_open, + .sock_close = sub0_sock_close, + .sock_send = sub0_sock_send, + .sock_recv = sub0_sock_recv, + .sock_recv_poll_fd = sub0_sock_get_recv_fd, + .sock_options = sub0_sock_options, }; static nni_proto sub0_proto = { diff --git a/src/sp/protocol/pubsub0/sub_test.c b/src/sp/protocol/pubsub0/sub_test.c index a332a0a7..ef38042a 100644 --- a/src/sp/protocol/pubsub0/sub_test.c +++ b/src/sp/protocol/pubsub0/sub_test.c @@ -7,6 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include static void @@ -70,7 +71,7 @@ test_sub_not_writeable(void) nng_socket sub; NUTS_PASS(nng_sub0_open(&sub)); - NUTS_FAIL(nng_socket_get_int(sub, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP); + NUTS_FAIL(nng_socket_get_send_poll_fd(sub, &fd), NNG_ENOTSUP); NUTS_CLOSE(sub); } @@ -86,7 +87,7 @@ test_sub_poll_readable(void) NUTS_PASS(nng_socket_set(sub, NNG_OPT_SUB_SUBSCRIBE, "a", 1)); NUTS_PASS(nng_socket_set_ms(sub, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(pub, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(sub, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(sub, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -130,7 +131,7 @@ test_sub_recv_late(void) NUTS_PASS(nng_socket_set(sub, NNG_OPT_SUB_SUBSCRIBE, "", 0)); NUTS_PASS(nng_socket_set_ms(sub, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(pub, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(sub, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(sub, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -161,21 +162,6 @@ test_sub_recv_late(void) NUTS_CLOSE(sub); } -void -test_sub_context_no_poll(void) -{ - int fd; - nng_socket sub; - nng_ctx ctx; - - NUTS_PASS(nng_sub0_open(&sub)); - NUTS_PASS(nng_ctx_open(&ctx, sub)); - 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(sub); -} - void test_sub_validate_peer(void) { @@ -603,7 +589,6 @@ TEST_LIST = { { "sub context cannot send", test_sub_context_cannot_send }, { "sub not writeable", test_sub_not_writeable }, { "sub poll readable", test_sub_poll_readable }, - { "sub context does not poll", test_sub_context_no_poll }, { "sub validate peer", test_sub_validate_peer }, { "sub recv late", test_sub_recv_late }, { "sub recv ctx closed", test_sub_recv_ctx_closed }, diff --git a/src/sp/protocol/pubsub0/xsub_test.c b/src/sp/protocol/pubsub0/xsub_test.c index 9f2be2be..b8f303f3 100644 --- a/src/sp/protocol/pubsub0/xsub_test.c +++ b/src/sp/protocol/pubsub0/xsub_test.c @@ -7,6 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include static void @@ -47,7 +48,7 @@ test_xsub_not_writeable(void) nng_socket sub; NUTS_PASS(nng_sub0_open_raw(&sub)); - NUTS_FAIL(nng_socket_get_int(sub, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP); + NUTS_FAIL(nng_socket_get_send_poll_fd(sub, &fd), NNG_ENOTSUP); NUTS_CLOSE(sub); } @@ -62,7 +63,7 @@ test_xsub_poll_readable(void) NUTS_PASS(nng_pub0_open(&pub)); NUTS_PASS(nng_socket_set_ms(sub, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(pub, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(sub, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(sub, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -101,7 +102,7 @@ test_xsub_recv_late(void) NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); NUTS_PASS(nng_socket_set_ms(sub, NNG_OPT_RECVTIMEO, 1000)); NUTS_PASS(nng_socket_set_ms(pub, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(sub, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(sub, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! diff --git a/src/sp/protocol/reqrep0/rep.c b/src/sp/protocol/reqrep0/rep.c index 8559ebeb..6c06489d 100644 --- a/src/sp/protocol/reqrep0/rep.c +++ b/src/sp/protocol/reqrep0/rep.c @@ -595,30 +595,19 @@ rep0_sock_get_max_ttl(void *arg, void *buf, size_t *szp, nni_opt_type t) } static int -rep0_sock_get_sendfd(void *arg, void *buf, size_t *szp, nni_opt_type t) +rep0_sock_get_sendfd(void *arg, int *fdp) { rep0_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 -rep0_sock_get_recvfd(void *arg, void *buf, size_t *szp, nni_opt_type t) +rep0_sock_get_recvfd(void *arg, int *fdp) { rep0_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 @@ -662,14 +651,6 @@ static nni_option rep0_sock_options[] = { .o_get = rep0_sock_get_max_ttl, .o_set = rep0_sock_set_max_ttl, }, - { - .o_name = NNG_OPT_RECVFD, - .o_get = rep0_sock_get_recvfd, - }, - { - .o_name = NNG_OPT_SENDFD, - .o_get = rep0_sock_get_sendfd, - }, // terminate list { .o_name = NULL, @@ -677,14 +658,16 @@ static nni_option rep0_sock_options[] = { }; static nni_proto_sock_ops rep0_sock_ops = { - .sock_size = sizeof(rep0_sock), - .sock_init = rep0_sock_init, - .sock_fini = rep0_sock_fini, - .sock_open = rep0_sock_open, - .sock_close = rep0_sock_close, - .sock_options = rep0_sock_options, - .sock_send = rep0_sock_send, - .sock_recv = rep0_sock_recv, + .sock_size = sizeof(rep0_sock), + .sock_init = rep0_sock_init, + .sock_fini = rep0_sock_fini, + .sock_open = rep0_sock_open, + .sock_close = rep0_sock_close, + .sock_send = rep0_sock_send, + .sock_recv = rep0_sock_recv, + .sock_send_poll_fd = rep0_sock_get_sendfd, + .sock_recv_poll_fd = rep0_sock_get_recvfd, + .sock_options = rep0_sock_options, }; static nni_proto rep0_proto = { diff --git a/src/sp/protocol/reqrep0/rep_test.c b/src/sp/protocol/reqrep0/rep_test.c index 1a535998..58a54afe 100644 --- a/src/sp/protocol/reqrep0/rep_test.c +++ b/src/sp/protocol/reqrep0/rep_test.c @@ -54,7 +54,7 @@ test_rep_poll_writeable(void) NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_rep0_open(&rep)); - NUTS_PASS(nng_socket_get_int(rep, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(rep, &fd)); NUTS_TRUE(fd >= 0); // Not writable before connect. @@ -91,7 +91,7 @@ test_rep_poll_readable(void) NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_rep0_open(&rep)); - NUTS_PASS(nng_socket_get_int(rep, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(rep, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -119,21 +119,6 @@ test_rep_poll_readable(void) NUTS_CLOSE(rep); } -void -test_rep_context_no_poll(void) -{ - int fd; - nng_socket req; - nng_ctx ctx; - - NUTS_PASS(nng_rep0_open(&req)); - NUTS_PASS(nng_ctx_open(&ctx, req)); - 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(req); -} - void test_rep_validate_peer(void) { @@ -763,7 +748,6 @@ NUTS_TESTS = { { "rep send bad state", test_rep_send_bad_state }, { "rep poll readable", test_rep_poll_readable }, { "rep poll writable", test_rep_poll_writeable }, - { "rep context does not poll", test_rep_context_no_poll }, { "rep validate peer", test_rep_validate_peer }, { "rep huge send", test_rep_huge_send }, { "rep huge send socket", test_rep_huge_send_socket }, diff --git a/src/sp/protocol/reqrep0/req.c b/src/sp/protocol/reqrep0/req.c index 416b6fb7..b8b42c26 100644 --- a/src/sp/protocol/reqrep0/req.c +++ b/src/sp/protocol/reqrep0/req.c @@ -838,30 +838,19 @@ req0_sock_get_resend_tick(void *arg, void *buf, size_t *szp, nni_opt_type t) } static int -req0_sock_get_send_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +req0_sock_get_send_fd(void *arg, int *fdp) { req0_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 -req0_sock_get_recv_fd(void *arg, void *buf, size_t *szp, nni_opt_type t) +req0_sock_get_recv_fd(void *arg, int *fdp) { req0_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 nni_proto_pipe_ops req0_pipe_ops = { @@ -904,14 +893,6 @@ static nni_option req0_sock_options[] = { .o_get = req0_sock_get_resend_time, .o_set = req0_sock_set_resend_time, }, - { - .o_name = NNG_OPT_RECVFD, - .o_get = req0_sock_get_recv_fd, - }, - { - .o_name = NNG_OPT_SENDFD, - .o_get = req0_sock_get_send_fd, - }, { .o_name = NNG_OPT_REQ_RESENDTICK, .o_get = req0_sock_get_resend_tick, @@ -925,14 +906,16 @@ static nni_option req0_sock_options[] = { }; static nni_proto_sock_ops req0_sock_ops = { - .sock_size = sizeof(req0_sock), - .sock_init = req0_sock_init, - .sock_fini = req0_sock_fini, - .sock_open = req0_sock_open, - .sock_close = req0_sock_close, - .sock_options = req0_sock_options, - .sock_send = req0_sock_send, - .sock_recv = req0_sock_recv, + .sock_size = sizeof(req0_sock), + .sock_init = req0_sock_init, + .sock_fini = req0_sock_fini, + .sock_open = req0_sock_open, + .sock_close = req0_sock_close, + .sock_send = req0_sock_send, + .sock_recv = req0_sock_recv, + .sock_recv_poll_fd = req0_sock_get_recv_fd, + .sock_send_poll_fd = req0_sock_get_send_fd, + .sock_options = req0_sock_options, }; static nni_proto req0_proto = { diff --git a/src/sp/protocol/reqrep0/req_test.c b/src/sp/protocol/reqrep0/req_test.c index 31175cfd..61d9b347 100644 --- a/src/sp/protocol/reqrep0/req_test.c +++ b/src/sp/protocol/reqrep0/req_test.c @@ -8,6 +8,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include static void @@ -517,7 +518,7 @@ test_req_poll_writeable(void) NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_rep0_open(&rep)); - NUTS_PASS(nng_socket_get_int(req, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(req, &fd)); NUTS_TRUE(fd >= 0); // Not writable before connect. @@ -570,7 +571,7 @@ test_req_poll_contention(void) NUTS_PASS(nng_aio_alloc(&aio, NULL, NULL)); NUTS_PASS(nng_msg_alloc(&msg, 0)); - NUTS_PASS(nng_socket_get_int(req, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(req, &fd)); NUTS_TRUE(fd >= 0); // Not writable before connect. @@ -627,7 +628,7 @@ test_req_poll_multi_pipe(void) NUTS_PASS(nng_socket_set_int(req, NNG_OPT_SENDBUF, 1)); NUTS_PASS(nng_socket_set_ms(req, NNG_OPT_SENDTIMEO, 1000)); - NUTS_PASS(nng_socket_get_int(req, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(req, &fd)); NUTS_TRUE(fd >= 0); // Not writable before connect. @@ -655,7 +656,7 @@ test_req_poll_readable(void) NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_rep0_open(&rep)); - NUTS_PASS(nng_socket_get_int(req, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(req, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! @@ -688,21 +689,6 @@ test_req_poll_readable(void) NUTS_CLOSE(rep); } -static void -test_req_ctx_no_poll(void) -{ - int fd; - nng_socket req; - nng_ctx ctx; - - NUTS_PASS(nng_req0_open(&req)); - NUTS_PASS(nng_ctx_open(&ctx, req)); - 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(req); -} - static void test_req_ctx_send_queued(void) { @@ -1027,7 +1013,6 @@ NUTS_TESTS = { { "req context send abort", test_req_ctx_send_abort }, { "req context send twice", test_req_ctx_send_twice }, { "req context send recv abort", test_req_ctx_send_recv_abort }, - { "req context does not poll", test_req_ctx_no_poll }, { "req context recv close socket", test_req_ctx_recv_close_socket }, { "req context recv nonblock", test_req_ctx_recv_nonblock }, { "req context send nonblock", test_req_ctx_send_nonblock }, diff --git a/src/sp/protocol/reqrep0/xrep_test.c b/src/sp/protocol/reqrep0/xrep_test.c index cee5952f..67e38449 100644 --- a/src/sp/protocol/reqrep0/xrep_test.c +++ b/src/sp/protocol/reqrep0/xrep_test.c @@ -7,6 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include static void @@ -63,7 +64,7 @@ test_xrep_poll_writeable(void) NUTS_PASS(nng_rep0_open_raw(&rep)); NUTS_PASS(nng_req0_open(&req)); - NUTS_PASS(nng_socket_get_int(rep, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(rep, &fd)); NUTS_TRUE(fd >= 0); // We are always writeable, even before connect. This is so that @@ -91,7 +92,7 @@ test_xrep_poll_readable(void) NUTS_PASS(nng_req0_open(&req)); NUTS_PASS(nng_rep0_open_raw(&rep)); - NUTS_PASS(nng_socket_get_int(rep, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(rep, &fd)); NUTS_TRUE(fd >= 0); // Not readable if not connected! diff --git a/src/sp/protocol/reqrep0/xreq_test.c b/src/sp/protocol/reqrep0/xreq_test.c index c2d6c9ed..3ebe92da 100644 --- a/src/sp/protocol/reqrep0/xreq_test.c +++ b/src/sp/protocol/reqrep0/xreq_test.c @@ -7,6 +7,7 @@ // found online at https://opensource.org/licenses/MIT. // +#include "nng/nng.h" #include static void @@ -63,7 +64,7 @@ test_xreq_poll_writeable(void) NUTS_PASS(nng_req0_open_raw(&req)); NUTS_PASS(nng_rep0_open(&rep)); - NUTS_PASS(nng_socket_get_int(req, NNG_OPT_SENDFD, &fd)); + NUTS_PASS(nng_socket_get_send_poll_fd(req, &fd)); NUTS_TRUE(fd >= 0); // We can't write until we have a connection. @@ -88,7 +89,7 @@ test_xreq_poll_readable(void) NUTS_PASS(nng_req0_open_raw(&req)); NUTS_PASS(nng_rep0_open(&rep)); - NUTS_PASS(nng_socket_get_int(req, NNG_OPT_RECVFD, &fd)); + NUTS_PASS(nng_socket_get_recv_poll_fd(req, &fd)); 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/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 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! @@ -117,21 +118,6 @@ test_resp_poll_readable(void) NUTS_CLOSE(resp); } -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) { @@ -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 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! @@ -371,21 +372,6 @@ test_surv_poll_readable(void) NUTS_CLOSE(resp); } -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) { @@ -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 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 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)); -- cgit v1.2.3-70-g09d2