|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "pipe.h"#include "common/memory.h"#include "kernel/errno.h"#include "kernel/vfs/poll.h"#include "kernel/process/process.h"#include "kernel/signal/signal.h"#include "kernel/memory/heap.h"#include "kernel/assert.h"Functions | |
| pipe_buf_t * | pipe_alloc (void) |
| allocate a pipe with one open read end and one open write end. | |
| void | pipe_ref (pipe_buf_t *pipe, pipe_dir_t dir) |
| open another end of a pipe (dup2 or fd inheritance). | |
| void | pipe_unref (pipe_buf_t *pipe, pipe_dir_t dir) |
| close one end of a pipe. | |
| int32_t | pipe_read (pipe_buf_t *pipe, char *buf, uint32_t count, bool nonblock) |
| read from a pipe, sleeping while it is empty and a write end is open. | |
| int32_t | pipe_write (pipe_buf_t *pipe, const char *buf, uint32_t count, bool nonblock) |
| write every byte to a pipe, sleeping whenever it is full. | |
| uint32_t | pipe_poll (pipe_buf_t *pipe, pipe_dir_t dir) |
| the readiness of one end of a pipe: the read end has POLLIN when there is data or no writer is left (POLLHUP then too); the write end has POLLOUT when PIPE_BUF bytes fit, and POLLERR when no reader is left. | |
| pipe_buf_t * pipe_alloc | ( | void | ) |
allocate a pipe with one open read end and one open write end.
| void pipe_ref | ( | pipe_buf_t * | pipe, |
| pipe_dir_t | dir ) |
open another end of a pipe (dup2 or fd inheritance).
| pipe | the pipe. |
| dir | which end the new reference is. |
| void pipe_unref | ( | pipe_buf_t * | pipe, |
| pipe_dir_t | dir ) |
close one end of a pipe.
closing the last read end wakes blocked writers (they then see a broken pipe); closing the last write end wakes blocked readers (they then see EOF). the pipe is freed once both ends are fully closed.
| pipe | the pipe. |
| dir | which end is being closed. |
| int32_t pipe_read | ( | pipe_buf_t * | pipe, |
| char * | buf, | ||
| uint32_t | count, | ||
| bool | nonblock ) |
read from a pipe, sleeping while it is empty and a write end is open.
| pipe | the pipe. |
| buf | destination buffer. |
| count | maximum number of bytes to read (> 0). |
| nonblock | return -EAGAIN instead of sleeping. |
| int32_t pipe_write | ( | pipe_buf_t * | pipe, |
| const char * | buf, | ||
| uint32_t | count, | ||
| bool | nonblock ) |
write every byte to a pipe, sleeping whenever it is full.
a write of at most PIPE_BUF bytes goes in as one piece.
| pipe | the pipe. |
| buf | source buffer. |
| count | number of bytes to write (> 0). |
| nonblock | stop instead of sleeping when the pipe is full. |
| uint32_t pipe_poll | ( | pipe_buf_t * | pipe, |
| pipe_dir_t | dir ) |
the readiness of one end of a pipe: the read end has POLLIN when there is data or no writer is left (POLLHUP then too); the write end has POLLOUT when PIPE_BUF bytes fit, and POLLERR when no reader is left.
| pipe | the pipe. |
| dir | which end. |