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/pair1/pair.c | 62 +++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 38 deletions(-) (limited to 'src/sp/protocol/pair1/pair.c') 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 = { -- cgit v1.2.3-70-g09d2