Module fifo

kfifo (kernel FIFO) implementation.

This library allows creating and managing fixed-size, lockless FIFO queues for byte streams, suitable for producer-consumer scenarios within the kernel.

Functions

pop (size) Pops data from the FIFO.
push (data) Pushes data into the FIFO.

Class fifo

fifo:close () Closes and releases the FIFO object.

fifo

new (size) Creates a new kernel FIFO (kfifo) object.


Functions

pop (size)
Pops data from the FIFO. Retrieves a specified number of bytes from the FIFO.

Parameters:

  • size integer The maximum number of bytes to retrieve from the FIFO.

Returns:

  1. string A string containing the bytes popped from the FIFO. The actual length of this string might be less than size if the FIFO contained fewer bytes.
  2. integer The actual number of bytes popped from the FIFO.

See also:

Usage:

    -- Assuming 'myfifo' is a fifo object
    local data, len = myfifo:pop(10)
    if len > 0 then
      print("Popped " .. len .. " bytes: " .. data)
    end
push (data)
Pushes data into the FIFO. Copies a string of bytes into the FIFO.

Parameters:

  • data string The string containing the bytes to be pushed into the FIFO.

Returns:

    nil

Raises:

Error if the provided data string is larger than the available space in the FIFO.

See also:

Usage:

    -- Assuming 'myfifo' is a fifo object
    myfifo:push("hello")

Class fifo

Represents a kernel FIFO (kfifo) object. This is a userdata object returned by fifo.new(). It encapsulates a struct kfifo from the Linux kernel, providing a first-in, first-out byte queue.
fifo:close ()
Closes and releases the FIFO object. This is an alias for the __close and __gc metamethods.

Returns:

    nil

fifo

new (size)
Creates a new kernel FIFO (kfifo) object. Allocates and initializes a kfifo of the specified size. The size should ideally be a power of two for kfifo's internal optimizations, though kfifo will handle non-power-of-two sizes by rounding up.

Parameters:

  • size integer The desired capacity of the FIFO in bytes.

Returns:

    fifo A new fifo object.

Raises:

Error if kfifo allocation fails (e.g., due to insufficient memory).

Usage:

    local myfifo = fifo.new(1024) -- Creates a FIFO with a capacity of 1024 bytes
generated by LDoc 1.5.0 Last updated 2025-06-27 17:53:55