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/bus0 | |
| 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/bus0')
| -rw-r--r-- | src/sp/protocol/bus0/bus.c | 66 | ||||
| -rw-r--r-- | src/sp/protocol/bus0/bus_test.c | 7 |
2 files changed, 28 insertions, 45 deletions
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 @@ -475,14 +461,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, .o_set = bus0_sock_set_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 <nuts.h> #include <nng/protocol/bus0/bus.h> @@ -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) |
