diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-11-04 12:45:38 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-11-04 12:46:30 +0000 |
| commit | 9ae5c311d1b0cb85e7cbcb86fef91827e9967868 (patch) | |
| tree | 0975f00b908e2612077acc5a5d71a7d0202e2fed /async.h | |
| parent | selection: send primary/clipboard data asynchronously (diff) | |
async: add async_write(), a write primitive to write to a NONBLOCK:ing FD
Diffstat (limited to 'async.h')
| -rw-r--r-- | async.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/async.h b/async.h new file mode 100644 index 00000000..876368de --- /dev/null +++ b/async.h @@ -0,0 +1,24 @@ +#pragma once + +#include <stddef.h> + +enum async_write_status {ASYNC_WRITE_DONE, ASYNC_WRITE_REMAIN, ASYNC_WRITE_ERR}; + +/* + * Primitive that writes data to a NONBLOCK:ing FD. + * + * _data: points to the beginning of the buffer + * len: total size of the data buffer + * idx: pointer to byte offset into data buffer - writing starts here. + * + * Thus, the total amount of data to write is (len - *idx). *idx is + * updated such that it points to the next unwritten byte in the data + * buffer. + * + * I.e. if the return value is: + * - ASYNC_WRITE_DONE, then the *idx == len. + * - ASYNC_WRITE_REMAIN, then *idx < len + * - ASYNC_WRITE_ERR, there was an error, and no data was written + */ +enum async_write_status async_write( + int fd, const void *data, size_t len, size_t *idx); |
