# io_uring: add zero-copy send operation · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/087ee497d430d30bd9c7a2cdfdfc3d2654d105d3)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 087ee497d430d30bd9c7a2cdfdfc3d2654d105d3

Requested commit: 087ee497d430d30bd9c7a2cdfdfc3d2654d105d3

Commit: 087ee497d430d30bd9c7a2cdfdfc3d2654d105d3

Tree: bfd7bf5d00f66d3e2803efd1ebbfd7bf2bc8154c

Author: Igor Anić

Committer: Igor Anić

## Message

```
io_uring: add zero-copy send operation

`send_zc` tries to avoid making intermediate copies of data. Zerocopy execution
is not guaranteed and may fall back to copying.

The flags field of the first struct io_uring_cqe may likely contain
IORING_CQE_F_MORE , which means that there will be a second completion event /
notification for the request, with the user_data field set to the same value.
The user must not modify the data buffer until the notification is posted. The
first cqe follows the usual rules and so its res field will contain the number
of bytes sent or a negative error code. The notification's res field will be set
to zero and the flags field will contain IORING_CQE_F_NOTIF. The two step model
is needed because the kernel may hold on to buffers for a long time, e.g.
waiting for a TCP ACK, and having a separate cqe for request completions allows
userspace to push more data without extra delays. Note, notifications are only
responsible for controlling the lifetime of the buffers, and as such don't mean
anything about whether the data has atually been sent out or received by the
other end. Even errored requests may generate a notification, and the user must
check for IORING_CQE_F_MORE rather than relying on the result.

Available since kernel 6.0.

References:
https://man7.org/linux/man-pages/man3/io_uring_prep_send_zc.3.html
https://man7.org/linux/man-pages/man2/io_uring_enter.2.html

```

## Parents

- [6b9f7e26c9e43700225b7c2479305015df75a2b9](https://git.cafe/gitcafe/zig/commit/6b9f7e26c9e43700225b7c2479305015df75a2b9?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/087ee497d430d30bd9c7a2cdfdfc3d2654d105d3?format=markdown)
