summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-10-19 15:16:25 -0700
committerGarrett D'Amore <garrett@damore.org>2017-10-19 17:56:49 -0700
commit4e668fdd5b5da0d46f97d835249dbe5f0ea319a7 (patch)
tree0aaad8a672024b3a510763150b167320be6f1f5b /src/core
parentd7e39a2423212a31c5ef62dcb0b7a5b4bf9f34df (diff)
downloadnng-4e668fdd5b5da0d46f97d835249dbe5f0ea319a7.tar.gz
nng-4e668fdd5b5da0d46f97d835249dbe5f0ea319a7.tar.bz2
nng-4e668fdd5b5da0d46f97d835249dbe5f0ea319a7.zip
fixes #84 Consider using msec for durations
There is now a public nng_duration type. We have also updated the zerotier work to work with the signed int64_t's that the latst ZeroTier dev branch is using.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/clock.c6
-rw-r--r--src/core/clock.h3
-rw-r--r--src/core/defs.h6
-rw-r--r--src/core/device.c2
-rw-r--r--src/core/options.c6
-rw-r--r--src/core/options.h6
-rw-r--r--src/core/platform.h4
-rw-r--r--src/core/socket.c24
8 files changed, 29 insertions, 28 deletions
diff --git a/src/core/clock.c b/src/core/clock.c
index 31678f67..f114daa1 100644
--- a/src/core/clock.c
+++ b/src/core/clock.c
@@ -16,7 +16,7 @@ nni_clock(void)
}
void
-nni_usleep(nni_duration usec)
+nni_msleep(nni_duration msec)
{
- nni_plat_usleep(usec);
-}
+ nni_plat_sleep(msec);
+} \ No newline at end of file
diff --git a/src/core/clock.h b/src/core/clock.h
index 3b607322..b369520b 100644
--- a/src/core/clock.h
+++ b/src/core/clock.h
@@ -1,5 +1,6 @@
//
// Copyright 2017 Garrett D'Amore <garrett@damore.org>
+// Copyright 2017 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
@@ -14,6 +15,6 @@
extern nni_time nni_clock(void);
-extern void nni_usleep(nni_duration usec);
+extern void nni_msleep(nni_duration);
#endif // CORE_CLOCK_H
diff --git a/src/core/defs.h b/src/core/defs.h
index ff02b28b..57f7f06a 100644
--- a/src/core/defs.h
+++ b/src/core/defs.h
@@ -53,8 +53,8 @@ typedef struct nni_thr nni_thr;
typedef void (*nni_thr_func)(void *);
typedef int nni_signal; // Wakeup channel.
-typedef uint64_t nni_time; // Abs. time (usec).
-typedef int64_t nni_duration; // Rel. time (usec).
+typedef uint64_t nni_time; // Abs. time (ms).
+typedef int32_t nni_duration; // Rel. time (ms).
typedef struct nni_aio nni_aio;
@@ -76,7 +76,7 @@ typedef struct {
// Some default timing things.
#define NNI_TIME_NEVER ((nni_time) -1)
#define NNI_TIME_ZERO ((nni_time) 0)
-#define NNI_SECOND (1000000)
+#define NNI_SECOND (1000)
// Structure allocation conveniences.
#define NNI_ALLOC_STRUCT(s) nni_alloc(sizeof(*s))
diff --git a/src/core/device.c b/src/core/device.c
index 9161e2f0..22ec086e 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -66,7 +66,7 @@ nni_device(nni_sock *sock1, nni_sock *sock2)
{
nni_device_pair pair;
int rv;
- nni_time never = NNI_TIME_NEVER;
+ nni_duration never = -1;
size_t sz;
memset(&pair, 0, sizeof(pair));
diff --git a/src/core/options.c b/src/core/options.c
index aa744642..3b787b82 100644
--- a/src/core/options.c
+++ b/src/core/options.c
@@ -14,7 +14,7 @@
#include <string.h>
int
-nni_chkopt_usec(const void *v, size_t sz)
+nni_chkopt_ms(const void *v, size_t sz)
{
nni_duration val;
if (sz != sizeof(val)) {
@@ -56,7 +56,7 @@ nni_chkopt_size(const void *v, size_t sz, size_t minv, size_t maxv)
}
int
-nni_setopt_usec(nni_duration *dp, const void *v, size_t sz)
+nni_setopt_ms(nni_duration *dp, const void *v, size_t sz)
{
nni_duration dur;
@@ -110,7 +110,7 @@ nni_setopt_size(size_t *sp, const void *v, size_t sz, size_t minv, size_t maxv)
}
int
-nni_getopt_usec(nni_duration u, void *val, size_t *sizep)
+nni_getopt_ms(nni_duration u, void *val, size_t *sizep)
{
size_t sz = sizeof(u);
diff --git a/src/core/options.h b/src/core/options.h
index cf2176b8..beeca951 100644
--- a/src/core/options.h
+++ b/src/core/options.h
@@ -23,10 +23,10 @@ extern int nni_getopt_buf(nni_msgq *, void *, size_t *);
// nni_setopt_duration sets the duration. Durations must be legal,
// either a positive value, 0, or -1 to indicate forever.
-extern int nni_setopt_usec(nni_duration *, const void *, size_t);
+extern int nni_setopt_ms(nni_duration *, const void *, size_t);
// nni_getopt_duration gets the duration.
-extern int nni_getopt_usec(nni_duration, void *, size_t *);
+extern int nni_getopt_ms(nni_duration, void *, size_t *);
// nni_setopt_int sets an integer, which must be between the minimum and
// maximum values (inclusive).
@@ -61,7 +61,7 @@ extern int nni_getopt_size(size_t, void *, size_t *);
// nni_getopt_fd obtains a notification file descriptor.
extern int nni_getopt_fd(nni_sock *, nni_notifyfd *, int, void *, size_t *);
-extern int nni_chkopt_usec(const void *, size_t);
+extern int nni_chkopt_ms(const void *, size_t);
extern int nni_chkopt_int(const void *, size_t, int, int);
extern int nni_chkopt_size(const void *, size_t, size_t, size_t);
diff --git a/src/core/platform.h b/src/core/platform.h
index 8b709e93..bff7f709 100644
--- a/src/core/platform.h
+++ b/src/core/platform.h
@@ -153,8 +153,8 @@ extern void nni_plat_thr_fini(nni_plat_thr *);
// of using negative values for other purposes in the future.)
extern nni_time nni_plat_clock(void);
-// nni_plat_usleep sleeps for the specified number of microseconds (at least).
-extern void nni_plat_usleep(nni_duration);
+// nni_plat_sleep sleeps for the specified number of milliseconds (at least).
+extern void nni_plat_sleep(nni_duration);
//
// Entropy Support
diff --git a/src/core/socket.c b/src/core/socket.c
index c64ab995..8895f7a7 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -95,49 +95,49 @@ nni_sock_getopt_recvfd(nni_sock *s, void *buf, size_t *szp)
static int
nni_sock_setopt_recvtimeo(nni_sock *s, const void *buf, size_t sz)
{
- return (nni_setopt_usec(&s->s_rcvtimeo, buf, sz));
+ return (nni_setopt_ms(&s->s_rcvtimeo, buf, sz));
}
static int
nni_sock_getopt_recvtimeo(nni_sock *s, void *buf, size_t *szp)
{
- return (nni_getopt_usec(s->s_rcvtimeo, buf, szp));
+ return (nni_getopt_ms(s->s_rcvtimeo, buf, szp));
}
static int
nni_sock_setopt_sendtimeo(nni_sock *s, const void *buf, size_t sz)
{
- return (nni_setopt_usec(&s->s_sndtimeo, buf, sz));
+ return (nni_setopt_ms(&s->s_sndtimeo, buf, sz));
}
static int
nni_sock_getopt_sendtimeo(nni_sock *s, void *buf, size_t *szp)
{
- return (nni_getopt_usec(s->s_sndtimeo, buf, szp));
+ return (nni_getopt_ms(s->s_sndtimeo, buf, szp));
}
static int
nni_sock_setopt_reconnmint(nni_sock *s, const void *buf, size_t sz)
{
- return (nni_setopt_usec(&s->s_reconn, buf, sz));
+ return (nni_setopt_ms(&s->s_reconn, buf, sz));
}
static int
nni_sock_getopt_reconnmint(nni_sock *s, void *buf, size_t *szp)
{
- return (nni_getopt_usec(s->s_reconn, buf, szp));
+ return (nni_getopt_ms(s->s_reconn, buf, szp));
}
static int
nni_sock_setopt_reconnmaxt(nni_sock *s, const void *buf, size_t sz)
{
- return (nni_setopt_usec(&s->s_reconnmax, buf, sz));
+ return (nni_setopt_ms(&s->s_reconnmax, buf, sz));
}
static int
nni_sock_getopt_reconnmaxt(nni_sock *s, void *buf, size_t *szp)
{
- return (nni_getopt_usec(s->s_reconnmax, buf, szp));
+ return (nni_getopt_ms(s->s_reconnmax, buf, szp));
}
static int
@@ -500,8 +500,8 @@ nni_sock_create(nni_sock **sp, const nni_proto *proto)
return (NNG_ENOMEM);
}
s->s_linger = 0;
- s->s_sndtimeo = NNI_TIME_NEVER;
- s->s_rcvtimeo = NNI_TIME_NEVER;
+ s->s_sndtimeo = -1;
+ s->s_rcvtimeo = -1;
s->s_closing = 0;
s->s_reconn = NNI_SECOND;
s->s_reconnmax = 0;
@@ -1026,7 +1026,7 @@ nni_sock_setopt(nni_sock *s, const char *name, const void *val, size_t size)
// was found, or even if a transport rejected one of the settings.
if ((rv == NNG_ENOTSUP) || (rv == 0)) {
if ((strcmp(name, NNG_OPT_LINGER) == 0)) {
- rv = nni_chkopt_usec(val, size);
+ rv = nni_chkopt_ms(val, size);
} else if (strcmp(name, NNG_OPT_RECVMAXSZ) == 0) {
// just a sanity test on the size; it also ensures that
// a size can be set even with no transport configured.
@@ -1090,7 +1090,7 @@ nni_sock_setopt(nni_sock *s, const char *name, const void *val, size_t size)
// will already have had a chance to veto this.
if (strcmp(name, NNG_OPT_LINGER) == 0) {
- rv = nni_setopt_usec(&s->s_linger, val, size);
+ rv = nni_setopt_ms(&s->s_linger, val, size);
}
if (rv == 0) {