diff options
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/SUMMARY.md | 2 | ||||
| -rw-r--r-- | docs/ref/api/time.md | 78 | ||||
| -rw-r--r-- | docs/ref/api/util/nng_clock.md | 46 | ||||
| -rw-r--r-- | docs/ref/api/util/nng_duration.md | 33 | ||||
| -rw-r--r-- | docs/ref/api/util/nng_msleep.md | 32 |
5 files changed, 80 insertions, 111 deletions
diff --git a/docs/ref/SUMMARY.md b/docs/ref/SUMMARY.md index cec19706..34319fa8 100644 --- a/docs/ref/SUMMARY.md +++ b/docs/ref/SUMMARY.md @@ -26,6 +26,8 @@ - [Statistics](./api/stats.md) + - [Time](./api/time.md) + - [Utility Functions](./api/util/index.md) - [nng_alloc](./api/util/nng_alloc.md) diff --git a/docs/ref/api/time.md b/docs/ref/api/time.md new file mode 100644 index 00000000..88e1f805 --- /dev/null +++ b/docs/ref/api/time.md @@ -0,0 +1,78 @@ +# Time + +_NNG_ supports has support for time in the form of access to a +system clock, and supporting timeouts for certain operations. + +## Time Type + +```c +typedef uint64_t nng_time; +``` + +The {{i:`nng_time`}} type is used to represent a clock offset from a common base time, +measured in milliseconds. + +The reference, or zero value, is some arbitrary point in time, most often sytem boot, but can +be process start time or any other convenient reference. + +All threads within a process will use the same reference time, but be aware that different processes +may use a different reference time. + +## Duration Type + +```c +typedef int64_t nng_duration; + +#define NNG_DURATION_INFINITE (-1) +#define NNG_DURATION_DEFAULT (-2) +#define NNG_DURATION_ZERO (0) +``` + +The {{i:`nng_duration`}} time measures a time {{i:duration}} in milliseconds. +Normally durations are positive, but some specific negative values are reserved. + +- {{i:`NNG_DURATION_INFINITE`}}: The duration essentially means forever. + This is most often used with a timeout to indicate that there is no timeout, the + operation should wait until it is complete, even forever. + +- {{i:`NNG_DURATION_DEFAULT`}}: This special value is used in some circumstances to + prevent overriding a default timeout. Some operations have a default maximum time, + and this value means that the previously established default should be used. + The precise meaning is context-specific. + +- {{i:`NNG_DURATION_ZERO`}}: A zero length duration is used to performan an immediate + poll. + +## Getting the Current Time + +```c +nng_time nng_clock(void); +``` + +The {{i:`nng_clock`}}{{hi:clock}} function returns the number of elapsed +milliseconds since some arbitrary time in the past. +The resolution of the clock depends on the underlying timing facilities of the system. +This function may be used for timing, but applications should not expect +very fine-grained values. + +## Waiting for Duration + +```c +void nng_msleep(nng_duration msec); +``` + +The {{i:`nng_msleep`}} function blocks the calling thread for at least the specified +number of milliseconds. + +> [!TIP] +> This function may block for longer than requested. +> The actual wait time is determined by the capabilities of the +> underlying system. + +## See Also + +[`nng_cv_until`][nng_cv_until], +[`nng_sleep_aio`][nng_sleep_aio] + +[nng_cv_until]: ./synch.md#waiting-for-the-condition +[nng_sleep_aio]: TODO.md diff --git a/docs/ref/api/util/nng_clock.md b/docs/ref/api/util/nng_clock.md deleted file mode 100644 index ca6d1c6e..00000000 --- a/docs/ref/api/util/nng_clock.md +++ /dev/null @@ -1,46 +0,0 @@ -# nng_clock - -## NAME - -nng_clock --- get time - -## SYNOPSIS - -```c -#include <nng/nng.h> - -typedef uint64_t nng_time; - -nng_time nng_clock(void); -``` - -## DESCRIPTION - -The {{i:`nng_clock`}}{{hi:clock}} function returns the number of elapsed -milliseconds since some arbitrary time in the past. -The resolution of the clock depends on the underlying timing facilities of the system. -This function may be used for timing, but applications should not expect -very fine-grained values. - -> [!NOTE] -> The reference time will be the same for a given program, -> but different programs may have different references. - -This function is intended to help with setting appropriate -timeouts using [`nng_cv_until`][nng_cv_until] -or [`nng_aio_set_expire`][nng_aio_set_timeout]. - -## RETURN VALUES - -Milliseconds since reference time. - -## SEE ALSO - -[nng_cv_until][nng_cv_until], -[nng_msleep][nng_msleep], -[nng_sleep_aio][nng_sleep_aio] - -[nng_cv_until]: ../thr/nng_cv.md -[nng_msleep]: ../util/nng_msleep.md -[nng_sleep_aio]: ../aio/nng_sleep_aio.md -[nng_aio_set_timeout]: ../aio/nng_aio_set_timeout.md diff --git a/docs/ref/api/util/nng_duration.md b/docs/ref/api/util/nng_duration.md deleted file mode 100644 index 9ad76256..00000000 --- a/docs/ref/api/util/nng_duration.md +++ /dev/null @@ -1,33 +0,0 @@ -# nng_duration - -## NAME - -nng_duration --- relative time in milliseconds - -## SYNOPSIS - -```c -#include <nng/nng.h> - -typedef int32_t nng_duration; - -#define NNG_DURATION_INFINITE (-1) -#define NNG_DURATION_DEFAULT (-2) -#define NNG_DURATION_ZERO (0) -``` - -## DESCRIPTION - -An {{i:`nng_duration`}}{{hi:duration}} is a relative time, measured in {{i:milliseconds}}. -This type is most often used in conjunction with timers and timeouts. - -A couple of special values have been set aside, and carry special meanings. - -- {{i:`NNG_DURATION_DEFAULT`}}: - Indicates a context-specific default value should be used. - -- {{i:`NNG_DURATION_INFINITE`}}: - Effectively an infinite duration; used most often to disable timeouts. - -- {{i:`NNG_DURATION_ZERO`}}: - Zero length duration; used to perform an immediate poll. diff --git a/docs/ref/api/util/nng_msleep.md b/docs/ref/api/util/nng_msleep.md deleted file mode 100644 index e055b2f9..00000000 --- a/docs/ref/api/util/nng_msleep.md +++ /dev/null @@ -1,32 +0,0 @@ -# nng_msleep - -## NAME - -nng_msleep --- sleep milliseconds - -## SYNOPSIS - -```c -#include <nng/nng.h> - -typedef int64_t nng_duration; - -void nng_msleep(nng_duration msec); -``` - -## DESCRIPTION - -The {{i:`nng_msleep`}}{{hi:sleep}} blocks the caller for at least _msec_ milliseconds. - -> [!NOTE] -> This function may block for longer than requested. -> The actual wait time is determined by the capabilities of the -> underlying system. - -## SEE ALSO - -[nng_sleep_aio][nng_sleep_aio], -[nng_clock][nng_clock] - -[nng_clock]: ../util/nng_clock.md -[nng_sleep_aio]: ../aio/nng_sleep_aio.md |
