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/pair0/pair.c | 44 ++++++++++++-------------------------- src/sp/protocol/pair0/pair0_test.c | 7 +++--- 2 files changed, 18 insertions(+), 33 deletions(-) (limited to 'src/sp/protocol/pair0') 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! -- cgit v1.2.3-70-g09d2