aboutsummaryrefslogtreecommitdiff
path: root/src/nng.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-26 09:57:56 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-26 09:57:56 -0800
commitd93cbc059cd1e42773d1aec19f8b49a972f2eac3 (patch)
tree71a6c79e8ae5c2ef9ed9beb06088ccd4d832fca9 /src/nng.c
parenta9e81c87a7b2a203c2bd4f310f936af46ef42fc1 (diff)
downloadnng-d93cbc059cd1e42773d1aec19f8b49a972f2eac3.tar.gz
nng-d93cbc059cd1e42773d1aec19f8b49a972f2eac3.tar.bz2
nng-d93cbc059cd1e42773d1aec19f8b49a972f2eac3.zip
Added more plumbing to facilitate test writing & compatibility.
Also, while here fixed a bug for the PAIR protocol in compat mode. It should now be possible to import more of the nanomsg tests directly with little or no modification.
Diffstat (limited to 'src/nng.c')
-rw-r--r--src/nng.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/nng.c b/src/nng.c
index bb36a236..b048194c 100644
--- a/src/nng.c
+++ b/src/nng.c
@@ -625,8 +625,50 @@ nng_device(nng_socket sock1, nng_socket sock2)
}
+// These routines exist as utility functions, exposing some of our "guts"
+// to the external world for the purposes of test code and bundled utilities.
+// They should not be considered part of our public API, and applications
+// should refrain from their use.
+
void
nng_usleep(uint64_t usec)
{
nni_usleep(usec);
}
+
+
+uint64_t
+nng_clock(void)
+{
+ return ((uint64_t) nni_clock());
+}
+
+
+// nng_thread_create creates a thread structure, and starts it running.
+// Unlike the internals, this allocates stuff dynamically, and does not
+// wait to start.
+int
+nng_thread_create(void **thrp, void (*func)(void *), void *arg)
+{
+ nni_thr *thr;
+ int rv;
+
+ if ((thr = NNI_ALLOC_STRUCT(thr)) == NULL) {
+ return (NNG_ENOMEM);
+ }
+ memset(thr, 0, sizeof (*thr));
+ *thrp = thr;
+ if ((rv = nni_thr_init(thr, func, arg)) != 0) {
+ return (rv);
+ }
+ nni_thr_run(thr);
+ return (0);
+}
+
+
+void
+nng_thread_destroy(void *thr)
+{
+ nni_thr_fini(thr);
+ NNI_FREE_STRUCT(thr);
+}