package mnet
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=98230fefe2962c4e766a32f3af206a09e2b866e1cab8e82ed24d27eb580b365a
sha512=08fb6d2876efc620742cea99203ee1d4af9979ea2af916c5fd11de2ecfeb6355d694fea513a4e45f7c85089b91a0dde3dc932d5b57d03770986a1a62b40fbbae
doc/mnet.ke/Ke/index.html
Module KeSource
Type of a ringbuffer.
Utilities.
Length of a ring buffer must be a power of two. Here we have few functions to help to user to generate a power of two value or to check if a value is a power of two. Due to this constraint, a ring buffer can not be larger than max_ke_length (otherwise, we raise an exception).
Ringbuffer.
create ?limit len creates a new ring-buffer of len bytes. len must be a power of two (you can use to_power_of_two to round-up a number to a next power of two).
When the user uses push, it may involve expanding the ring buffer in order to ensure that the entire given str string is added. In this case, it may be worth imposing a limit so that the ring buffer does not grow beyond a certain number of bytes (for example, DNS packets cannot be larger than 65,535 bytes, so a limit of 0x2000 bytes is ideal).
By default, limit is set to 0x2000. The given len must be lesser or equal to the given limit (by default, len should be always lesser or equal than 0x2000).
It is possible not to impose a limit on the ring buffer (~limit:None), but it should be noted that OCaml has a limit on buffer allocation, which is max_ke_length: we cannot exceed this limit.
unsafe_create ?limit len is like create without verification. Useful when you create a ring-buffer from constants.
push t str inserts the given str into the given ring-buffer t. This operation can involves an allocation if the current size of the ring-buffer is not enough to store the given str.
However, if a limit was specified (see create), we ensure to not allocate more than what it was specified. In that case, we raise a Failure exception.
peek_into t filler calls filler using the available bytes in the given ring buffer t that have not yet been used. Note that there may be several calls to filler (particularly if the bytes are not contiguous). Only a call to
al:compress} ensures that [peek_into] calls [filler] only once.
unsafe_shift t len does the same as shift but it does not raise an exception.
available t is the number of bytes available in the given ring buffer t.