From 27b7827532abcbdbecc54795da5b5ac66e7f5e9f Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 29 Dec 2018 18:54:22 -0800 Subject: progress on IPC endpoints --- src/platform/windows/win_ipc.h | 4 ++- src/platform/windows/win_ipcconn.c | 4 +-- src/platform/windows/win_ipcdial.c | 21 +++++++++++ src/platform/windows/win_ipclisten.c | 67 ++++++++++++++++++++++++++++-------- 4 files changed, 77 insertions(+), 19 deletions(-) (limited to 'src/platform/windows') diff --git a/src/platform/windows/win_ipc.h b/src/platform/windows/win_ipc.h index 9a4e245a..781522b9 100644 --- a/src/platform/windows/win_ipc.h +++ b/src/platform/windows/win_ipc.h @@ -1,7 +1,7 @@ // // Copyright 2018 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV -// Copyright 2018 Devolutions +// Copyright 2018 Devolutions // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -16,6 +16,7 @@ #include "core/nng_impl.h" #include "win_impl.h" +#include #define IPC_PIPE_PREFIX "\\\\.\\pipe\\" @@ -54,6 +55,7 @@ struct nni_ipc_listener { nni_mtx mtx; nni_cv cv; nni_win_io io; + nni_sockaddr sa; int rv; }; diff --git a/src/platform/windows/win_ipcconn.c b/src/platform/windows/win_ipcconn.c index 5a1e4743..ded9ed76 100644 --- a/src/platform/windows/win_ipcconn.c +++ b/src/platform/windows/win_ipcconn.c @@ -1,7 +1,7 @@ // // Copyright 2018 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV -// Copyright 2018 Devolutions +// Copyright 2018 Devolutions // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -15,8 +15,6 @@ #include -#include - #define CONN(c) ((nni_ipc_conn *) (c)) static void diff --git a/src/platform/windows/win_ipcdial.c b/src/platform/windows/win_ipcdial.c index 4c3d5c6c..98d848ae 100644 --- a/src/platform/windows/win_ipcdial.c +++ b/src/platform/windows/win_ipcdial.c @@ -1,6 +1,7 @@ // // Copyright 2018 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV +// Copyright 2018 Devolutions // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -227,6 +228,26 @@ nni_ipc_dialer_close(nni_ipc_dialer *d) nni_mtx_unlock(&w->mtx); } +static const nni_option ipc_dialer_options[] = { + { + .o_name = NULL, + }, +}; + +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)); +} + +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_win_ipc_sysinit(void) { diff --git a/src/platform/windows/win_ipclisten.c b/src/platform/windows/win_ipclisten.c index d0fd6ef9..4b3660ec 100644 --- a/src/platform/windows/win_ipclisten.c +++ b/src/platform/windows/win_ipclisten.c @@ -1,6 +1,7 @@ // // Copyright 2018 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV +// Copyright 2018 Devolutions // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -146,30 +147,66 @@ nni_ipc_listener_init(nni_ipc_listener **lp) return (0); } -int -nni_ipc_listener_set_permissions(nni_ipc_listener *l, int bits) +static int +ipc_listener_set_sec_desc(void *arg, const void *buf, size_t sz, nni_type t) { - NNI_ARG_UNUSED(l); - NNI_ARG_UNUSED(bits); - return (NNG_ENOTSUP); -} + nni_ipc_listener *l = arg; + void * desc; + int rv; -int -nni_ipc_listener_set_security_descriptor(nni_ipc_listener *l, void *desc) -{ + if ((rv = nni_copyin_ptr(&desc, buf, sz, t)) != 0) { + return (rv); + } if (!IsValidSecurityDescriptor((SECURITY_DESCRIPTOR *) desc)) { return (NNG_EINVAL); } - nni_mtx_lock(&l->mtx); - if (l->started) { + if (l != NULL) { + nni_mtx_lock(&l->mtx); + if (l->started) { + nni_mtx_unlock(&l->mtx); + return (NNG_EBUSY); + } + l->sec_attr.lpSecurityDescriptor = desc; nni_mtx_unlock(&l->mtx); - return (NNG_EBUSY); } - l->sec_attr.lpSecurityDescriptor = desc; - nni_mtx_unlock(&l->mtx); return (0); } +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 const nni_option ipc_listener_options[] = { + { + .o_name = NNG_OPT_IPC_SECURITY_DESCRIPTOR, + .o_set = ipc_listener_set_sec_desc, + }, + { + .o_name = NNG_OPT_LOCADDR, + .o_get = ipc_listener_get_addr, + }, + { + .o_name = NULL, + }, +}; + +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 +nni_ipc_listener_getopt( + nni_ipc_listener *l, const char *name, void *buf, size_t *szp, nni_type t) +{ + return (nni_getopt(ipc_listener_options, name, l, buf, szp, t)); +} + int nni_ipc_listener_listen(nni_ipc_listener *l, const nni_sockaddr *sa) { @@ -218,6 +255,7 @@ nni_ipc_listener_listen(nni_ipc_listener *l, const nni_sockaddr *sa) l->f = f; l->path = path; l->started = true; + l->sa = *sa; nni_mtx_unlock(&l->mtx); return (0); } @@ -266,7 +304,6 @@ nni_ipc_listener_accept(nni_ipc_listener *l, nni_aio *aio) void nni_ipc_listener_close(nni_ipc_listener *l) { - nni_mtx_lock(&l->mtx); if (!l->closed) { l->closed = true; -- cgit v1.2.3-70-g09d2