diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-11-02 13:57:53 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-11-02 14:47:50 -0700 |
| commit | 279180c1d07fc2c4c0bfa8f5a418cb02c4b87863 (patch) | |
| tree | b451ac7f845062674d6ab45eb5d530628d3ff47c /src/sp/protocol/reqrep0 | |
| parent | 9b27984d0e2da430b78a975e59f55c96de5f6056 (diff) | |
| download | nng-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/reqrep0')
| -rw-r--r-- | src/sp/protocol/reqrep0/rep.c | 45 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/rep_test.c | 20 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/req.c | 45 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/req_test.c | 25 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/xrep_test.c | 5 | ||||
| -rw-r--r-- | src/sp/protocol/reqrep0/xreq_test.c | 5 |
6 files changed, 41 insertions, 104 deletions
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! @@ -120,21 +120,6 @@ test_rep_poll_readable(void) } 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) { nng_socket s1, s2; @@ -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 = { @@ -905,14 +894,6 @@ static nni_option req0_sock_options[] = { .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, .o_set = req0_sock_set_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 <nuts.h> 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! @@ -689,21 +690,6 @@ test_req_poll_readable(void) } 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) { nng_socket req; @@ -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 <nuts.h> 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 <nuts.h> 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)); |
