aboutsummaryrefslogtreecommitdiff
path: root/src/core/socket.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-04-16 11:40:28 -0700
committerGarrett D'Amore <garrett@damore.org>2018-04-16 20:56:32 -0700
commit45f3f141850a0ac07c31906748752571652683df (patch)
tree0e14b8e5a72972e370f60ea5fd230a790195cd28 /src/core/socket.c
parente3b8f31b044e4fe7d47439467fc1622266b5335c (diff)
downloadnng-45f3f141850a0ac07c31906748752571652683df.tar.gz
nng-45f3f141850a0ac07c31906748752571652683df.tar.bz2
nng-45f3f141850a0ac07c31906748752571652683df.zip
fixes #344 nn_poll() legacy API missing
This includes the test from legacy libnanomsg and a man page. We have refactored the message queue notification system so that it uses nni_pollable, leading we hope to a more consistent system, and reducing the code size and complexity. We also fixed the size of the NN_RCVFD and NN_SNDFD so that they are a SOCKET on Windows systems, rather than an integer. This addresses 64-bit compilation problems.
Diffstat (limited to 'src/core/socket.c')
-rw-r--r--src/core/socket.c62
1 files changed, 8 insertions, 54 deletions
diff --git a/src/core/socket.c b/src/core/socket.c
index 4021c0c6..5c28dbbb 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -92,37 +92,11 @@ struct nni_socket {
static void nni_ctx_destroy(nni_ctx *);
-static void
-nni_sock_can_send_cb(void *arg, int flags)
-{
- nni_notifyfd *fd = arg;
-
- if ((flags & nni_msgq_f_can_put) == 0) {
- nni_plat_pipe_clear(fd->sn_rfd);
- } else {
- nni_plat_pipe_raise(fd->sn_wfd);
- }
-}
-
-static void
-nni_sock_can_recv_cb(void *arg, int flags)
-{
- nni_notifyfd *fd = arg;
-
- if ((flags & nni_msgq_f_can_get) == 0) {
- nni_plat_pipe_clear(fd->sn_rfd);
- } else {
- nni_plat_pipe_raise(fd->sn_wfd);
- }
-}
-
static int
nni_sock_get_fd(nni_sock *s, int flag, int *fdp)
{
int rv;
- nni_notifyfd *fd;
- nni_msgq * mq;
- nni_msgq_cb cb;
+ nni_pollable *p;
if ((flag & nni_sock_flags(s)) == 0) {
return (NNG_ENOTSUP);
@@ -130,41 +104,21 @@ nni_sock_get_fd(nni_sock *s, int flag, int *fdp)
switch (flag) {
case NNI_PROTO_FLAG_SND:
- fd = &s->s_send_fd;
- mq = s->s_uwq;
- cb = nni_sock_can_send_cb;
+ rv = nni_msgq_get_sendable(s->s_uwq, &p);
break;
case NNI_PROTO_FLAG_RCV:
- fd = &s->s_recv_fd;
- mq = s->s_urq;
- cb = nni_sock_can_recv_cb;
+ rv = nni_msgq_get_recvable(s->s_urq, &p);
break;
default:
- // This should never occur.
- return (NNG_EINVAL);
+ rv = NNG_EINVAL;
+ break;
}
- // Open if not already done.
- if (!fd->sn_init) {
- if ((rv = nni_plat_pipe_open(&fd->sn_wfd, &fd->sn_rfd)) != 0) {
- return (rv);
- }
-
- // Only set the callback on the message queue if we are
- // using it. The message queue automatically updates
- // the pipe when the callback is first established.
- // If we are not using the message queue, then we have
- // to update the initial state explicitly ourselves.
-
- if ((nni_sock_flags(s) & NNI_PROTO_FLAG_NOMSGQ) == 0) {
- nni_msgq_set_cb(mq, cb, fd);
- }
-
- fd->sn_init = 1;
+ if (rv == 0) {
+ rv = nni_pollable_getfd(p, fdp);
}
- *fdp = fd->sn_rfd;
- return (0);
+ return (rv);
}
static int