No matching definitions.

tur/async_file

stdlib/async_file.tur

non-blocking file I/O integrated with the cooperative scheduler.

Since: Phase T24

defn

async-file-open

(async-file-open [path :cstr flags :int])

open a file with O_NONBLOCK and return its file descriptor.

pathfilesystem path to the file
flags0 = 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

defn

async-file-read

(async-file-read [fd :int buf-size :int])

read up to buf-size bytes from a non-blocking file descriptor.

fdfile descriptor returned by async-file-open
buf-sizemaximum number of bytes to read

int -- bytes read (>= 0), 0 on EOF, -1 on error

(async-file-read fd 4096)  ; => 128

Since: Phase T24

defn

async-file-write

(async-file-write [fd :int data :cstr len :int])

write len bytes from data to a non-blocking file descriptor.

fdfile descriptor returned by async-file-open
datapointer to the bytes to write
lennumber of bytes to write

int -- total bytes written, or -1 on error

(async-file-write fd "hello" 5)  ; => 5

Since: Phase T24

defn

async-file-close

(async-file-close [fd :int])

close a file descriptor and unregister it from IO polling.

fdfile descriptor to close

int -- 0 on success, -1 on error

(async-file-close fd)  ; => 0

Since: Phase T24

defn

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

defn

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