aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-12-29 19:29:14 -0800
committerGarrett D'Amore <garrett@damore.org>2018-12-31 14:20:08 -0800
commit97118a423a48ecea816f37cb86378c5bafba2d51 (patch)
treedf9e70d0e5e48f3ab69ca3351171003c2b63ed38 /src/platform/posix
parent27b7827532abcbdbecc54795da5b5ac66e7f5e9f (diff)
downloadnng-97118a423a48ecea816f37cb86378c5bafba2d51.tar.gz
nng-97118a423a48ecea816f37cb86378c5bafba2d51.tar.bz2
nng-97118a423a48ecea816f37cb86378c5bafba2d51.zip
fixes #834 Simplify IPC internal API & update
This also makes some smaller related changes to use the new nni_type instead of nni_opt_type.
Diffstat (limited to 'src/platform/posix')
-rw-r--r--src/platform/posix/posix_ipc.h4
-rw-r--r--src/platform/posix/posix_ipcconn.c4
-rw-r--r--src/platform/posix/posix_ipcdial.c23
-rw-r--r--src/platform/posix/posix_ipclisten.c66
4 files changed, 75 insertions, 22 deletions
diff --git a/src/platform/posix/posix_ipc.h b/src/platform/posix/posix_ipc.h
index caf7ed7b..baf27206 100644
--- a/src/platform/posix/posix_ipc.h
+++ b/src/platform/posix/posix_ipc.h
@@ -1,6 +1,7 @@
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Devolutions <info@devolutions.net>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -13,6 +14,8 @@
#ifdef NNG_PLATFORM_POSIX
#include "platform/posix/posix_aio.h"
+#include <nng/transport/ipc/ipc.h>
+
#include <sys/types.h> // For mode_t
struct nni_ipc_conn {
@@ -34,6 +37,7 @@ struct nni_ipc_dialer {
struct nni_ipc_listener {
nni_posix_pfd *pfd;
+ nng_sockaddr sa;
nni_list acceptq;
bool started;
bool closed;
diff --git a/src/platform/posix/posix_ipcconn.c b/src/platform/posix/posix_ipcconn.c
index 8e4ae2f6..48bd75a4 100644
--- a/src/platform/posix/posix_ipcconn.c
+++ b/src/platform/posix/posix_ipcconn.c
@@ -1,7 +1,7 @@
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
-// Copyright 2018 Devolutions <infos@devolutions.net>
+// Copyright 2018 Devolutions <info@devolutions.net>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -39,8 +39,6 @@
#include "posix_ipc.h"
-#include <nng/transport/ipc/ipc.h>
-
static void
ipc_conn_dowrite(nni_ipc_conn *c)
{
diff --git a/src/platform/posix/posix_ipcdial.c b/src/platform/posix/posix_ipcdial.c
index 3d0ad0d8..d3dc2109 100644
--- a/src/platform/posix/posix_ipcdial.c
+++ b/src/platform/posix/posix_ipcdial.c
@@ -1,6 +1,7 @@
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Devolutions <info@devolutions.net>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -10,8 +11,6 @@
#include "core/nng_impl.h"
-#ifdef NNG_PLATFORM_POSIX
-
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
@@ -235,4 +234,22 @@ error:
nni_aio_finish_error(aio, rv);
}
-#endif // NNG_PLATFORM_POSIX
+static const nni_option ipc_dialer_options[] = {
+ {
+ .o_name = NULL,
+ },
+};
+
+int
+nni_ipc_dialer_getopt(
+ nni_ipc_dialer *d, const char *name, void *buf, size_t *szp, nni_type t)
+{
+ return (nni_getopt(ipc_dialer_options, name, d, buf, szp, t));
+}
+
+int
+nni_ipc_dialer_setopt(nni_ipc_dialer *d, const char *name, const void *buf,
+ size_t sz, nni_type t)
+{
+ return (nni_setopt(ipc_dialer_options, name, d, buf, sz, t));
+} \ No newline at end of file
diff --git a/src/platform/posix/posix_ipclisten.c b/src/platform/posix/posix_ipclisten.c
index 6ac3eaa8..11b56ab0 100644
--- a/src/platform/posix/posix_ipclisten.c
+++ b/src/platform/posix/posix_ipclisten.c
@@ -1,6 +1,7 @@
//
// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 Devolutions <info@devolutions.net>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -10,8 +11,6 @@
#include "core/nng_impl.h"
-#ifdef NNG_PLATFORM_POSIX
-
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -220,29 +219,65 @@ ipc_remove_stale(const char *path)
return (0);
}
-int
-nni_ipc_listener_set_permissions(nni_ipc_listener *l, int mode)
+static int
+ipc_listener_get_addr(void *arg, void *buf, size_t *szp, nni_type t)
{
+ nni_ipc_listener *l = arg;
+ return (nni_copyout_sockaddr(&l->sa, buf, szp, t));
+}
+
+static int
+ipc_listener_set_perms(void *arg, const void *buf, size_t sz, nni_type t)
+{
+ nni_ipc_listener *l = arg;
+ int mode;
+ int rv;
+
+ if ((rv = nni_copyin_int(&mode, buf, sz, 0, S_IFMT, t)) != 0) {
+ return (rv);
+ }
if ((mode & S_IFMT) != 0) {
return (NNG_EINVAL);
}
- mode |= S_IFSOCK; // set IFSOCK to ensure non-zero
- nni_mtx_lock(&l->mtx);
- if (l->started) {
+ if (l != NULL) {
+ mode |= S_IFSOCK; // set IFSOCK to ensure non-zero
+ nni_mtx_lock(&l->mtx);
+ if (l->started) {
+ nni_mtx_unlock(&l->mtx);
+ return (NNG_EBUSY);
+ }
+ l->perms = mode;
nni_mtx_unlock(&l->mtx);
- return (NNG_EBUSY);
}
- l->perms = mode;
- nni_mtx_unlock(&l->mtx);
return (0);
}
+static const nni_option ipc_listener_options[] = {
+ {
+ .o_name = NNG_OPT_LOCADDR,
+ .o_get = ipc_listener_get_addr,
+ },
+ {
+ .o_name = NNG_OPT_IPC_PERMISSIONS,
+ .o_set = ipc_listener_set_perms,
+ },
+ {
+ .o_name = NULL,
+ },
+};
+
int
-nni_ipc_listener_set_security_descriptor(nni_ipc_listener *l, void *sd)
+nni_ipc_listener_getopt(
+ nni_ipc_listener *l, const char *name, void *buf, size_t *szp, nni_type t)
{
- NNI_ARG_UNUSED(l);
- NNI_ARG_UNUSED(sd);
- return (NNG_ENOTSUP);
+ return (nni_getopt(ipc_listener_options, name, l, buf, szp, t));
+}
+
+int
+nni_ipc_listener_setopt(nni_ipc_listener *l, const char *name, const void *buf,
+ size_t sz, nni_type t)
+{
+ return (nni_setopt(ipc_listener_options, name, l, buf, sz, t));
}
int
@@ -317,6 +352,7 @@ nni_ipc_listener_listen(nni_ipc_listener *l, const nni_sockaddr *sa)
l->pfd = pfd;
l->started = true;
l->path = path;
+ l->sa = *sa;
nni_mtx_unlock(&l->mtx);
return (0);
@@ -374,5 +410,3 @@ nni_ipc_listener_accept(nni_ipc_listener *l, nni_aio *aio)
}
nni_mtx_unlock(&l->mtx);
}
-
-#endif // NNG_PLATFORM_POSIX