libxtc
0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_aio.h
1
/*-
2
* Copyright (c) 2026, The XTC Project
3
* @stability stable
4
* Use of this source code is governed by the ISC License.
5
*
6
* src/inc/xtc_aio.h
7
* Async file I/O for fibers. A read/write/fsync that suspends the
8
* calling fiber and resumes it on completion, keeping the loop live
9
* for other work meanwhile.
10
*
11
* This is a SINGLE, PORTABLE async-file-I/O API: write storage code
12
* once as though true AIO is always available, and it runs unchanged
13
* everywhere libxtc builds. Where the host has a native completion
14
* engine (io_uring on Linux, IOCP on Windows) the call uses it; where
15
* it does not, the call transparently offloads to the blocking thread
16
* pool -- the SAME API and the same observable behavior (the fiber
17
* parks, the loop keeps running, the call returns the byte count or a
18
* negative errno). The caller never branches on the platform.
19
*
20
* Must be called from a fiber running on a loop; off a loop the op
21
* runs synchronously. Returns the byte count transferred (>= 0) or
22
* a negative errno; xtc_aio_fsync returns 0 or a negative errno.
23
* See xtc_aio(3).
24
*/
25
26
#ifndef XTC_AIO_H
27
#define XTC_AIO_H
28
29
#include "xtc_export.h"
30
31
#include <stdint.h>
32
#if !defined(_WIN32)
33
#include <sys/uio.h>
/* struct iovec (POSIX scatter/gather) */
34
#endif
35
36
/*
37
* PUBLIC: int xtc_aio_pread __P((int, void *, uint32_t, int64_t));
38
* PUBLIC: int xtc_aio_pwrite __P((int, const void *, uint32_t, int64_t));
39
* PUBLIC: int xtc_aio_fsync __P((int));
40
* PUBLIC: int xtc_aio_fdatasync __P((int));
41
*/
42
43
XTC_API
int
xtc_aio_pread(
int
fd,
void
*buf, uint32_t len, int64_t off);
44
XTC_API
int
xtc_aio_pwrite(
int
fd,
const
void
*buf, uint32_t len, int64_t off);
45
46
#if !defined(_WIN32)
47
/*
48
* PUBLIC: int xtc_aio_preadv __P((int, const struct iovec *, int, int64_t));
49
* PUBLIC: int xtc_aio_pwritev __P((int, const struct iovec *, int, int64_t));
50
*
51
* Vectored (scatter/gather) variants: read into / write from the
52
* iovcnt buffers described by iov, at file offset off, as one atomic
53
* positioned op -- the async-fiber analog of preadv(2)/pwritev(2).
54
* They exist so code that already builds struct iovec arrays (a WAL
55
* writer, PostgreSQL's smgr/md layer, any readv/writev consumer) can
56
* move to libxtc without flattening or looping. Same semantics as the
57
* scalar calls: the fiber parks and the loop stays live; returns the
58
* total byte count transferred (>= 0) or a negative errno.
59
*
60
* Where the host has io_uring the op is submitted natively
61
* (IORING_OP_READV/WRITEV); elsewhere it transparently offloads to the
62
* blocking pool (preadv/pwritev on a worker thread) -- identical
63
* observable behavior, as with the scalar API. iovcnt must be in
64
* [1, IOV_MAX]; out of range returns -EINVAL (the AIO surface's
65
* negative-errno convention), so a caller cannot force an unbounded
66
* submission. Direct-I/O builds validate each iovec base and the
67
* total length against the device alignment.
68
*
69
* POSIX only: Windows lacks preadv/pwritev and struct iovec; a
70
* WSABUF/OVERLAPPED-scatter port is future work, so these are not
71
* declared there. The scalar xtc_aio_pread/pwrite remain available on
72
* every platform.
73
*/
74
XTC_API
int
xtc_aio_preadv(
int
fd,
const
struct
iovec *iov,
int
iovcnt, int64_t off);
75
XTC_API
int
xtc_aio_pwritev(
int
fd,
const
struct
iovec *iov,
int
iovcnt, int64_t off);
76
#endif
/* !_WIN32 */
77
78
XTC_API
int
xtc_aio_fsync(
int
fd);
/* full sync: data + metadata */
79
XTC_API
int
xtc_aio_fdatasync(
int
fd);
/* data only (the page/WAL flush hot path) */
80
81
/*
82
* The internal / test hook __xtc_aio_force_offload (force the
83
* blocking-pool offload path even on a host with a native completion
84
* engine) is library-internal (the __ prefix) and not part of the
85
* stable API; it lives in "aio_int.h", not in this installed public
86
* header.
87
*/
88
89
#endif
/* XTC_AIO_H */
src
inc
xtc_aio.h
Generated by
1.9.8