tur/async_file
non-blocking file I/O integrated with the cooperative scheduler.
Since: Phase T24
async-file-open
(async-file-open [path :cstr flags :int])
open a file with O_NONBLOCK and return its file descriptor.
| path | filesystem path to the file | |
| flags | 0 = O_RDONLY, 1 = O_WRONLY|O_CREAT|O_TRUNC, 2 = O_RDWR |
int -- the file descriptor, or -1 on error
(async-file-open "/tmp/out.txt" 1) ; => 5
Since: Phase T24
async-file-read
(async-file-read [fd :int buf-size :int])
read up to buf-size bytes from a non-blocking file descriptor.
| fd | file descriptor returned by async-file-open | |
| buf-size | maximum number of bytes to read |
int -- bytes read (>= 0), 0 on EOF, -1 on error
(async-file-read fd 4096) ; => 128
Since: Phase T24
async-file-write
(async-file-write [fd :int data :cstr len :int])
write len bytes from data to a non-blocking file descriptor.
| fd | file descriptor returned by async-file-open | |
| data | pointer to the bytes to write | |
| len | number of bytes to write |
int -- total bytes written, or -1 on error
(async-file-write fd "hello" 5) ; => 5
Since: Phase T24
async-file-close
(async-file-close [fd :int])
close a file descriptor and unregister it from IO polling.
| fd | file descriptor to close |
int -- 0 on success, -1 on error
(async-file-close fd) ; => 0
Since: Phase T24
async-file-read-buf
(async-file-read-buf)
retrieve the buffer pointer from the last async-file-read call.
ptr<void> -- pointer to the read buffer stored in fiber-local storage (caller must free)
(async-file-read-buf) ; => buf-ptr
Since: Phase T24
async-file-read-len
(async-file-read-len)
retrieve the byte count from the last async-file-read call.
int -- number of bytes read in the most recent async-file-read
(async-file-read-len) ; => 128
Since: Phase T24