documentation/kernel/proc/pipe.h.md

45 lines
2.4 KiB
Markdown

# pipe.h
Pipes are data streams between processes.
# `PIPE_MAX_SENDERS` - macro
The maximum amount of processes, which can write data to one pipe.
# `PIPE_STD_STREAM_SIZE` - macro
The size of a pipes stream buffer, in bytes.
# `pipe_T` - struct
| Name | Type | Description |
|----------------|-------------------------------|-----------------------------------------------------------------------------------------|
| stream | stream_T* | The stream, where the pipes data is saved. |
| receiver | process_T* | The process which is allowed to read from the pipe. |
| senders | process_T* [PIPE_MAX_SENDERS] | The processes which are allowed to write to the pipe. |
| senders_bitmap | bitmap_T | Indicates which fields of _senders_ are currently used. |
| on_write | void function pointer | If this is not NULL, this function will be called when data is written into the stream. |
# `pipe_init(pipe*, receiver*, (*on_write)())` - function (void)
Initializes **_pipe_** and allocates a stream for it.
# `pipe_destruct(pipe*)` - function (void)
Destructs **_pipe_** and frees all of its resources.
# `pipe_add_sender(pipe*, sender*)` - function (bool)
Adds **_sender_** to the sender list of **_pipe_**.
Returns if the operation was successful.
# `pipe_remove_sender(pipe*, sender*)` - function (void)
Removes **_sender_** from the sender list of **_pipe_**.
# `pipe_write(pipe*, buffer_in*, n)` - function (uint64_t)
Writes at most **_n_** bytes from **_buffer_in_** into **_pipe_**.
Returns the amount of bytes that were actually written.
If the amount of actually written bytes is smaller than **_n_** all sender processes of **_pipe_** will be _PIPE_OUT blocked_.
If the receiver is _PIPE_IN blocked_ the blocker will be removed.
# `pipe_read(pipe*, buffer_out*, n)` - function (uint64_t)
Reads at most **_n_** bytes from **_buffer_in_** into **_pipe_**.
Returns the amount of bytes that were actually read.
If the amount of actually read bytes is smaller than **_n_** the receiver process of **_pipe_** will be _PIPE_IN blocked_.
If the senders are _PIPE_OUT blocked_ the blockers will be removed.