diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-12-29 19:29:14 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-12-31 14:20:08 -0800 |
| commit | 97118a423a48ecea816f37cb86378c5bafba2d51 (patch) | |
| tree | df9e70d0e5e48f3ab69ca3351171003c2b63ed38 /src | |
| parent | 27b7827532abcbdbecc54795da5b5ac66e7f5e9f (diff) | |
| download | nng-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')
| -rw-r--r-- | src/core/options.c | 1 | ||||
| -rw-r--r-- | src/core/options.h | 1 | ||||
| -rw-r--r-- | src/core/platform.h | 35 | ||||
| -rw-r--r-- | src/platform/posix/posix_ipc.h | 4 | ||||
| -rw-r--r-- | src/platform/posix/posix_ipcconn.c | 4 | ||||
| -rw-r--r-- | src/platform/posix/posix_ipcdial.c | 23 | ||||
| -rw-r--r-- | src/platform/posix/posix_ipclisten.c | 66 | ||||
| -rw-r--r-- | src/supplemental/ipc/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/supplemental/ipc/ipc.c | 2 | ||||
| -rw-r--r-- | src/transport/ipc/ipc.c | 16 |
10 files changed, 83 insertions, 71 deletions
diff --git a/src/core/options.c b/src/core/options.c index 097b92b2..23118116 100644 --- a/src/core/options.c +++ b/src/core/options.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 diff --git a/src/core/options.h b/src/core/options.h index c0d5b23d..9c5d4817 100644 --- a/src/core/options.h +++ b/src/core/options.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 diff --git a/src/core/platform.h b/src/core/platform.h index b6916b2e..58955a3a 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -260,7 +260,7 @@ extern int nni_tcp_conn_sockname(nni_tcp_conn *, nni_sockaddr *); extern int nni_tcp_conn_set_nodelay(nni_tcp_conn *, bool); // nni_tcp_conn_set_keepalive indicates that the TCP pipe should send -// keepalive probes. Tuning of these keepalives is current unsupported. +// keepalive probes. Tuning of these keepalives is currently unsupported. extern int nni_tcp_conn_set_keepalive(nni_tcp_conn *, bool); // nni_tcp_dialer_init creates a new dialer object. @@ -361,21 +361,6 @@ extern void nni_ipc_conn_send(nni_ipc_conn *, nni_aio *); // receive zero bytes.) The platform may modify the iovs. extern void nni_ipc_conn_recv(nni_ipc_conn *, nni_aio *); -// nni_ipc_conn_get_peer_uid obtains the peer user id, if possible. -// NB: Only POSIX systems support user IDs. -extern int nni_ipc_conn_get_peer_uid(nni_ipc_conn *, uint64_t *); - -// nni_ipc_conn_get_peer_gid obtains the peer group id, if possible. -// NB: Only POSIX systems support group IDs. -extern int nni_ipc_conn_get_peer_gid(nni_ipc_conn *, uint64_t *); - -// nni_ipc_conn_get_peer_pid obtains the peer process id, if possible. -extern int nni_ipc_conn_get_peer_pid(nni_ipc_conn *, uint64_t *); - -// nni_ipc_conn_get_peer_zoneid obtains the peer zone id, if possible. -// NB: Only illumos & SunOS systems have the notion of "zones". -extern int nni_ipc_conn_get_peer_zoneid(nni_ipc_conn *, uint64_t *); - // nni_ipc_conn_setopt is like setsockopt, but uses string names. These // are the same names from the IPC transport, generally. There are no // options that are generally settable on an IPC connection. @@ -437,24 +422,6 @@ extern int nni_ipc_listener_listen(nni_ipc_listener *, const nni_sockaddr *); // associated with the remote peer. extern void nni_ipc_listener_accept(nni_ipc_listener *, nni_aio *); -// nni_ipc_listener_set_permissions sets UNIX style permissions -// on the named pipes. This basically just does a chmod() on the -// named pipe, and is only supported o the server side, and only on -// systems that support this (POSIX, not Windows). Note that changing -// ownership is not supported at this time. Most systems use only -// 16-bits, the lower 12 of which are user, group, and other, e.g. -// 0640 gives read/write access to user, read to group, and prevents -// any other user from accessing it. On platforms without this support, -// ENOTSUP is returned. -extern int nni_ipc_listener_set_permissions(nni_ipc_listener *, int); - -// nni_ipc_listener_set_security_descriptor sets the Windows security -// descriptor. This is *only* supported for Windows platforms. All -// others return NNG_ENOTSUP. The void argument is a pointer to -// a SECURITY_DESCRIPTOR object, and must be valid. -extern int nni_ipc_listener_set_security_descriptor( - nni_ipc_listener *, void *); - // nni_ipc_listener_getopt is used to get options from the listener. // The only valid option is NNG_OPT_LOCADDR, which will only have // a valid value if the socket is bound, otherwise the value returned 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 diff --git a/src/supplemental/ipc/CMakeLists.txt b/src/supplemental/ipc/CMakeLists.txt index 691522f0..3bc0e4de 100644 --- a/src/supplemental/ipc/CMakeLists.txt +++ b/src/supplemental/ipc/CMakeLists.txt @@ -1,7 +1,7 @@ # # Copyright 2018 Capitar IT Group BV <info@capitar.com> # Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> -# 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 diff --git a/src/supplemental/ipc/ipc.c b/src/supplemental/ipc/ipc.c index f5e590fc..cf78dfbd 100644 --- a/src/supplemental/ipc/ipc.c +++ b/src/supplemental/ipc/ipc.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 diff --git a/src/transport/ipc/ipc.c b/src/transport/ipc/ipc.c index 1f8f27c4..87764023 100644 --- a/src/transport/ipc/ipc.c +++ b/src/transport/ipc/ipc.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 @@ -13,7 +14,8 @@ #include <string.h> #include "core/nng_impl.h" -#include "nng/transport/ipc/ipc.h" + +#include <nng/transport/ipc/ipc.h> // IPC transport. Platform specific IPC operations must be // supplied as well. Normally the IPC is UNIX domain sockets or @@ -872,18 +874,6 @@ ipctran_ep_accept(void *arg, nni_aio *aio) } static int -ipctran_ep_get_locaddr(void *arg, void *buf, size_t *szp, nni_opt_type t) -{ - ipctran_ep *ep = arg; - int rv; - - nni_mtx_lock(&ep->mtx); - rv = nni_copyout_sockaddr(&ep->sa, buf, szp, t); - nni_mtx_unlock(&ep->mtx); - return (rv); -} - -static int ipctran_pipe_getopt( void *arg, const char *name, void *buf, size_t *szp, nni_type t) { |
