aboutsummaryrefslogtreecommitdiff
path: root/src/sp/protocol/pipeline0
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-11-02 13:57:53 -0700
committerGarrett D'Amore <garrett@damore.org>2024-11-02 14:47:50 -0700
commit279180c1d07fc2c4c0bfa8f5a418cb02c4b87863 (patch)
treeb451ac7f845062674d6ab45eb5d530628d3ff47c /src/sp/protocol/pipeline0
parent9b27984d0e2da430b78a975e59f55c96de5f6056 (diff)
downloadnng-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/pipeline0')
-rw-r--r--src/sp/protocol/pipeline0/pull.c30
-rw-r--r--src/sp/protocol/pipeline0/pull_test.c7
-rw-r--r--src/sp/protocol/pipeline0/push.c30
-rw-r--r--src/sp/protocol/pipeline0/push_test.c9
4 files changed, 31 insertions, 45 deletions
diff --git a/src/sp/protocol/pipeline0/pull.c b/src/sp/protocol/pipeline0/pull.c
index 40dd514c..bfd8f6ea 100644
--- a/src/sp/protocol/pipeline0/pull.c
+++ b/src/sp/protocol/pipeline0/pull.c
@@ -253,23 +253,14 @@ pull0_sock_recv(void *arg, nni_aio *aio)
}
static int
-pull0_sock_get_recv_fd(void *arg, void *buf, size_t *szp, nni_opt_type t)
+pull0_sock_get_recv_fd(void *arg, int *fdp)
{
pull0_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_option pull0_sock_options[] = {
- {
- .o_name = NNG_OPT_RECVFD,
- .o_get = pull0_sock_get_recv_fd,
- },
// terminate list
{
.o_name = NULL,
@@ -286,14 +277,15 @@ static nni_proto_pipe_ops pull0_pipe_ops = {
};
static nni_proto_sock_ops pull0_sock_ops = {
- .sock_size = sizeof(pull0_sock),
- .sock_init = pull0_sock_init,
- .sock_fini = pull0_sock_fini,
- .sock_open = pull0_sock_open,
- .sock_close = pull0_sock_close,
- .sock_send = pull0_sock_send,
- .sock_recv = pull0_sock_recv,
- .sock_options = pull0_sock_options,
+ .sock_size = sizeof(pull0_sock),
+ .sock_init = pull0_sock_init,
+ .sock_fini = pull0_sock_fini,
+ .sock_open = pull0_sock_open,
+ .sock_close = pull0_sock_close,
+ .sock_send = pull0_sock_send,
+ .sock_recv = pull0_sock_recv,
+ .sock_recv_poll_fd = pull0_sock_get_recv_fd,
+ .sock_options = pull0_sock_options,
};
static nni_proto pull0_proto = {
diff --git a/src/sp/protocol/pipeline0/pull_test.c b/src/sp/protocol/pipeline0/pull_test.c
index be11a42d..6be5c2f5 100644
--- a/src/sp/protocol/pipeline0/pull_test.c
+++ b/src/sp/protocol/pipeline0/pull_test.c
@@ -7,6 +7,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include "nng/nng.h"
#include <nuts.h>
static void
@@ -58,7 +59,7 @@ test_pull_not_writeable(void)
nng_socket s;
NUTS_PASS(nng_pull0_open(&s));
- NUTS_FAIL(nng_socket_get_int(s, NNG_OPT_SENDFD, &fd), NNG_ENOTSUP);
+ NUTS_FAIL(nng_socket_get_send_poll_fd(s, &fd), NNG_ENOTSUP);
NUTS_CLOSE(s);
}
@@ -73,7 +74,7 @@ test_pull_poll_readable(void)
NUTS_PASS(nng_push0_open(&push));
NUTS_PASS(nng_socket_set_ms(pull, NNG_OPT_RECVTIMEO, 1000));
NUTS_PASS(nng_socket_set_ms(push, NNG_OPT_SENDTIMEO, 1000));
- NUTS_PASS(nng_socket_get_int(pull, NNG_OPT_RECVFD, &fd));
+ NUTS_PASS(nng_socket_get_recv_poll_fd(pull, &fd));
NUTS_TRUE(fd >= 0);
// Not readable if not connected!
@@ -110,7 +111,7 @@ test_pull_close_pending(void)
NUTS_PASS(nng_pull0_open(&pull));
NUTS_PASS(nng_push0_open(&push));
- NUTS_PASS(nng_socket_get_int(pull, NNG_OPT_RECVFD, &fd));
+ NUTS_PASS(nng_socket_get_recv_poll_fd(pull, &fd));
NUTS_TRUE(fd >= 0);
NUTS_MARRY_EX(pull, push, addr, &p1, &p2);
diff --git a/src/sp/protocol/pipeline0/push.c b/src/sp/protocol/pipeline0/push.c
index 0bd57d0a..f99dddc3 100644
--- a/src/sp/protocol/pipeline0/push.c
+++ b/src/sp/protocol/pipeline0/push.c
@@ -364,16 +364,11 @@ push0_get_send_buf_len(void *arg, void *buf, size_t *szp, nni_opt_type t)
}
static int
-push0_sock_get_send_fd(void *arg, void *buf, size_t *szp, nni_opt_type t)
+push0_sock_get_send_fd(void *arg, int *fdp)
{
push0_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 push0_pipe_ops = {
@@ -387,10 +382,6 @@ static nni_proto_pipe_ops push0_pipe_ops = {
static nni_option push0_sock_options[] = {
{
- .o_name = NNG_OPT_SENDFD,
- .o_get = push0_sock_get_send_fd,
- },
- {
.o_name = NNG_OPT_SENDBUF,
.o_get = push0_get_send_buf_len,
.o_set = push0_set_send_buf_len,
@@ -402,14 +393,15 @@ static nni_option push0_sock_options[] = {
};
static nni_proto_sock_ops push0_sock_ops = {
- .sock_size = sizeof(push0_sock),
- .sock_init = push0_sock_init,
- .sock_fini = push0_sock_fini,
- .sock_open = push0_sock_open,
- .sock_close = push0_sock_close,
- .sock_options = push0_sock_options,
- .sock_send = push0_sock_send,
- .sock_recv = push0_sock_recv,
+ .sock_size = sizeof(push0_sock),
+ .sock_init = push0_sock_init,
+ .sock_fini = push0_sock_fini,
+ .sock_open = push0_sock_open,
+ .sock_close = push0_sock_close,
+ .sock_options = push0_sock_options,
+ .sock_send = push0_sock_send,
+ .sock_recv = push0_sock_recv,
+ .sock_send_poll_fd = push0_sock_get_send_fd,
};
static nni_proto push0_proto = {
diff --git a/src/sp/protocol/pipeline0/push_test.c b/src/sp/protocol/pipeline0/push_test.c
index 15574732..249c62a9 100644
--- a/src/sp/protocol/pipeline0/push_test.c
+++ b/src/sp/protocol/pipeline0/push_test.c
@@ -7,6 +7,7 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include "nng/nng.h"
#include <nuts.h>
static void
@@ -59,7 +60,7 @@ test_push_not_readable(void)
nng_socket s;
NUTS_PASS(nng_push0_open(&s));
- NUTS_FAIL(nng_socket_get_int(s, NNG_OPT_RECVFD, &fd), NNG_ENOTSUP);
+ NUTS_FAIL(nng_socket_get_recv_poll_fd(s, &fd), NNG_ENOTSUP);
NUTS_CLOSE(s);
}
@@ -74,7 +75,7 @@ test_push_poll_writable(void)
NUTS_PASS(nng_push0_open(&push));
NUTS_PASS(nng_socket_set_ms(pull, NNG_OPT_RECVTIMEO, 1000));
NUTS_PASS(nng_socket_set_ms(push, NNG_OPT_SENDTIMEO, 1000));
- NUTS_PASS(nng_socket_get_int(push, NNG_OPT_SENDFD, &fd));
+ NUTS_PASS(nng_socket_get_send_poll_fd(push, &fd));
NUTS_TRUE(fd >= 0);
// This tests unbuffered sockets for now.
@@ -118,7 +119,7 @@ test_push_poll_buffered(void)
NUTS_PASS(nng_socket_set_ms(pull, NNG_OPT_RECVTIMEO, 1000));
NUTS_PASS(nng_socket_set_ms(push, NNG_OPT_SENDTIMEO, 1000));
NUTS_PASS(nng_socket_set_int(push, NNG_OPT_SENDBUF, 2));
- NUTS_PASS(nng_socket_get_int(push, NNG_OPT_SENDFD, &fd));
+ NUTS_PASS(nng_socket_get_send_poll_fd(push, &fd));
NUTS_TRUE(fd >= 0);
// We can write two message while unbuffered.
@@ -168,7 +169,7 @@ test_push_poll_truncate(void)
NUTS_PASS(nng_socket_set_ms(pull, NNG_OPT_RECVTIMEO, 1000));
NUTS_PASS(nng_socket_set_ms(push, NNG_OPT_SENDTIMEO, 1000));
NUTS_PASS(nng_socket_set_int(push, NNG_OPT_SENDBUF, 3));
- NUTS_PASS(nng_socket_get_int(push, NNG_OPT_SENDFD, &fd));
+ NUTS_PASS(nng_socket_get_send_poll_fd(push, &fd));
NUTS_TRUE(fd >= 0);
// We can write two message while unbuffered.