|
int | set_non_blocking (int fd) |
| Set non-blocking mode on a file descriptor. Returns 0 on success, logs failures to syslog.
|
|
int | clear_non_blocking (int fd) |
| Clear non-blocking mode on a file descriptor. Returns 0 on success, logs failures to syslog.
|
|
int | gsl_set_cloexec (int fd) |
| Set close-on-exec() mode on a file descriptor. More...
|
|
int | gsl_clear_cloexec (int fd) |
| Clear close-on-exec() mode on a file descriptor. More...
|
|
int | gsl_set_nonblocking (int fd) |
| Set non-blocking mode on a file descriptor. More...
|
|
int | gsl_clear_nonblocking (int fd) |
| Clear non-blocking mode on a file descriptor. More...
|
|
int | membuf_drain_input (struct membuf_t *m, int fd)) |
| Read input from a file into a memory buffer. More...
|
|
int | membuf_drain_output (struct membuf_t *m, int fd)) |
| Drain output from a memory buffer to a file. More...
|
|
ssize_t | safe_read_fixed (int fd, char *buf, size_t amt)) |
| Read fixed amount of data into memory. More...
|
|
ssize_t | safe_pread_fixed (int fd, char *buf, size_t amt, int64_t offset)) |
| Read fixed amount of data into memory from position in file. More...
|
|
ssize_t | safe_write_fixed (int fd, const char *buf, size_t amt)) |
| Write fixed amount of data from memory. More...
|
|
ssize_t | safe_pwrite_fixed (int fd, const char *buf, size_t amt, int64_t offset)) |
| Write fixed amount of data from memory to position in file. More...
|
|
int | poll_flags (int fd) |
| Get poll(2) flags for file descriptor. More...
|
|
const char * | display_poll_flags (int flags) |
| Display poll(2) flags in human-readable form. More...
|
|
Routines for helping with generic posix I/O.
int membuf_drain_input |
( |
struct membuf_t * |
m, |
|
|
int |
fd |
|
) |
| |
Read input from a file into a memory buffer.
- Parameters
-
m | Memory buffer to read data into. |
fd | File descriptor to read from. |
- Returns
- Number of bytes available in buffer.
- Return values
-
-1 | on EOF or error (and see errno). |
This function will read input from a file descriptor fd into the memory buffer m. It will attempt to drain as much input as possible from fd (which should be non-blocking). The return value is the number of bytes available in the buffer after the read (which will include any data already in the buffer).
If there is no data waiting to be collected and we get EAGAIN immediately, then we simply return the number of bytes remaining in the buffer (which may be 0 if the buffer was empty). We do not return -1 in this case.
If there is no data to read, and an EOF condition occurs (socket closed etc.) then -1 is returned and errno is set to EPIPE
. If an error occurs (but not EAGAIN
) then -1 is returned and errno set as per read(). Errors (except EPIPE
and EAGAIN
) are logged to syslog.
int membuf_drain_output |
( |
struct membuf_t * |
m, |
|
|
int |
fd |
|
) |
| |
Drain output from a memory buffer to a file.
- Parameters
-
m | Memory buffer to write data from. |
fd | File descriptor to write data to. |
- Returns
- Number of bytes remaining in the buffer.
- Return values
-
-1 | on error (and see errno). |
This function will write data from a memory buffer m to the file descriptor fd. It will attempt to drain as much data as possible to fd (which may be non-blocking). The return value is the number of bytes remaining in the buffer after the write (zero if all output is written).
If an error occurs (but not EAGAIN
), then it is logged to syslog and -1 is returned.