diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-05-05 11:03:33 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-05-06 15:21:33 -0700 |
| commit | 916ba1ab23aa50b855fd795f095eaedb328e84d9 (patch) | |
| tree | b764e37145e7caf8f2fe7d1a3999ab6798c3a095 | |
| parent | 7ecb0e4a74bbb3d49ebe37a14b2534a242cb930a (diff) | |
| download | nng-916ba1ab23aa50b855fd795f095eaedb328e84d9.tar.gz nng-916ba1ab23aa50b855fd795f095eaedb328e84d9.tar.bz2 nng-916ba1ab23aa50b855fd795f095eaedb328e84d9.zip | |
fixes #396 illumos doesn't build (missing NNG_PLATFORM_POSIX ON)
fixes #397 Need to cast zoneid
fixes #395 sun is predefined on illumos/Solaris
fixes #394 alloca needs to #include <alloca.h>
fixes #399 Cannot use SVR4.2 specific msghdr
fixes #402 getpeerucred needs a NULL initialized ucred
fixes #403 syntax error in posix_tcp - attempt to return void
fixes #407 illumos getegid wrong
fixes #406 nni_idhash_count is dead code
fixes #404 idhash typedef redeclared
fixes #405 warning: newline not last character in file
This is basically a slew of related bug fixes required to make this
work on illumos. Note that the fixes are not "complete", because
more work is required to support port events given that epoll is busted
on illumos.
We also fixed a bunch of things that aren't actually "bugs" per se, but
really just warnings. Silencing them makes things better for everyone.
Apparently not all compilers are equally happy with redundant (but
otherwise identical) typedefs; we use structs in some places instead of
shorter type names to silence these complaints.
Note that IPC permissions (the mode bits on the socket vnode) are not
validated on SunOS systems. This change includes documentation to reflect
that.
47 files changed, 185 insertions, 175 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index f1bde337..c91e6a34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -307,6 +307,7 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") elseif (CMAKE_SYSTEM_NAME MATCHES "SunOS") add_definitions (-DNNG_PLATFORM_POSIX) add_definitions (-DNNG_PLATFORM_SUNOS) + set(NNG_PLATFORM_POSIX ON) elseif (CMAKE_SYSTEM_NAME MATCHES "Windows") add_definitions (-DNNG_PLATFORM_WINDOWS) diff --git a/docs/man/nng_ipc.7.adoc b/docs/man/nng_ipc.7.adoc index 6bfa338b..ef9fd1b1 100644 --- a/docs/man/nng_ipc.7.adoc +++ b/docs/man/nng_ipc.7.adoc @@ -77,12 +77,27 @@ on a file, such as `0600` (typically meaning read-write to the owner, and no permissions for anyone else.) The default is system-specific, most often `0644`. +IMPORTANT: Not all systems validate these permissions. +In particular, illumos and Solaris are known to ignore these permission +settings when connecting. + NOTE: Normally both read and write permission will be necessary for a peer dialer to connect. See your system documentation for UNIX domain sockets for more information. NOTE: The _umask_ of the process is *not* applied to these bits. +TIP: The best practice for limiting access is to place the socket in a +directory writable only by the server, and only readable and searchable +by clients. +All mainstream POSIX systems will fail to permit a client to connect +to a socket located in a diretor for which the client lacks search (execute) +permission. + +TIP: Also consider using the `NNG_OPT_IPC_PEER_UID` property from within a +a pipe notification callback (`<<nng_pipe_notify.3#,nng_pipe_notify()>>`) +to validate peer credentials. + ((`NNG_OPT_IPC_SECURITY_DESCRIPTOR`)):: (`PSECURITY_DESCRIPTOR`) diff --git a/src/compat/nanomsg/nn.c b/src/compat/nanomsg/nn.c index 03df279b..6d23106c 100644 --- a/src/compat/nanomsg/nn.c +++ b/src/compat/nanomsg/nn.c @@ -1166,4 +1166,4 @@ nn_get_statistic(int x, int y) (void) y; return (0); -}
\ No newline at end of file +} diff --git a/src/core/clock.c b/src/core/clock.c index f114daa1..49b972e7 100644 --- a/src/core/clock.c +++ b/src/core/clock.c @@ -19,4 +19,4 @@ void nni_msleep(nni_duration msec) { nni_plat_sleep(msec); -}
\ No newline at end of file +} diff --git a/src/core/defs.h b/src/core/defs.h index 1d656bb2..b9c9b7e5 100644 --- a/src/core/defs.h +++ b/src/core/defs.h @@ -59,7 +59,6 @@ typedef struct nni_proto nni_proto; typedef struct nni_plat_mtx nni_mtx; typedef struct nni_plat_cv nni_cv; -typedef struct nni_idhash nni_idhash; typedef struct nni_thr nni_thr; typedef void (*nni_thr_func)(void *); diff --git a/src/core/file.c b/src/core/file.c index b76fdcda..173a864d 100644 --- a/src/core/file.c +++ b/src/core/file.c @@ -156,4 +156,4 @@ nni_file_unlock(nni_file_lockh *h) { nni_plat_file_unlock(&h->lk); NNI_FREE_STRUCT(h); -}
\ No newline at end of file +} diff --git a/src/core/idhash.c b/src/core/idhash.c index 2bf01d6b..0de83eb1 100644 --- a/src/core/idhash.c +++ b/src/core/idhash.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore <garrett@damore.org> -// Copyright 2017 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -306,14 +306,3 @@ nni_idhash_alloc(nni_idhash *h, uint64_t *idp, void *val) return (rv); } - -size_t -nni_idhash_count(nni_idhash *h) -{ - size_t num; - nni_mtx_lock(&h->ih_mtx); - num = h->ih_count; - nni_mtx_unlock(&h->ih_mtx); - - return (num); -} diff --git a/src/core/idhash.h b/src/core/idhash.h index 9dbdd45e..36797a76 100644 --- a/src/core/idhash.h +++ b/src/core/idhash.h @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore <garrett@damore.org> -// Copyright 2017 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> // // 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/message.c b/src/core/message.c index 5c396f21..ba3c0e84 100644 --- a/src/core/message.c +++ b/src/core/message.c @@ -627,4 +627,4 @@ uint32_t nni_msg_get_pipe(const nni_msg *m) { return (m->m_pipe); -}
\ No newline at end of file +} diff --git a/src/core/protocol.c b/src/core/protocol.c index 52b9b7fb..ea28ad0a 100644 --- a/src/core/protocol.c +++ b/src/core/protocol.c @@ -95,4 +95,4 @@ nni_proto_sys_fini(void) } nni_proto_inited = 0; nni_mtx_fini(&nni_proto_lk); -}
\ No newline at end of file +} diff --git a/src/core/strs.c b/src/core/strs.c index 66a385d0..98c1a5fa 100644 --- a/src/core/strs.c +++ b/src/core/strs.c @@ -201,4 +201,4 @@ nni_asprintf(char **sp, const char *fmt, ...) va_end(ap); *sp = s; return (0); -}
\ No newline at end of file +} @@ -160,7 +160,7 @@ enum nng_sockaddr_family { NNG_AF_IPC = 2, NNG_AF_INET = 3, NNG_AF_INET6 = 4, - NNG_AF_ZT = 5, // ZeroTier + NNG_AF_ZT = 5 // ZeroTier }; // Scatter/gather I/O. @@ -223,9 +223,10 @@ NNG_DECL int nng_getopt_ptr(nng_socket, const char *, void **); // Only one callback can be set on a given socket, and there is no way // to retrieve the old value. typedef enum { - NNG_PIPE_ADD, - NNG_PIPE_REM, + NNG_PIPE_ADD, // Pipe added to socket + NNG_PIPE_REM // Pipe removed from socket } nng_pipe_action; + typedef void (*nng_pipe_cb)(nng_pipe, nng_pipe_action, void *); NNG_DECL int nng_pipe_notify(nng_socket, nng_pipe_cb, void *); @@ -619,7 +620,7 @@ NNG_DECL nng_listener nng_pipe_listener(nng_pipe); // Flags. enum nng_flag_enum { NNG_FLAG_ALLOC = 1, // Recv to allocate receive buffer. - NNG_FLAG_NONBLOCK = 2, // Non-blocking operations. + NNG_FLAG_NONBLOCK = 2 // Non-blocking operations. }; // Options. @@ -758,8 +759,8 @@ enum nng_flag_enum { // NNG_DECL int nng_stat_type(nng_stat *); enum nng_stat_type_enum { - NNG_STAT_LEVEL = 0, - NNG_STAT_COUNTER = 1, + NNG_STAT_LEVEL = 0, // Numeric "absolute" value, diffs meaningless + NNG_STAT_COUNTER = 1 // Incrementing value (diffs are meaningful) }; // nng_stat_unit provides information about the unit for the statistic, @@ -774,7 +775,7 @@ enum nng_unit_enum { NNG_UNIT_MESSAGES = 2, NNG_UNIT_BOOLEAN = 3, NNG_UNIT_MILLIS = 4, - NNG_UNIT_EVENTS = 5, + NNG_UNIT_EVENTS = 5 }; // nng_stat_value returns returns the actual value of the statistic. @@ -845,7 +846,7 @@ enum nng_errno_enum { NNG_EBADTYPE = 30, NNG_EINTERNAL = 1000, NNG_ESYSERR = 0x10000000, - NNG_ETRANERR = 0x20000000, + NNG_ETRANERR = 0x20000000 }; // URL support. We frequently want to process a URL, and these methods diff --git a/src/platform/posix/posix_aio.h b/src/platform/posix/posix_aio.h index 7d6a7231..15d91db2 100644 --- a/src/platform/posix/posix_aio.h +++ b/src/platform/posix/posix_aio.h @@ -19,8 +19,6 @@ #include "core/nng_impl.h" -typedef struct nni_posix_pollq nni_posix_pollq; - typedef struct nni_posix_pipedesc nni_posix_pipedesc; typedef struct nni_posix_epdesc nni_posix_epdesc; diff --git a/src/platform/posix/posix_epdesc.c b/src/platform/posix/posix_epdesc.c index 0f63304f..7431dedf 100644 --- a/src/platform/posix/posix_epdesc.c +++ b/src/platform/posix/posix_epdesc.c @@ -28,6 +28,10 @@ #include <sys/un.h> #include <unistd.h> +#ifdef sun +#undef sun +#endif + #ifdef SOCK_CLOEXEC #define NNI_STREAM_SOCKTYPE (SOCK_STREAM | SOCK_CLOEXEC) #else diff --git a/src/platform/posix/posix_pipedesc.c b/src/platform/posix/posix_pipedesc.c index 61005ca8..3745f11f 100644 --- a/src/platform/posix/posix_pipedesc.c +++ b/src/platform/posix/posix_pipedesc.c @@ -32,6 +32,9 @@ #include <sys/ucred.h> #include <sys/un.h> #endif +#ifdef NNG_HAVE_ALLOCA +#include <alloca.h> +#endif // nni_posix_pipedesc is a descriptor kept one per transport pipe (i.e. open // file descriptor for TCP socket, etc.) This contains the list of pending @@ -426,12 +429,12 @@ nni_posix_pipedesc_get_peerid(nni_posix_pipedesc *pd, uint64_t *euid, *znid = (uint64_t) -1; return (0); #elif defined(NNG_HAVE_GETPEERUCRED) - ucred *ucp; + ucred_t *ucp = NULL; if (getpeerucred(fd, &ucp) != 0) { return (nni_plat_errno(errno)); } *euid = ucred_geteuid(ucp); - *egid = ucred_geteuid(ucp); + *egid = ucred_getegid(ucp); *prid = ucred_getpid(ucp); *znid = ucred_getzoneid(ucp); ucred_free(ucp); diff --git a/src/platform/posix/posix_tcp.c b/src/platform/posix/posix_tcp.c index c00f9433..ace1f6bd 100644 --- a/src/platform/posix/posix_tcp.c +++ b/src/platform/posix/posix_tcp.c @@ -79,13 +79,13 @@ nni_plat_tcp_ep_listen(nni_plat_tcp_ep *ep, nng_sockaddr *bsa) void nni_plat_tcp_ep_connect(nni_plat_tcp_ep *ep, nni_aio *aio) { - return (nni_posix_epdesc_connect((void *) ep, aio)); + nni_posix_epdesc_connect((void *) ep, aio); } void nni_plat_tcp_ep_accept(nni_plat_tcp_ep *ep, nni_aio *aio) { - return (nni_posix_epdesc_accept((void *) ep, aio)); + nni_posix_epdesc_accept((void *) ep, aio); } void diff --git a/src/platform/posix/posix_udp.c b/src/platform/posix/posix_udp.c index 37f79431..654d31e3 100644 --- a/src/platform/posix/posix_udp.c +++ b/src/platform/posix/posix_udp.c @@ -24,14 +24,15 @@ #include <sys/types.h> #include <sys/uio.h> #include <unistd.h> +#ifdef NNG_HAVE_ALLOCA +#include <alloca.h> +#endif // UDP support. // If we can suppress SIGPIPE on send, please do so. -#ifdef MSG_NOSIGNAL -#define NNI_MSG_NOSIGNAL MSG_NOSIGNAL -#else -#define NNI_MSG_NOSIGNAL 0 +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 #endif struct nni_plat_udp { @@ -67,7 +68,7 @@ nni_posix_udp_dorecv(nni_plat_udp *udp) nni_iov * aiov; struct sockaddr_storage ss; nng_sockaddr * sa; - struct msghdr hdr; + struct msghdr hdr = { .msg_name = NULL }; int rv = 0; int cnt = 0; @@ -77,13 +78,10 @@ nni_posix_udp_dorecv(nni_plat_udp *udp) iov[i].iov_base = aiov[i].iov_buf; iov[i].iov_len = aiov[i].iov_len; } - hdr.msg_iov = iov; - hdr.msg_iovlen = niov; - hdr.msg_name = &ss; - hdr.msg_namelen = sizeof(ss); - hdr.msg_flags = 0; - hdr.msg_control = NULL; - hdr.msg_controllen = 0; + hdr.msg_iov = iov; + hdr.msg_iovlen = niov; + hdr.msg_name = &ss; + hdr.msg_namelen = sizeof(ss); if ((cnt = recvmsg(udp->udp_fd, &hdr, 0)) < 0) { if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { @@ -121,9 +119,8 @@ nni_posix_udp_dosend(nni_plat_udp *udp) if (len < 1) { rv = NNG_EADDRINVAL; } else { - struct msghdr hdr; - unsigned niov; - nni_iov * aiov; + unsigned niov; + nni_iov *aiov; #ifdef NNG_HAVE_ALLOCA struct iovec *iov; #else @@ -142,22 +139,19 @@ nni_posix_udp_dosend(nni_plat_udp *udp) rv = NNG_EINVAL; } #endif - if (rv == 0) { + struct msghdr hdr = { .msg_name = NULL }; for (unsigned i = 0; i < niov; i++) { iov[i].iov_base = aiov[i].iov_buf; iov[i].iov_len = aiov[i].iov_len; } - hdr.msg_iov = iov; - hdr.msg_iovlen = niov; - hdr.msg_name = &ss; - hdr.msg_namelen = len; - hdr.msg_flags = NNI_MSG_NOSIGNAL; - hdr.msg_control = NULL; - hdr.msg_controllen = 0; - - if ((cnt = sendmsg(udp->udp_fd, &hdr, 0)) < - 0) { + hdr.msg_iov = iov; + hdr.msg_iovlen = niov; + hdr.msg_name = &ss; + hdr.msg_namelen = len; + + cnt = sendmsg(udp->udp_fd, &hdr, MSG_NOSIGNAL); + if (cnt < 0) { if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) { // Cannot send now, leave. diff --git a/src/supplemental/http/http.h b/src/supplemental/http/http.h index 470ffbfa..f6a45df7 100644 --- a/src/supplemental/http/http.h +++ b/src/supplemental/http/http.h @@ -21,7 +21,7 @@ extern "C" { #include <stdint.h> -typedef struct nng_tls_config nng_tls_config; +struct nng_tls_config; // HTTP status codes. This list is not exhaustive. enum nng_http_status { @@ -398,12 +398,14 @@ NNG_DECL int nng_http_server_del_handler( // server client, so the caller must have configured it reasonably. // This API is not recommended unless the caller needs complete control // over the TLS configuration. -NNG_DECL int nng_http_server_set_tls(nng_http_server *, nng_tls_config *); +NNG_DECL int nng_http_server_set_tls( + nng_http_server *, struct nng_tls_config *); // nng_http_server_get_tls obtains the TLS configuration if one is present, // or returns NNG_EINVAL. The TLS configuration is invalidated if the // nng_http_server_set_tls function is called, so be careful. -NNG_DECL int nng_http_server_get_tls(nng_http_server *, nng_tls_config **); +NNG_DECL int nng_http_server_get_tls( + nng_http_server *, struct nng_tls_config **); // nng_http_hijack is intended to be called by a handler that wishes to // take over the processing of the HTTP session -- usually to change protocols @@ -435,12 +437,14 @@ NNG_DECL void nng_http_client_free(nng_http_client *); // the entire TLS configuration on the client, so the caller must have // configured it reasonably. This API is not recommended unless the // caller needs complete control over the TLS configuration. -NNG_DECL int nng_http_client_set_tls(nng_http_client *, nng_tls_config *); +NNG_DECL int nng_http_client_set_tls( + nng_http_client *, struct nng_tls_config *); // nng_http_client_get_tls obtains the TLS configuration if one is present, // or returns NNG_EINVAL. The supplied TLS configuration object may // be invalidated by any future calls to nni_http_client_set_tls. -NNG_DECL int nng_http_client_get_tls(nng_http_client *, nng_tls_config **); +NNG_DECL int nng_http_client_get_tls( + nng_http_client *, struct nng_tls_config **); // nng_http_client_connect establishes a new connection with the server // named in the URL used when the client was created. Once the connection diff --git a/src/supplemental/http/http_api.h b/src/supplemental/http/http_api.h index 8de859b4..f1a5c0fa 100644 --- a/src/supplemental/http/http_api.h +++ b/src/supplemental/http/http_api.h @@ -65,7 +65,8 @@ extern void *nni_http_conn_get_ctx(nni_http_conn *); // They should only be used by the server or client HTTP implementations, // and are not for use by other code. extern int nni_http_conn_init_tcp(nni_http_conn **, void *); -extern int nni_http_conn_init_tls(nni_http_conn **, nng_tls_config *, void *); +extern int nni_http_conn_init_tls( + nni_http_conn **, struct nng_tls_config *, void *); extern void nni_http_conn_close(nni_http_conn *); extern void nni_http_conn_fini(nni_http_conn *); @@ -153,12 +154,13 @@ extern int nni_http_server_del_handler(nni_http_server *, nni_http_handler *); // server client, so the caller must have configured it reasonably. // This API is not recommended unless the caller needs complete control // over the TLS configuration. -extern int nni_http_server_set_tls(nni_http_server *, nng_tls_config *); +extern int nni_http_server_set_tls(nni_http_server *, struct nng_tls_config *); // nni_http_server_get_tls obtains the TLS configuration if one is present, // or returns NNG_EINVAL. The TLS configuration is invalidated if the // nni_http_server_set_tls function is called, so be careful. -extern int nni_http_server_get_tls(nni_http_server *, nng_tls_config **); +extern int nni_http_server_get_tls( + nni_http_server *, struct nng_tls_config **); // nni_http_server_start starts listening on the supplied port. extern int nni_http_server_start(nni_http_server *); @@ -273,12 +275,13 @@ extern void nni_http_client_fini(nni_http_client *); // the entire TLS configuration on the client, so the caller must have // configured it reasonably. This API is not recommended unless the // caller needs complete control over the TLS configuration. -extern int nni_http_client_set_tls(nni_http_client *, nng_tls_config *); +extern int nni_http_client_set_tls(nni_http_client *, struct nng_tls_config *); // nni_http_client_get_tls obtains the TLS configuration if one is present, // or returns NNG_EINVAL. The supplied TLS configuration object may // be invalidated by any future calls to nni_http_client_set_tls. -extern int nni_http_client_get_tls(nni_http_client *, nng_tls_config **); +extern int nni_http_client_get_tls( + nni_http_client *, struct nng_tls_config **); extern void nni_http_client_connect(nni_http_client *, nni_aio *); diff --git a/src/supplemental/http/http_client.c b/src/supplemental/http/http_client.c index 2a9be4bb..a2427009 100644 --- a/src/supplemental/http/http_client.c +++ b/src/supplemental/http/http_client.c @@ -20,12 +20,12 @@ #include "http_api.h" struct nng_http_client { - nni_list aios; - nni_mtx mtx; - bool closed; - nng_tls_config * tls; - nni_aio * connaio; - nni_plat_tcp_ep *tep; + nni_list aios; + nni_mtx mtx; + bool closed; + struct nng_tls_config *tls; + nni_aio * connaio; + nni_plat_tcp_ep * tep; }; static void @@ -182,10 +182,10 @@ nni_http_client_init(nni_http_client **cp, const nni_url *url) } int -nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls) +nni_http_client_set_tls(nni_http_client *c, struct nng_tls_config *tls) { #ifdef NNG_SUPP_TLS - nng_tls_config *old; + struct nng_tls_config *old; nni_mtx_lock(&c->mtx); old = c->tls; c->tls = tls; @@ -205,7 +205,7 @@ nni_http_client_set_tls(nni_http_client *c, nng_tls_config *tls) } int -nni_http_client_get_tls(nni_http_client *c, nng_tls_config **tlsp) +nni_http_client_get_tls(nni_http_client *c, struct nng_tls_config **tlsp) { #ifdef NNG_SUPP_TLS nni_mtx_lock(&c->mtx); diff --git a/src/supplemental/http/http_conn.c b/src/supplemental/http/http_conn.c index a3039d0d..0de40e10 100644 --- a/src/supplemental/http/http_conn.c +++ b/src/supplemental/http/http_conn.c @@ -36,14 +36,21 @@ enum write_flavor { HTTP_WR_RES, }; +typedef void (*http_read_fn)(void *, nni_aio *); +typedef void (*http_write_fn)(void *, nni_aio *); +typedef void (*http_close_fn)(void *); +typedef void (*http_fini_fn)(void *); +typedef bool (*http_verified_fn)(void *); +typedef int (*http_addr_fn)(void *, nni_sockaddr *); + typedef struct nni_http_tran { - void (*h_read)(void *, nni_aio *); - void (*h_write)(void *, nni_aio *); - int (*h_sock_addr)(void *, nni_sockaddr *); - int (*h_peer_addr)(void *, nni_sockaddr *); - bool (*h_verified)(void *); - void (*h_close)(void *); - void (*h_fini)(void *); + http_read_fn h_read; + http_write_fn h_write; + http_addr_fn h_sock_addr; + http_addr_fn h_peer_addr; + http_verified_fn h_verified; + http_close_fn h_close; + http_fini_fn h_fini; } nni_http_tran; #define SET_RD_FLAVOR(aio, f) \ @@ -54,20 +61,18 @@ typedef struct nni_http_tran { #define GET_WR_FLAVOR(aio) (int) ((intptr_t) nni_aio_get_prov_extra(aio, 0)) struct nng_http_conn { - void *sock; - void (*rd)(void *, nni_aio *); - void (*wr)(void *, nni_aio *); - int (*sock_addr)(void *, nni_sockaddr *); - int (*peer_addr)(void *, nni_sockaddr *); - bool (*verified)(void *); - void (*close)(void *); - void (*fini)(void *); - - void *ctx; - bool closed; - - nni_list rdq; // high level http read requests - nni_list wrq; // high level http write requests + void * sock; + http_read_fn rd; + http_write_fn wr; + http_addr_fn sock_addr; + http_addr_fn peer_addr; + http_verified_fn verified; + http_close_fn close; + http_fini_fn fini; + void * ctx; + bool closed; + nni_list rdq; // high level http read requests + nni_list wrq; // high level http write requests nni_aio *rd_uaio; // user aio for read nni_aio *wr_uaio; // user aio for write @@ -715,13 +720,13 @@ nni_http_verified_tcp(void *arg) } static nni_http_tran http_tcp_ops = { - .h_read = (void *) nni_plat_tcp_pipe_recv, - .h_write = (void *) nni_plat_tcp_pipe_send, - .h_close = (void *) nni_plat_tcp_pipe_close, - .h_fini = (void *) nni_plat_tcp_pipe_fini, - .h_sock_addr = (void *) nni_plat_tcp_pipe_sockname, - .h_peer_addr = (void *) nni_plat_tcp_pipe_peername, - .h_verified = nni_http_verified_tcp, + .h_read = (http_read_fn) nni_plat_tcp_pipe_recv, + .h_write = (http_write_fn) nni_plat_tcp_pipe_send, + .h_close = (http_close_fn) nni_plat_tcp_pipe_close, + .h_fini = (http_fini_fn) nni_plat_tcp_pipe_fini, + .h_sock_addr = (http_addr_fn) nni_plat_tcp_pipe_sockname, + .h_peer_addr = (http_addr_fn) nni_plat_tcp_pipe_peername, + .h_verified = (http_verified_fn) nni_http_verified_tcp, }; int @@ -732,17 +737,18 @@ nni_http_conn_init_tcp(nni_http_conn **connp, void *tcp) #ifdef NNG_SUPP_TLS static nni_http_tran http_tls_ops = { - .h_read = (void *) nni_tls_recv, - .h_write = (void *) nni_tls_send, - .h_close = (void *) nni_tls_close, - .h_fini = (void *) nni_tls_fini, - .h_sock_addr = (void *) nni_tls_sockname, - .h_peer_addr = (void *) nni_tls_peername, - .h_verified = (void *) nni_tls_verified, + .h_read = (http_read_fn) nni_tls_recv, + .h_write = (http_write_fn) nni_tls_send, + .h_close = (http_close_fn) nni_tls_close, + .h_fini = (http_fini_fn) nni_tls_fini, + .h_sock_addr = (http_addr_fn) nni_tls_sockname, + .h_peer_addr = (http_addr_fn) nni_tls_peername, + .h_verified = (http_verified_fn) nni_tls_verified, }; int -nni_http_conn_init_tls(nni_http_conn **connp, nng_tls_config *cfg, void *tcp) +nni_http_conn_init_tls( + nni_http_conn **connp, struct nng_tls_config *cfg, void *tcp) { nni_tls *tls; int rv; @@ -756,7 +762,8 @@ nni_http_conn_init_tls(nni_http_conn **connp, nng_tls_config *cfg, void *tcp) } #else int -nni_http_conn_init_tls(nni_http_conn **connp, nng_tls_config *cfg, void *tcp) +nni_http_conn_init_tls( + nni_http_conn **connp, struct nng_tls_config *cfg, void *tcp) { NNI_ARG_UNUSED(connp); NNI_ARG_UNUSED(cfg); diff --git a/src/supplemental/http/http_public.c b/src/supplemental/http/http_public.c index 7aae45b2..40d4a19c 100644 --- a/src/supplemental/http/http_public.c +++ b/src/supplemental/http/http_public.c @@ -676,7 +676,7 @@ nng_http_server_del_handler(nng_http_server *srv, nng_http_handler *h) } int -nng_http_server_set_tls(nng_http_server *srv, nng_tls_config *cfg) +nng_http_server_set_tls(nng_http_server *srv, struct nng_tls_config *cfg) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_server_set_tls(srv, cfg)); @@ -688,7 +688,7 @@ nng_http_server_set_tls(nng_http_server *srv, nng_tls_config *cfg) } int -nng_http_server_get_tls(nng_http_server *srv, nng_tls_config **cfgp) +nng_http_server_get_tls(nng_http_server *srv, struct nng_tls_config **cfgp) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_server_get_tls(srv, cfgp)); @@ -734,7 +734,7 @@ nng_http_client_free(nng_http_client *cli) } int -nng_http_client_set_tls(nng_http_client *cli, nng_tls_config *cfg) +nng_http_client_set_tls(nng_http_client *cli, struct nng_tls_config *cfg) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_client_set_tls(cli, cfg)); @@ -746,7 +746,7 @@ nng_http_client_set_tls(nng_http_client *cli, nng_tls_config *cfg) } int -nng_http_client_get_tls(nng_http_client *cli, nng_tls_config **cfgp) +nng_http_client_get_tls(nng_http_client *cli, struct nng_tls_config **cfgp) { #if defined(NNG_SUPP_HTTP) && defined(NNG_SUPP_TLS) return (nni_http_client_get_tls(cli, cfgp)); diff --git a/src/supplemental/util/options.h b/src/supplemental/util/options.h index 02b3a9d4..00cf1351 100644 --- a/src/supplemental/util/options.h +++ b/src/supplemental/util/options.h @@ -45,4 +45,4 @@ NNG_DECL int nng_opts_parse(int argc, const char **argv, } #endif -#endif // NNG_SUPPLEMENTAL_UTIL_OPTIONS_H
\ No newline at end of file +#endif // NNG_SUPPLEMENTAL_UTIL_OPTIONS_H diff --git a/src/supplemental/util/platform.c b/src/supplemental/util/platform.c index ce52491a..fc0f839e 100644 --- a/src/supplemental/util/platform.c +++ b/src/supplemental/util/platform.c @@ -29,10 +29,6 @@ nng_msleep(nng_duration dur) nni_msleep(dur); } -// nng_thread is a handle to a "thread", which may be a real system -// thread, or a coroutine on some platforms. -typedef struct nng_thread nng_thread; - // Create and start a thread. Note that on some platforms, this might // actually be a coroutine, with limitations about what system APIs // you can call. Therefore, these threads should only be used with the @@ -111,8 +107,6 @@ struct nng_cv { nni_cv c; }; -typedef struct nng_cv nng_cv; - int nng_cv_alloc(nng_cv **cvp, nng_mtx *mx) { diff --git a/tests/base64.c b/tests/base64.c index eac84df2..6641928a 100644 --- a/tests/base64.c +++ b/tests/base64.c @@ -82,7 +82,5 @@ TestMain("Base64 Verification", { enc, strlen(enc), buf, strlen(dec) - 1) == -1); So(nni_base64_encode(enc, strlen(enc), buf, 0) == -1); } - }) - -}); +}) diff --git a/tests/files.c b/tests/files.c index 9983d7d3..3690ef63 100644 --- a/tests/files.c +++ b/tests/files.c @@ -256,4 +256,4 @@ TestMain("Platform File Support", { }); test_permissions(); -}); +}) diff --git a/tests/httpclient.c b/tests/httpclient.c index 5180d13f..e167587e 100644 --- a/tests/httpclient.c +++ b/tests/httpclient.c @@ -71,7 +71,6 @@ TestMain("HTTP Client", { nng_http_conn_read_res(http, res, aio); nng_aio_wait(aio); So(nng_aio_result(aio) == 0); - printf("RESULT IS %d\n", nng_http_res_get_status(res)); So(nng_http_res_get_status(res) == 200); Convey("The message contents are correct", { @@ -107,4 +106,4 @@ TestMain("HTTP Client", { }); }); }); -}); +}) diff --git a/tests/idhash.c b/tests/idhash.c index 32751334..eb62fd76 100644 --- a/tests/idhash.c +++ b/tests/idhash.c @@ -24,7 +24,6 @@ Main({ So(nni_idhash_init(&h) == 0); So(h != NULL); - So(nni_idhash_count(h) == 0); Reset({ nni_idhash_fini(h); }); @@ -32,7 +31,6 @@ Main({ char *five = "five"; char *four = "four"; rv = nni_idhash_insert(h, 5, five); - So(nni_idhash_count(h) == 1); So(rv == 0); Convey("And we can find it", { @@ -51,7 +49,6 @@ Main({ Convey("We can change the value", { void *ptr; So(nni_idhash_insert(h, 5, four) == 0); - So(nni_idhash_count(h) == 1); So(nni_idhash_find(h, 5, &ptr) == 0); So(ptr == four); }); @@ -59,7 +56,6 @@ Main({ void *ptr; So(nni_idhash_insert(h, 13, four) == 0); - So(nni_idhash_count(h) == 2); So(nni_idhash_find(h, 5, &ptr) == 0); So(ptr == five); So(nni_idhash_find(h, 13, &ptr) == 0); @@ -120,7 +116,6 @@ Main({ nni_idhash *h; So(nni_idhash_init(&h) == 0); - So(nni_idhash_count(h) == 0); Reset({ nni_idhash_fini(h); }); @@ -128,13 +123,11 @@ Main({ for (i = 0; i < 1024; i++) { nni_idhash_insert(h, i, &expect[i]); } - So(nni_idhash_count(h) == 1024); Convey("We can remove them", { for (i = 0; i < 1024; i++) { nni_idhash_remove(h, i); } - So(nni_idhash_count(h) == 0); }); }); }); @@ -175,4 +168,4 @@ Main({ }); }); }); -}); +}) diff --git a/tests/ipc.c b/tests/ipc.c index 4c8f5e41..5956b5d3 100644 --- a/tests/ipc.c +++ b/tests/ipc.c @@ -1,6 +1,6 @@ // -// Copyright 2017 Garrett D'Amore <garrett@damore.org> -// Copyright 2017 Capitar IT Group BV <info@capitar.com> +// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a // copy of which should be located in the distribution where this @@ -69,7 +69,7 @@ check_props(nng_msg *msg) #ifdef NNG_HAVE_GETPEERUCRED So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_ZONEID, &id) == 0); - So(id == getzoneid()); + So(id == (uint64_t) getzoneid()); #else So(nng_pipe_getopt_uint64(p, NNG_OPT_IPC_PEER_ZONEID, &id) == NNG_ENOTSUP); diff --git a/tests/ipcperms.c b/tests/ipcperms.c index 84801efd..6d083d00 100644 --- a/tests/ipcperms.c +++ b/tests/ipcperms.c @@ -30,6 +30,12 @@ #define ADDR "/tmp/ipc_perms_test" +#if defined(__sun) +#define honor_chmod() false +#else +#define honor_chmod() true +#endif + // Inproc tests. #ifdef _WIN32 @@ -78,6 +84,9 @@ TestMain("IPC Permissions", { if (geteuid() == 0) { Skip("Running as root"); } + if (!honor_chmod()) { + Skip("System does not honor chmod"); + } strcpy(sa.sun_path, ADDR); sa.sun_family = AF_UNIX; So((cfd = socket(AF_UNIX, SOCK_STREAM, 0)) >= @@ -111,4 +120,4 @@ TestMain("IPC Permissions", { NNG_ENOTSUP); }); }) -#endif
\ No newline at end of file +#endif diff --git a/tests/ipcwinsec.c b/tests/ipcwinsec.c index 80ec163c..e6d2a205 100644 --- a/tests/ipcwinsec.c +++ b/tests/ipcwinsec.c @@ -197,4 +197,4 @@ TestMain("IPC Security Descriptor", { sdesc) == NNG_ENOTSUP); }); }) -#endif
\ No newline at end of file +#endif diff --git a/tests/message.c b/tests/message.c index 7f40cd38..d680c100 100644 --- a/tests/message.c +++ b/tests/message.c @@ -253,4 +253,4 @@ TestMain("Message Tests", { }); }); -}); +}) diff --git a/tests/multistress.c b/tests/multistress.c index 1ae6f323..d88d0af5 100644 --- a/tests/multistress.c +++ b/tests/multistress.c @@ -650,4 +650,4 @@ Main({ } }); }); -}); +}) diff --git a/tests/options.c b/tests/options.c index 166af37c..db04eea6 100644 --- a/tests/options.c +++ b/tests/options.c @@ -248,5 +248,4 @@ TestMain("Option Parsing", { So(nng_opts_parse(ac, av, case1, &v, &a, &opti) == -1); So(opti == 6); }); - -}); +}) diff --git a/tests/pipe.c b/tests/pipe.c index b81f72b8..3457db9b 100644 --- a/tests/pipe.c +++ b/tests/pipe.c @@ -146,4 +146,4 @@ TestMain("Pipe notify works", { }); }); }); -}); +}) diff --git a/tests/pipeline.c b/tests/pipeline.c index 2b61d99a..f7d89367 100644 --- a/tests/pipeline.c +++ b/tests/pipeline.c @@ -166,4 +166,4 @@ TestMain("PIPELINE (PUSH/PULL) pattern", { So(nng_recvmsg(pull1, &abc, 0) == NNG_ETIMEDOUT); So(nng_recvmsg(pull2, &abc, 0) == NNG_ETIMEDOUT); }); -}); +}) diff --git a/tests/reconnect.c b/tests/reconnect.c index 6b4e8586..d13e6ad9 100644 --- a/tests/reconnect.c +++ b/tests/reconnect.c @@ -101,4 +101,4 @@ TestMain("Reconnect works", { }); }); }); -}); +}) diff --git a/tests/reqctx.c b/tests/reqctx.c index 4aae2e24..de9f1ef2 100644 --- a/tests/reqctx.c +++ b/tests/reqctx.c @@ -26,9 +26,10 @@ static struct { } rep_state; void -rep_cb(void) +rep_cb(void *notused) { int rv; + (void) notused; if (rep_state.state == START) { rep_state.state = RECV; @@ -94,7 +95,7 @@ TestMain("REQ concurrent contexts", { Convey("We can use REQ contexts concurrently", { nng_socket req; - So(nng_aio_alloc(&rep_state.aio, (void *) rep_cb, NULL) == 0); + So(nng_aio_alloc(&rep_state.aio, rep_cb, NULL) == 0); So(nng_rep_open(&rep_state.s) == 0); So(nng_req_open(&req) == 0); @@ -137,7 +138,7 @@ TestMain("REQ concurrent contexts", { nng_msleep(100); // let things establish. // Start the rep state machine going. - rep_cb(); + rep_cb(NULL); for (i = 0; i < NCTX; i++) { if ((rv = nng_ctx_open(&ctxs[i], req)) != 0) { @@ -255,4 +256,4 @@ TestMain("REQ concurrent contexts", { nng_close(req); }); }); -}); +}) diff --git a/tests/reqpoll.c b/tests/reqpoll.c index aeee7d0b..e1a996dd 100644 --- a/tests/reqpoll.c +++ b/tests/reqpoll.c @@ -145,4 +145,4 @@ TestMain("REQ pollable", { }); }); }); -}); +}) diff --git a/tests/reqstress.c b/tests/reqstress.c index 3f1e7396..81249946 100644 --- a/tests/reqstress.c +++ b/tests/reqstress.c @@ -274,4 +274,4 @@ Main({ } }); }); -}); +}) diff --git a/tests/respondpoll.c b/tests/respondpoll.c index 2e24b5b2..5dd34c7f 100644 --- a/tests/respondpoll.c +++ b/tests/respondpoll.c @@ -106,4 +106,4 @@ TestMain("Respondent pollable", { }); }); }); -}); +}) diff --git a/tests/scalability.c b/tests/scalability.c index 84395f9d..38137e90 100644 --- a/tests/scalability.c +++ b/tests/scalability.c @@ -13,8 +13,8 @@ #include "protocol/reqrep0/rep.h" #include "protocol/reqrep0/req.h" -#include "supplemental/util/platform.h" #include "stubs.h" +#include "supplemental/util/platform.h" #include <string.h> @@ -22,7 +22,7 @@ static int nclients = 200; static char *addr = "inproc:///atscale"; nng_socket rep; -nng_thread *server; +nng_thread * server; void serve(void *arg) @@ -124,4 +124,4 @@ Main({ free(clients); free(results); -}); +}) diff --git a/tests/sha1.c b/tests/sha1.c index 9f1901e0..1aa137d7 100644 --- a/tests/sha1.c +++ b/tests/sha1.c @@ -60,4 +60,4 @@ TestMain("SHA1 Verification", { So(strcmp(strout, resultarray[i]) == 0); } }); -}); +}) diff --git a/tests/survey.c b/tests/survey.c index ed73b3dd..d6d35c1b 100644 --- a/tests/survey.c +++ b/tests/survey.c @@ -332,4 +332,4 @@ TestMain("SURVEY pattern", { So(nng_recvmsg(surv, &msg, 0) == NNG_ETIMEDOUT); }); -}); +}) diff --git a/tests/surveyctx.c b/tests/surveyctx.c index aa36eca1..b3843e9d 100644 --- a/tests/surveyctx.c +++ b/tests/surveyctx.c @@ -26,9 +26,10 @@ static struct { } resp_state; void -resp_cb(void) +resp_cb(void *notused) { int rv; + (void) notused; if (resp_state.state == START) { resp_state.state = RECV; @@ -94,8 +95,7 @@ TestMain("Surveyor concurrent contexts", { Convey("We can use Surveyor contexts concurrently", { nng_socket surv = NNG_SOCKET_INITIALIZER; - So(nng_aio_alloc(&resp_state.aio, (void *) resp_cb, NULL) == - 0); + So(nng_aio_alloc(&resp_state.aio, resp_cb, NULL) == 0); So(nng_respondent0_open(&resp_state.s) == 0); So(nng_surveyor0_open(&surv) == 0); @@ -139,7 +139,7 @@ TestMain("Surveyor concurrent contexts", { nng_msleep(100); // let things establish. // Start the rep state machine going. - resp_cb(); + resp_cb(NULL); for (i = 0; i < NCTX; i++) { if ((rv = nng_ctx_open(&ctxs[i], surv)) != 0) { @@ -303,4 +303,4 @@ TestMain("Surveyor concurrent contexts", { So(nng_ctx_open(&ctx, surv) == NNG_ENOTSUP); nng_close(surv); }); -}); +}) diff --git a/tests/surveypoll.c b/tests/surveypoll.c index f97e1c22..a2264d3e 100644 --- a/tests/surveypoll.c +++ b/tests/surveypoll.c @@ -123,4 +123,4 @@ TestMain("Survey pollable", { }); }); }); -}); +}) diff --git a/tests/udp.c b/tests/udp.c index b0def72a..15520791 100644 --- a/tests/udp.c +++ b/tests/udp.c @@ -292,5 +292,4 @@ TestMain("UDP support", { So(nni_plat_udp_open(&u2, &sa) == NNG_EADDRINUSE); nni_plat_udp_close(u1); }); - -}); +}) |
