summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-04-23 07:39:59 -0700
committerGarrett D'Amore <garrett@damore.org>2024-04-23 07:39:59 -0700
commit01817988f4631bdd8ee5cec9c6b69039712a93fe (patch)
treec8c4259671fbb586a466a8c5d623fc8c183f8927
parentff00eac2401732e9efb6170ffb90100dcf6332a7 (diff)
downloadnng-01817988f4631bdd8ee5cec9c6b69039712a93fe.tar.gz
nng-01817988f4631bdd8ee5cec9c6b69039712a93fe.tar.bz2
nng-01817988f4631bdd8ee5cec9c6b69039712a93fe.zip
Move the rest of the functionality from platform.h into core.
This also deprecates supplemental/util/platform.h.
-rw-r--r--docs/man/nng_cv_alloc.3supp.adoc3
-rw-r--r--docs/man/nng_cv_free.3supp.adoc3
-rw-r--r--docs/man/nng_cv_until.3supp.adoc3
-rw-r--r--docs/man/nng_cv_wait.3supp.adoc3
-rw-r--r--docs/man/nng_cv_wake.3supp.adoc3
-rw-r--r--docs/man/nng_cv_wake1.3supp.adoc3
-rw-r--r--docs/man/nng_mtx_alloc.3supp.adoc3
-rw-r--r--docs/man/nng_mtx_free.3supp.adoc3
-rw-r--r--docs/man/nng_mtx_lock.3supp.adoc12
-rw-r--r--docs/man/nng_mtx_unlock.3supp.adoc3
-rw-r--r--docs/man/nng_thread_create.3supp.adoc3
-rw-r--r--docs/man/nng_thread_destroy.3supp.adoc3
-rw-r--r--docs/man/nng_thread_set_name.3supp.adoc3
-rw-r--r--include/nng/nng.h64
-rw-r--r--include/nng/supplemental/util/platform.h86
-rw-r--r--src/nng.c161
-rw-r--r--src/supplemental/util/CMakeLists.txt2
-rw-r--r--src/supplemental/util/platform.c172
-rw-r--r--src/supplemental/websocket/websocket_test.c3
-rw-r--r--src/testing/nuts.h1
-rw-r--r--src/testing/streams.c9
-rw-r--r--src/tools/nngcat/nngcat.c47
-rw-r--r--src/tools/perf/perf.c23
-rw-r--r--src/tools/perf/pubdrop.c15
-rw-r--r--tests/device.c15
-rw-r--r--tests/multistress.c21
-rw-r--r--tests/nonblock.c5
-rw-r--r--tests/pipe.c16
-rw-r--r--tests/pollfd.c7
-rw-r--r--tests/reqctx.c12
-rw-r--r--tests/reqstress.c13
-rw-r--r--tests/scalability.c7
-rw-r--r--tests/synch.c9
-rw-r--r--tests/trantest.h37
34 files changed, 352 insertions, 421 deletions
diff --git a/docs/man/nng_cv_alloc.3supp.adoc b/docs/man/nng_cv_alloc.3supp.adoc
index 9e58e3f1..f87f70f8 100644
--- a/docs/man/nng_cv_alloc.3supp.adoc
+++ b/docs/man/nng_cv_alloc.3supp.adoc
@@ -1,6 +1,6 @@
= nng_cv_alloc(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_cv_alloc - allocate condition variable
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
typedef struct nng_cv nng_cv;
diff --git a/docs/man/nng_cv_free.3supp.adoc b/docs/man/nng_cv_free.3supp.adoc
index 0610b52f..82eeb033 100644
--- a/docs/man/nng_cv_free.3supp.adoc
+++ b/docs/man/nng_cv_free.3supp.adoc
@@ -1,6 +1,6 @@
= nng_cv_free(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_cv_free - free condition variable
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_cv_free(nng_cv *cv);
----
diff --git a/docs/man/nng_cv_until.3supp.adoc b/docs/man/nng_cv_until.3supp.adoc
index 9cf7c714..a168599d 100644
--- a/docs/man/nng_cv_until.3supp.adoc
+++ b/docs/man/nng_cv_until.3supp.adoc
@@ -1,6 +1,6 @@
= nng_cv_until(3supp)
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_cv_until - wait for condition or timeout
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
int nng_cv_until(nng_cv *cv, nng_time when);
----
diff --git a/docs/man/nng_cv_wait.3supp.adoc b/docs/man/nng_cv_wait.3supp.adoc
index 1d9c16be..9078ac44 100644
--- a/docs/man/nng_cv_wait.3supp.adoc
+++ b/docs/man/nng_cv_wait.3supp.adoc
@@ -1,6 +1,6 @@
= nng_cv_wait(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_cv_wait - wait for condition
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_cv_wait(nng_cv *cv);
----
diff --git a/docs/man/nng_cv_wake.3supp.adoc b/docs/man/nng_cv_wake.3supp.adoc
index 6ee2945d..a4fe2eca 100644
--- a/docs/man/nng_cv_wake.3supp.adoc
+++ b/docs/man/nng_cv_wake.3supp.adoc
@@ -1,6 +1,6 @@
= nng_cv_wake(3supp)
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_cv_wake - wake all waiters
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_cv_wake(nng_cv *cv);
----
diff --git a/docs/man/nng_cv_wake1.3supp.adoc b/docs/man/nng_cv_wake1.3supp.adoc
index 4f8b8326..de556698 100644
--- a/docs/man/nng_cv_wake1.3supp.adoc
+++ b/docs/man/nng_cv_wake1.3supp.adoc
@@ -1,6 +1,6 @@
= nng_cv_wake1(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_cv_wake1 - wake one waiter
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_cv_wake1(nng_cv *cv);
----
diff --git a/docs/man/nng_mtx_alloc.3supp.adoc b/docs/man/nng_mtx_alloc.3supp.adoc
index 45bbfac2..68ce691b 100644
--- a/docs/man/nng_mtx_alloc.3supp.adoc
+++ b/docs/man/nng_mtx_alloc.3supp.adoc
@@ -1,6 +1,6 @@
= nng_mtx_alloc(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_mtx_alloc - allocate mutex
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
typedef struct nng_mtx nng_mtx;
diff --git a/docs/man/nng_mtx_free.3supp.adoc b/docs/man/nng_mtx_free.3supp.adoc
index 2867afe1..f247cbf9 100644
--- a/docs/man/nng_mtx_free.3supp.adoc
+++ b/docs/man/nng_mtx_free.3supp.adoc
@@ -1,6 +1,6 @@
= nng_mtx_free(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_mtx_free - free mutex
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_mtx_free(nng_mtx *mtx);
----
diff --git a/docs/man/nng_mtx_lock.3supp.adoc b/docs/man/nng_mtx_lock.3supp.adoc
index 91fd2ab5..5f4276fc 100644
--- a/docs/man/nng_mtx_lock.3supp.adoc
+++ b/docs/man/nng_mtx_lock.3supp.adoc
@@ -1,6 +1,6 @@
= nng_mtx_lock(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_mtx_lock - lock mutex
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_mtx_lock(nng_mtx *mtx);
----
@@ -39,15 +38,6 @@ same mutex may result in deadlock or aborting the current program.
It is a programming error for the owner of a mutex to attempt to
reacquire it.
-****
-_NNG_ offers neither a non-blocking variant that can fail,
-nor recursive mutexes.
-This is by design, as _NNG_ itself does not use such things,
-and most often the need for them is the result of poor design.
-If such capabilities are needed, they may be synthesized fairly
-easily from mutexes and condition variables.
-****
-
== RETURN VALUES
None.
diff --git a/docs/man/nng_mtx_unlock.3supp.adoc b/docs/man/nng_mtx_unlock.3supp.adoc
index d1b048e6..1752fcf7 100644
--- a/docs/man/nng_mtx_unlock.3supp.adoc
+++ b/docs/man/nng_mtx_unlock.3supp.adoc
@@ -1,6 +1,6 @@
= nng_mtx_unlock(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_mtx_unlock - unlock mutex
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_mtx_unlock(nng_mtx *mtx);
----
diff --git a/docs/man/nng_thread_create.3supp.adoc b/docs/man/nng_thread_create.3supp.adoc
index 129bddea..10b02e22 100644
--- a/docs/man/nng_thread_create.3supp.adoc
+++ b/docs/man/nng_thread_create.3supp.adoc
@@ -1,6 +1,6 @@
= nng_thread_create(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_thread_create - create thread
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
typedef struct nng_thread nng_thread;
diff --git a/docs/man/nng_thread_destroy.3supp.adoc b/docs/man/nng_thread_destroy.3supp.adoc
index 95eed813..7caa1cd3 100644
--- a/docs/man/nng_thread_destroy.3supp.adoc
+++ b/docs/man/nng_thread_destroy.3supp.adoc
@@ -1,6 +1,6 @@
= nng_thread_destroy(3supp)
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This document is supplied under the terms of the MIT License, a
@@ -18,7 +18,6 @@ nng_thread_destroy - reap thread
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_thread_destroy(nng_thread *thread);
----
diff --git a/docs/man/nng_thread_set_name.3supp.adoc b/docs/man/nng_thread_set_name.3supp.adoc
index 36dd8267..fb54fb02 100644
--- a/docs/man/nng_thread_set_name.3supp.adoc
+++ b/docs/man/nng_thread_set_name.3supp.adoc
@@ -1,6 +1,6 @@
= nng_thread_set_name(3supp)
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
//
// This document is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -17,7 +17,6 @@ nng_thread_set_name - set thread name
[source, c]
----
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
void nng_thread_set_name(nng_thread *thread, const char *name);
----
diff --git a/include/nng/nng.h b/include/nng/nng.h
index 9192cc5e..931c550e 100644
--- a/include/nng/nng.h
+++ b/include/nng/nng.h
@@ -1585,6 +1585,70 @@ NNG_DECL uint32_t nng_random(void);
// to an array of file descriptors (or HANDLES or similar).
NNG_DECL int nng_socket_pair(int[2]);
+// Multithreading and synchronization functions.
+
+// 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
+// I/O APIs provided by nng. The thread runs until completion.
+NNG_DECL int nng_thread_create(nng_thread **, void (*)(void *), void *);
+
+// Set the thread name. Support for this is platform specific and varies.
+// It is intended to provide information for use when debugging applications,
+// and not for programmatic use beyond that.
+NNG_DECL void nng_thread_set_name(nng_thread *, const char *);
+
+// Destroy a thread (waiting for it to complete.) When this function
+// returns all resources for the thread are cleaned up.
+NNG_DECL void nng_thread_destroy(nng_thread *);
+
+// nng_mtx represents a mutex, which is a simple, non-reentrant, boolean lock.
+typedef struct nng_mtx nng_mtx;
+
+// nng_mtx_alloc allocates a mutex structure.
+NNG_DECL int nng_mtx_alloc(nng_mtx **);
+
+// nng_mtx_free frees the mutex. It must not be locked.
+NNG_DECL void nng_mtx_free(nng_mtx *);
+
+// nng_mtx_lock locks the mutex; if it is already locked it will block
+// until it can be locked. If the caller already holds the lock, the
+// results are undefined (a panic may occur).
+NNG_DECL void nng_mtx_lock(nng_mtx *);
+
+// nng_mtx_unlock unlocks a previously locked mutex. It is an error to
+// call this on a mutex which is not owned by caller.
+NNG_DECL void nng_mtx_unlock(nng_mtx *);
+
+// nng_cv is a condition variable. It is always allocated with an
+// associated mutex, which must be held when waiting for it, or
+// when signaling it.
+typedef struct nng_cv nng_cv;
+
+NNG_DECL int nng_cv_alloc(nng_cv **, nng_mtx *);
+
+// nng_cv_free frees the condition variable.
+NNG_DECL void nng_cv_free(nng_cv *);
+
+// nng_cv_wait waits until the condition variable is "signaled".
+NNG_DECL void nng_cv_wait(nng_cv *);
+
+// nng_cv_until waits until either the condition is signaled, or
+// the timeout expires. It returns NNG_ETIMEDOUT in that case.
+NNG_DECL int nng_cv_until(nng_cv *, nng_time);
+
+// nng_cv_wake wakes all threads waiting on the condition.
+NNG_DECL void nng_cv_wake(nng_cv *);
+
+// nng_cv_wake1 wakes only one thread waiting on the condition. This may
+// reduce the thundering herd problem, but care must be taken to ensure
+// that no waiter starves forever.
+NNG_DECL void nng_cv_wake1(nng_cv *);
+
#ifdef __cplusplus
}
#endif
diff --git a/include/nng/supplemental/util/platform.h b/include/nng/supplemental/util/platform.h
index 70eee1b8..84286388 100644
--- a/include/nng/supplemental/util/platform.h
+++ b/include/nng/supplemental/util/platform.h
@@ -1,6 +1,5 @@
//
// Copyright 2024 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
@@ -11,88 +10,9 @@
#ifndef NNG_SUPPLEMENTAL_UTIL_PLATFORM_H
#define NNG_SUPPLEMENTAL_UTIL_PLATFORM_H
-// The declarations in this file are provided to assist with application
-// portability. Conceptually these APIs are based on work we have already
-// done for NNG internals, and we find that they are useful in building
-// portable applications.
-
-// If it is more natural to use native system APIs like pthreads or C11
-// APIs or Windows APIs, then by all means please feel free to simply
-// ignore this.
-
-#include <stddef.h>
-#include <stdint.h>
-
+// The declarations in this file have been relocated to <nng/nng.h>.
+// This file itself is deprecated, and applications should stop including
+// it directly.
#include <nng/nng.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-// 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
-// I/O APIs provided by nng. The thread runs until completion.
-NNG_DECL int nng_thread_create(nng_thread **, void (*)(void *), void *);
-
-// Set the thread name. Support for this is platform specific and varies.
-// It is intended to provide information for use when debugging applications,
-// and not for programmatic use beyond that.
-NNG_DECL void nng_thread_set_name(nng_thread *, const char *);
-
-// Destroy a thread (waiting for it to complete.) When this function
-// returns all resources for the thread are cleaned up.
-NNG_DECL void nng_thread_destroy(nng_thread *);
-
-// nng_mtx represents a mutex, which is a simple, non-reentrant, boolean lock.
-typedef struct nng_mtx nng_mtx;
-
-// nng_mtx_alloc allocates a mutex structure.
-NNG_DECL int nng_mtx_alloc(nng_mtx **);
-
-// nng_mtx_free frees the mutex. It must not be locked.
-NNG_DECL void nng_mtx_free(nng_mtx *);
-
-// nng_mtx_lock locks the mutex; if it is already locked it will block
-// until it can be locked. If the caller already holds the lock, the
-// results are undefined (a panic may occur).
-NNG_DECL void nng_mtx_lock(nng_mtx *);
-
-// nng_mtx_unlock unlocks a previously locked mutex. It is an error to
-// call this on a mutex which is not owned by caller.
-NNG_DECL void nng_mtx_unlock(nng_mtx *);
-
-// nng_cv is a condition variable. It is always allocated with an
-// associated mutex, which must be held when waiting for it, or
-// when signaling it.
-typedef struct nng_cv nng_cv;
-
-NNG_DECL int nng_cv_alloc(nng_cv **, nng_mtx *);
-
-// nng_cv_free frees the condition variable.
-NNG_DECL void nng_cv_free(nng_cv *);
-
-// nng_cv_wait waits until the condition variable is "signaled".
-NNG_DECL void nng_cv_wait(nng_cv *);
-
-// nng_cv_until waits until either the condition is signaled, or
-// the timeout expires. It returns NNG_ETIMEDOUT in that case.
-NNG_DECL int nng_cv_until(nng_cv *, nng_time);
-
-// nng_cv_wake wakes all threads waiting on the condition.
-NNG_DECL void nng_cv_wake(nng_cv *);
-
-// nng_cv_wake1 wakes only one thread waiting on the condition. This may
-// reduce the thundering herd problem, but care must be taken to ensure
-// that no waiter starves forever.
-NNG_DECL void nng_cv_wake1(nng_cv *);
-
-#ifdef __cplusplus
-}
-#endif
-
#endif // NNG_SUPPLEMENTAL_UTIL_PLATFORM_H
diff --git a/src/nng.c b/src/nng.c
index 965aab86..474f07b1 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -1,5 +1,5 @@
//
-// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -2016,4 +2016,161 @@ void
nng_init_set_parameter(nng_init_parameter p, uint64_t value)
{
nni_init_set_param(p, value);
-} \ No newline at end of file
+}
+
+nng_time
+nng_clock(void)
+{
+ (void) nni_init();
+ return (nni_clock());
+}
+
+// Sleep for specified msecs.
+void
+nng_msleep(nng_duration dur)
+{
+ (void) nni_init();
+ nni_msleep(dur);
+}
+
+// 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
+// I/O APIs provided by nng. The thread runs until completion.
+int
+nng_thread_create(nng_thread **thrp, void (*func)(void *), void *arg)
+{
+ nni_thr *thr;
+ int rv;
+
+ (void) nni_init();
+
+ if ((thr = NNI_ALLOC_STRUCT(thr)) == NULL) {
+ return (NNG_ENOMEM);
+ }
+ *thrp = (void *) thr;
+ if ((rv = nni_thr_init(thr, func, arg)) != 0) {
+ return (rv);
+ }
+ nni_thr_run(thr);
+ return (0);
+}
+
+void
+nng_thread_set_name(nng_thread *thr, const char *name)
+{
+ nni_thr_set_name((void *) thr, name);
+}
+
+// Destroy a thread (waiting for it to complete.) When this function
+// returns all resources for the thread are cleaned up.
+void
+nng_thread_destroy(nng_thread *thr)
+{
+ nni_thr *t = (void *) thr;
+ nni_thr_fini(t);
+ NNI_FREE_STRUCT(t);
+}
+
+struct nng_mtx {
+ nni_mtx m;
+};
+
+int
+nng_mtx_alloc(nng_mtx **mpp)
+{
+ nng_mtx *mp;
+
+ (void) nni_init();
+
+ if ((mp = NNI_ALLOC_STRUCT(mp)) == NULL) {
+ return (NNG_ENOMEM);
+ }
+ nni_mtx_init(&mp->m);
+ *mpp = mp;
+ return (0);
+}
+
+void
+nng_mtx_free(nng_mtx *mp)
+{
+ if (mp != NULL) {
+ nni_mtx_fini(&mp->m);
+ NNI_FREE_STRUCT(mp);
+ }
+}
+
+void
+nng_mtx_lock(nng_mtx *mp)
+{
+ nni_mtx_lock(&mp->m);
+}
+
+void
+nng_mtx_unlock(nng_mtx *mp)
+{
+ nni_mtx_unlock(&mp->m);
+}
+
+struct nng_cv {
+ nni_cv c;
+};
+
+int
+nng_cv_alloc(nng_cv **cvp, nng_mtx *mx)
+{
+ nng_cv *cv;
+
+ if ((cv = NNI_ALLOC_STRUCT(cv)) == NULL) {
+ return (NNG_ENOMEM);
+ }
+ nni_cv_init(&cv->c, &mx->m);
+ *cvp = cv;
+ return (0);
+}
+
+void
+nng_cv_free(nng_cv *cv)
+{
+ if (cv != NULL) {
+ nni_cv_fini(&cv->c);
+ NNI_FREE_STRUCT(cv);
+ }
+}
+
+void
+nng_cv_wait(nng_cv *cv)
+{
+ nni_cv_wait(&cv->c);
+}
+
+int
+nng_cv_until(nng_cv *cv, nng_time when)
+{
+ return (nni_cv_until(&cv->c, (nni_time) when));
+}
+
+void
+nng_cv_wake(nng_cv *cv)
+{
+ nni_cv_wake(&cv->c);
+}
+
+void
+nng_cv_wake1(nng_cv *cv)
+{
+ nni_cv_wake1(&cv->c);
+}
+
+uint32_t
+nng_random(void)
+{
+ (void) nni_init();
+ return (nni_random());
+}
+
+int
+nng_socket_pair(int fds[2])
+{
+ return (nni_socket_pair(fds));
+}
diff --git a/src/supplemental/util/CMakeLists.txt b/src/supplemental/util/CMakeLists.txt
index f62026fb..6a820b21 100644
--- a/src/supplemental/util/CMakeLists.txt
+++ b/src/supplemental/util/CMakeLists.txt
@@ -7,7 +7,7 @@
# found online at https://opensource.org/licenses/MIT.
#
-nng_sources(idhash.c options.c platform.c)
+nng_sources(idhash.c options.c)
nng_headers(
nng/supplemental/util/idhash.h
nng/supplemental/util/options.h
diff --git a/src/supplemental/util/platform.c b/src/supplemental/util/platform.c
deleted file mode 100644
index 0f9e7a1a..00000000
--- a/src/supplemental/util/platform.c
+++ /dev/null
@@ -1,172 +0,0 @@
-//
-// Copyright 2024 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
-// file was obtained (LICENSE.txt). A copy of the license may also be
-// found online at https://opensource.org/licenses/MIT.
-//
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "core/nng_impl.h"
-#include "nng/supplemental/util/platform.h"
-
-nng_time
-nng_clock(void)
-{
- (void) nni_init();
- return (nni_clock());
-}
-
-// Sleep for specified msecs.
-void
-nng_msleep(nng_duration dur)
-{
- (void) nni_init();
- nni_msleep(dur);
-}
-
-// 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
-// I/O APIs provided by nng. The thread runs until completion.
-int
-nng_thread_create(nng_thread **thrp, void (*func)(void *), void *arg)
-{
- nni_thr *thr;
- int rv;
-
- (void) nni_init();
-
- if ((thr = NNI_ALLOC_STRUCT(thr)) == NULL) {
- return (NNG_ENOMEM);
- }
- *thrp = (void *) thr;
- if ((rv = nni_thr_init(thr, func, arg)) != 0) {
- return (rv);
- }
- nni_thr_run(thr);
- return (0);
-}
-
-void
-nng_thread_set_name(nng_thread *thr, const char *name)
-{
- nni_thr_set_name((void *)thr, name);
-}
-
-// Destroy a thread (waiting for it to complete.) When this function
-// returns all resources for the thread are cleaned up.
-void
-nng_thread_destroy(nng_thread *thr)
-{
- nni_thr *t = (void *) thr;
- nni_thr_fini(t);
- NNI_FREE_STRUCT(t);
-}
-
-struct nng_mtx {
- nni_mtx m;
-};
-
-int
-nng_mtx_alloc(nng_mtx **mpp)
-{
- nng_mtx *mp;
-
- (void) nni_init();
-
- if ((mp = NNI_ALLOC_STRUCT(mp)) == NULL) {
- return (NNG_ENOMEM);
- }
- nni_mtx_init(&mp->m);
- *mpp = mp;
- return (0);
-}
-
-void
-nng_mtx_free(nng_mtx *mp)
-{
- if (mp != NULL) {
- nni_mtx_fini(&mp->m);
- NNI_FREE_STRUCT(mp);
- }
-}
-
-void
-nng_mtx_lock(nng_mtx *mp)
-{
- nni_mtx_lock(&mp->m);
-}
-
-void
-nng_mtx_unlock(nng_mtx *mp)
-{
- nni_mtx_unlock(&mp->m);
-}
-
-struct nng_cv {
- nni_cv c;
-};
-
-int
-nng_cv_alloc(nng_cv **cvp, nng_mtx *mx)
-{
- nng_cv *cv;
-
- if ((cv = NNI_ALLOC_STRUCT(cv)) == NULL) {
- return (NNG_ENOMEM);
- }
- nni_cv_init(&cv->c, &mx->m);
- *cvp = cv;
- return (0);
-}
-
-void
-nng_cv_free(nng_cv *cv)
-{
- if (cv != NULL) {
- nni_cv_fini(&cv->c);
- NNI_FREE_STRUCT(cv);
- }
-}
-
-void
-nng_cv_wait(nng_cv *cv)
-{
- nni_cv_wait(&cv->c);
-}
-
-int
-nng_cv_until(nng_cv *cv, nng_time when)
-{
- return (nni_cv_until(&cv->c, (nni_time) when));
-}
-
-void
-nng_cv_wake(nng_cv *cv)
-{
- nni_cv_wake(&cv->c);
-}
-
-void
-nng_cv_wake1(nng_cv *cv)
-{
- nni_cv_wake1(&cv->c);
-}
-
-uint32_t
-nng_random(void)
-{
- (void) nni_init();
- return (nni_random());
-}
-
-int
-nng_socket_pair(int fds[2])
-{
- return (nni_socket_pair(fds));
-}
diff --git a/src/supplemental/websocket/websocket_test.c b/src/supplemental/websocket/websocket_test.c
index be4e1b30..edd3d609 100644
--- a/src/supplemental/websocket/websocket_test.c
+++ b/src/supplemental/websocket/websocket_test.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -10,7 +10,6 @@
#include <string.h>
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
#include <nuts.h>
diff --git a/src/testing/nuts.h b/src/testing/nuts.h
index da0f525f..e13a44da 100644
--- a/src/testing/nuts.h
+++ b/src/testing/nuts.h
@@ -48,7 +48,6 @@ extern void nng_fini(void);
#include <nng/protocol/survey0/respond.h>
#include <nng/protocol/survey0/survey.h>
#include <nng/supplemental/tls/tls.h>
-#include <nng/supplemental/util/platform.h>
#include <nng/transport/ws/websocket.h>
#include <supplemental/sha1/sha1.h>
diff --git a/src/testing/streams.c b/src/testing/streams.c
index 33c70c00..92d52f37 100644
--- a/src/testing/streams.c
+++ b/src/testing/streams.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -11,14 +11,13 @@
#define TEST_NO_MAIN
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
typedef struct {
- uint8_t * base;
+ uint8_t *base;
size_t rem;
nng_iov iov;
- nng_aio * upper_aio;
- nng_aio * lower_aio;
+ nng_aio *upper_aio;
+ nng_aio *lower_aio;
nng_stream *s;
void (*submit)(nng_stream *, nng_aio *);
} stream_xfr_t;
diff --git a/src/tools/nngcat/nngcat.c b/src/tools/nngcat/nngcat.c
index 3f29f114..bdf6823c 100644
--- a/src/tools/nngcat/nngcat.c
+++ b/src/tools/nngcat/nngcat.c
@@ -1,5 +1,5 @@
//
-// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
// Copyright 2020 Lager Data, Inc. <support@lagerdata.com>
//
@@ -31,7 +31,6 @@
#include <nng/protocol/survey0/survey.h>
#include <nng/supplemental/tls/tls.h>
#include <nng/supplemental/util/options.h>
-#include <nng/supplemental/util/platform.h>
#include <nng/transport/zerotier/zerotier.h>
// Globals. We need this to avoid passing around everything.
@@ -42,18 +41,18 @@ int delay = 0;
nng_duration interval = NNG_DURATION_INFINITE;
nng_duration sendtimeo = NNG_DURATION_INFINITE;
nng_duration recvtimeo = NNG_DURATION_INFINITE;
-void * data = NULL;
+void *data = NULL;
size_t datalen = 0;
int compat = 0;
int async = 0;
int insecure = 0;
-void * cacert = NULL;
+void *cacert = NULL;
size_t cacertlen = 0;
-void * keyfile = NULL;
+void *keyfile = NULL;
size_t keylen = 0;
-void * certfile = NULL;
+void *certfile = NULL;
size_t certlen = 0;
-const char * zthome = NULL;
+const char *zthome = NULL;
int count = 0;
int recvmaxsz = -1;
@@ -310,11 +309,11 @@ intarg(const char *val, int maxv)
static void
loadfile(const char *path, void **datap, size_t *lenp)
{
- FILE * f;
+ FILE *f;
size_t total_read = 0;
size_t allocation_size = BUFSIZ;
- char * fdata;
- char * realloc_result;
+ char *fdata;
+ char *realloc_result;
if (strcmp(path, "-") == 0) {
f = stdin;
@@ -385,7 +384,7 @@ configtls(nng_tls_config *tls)
struct addr {
struct addr *next;
int mode;
- char * val;
+ char *val;
};
struct addr **
@@ -406,7 +405,7 @@ addaddr(struct addr **endp, int mode, const char *a)
struct topic {
struct topic *next;
- char * val;
+ char *val;
};
struct topic **
@@ -578,7 +577,7 @@ sendloop(nng_socket sock)
for (;;) {
int rv;
- nng_msg * msg;
+ nng_msg *msg;
nng_time start;
nng_time end;
nng_duration delta;
@@ -592,7 +591,7 @@ sendloop(nng_socket sock)
fatal("Send error: %s", nng_strerror(rv));
}
end = nng_clock();
- delta = (nng_duration)(end - start);
+ delta = (nng_duration) (end - start);
iters++;
// By default, we don't loop.
@@ -630,7 +629,7 @@ sendrecv(nng_socket sock)
// that we exit the receive loop, and can continue.
for (;;) {
int rv;
- nng_msg * msg;
+ nng_msg *msg;
nng_time start;
nng_time end;
nng_duration delta;
@@ -655,7 +654,7 @@ sendrecv(nng_socket sock)
// want to increment the iteration count.
for (;;) {
- delta = (nng_duration)(nng_clock() - start);
+ delta = (nng_duration) (nng_clock() - start);
nng_duration expire = interval - delta;
if ((recvtimeo >= 0) && (expire > recvtimeo)) {
@@ -688,7 +687,7 @@ sendrecv(nng_socket sock)
}
end = nng_clock();
- delta = (nng_duration)(end - start);
+ delta = (nng_duration) (end - start);
iters++;
if ((count > 0) && (iters >= count)) {
@@ -709,13 +708,13 @@ int
main(int ac, char **av)
{
int idx;
- char * arg;
+ char *arg;
int val;
int rv;
char scratch[512];
- struct addr * addrs = NULL;
- struct addr ** addrend;
- struct topic * topics = NULL;
+ struct addr *addrs = NULL;
+ struct addr **addrend;
+ struct topic *topics = NULL;
struct topic **topicend;
nng_socket sock;
int port;
@@ -1092,7 +1091,7 @@ main(int ac, char **av)
}
for (struct addr *a = addrs; a != NULL; a = a->next) {
- char * act;
+ char *act;
nng_listener l;
nng_dialer d;
nng_tls_config *tls;
@@ -1114,8 +1113,8 @@ main(int ac, char **av)
nng_strerror(rv));
}
if (zthome != NULL) {
- rv = nng_dialer_set(d, NNG_OPT_ZT_HOME,
- zthome, strlen(zthome) + 1);
+ rv = nng_dialer_set(d, NNG_OPT_ZT_HOME, zthome,
+ strlen(zthome) + 1);
if ((rv != 0) && (rv != NNG_ENOTSUP)) {
fatal("Unable to set ZT home: %s",
nng_strerror(rv));
diff --git a/src/tools/perf/perf.c b/src/tools/perf/perf.c
index 46d91cd8..2801ce51 100644
--- a/src/tools/perf/perf.c
+++ b/src/tools/perf/perf.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -17,7 +17,6 @@
#include <nng/nng.h>
#include <nng/supplemental/util/options.h>
-#include <nng/supplemental/util/platform.h>
static void die(const char *, ...);
static int
@@ -328,13 +327,13 @@ do_inproc(void *args)
void
do_inproc_lat(int argc, char **argv)
{
- nng_thread * thr;
+ nng_thread *thr;
struct inproc_args ia;
int rv;
int val;
int optidx;
- char * arg;
- char * addr;
+ char *arg;
+ char *addr;
addr = "inproc://latency_test";
@@ -392,13 +391,13 @@ do_inproc_lat(int argc, char **argv)
void
do_inproc_thr(int argc, char **argv)
{
- nng_thread * thr;
+ nng_thread *thr;
struct inproc_args ia;
int rv;
int optidx;
int val;
- char * arg;
- char * addr = "inproc://throughput-test";
+ char *arg;
+ char *addr = "inproc://throughput-test";
optidx = 0;
while ((rv = nng_opts_parse(argc, argv, opts, &val, &arg, &optidx)) ==
@@ -461,7 +460,7 @@ void
latency_client(const char *addr, size_t msgsize, int trips)
{
nng_socket s;
- nng_msg * msg;
+ nng_msg *msg;
nng_time start, end;
int rv;
int i;
@@ -511,7 +510,7 @@ void
latency_server(const char *addr, size_t msgsize, int trips)
{
nng_socket s;
- nng_msg * msg;
+ nng_msg *msg;
int rv;
int i;
@@ -553,7 +552,7 @@ void
throughput_server(const char *addr, size_t msgsize, int count)
{
nng_socket s;
- nng_msg * msg;
+ nng_msg *msg;
int rv;
int i;
uint64_t start, end;
@@ -611,7 +610,7 @@ void
throughput_client(const char *addr, size_t msgsize, int count)
{
nng_socket s;
- nng_msg * msg;
+ nng_msg *msg;
int rv;
int i;
diff --git a/src/tools/perf/pubdrop.c b/src/tools/perf/pubdrop.c
index f7e1dbfd..bc067d76 100644
--- a/src/tools/perf/pubdrop.c
+++ b/src/tools/perf/pubdrop.c
@@ -1,5 +1,5 @@
//
-// Copyright 2019 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
//
// This software is supplied under the terms of the MIT License, a
// copy of which should be located in the distribution where this
@@ -15,7 +15,6 @@
#include <string.h>
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
// pubdrop - this is a simple testing utility that lets us measure PUB/SUB
// performance, including dropped messages, delivery across multiple threads,
@@ -117,7 +116,7 @@ parse_int(const char *arg, const char *what)
}
struct pubdrop_args {
- const char * addr;
+ const char *addr;
bool start;
unsigned long long msgsize;
unsigned long long count;
@@ -128,8 +127,8 @@ struct pubdrop_args {
unsigned long long recvs;
nng_time beg;
nng_time end;
- nng_mtx * mtx;
- nng_cv * cv;
+ nng_mtx *mtx;
+ nng_cv *cv;
};
static void
@@ -138,7 +137,7 @@ pub_server(void *arg)
struct pubdrop_args *pa = arg;
nng_socket sock;
int rv;
- nng_msg * msg;
+ nng_msg *msg;
nng_time start;
nng_time end;
@@ -191,7 +190,7 @@ sub_client(void *arg)
struct pubdrop_args *pa = arg;
nng_socket sock;
int rv;
- nng_msg * msg;
+ nng_msg *msg;
unsigned long long recvs;
unsigned long long drops;
unsigned long long gaps;
@@ -255,7 +254,7 @@ sub_client(void *arg)
static void
do_pubdrop(int argc, char **argv)
{
- nng_thread ** thrs;
+ nng_thread **thrs;
struct pubdrop_args pa;
int rv;
int nsubs;
diff --git a/tests/device.c b/tests/device.c
index 77da41b6..53f51ba3 100644
--- a/tests/device.c
+++ b/tests/device.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -12,7 +12,6 @@
#include <nng/nng.h>
#include <nng/protocol/pair1/pair.h>
-#include <nng/supplemental/util/platform.h>
#include "convey.h"
#include "stubs.h"
@@ -38,7 +37,6 @@ dodev(void *arg)
#define SECOND(x) ((x) *1000)
Main({
-
Test("PAIRv1 device", {
const char *addr1 = "inproc://dev1";
const char *addr2 = "inproc://dev2";
@@ -55,8 +53,8 @@ Main({
nng_socket end1;
nng_socket end2;
nng_duration tmo;
- nng_msg * msg;
- nng_thread * thr;
+ nng_msg *msg;
+ nng_thread *thr;
So(nng_pair1_open_raw(&dev1) == 0);
So(nng_pair1_open_raw(&dev2) == 0);
@@ -82,12 +80,13 @@ Main({
So(nng_dial(end2, addr2, NULL, 0) == 0);
tmo = SECOND(1);
- So(nng_socket_set_ms(end1, NNG_OPT_RECVTIMEO, tmo) == 0);
- So(nng_socket_set_ms(end2, NNG_OPT_RECVTIMEO, tmo) == 0);
+ So(nng_socket_set_ms(end1, NNG_OPT_RECVTIMEO, tmo) ==
+ 0);
+ So(nng_socket_set_ms(end2, NNG_OPT_RECVTIMEO, tmo) ==
+ 0);
nng_msleep(100);
Convey("Device can send and receive", {
-
So(nng_msg_alloc(&msg, 0) == 0);
APPENDSTR(msg, "ALPHA");
So(nng_sendmsg(end1, msg, 0) == 0);
diff --git a/tests/multistress.c b/tests/multistress.c
index e4fa1f2f..5511fcc4 100644
--- a/tests/multistress.c
+++ b/tests/multistress.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -24,7 +24,6 @@
#include <nng/protocol/reqrep0/req.h>
#include <nng/protocol/survey0/respond.h>
#include <nng/protocol/survey0/survey.h>
-#include <nng/supplemental/util/platform.h>
#include <nng/transport/inproc/inproc.h>
#include <nng/transport/ipc/ipc.h>
#include <nng/transport/tcp/tcp.h>
@@ -69,9 +68,9 @@ typedef struct test_case {
int nrecv;
int nsend;
int nfail;
- nng_aio * recd;
- nng_aio * sent;
- nng_aio * woke;
+ nng_aio *recd;
+ nng_aio *sent;
+ nng_aio *woke;
char addr[NNG_MAXADDRLEN];
char buf[32];
@@ -151,7 +150,7 @@ static void
req0_woke(void *arg)
{
test_case *c = arg;
- nng_msg * msg = NULL;
+ nng_msg *msg = NULL;
int rv;
if ((rv = nng_aio_result(c->woke)) != 0) {
@@ -173,7 +172,7 @@ static void
req0_recd(void *arg)
{
test_case *c = arg;
- nng_msg * msg = NULL;
+ nng_msg *msg = NULL;
int rv;
if ((rv = nng_aio_result(c->recd)) != 0) {
@@ -290,7 +289,7 @@ static void
pair0_woke(void *arg)
{
test_case *c = arg;
- nng_msg * msg = NULL;
+ nng_msg *msg = NULL;
int rv;
if ((rv = nng_aio_result(c->woke)) != 0) {
@@ -390,7 +389,7 @@ static void
bus0_woke(void *arg)
{
test_case *c = arg;
- nng_msg * msg = NULL;
+ nng_msg *msg = NULL;
int rv;
if ((rv = nng_aio_result(c->woke)) != 0) {
@@ -470,7 +469,7 @@ void
pub0_woke(void *arg)
{
test_case *c = arg;
- nng_msg * msg = NULL;
+ nng_msg *msg = NULL;
int rv;
if ((rv = nng_aio_result(c->woke)) != 0) {
@@ -627,7 +626,7 @@ void
push0_woke(void *arg)
{
test_case *c = arg;
- nng_msg * msg = NULL;
+ nng_msg *msg = NULL;
int rv;
if ((rv = nng_aio_result(c->woke)) != 0) {
diff --git a/tests/nonblock.c b/tests/nonblock.c
index 4fde2c80..19174882 100644
--- a/tests/nonblock.c
+++ b/tests/nonblock.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -19,7 +19,6 @@
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
-#include <nng/supplemental/util/platform.h>
#include "convey.h"
#include "stubs.h"
@@ -42,7 +41,7 @@ repthr(void *arg)
for (;;) {
fd_set fset;
struct timeval tmo;
- char * msgbuf;
+ char *msgbuf;
size_t msglen;
FD_ZERO(&fset);
diff --git a/tests/pipe.c b/tests/pipe.c
index c2d1f06c..665018b0 100644
--- a/tests/pipe.c
+++ b/tests/pipe.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -14,7 +14,6 @@
#include <nng/nng.h>
#include <nng/protocol/pipeline0/pull.h>
#include <nng/protocol/pipeline0/push.h>
-#include <nng/supplemental/util/platform.h>
#include "convey.h"
#include "stubs.h"
@@ -34,8 +33,8 @@ struct testcase {
int rem;
int err;
int rej;
- nng_mtx * lk;
- nng_cv * cv;
+ nng_mtx *lk;
+ nng_cv *cv;
};
static bool
@@ -114,7 +113,6 @@ char addr[64];
static int cnt;
TestMain("Pipe notify works", {
-
Convey("We can create a pipeline", {
struct testcase push;
struct testcase pull;
@@ -161,10 +159,10 @@ TestMain("Pipe notify works", {
So(nng_dialer_create(&push.d, push.s, addr) == 0);
So(nng_listener_id(pull.l) > 0);
So(nng_dialer_id(push.d) > 0);
- So(nng_dialer_set_ms(
- push.d, NNG_OPT_RECONNMINT, 10) == 0);
- So(nng_dialer_set_ms(
- push.d, NNG_OPT_RECONNMAXT, 10) == 0);
+ So(nng_dialer_set_ms(push.d, NNG_OPT_RECONNMINT, 10) ==
+ 0);
+ So(nng_dialer_set_ms(push.d, NNG_OPT_RECONNMAXT, 10) ==
+ 0);
So(nng_listener_start(pull.l, 0) == 0);
So(nng_dialer_start(push.d, 0) == 0);
So(expect(&pull, &pull.add_pre, 1));
diff --git a/tests/pollfd.c b/tests/pollfd.c
index 0c93c365..adb9d806 100644
--- a/tests/pollfd.c
+++ b/tests/pollfd.c
@@ -1,5 +1,5 @@
//
-// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -33,7 +33,6 @@
#include <nng/protocol/pair1/pair.h>
#include <nng/protocol/pipeline0/pull.h>
#include <nng/protocol/pipeline0/push.h>
-#include <nng/supplemental/util/platform.h>
#include "convey.h"
#include "stubs.h"
@@ -64,8 +63,8 @@ TestMain("Poll FDs", {
Convey("And it is always the same fd", {
int fd2;
sz = sizeof(fd2);
- So(nng_socket_get(s1, NNG_OPT_RECVFD, &fd2, &sz) ==
- 0);
+ So(nng_socket_get(
+ s1, NNG_OPT_RECVFD, &fd2, &sz) == 0);
So(fd2 == fd);
});
diff --git a/tests/reqctx.c b/tests/reqctx.c
index e878037f..47222c00 100644
--- a/tests/reqctx.c
+++ b/tests/reqctx.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -13,7 +13,6 @@
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
-#include <nng/supplemental/util/platform.h>
#include "convey.h"
#include "stubs.h"
@@ -22,9 +21,9 @@ static struct {
nng_aio *aio;
enum { START, SEND, RECV } state;
nng_socket s;
- nng_msg * msg;
+ nng_msg *msg;
int cnt;
- nng_mtx * mtx;
+ nng_mtx *mtx;
} rep_state;
void
@@ -117,7 +116,8 @@ TestMain("REQ concurrent contexts", {
nng_aio_set_timeout(saios[i], 5000);
}
- So(nng_socket_set_int(rep_state.s, NNG_OPT_SENDBUF, NCTX) == 0);
+ So(nng_socket_set_int(rep_state.s, NNG_OPT_SENDBUF, NCTX) ==
+ 0);
So(i == NCTX);
for (i = 0; i < NCTX; i++) {
uint32_t tmp;
@@ -230,7 +230,7 @@ TestMain("REQ concurrent contexts", {
Convey("Given a socket and a context", {
nng_socket req;
nng_ctx ctx;
- nng_aio * aio;
+ nng_aio *aio;
So(nng_req0_open(&req) == 0);
So(nng_ctx_open(&ctx, req) == 0);
diff --git a/tests/reqstress.c b/tests/reqstress.c
index 89190c64..6696eace 100644
--- a/tests/reqstress.c
+++ b/tests/reqstress.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -16,7 +16,6 @@
#include <nng/protocol/bus0/bus.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
-#include <nng/supplemental/util/platform.h>
#include <nng/transport/inproc/inproc.h>
#include <nng/transport/ipc/ipc.h>
#include <nng/transport/tcp/tcp.h>
@@ -64,9 +63,9 @@ typedef struct test_case {
int nrecv;
int nsend;
int nfail;
- nng_aio * recv_aio;
- nng_aio * send_aio;
- nng_aio * time_aio;
+ nng_aio *recv_aio;
+ nng_aio *send_aio;
+ nng_aio *time_aio;
char buf[32];
} test_case;
@@ -144,7 +143,7 @@ static void
req_time_cb(void *arg)
{
test_case *c = arg;
- nng_msg * msg = NULL;
+ nng_msg *msg = NULL;
int rv;
if ((rv = nng_aio_result(c->time_aio)) != 0) {
@@ -167,7 +166,7 @@ static void
req_recv_cb(void *arg)
{
test_case *c = arg;
- nng_msg * msg = NULL;
+ nng_msg *msg = NULL;
int rv;
if ((rv = nng_aio_result(c->recv_aio)) != 0) {
diff --git a/tests/scalability.c b/tests/scalability.c
index c794a4ee..0b4b1799 100644
--- a/tests/scalability.c
+++ b/tests/scalability.c
@@ -1,5 +1,5 @@
//
-// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -13,7 +13,6 @@
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
-#include <nng/supplemental/util/platform.h>
#include "convey.h"
#include "stubs.h"
@@ -22,7 +21,7 @@ static int nclients = 200;
static char *addr = "inproc:///atscale";
nng_socket rep;
-nng_thread * server;
+nng_thread *server;
void
serve(void *arg)
@@ -87,7 +86,7 @@ transact(nng_socket *clients, int num)
Main({
nng_socket *clients;
- int * results;
+ int *results;
clients = calloc(nclients, sizeof(nng_socket));
results = calloc(nclients, sizeof(int));
diff --git a/tests/synch.c b/tests/synch.c
index 9174385d..c0bf18c9 100644
--- a/tests/synch.c
+++ b/tests/synch.c
@@ -1,6 +1,6 @@
//
// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
-// Copyright 2018 Capitar IT Group BV <info@capitar.com>
+// Copyright 2024 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
@@ -9,7 +9,6 @@
//
#include <nng/nng.h>
-#include <nng/supplemental/util/platform.h>
#include "convey.h"
@@ -17,8 +16,8 @@
struct notifyarg {
int did;
nng_duration when;
- nng_mtx * mx;
- nng_cv * cv;
+ nng_mtx *mx;
+ nng_cv *cv;
};
void
@@ -34,7 +33,7 @@ notifyafter(void *a)
}
struct notifyarg arg;
-nng_thread * thr;
+nng_thread *thr;
static void
test_sync(void)
diff --git a/tests/trantest.h b/tests/trantest.h
index 91b75494..9176c543 100644
--- a/tests/trantest.h
+++ b/tests/trantest.h
@@ -1,5 +1,5 @@
//
-// Copyright 2022 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2024 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
@@ -14,7 +14,6 @@
#include <nng/nng.h>
#include <nng/protocol/reqrep0/rep.h>
#include <nng/protocol/reqrep0/req.h>
-#include <nng/supplemental/util/platform.h>
#include "convey.h"
#include "core/nng_impl.h"
@@ -28,11 +27,11 @@ typedef int (*trantest_proptest_t)(nng_msg *);
typedef struct trantest trantest;
struct trantest {
- const char *tmpl;
- char addr[NNG_MAXADDRLEN + 1];
- nng_socket reqsock;
- nng_socket repsock;
- nni_sp_tran * tran;
+ const char *tmpl;
+ char addr[NNG_MAXADDRLEN + 1];
+ nng_socket reqsock;
+ nng_socket repsock;
+ nni_sp_tran *tran;
int (*init)(struct trantest *);
void (*fini)(struct trantest *);
int (*dialer_init)(nng_dialer);
@@ -105,7 +104,7 @@ trantest_next_address(char *out, const char *prefix)
// we append the port, and for web sockets also a /test path
(void) snprintf(out, NNG_MAXADDRLEN, "%s%u%s", prefix, trantest_port,
- prefix[0] == 'w' ? "/test" : "");
+ prefix[0] == 'w' ? "/test" : "");
trantest_port++;
}
@@ -249,10 +248,10 @@ trantest_send_recv(trantest *tt)
nng_listener l = NNG_LISTENER_INITIALIZER;
nng_dialer d = NNG_DIALER_INITIALIZER;
nng_pipe p = NNG_PIPE_INITIALIZER;
- nng_msg * send;
- nng_msg * recv;
+ nng_msg *send;
+ nng_msg *recv;
size_t len;
- char * url;
+ char *url;
So(trantest_listen(tt, &l) == 0);
So(nng_listener_id(l) > 0);
@@ -299,9 +298,9 @@ trantest_send_recv_multi(trantest *tt)
nng_listener l = NNG_LISTENER_INITIALIZER;
nng_dialer d = NNG_DIALER_INITIALIZER;
nng_pipe p = NNG_PIPE_INITIALIZER;
- nng_msg * send;
- nng_msg * recv;
- char * url;
+ nng_msg *send;
+ nng_msg *recv;
+ char *url;
int i;
char msgbuf[16];
@@ -353,8 +352,8 @@ trantest_check_properties(trantest *tt, trantest_proptest_t f)
Convey("Properties test", {
nng_listener l = NNG_LISTENER_INITIALIZER;
nng_dialer d = NNG_DIALER_INITIALIZER;
- nng_msg * send;
- nng_msg * recv;
+ nng_msg *send;
+ nng_msg *recv;
int rv;
So(trantest_listen(tt, &l) == 0);
@@ -388,9 +387,9 @@ trantest_send_recv_large(trantest *tt)
Convey("Send and recv large data", {
nng_listener l = NNG_LISTENER_INITIALIZER;
nng_dialer d = NNG_DIALER_INITIALIZER;
- nng_msg * send;
- nng_msg * recv;
- char * data;
+ nng_msg *send;
+ nng_msg *recv;
+ char *data;
size_t size;
size = 1024 * 128; // bigger than any transport segment