summaryrefslogtreecommitdiff
path: root/docs/reference/src/api/util
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2024-03-24 22:19:42 -0700
committerGarrett D'Amore <garrett@damore.org>2024-03-24 22:19:42 -0700
commit331bd5a7c360083f245fe6c82afa38dd05c4a9c9 (patch)
treef7a50976a4a6a717660d1c94a9808e896c3c2059 /docs/reference/src/api/util
parent962553386968a528593665e228b9424de84d7f4e (diff)
downloadnng-331bd5a7c360083f245fe6c82afa38dd05c4a9c9.tar.gz
nng-331bd5a7c360083f245fe6c82afa38dd05c4a9c9.tar.bz2
nng-331bd5a7c360083f245fe6c82afa38dd05c4a9c9.zip
More org stuff
Diffstat (limited to 'docs/reference/src/api/util')
-rw-r--r--docs/reference/src/api/util/index.md1
-rw-r--r--docs/reference/src/api/util/nng_alloc.md44
-rw-r--r--docs/reference/src/api/util/nng_clock.md43
-rw-r--r--docs/reference/src/api/util/nng_free.md35
-rw-r--r--docs/reference/src/api/util/nng_version.md36
5 files changed, 159 insertions, 0 deletions
diff --git a/docs/reference/src/api/util/index.md b/docs/reference/src/api/util/index.md
new file mode 100644
index 00000000..a830d6bd
--- /dev/null
+++ b/docs/reference/src/api/util/index.md
@@ -0,0 +1 @@
+# General Purpose Functions
diff --git a/docs/reference/src/api/util/nng_alloc.md b/docs/reference/src/api/util/nng_alloc.md
new file mode 100644
index 00000000..98f71fa5
--- /dev/null
+++ b/docs/reference/src/api/util/nng_alloc.md
@@ -0,0 +1,44 @@
+# nng_alloc()
+
+## NAME
+
+nng_alloc --- allocate memory
+
+## SYNOPSIS
+
+```c
+#include <nng/nng.h>
+
+void *nng_alloc(size_t size);
+```
+
+## DESCRIPTION
+
+The `nng_alloc()` function allocates a contiguous memory region of
+at least _size_ bytes.
+The memory will be 64-bit aligned.
+
+The returned memory can be used to hold message buffers, in which
+case it can be directly passed to [`nng_send()`](../socket/nng_send.md) using
+the flag `NNG_FLAG_ALLOC`. Alternatively, it can be freed when no
+longer needed using [`nng_free()`](nng_free.md).
+
+> [!IMPORTANT]
+> Do not use the system `free()` function (or the C++ `delete` operator) to release this memory.
+> On some configurations this may work, but on others it will lead to a crash or
+> other unpredictable behavior.
+
+## RETURN VALUES
+
+This function returns a pointer to the allocated memory on success,
+and `NULL` otherwise.
+
+## ERRORS
+
+No errors are returned, but if memory cannot be allocated then `NULL`
+is returned.
+
+## SEE ALSO
+
+[nng_free()](nng_free.md),
+[nng_send()](../socket/nng_send.md)
diff --git a/docs/reference/src/api/util/nng_clock.md b/docs/reference/src/api/util/nng_clock.md
new file mode 100644
index 00000000..3653bfa2
--- /dev/null
+++ b/docs/reference/src/api/util/nng_clock.md
@@ -0,0 +1,43 @@
+# nng_clock()
+
+## NAME
+
+nng_clock - get time
+
+## SYNOPSIS
+
+```c
+#include <nng/nng.h>
+#include <nng/supplemental/util/platform.h>
+
+typedef uint64_t nng_time;
+
+nng_time nng_clock(void);
+```
+
+## DESCRIPTION
+
+The `nng_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()`](../threads/nng_cv_until.md).
+
+## RETURN VALUES
+
+Milliseconds since reference time.
+
+## SEE ALSO
+
+[nng_sleep_aio()](nng_sleep_aio.md),
+[nng_cv_until()](../threads/nng_cv_until.md),
+[nng_msleep()](nng_msleep.md),
+[nng_duration](nng_duration.md)
diff --git a/docs/reference/src/api/util/nng_free.md b/docs/reference/src/api/util/nng_free.md
new file mode 100644
index 00000000..ca527914
--- /dev/null
+++ b/docs/reference/src/api/util/nng_free.md
@@ -0,0 +1,35 @@
+# nng_free()
+
+## NAME
+
+nng_free --- free memory
+
+## SYNOPSIS
+
+```c
+#include <nng/nng.h>
+
+void nng_free(void *ptr, size_t size);
+```
+
+## DESCRIPTION
+
+The `nng_free()` function deallocates a memory region of size _size_,
+that was previously allocated by [`nng_alloc()`](nng_alloc.md) or
+[`nng_recv()`](../socket/nng_recv.md) with the `NNG_FLAG_ALLOC` flag.
+
+> [!IMPORTANT]
+> It is very important that _size_ match the allocation size
+> used to allocate the memory.
+
+> [!IMPORTANT]
+> Do not attempt to use this function to deallocate memory
+> obtained by a call to the system `malloc()` or `calloc()` functions,
+> or the C++ `new` operator.
+> Doing so may result in unpredictable
+> behavior, including corruption of application memory.
+
+## SEE ALSO
+
+[nng_alloc()](nng_alloc.md),
+[nng_recv()](nng_free.md)
diff --git a/docs/reference/src/api/util/nng_version.md b/docs/reference/src/api/util/nng_version.md
new file mode 100644
index 00000000..7cc10bdf
--- /dev/null
+++ b/docs/reference/src/api/util/nng_version.md
@@ -0,0 +1,36 @@
+# nng_version(3)
+
+## NAME
+
+nng_version - report library version
+
+## SYNOPSIS
+
+```c
+#include <nng/nng.h>
+
+const char * nng_version(void);
+```
+
+## DESCRIPTION
+
+The `nng_version()` function returns a human readable {{i:version number}}
+for _NNG_.
+
+Additionally, compile time version information is available
+via some predefined macros:
+
+- {{i:`NNG_MAJOR_VERSION`}}: Major version number.
+- {{i:`NNG_MINOR_VERSION`}}: Minor version number.
+- {{i:`NNG_PATCH_VERSION`}}: Patch version number.
+
+_NNG_ is developed and released using
+[Semantic Versioning 2.0](http://www.semver.org), and
+the version numbers reported refer to both the API and the library itself.
+(The {{i:ABI}} -- {{i:application binary interface}} -- between the
+library and the application is controlled in a similar, but different
+manner depending upon the link options and how the library is built.)
+
+## RETURN VALUES
+
+Null-terminated string containing the library version number.