stumpless_read_buffer

Function stumpless_read_buffer 

Source
pub unsafe extern "C" fn stumpless_read_buffer(
    target: *mut stumpless_target,
    buffer: *mut c_char,
    max_length: usize,
) -> usize
Expand description

Reads the next message from the provided buffer target and writes it into the given buffer.

If the buffer has not been read from before messages have wrapped around, then you may only get the end of a message. To avoid this situation, you will need to read the buffer often enough to stay ahead of the written messages. Making sure that the log buffer is sufficiently sized may help with this.

A terminating NULL character will always be written at the end of the output. Note that this means that if the read operation was successful but there was no message to read, the result will be 1 with a single NULL character being written to the read buffer.

Thread Safety: MT-Safe This function is thread safe. A mutex is used to coordinate reads and writes of the message buffer.

Async Signal Safety: AS-Unsafe heap This function is not safe to call from signal handlers due to the use of a non-reentrant lock to coordinate accesses.

Async Cancel Safety: AC-Unsafe heap This function is not safe to call from threads that may be asynchronously cancelled, as a lock may be left locked when a thread exits prematurely.

@param target The buffer target to read from.

@param buffer The buffer to write the message in to.

@param max_length The maximum number of bytes to write into the provided buffer. If this is zero, then the read buffer will be considered an empty argument and an error will be raised.

@return The number of bytes written into buffer, including the terminating NULL character. In the event of an error, 0 is returned and an error code is set appropriately.