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/pubsub0/pub.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'src/sp/protocol/pubsub0/pub.c') 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 = { -- cgit v1.2.3-70-g09d2