io_uring_prep_sendmsg(3)
π io_uring_prep_sendmsg β from the liburing manual, bestie edition
okay so welcome to the io_uring_prep_sendmsg(3) page, you're gonna eat this up π
β¨ NAME β¨
io_uring_prep_sendmsg β get a sendmsg request all prepped and ready to go, no cap
πΈ SYNOPSIS πΈ
#include <sys/types.h>
#include <sys/socket.h>
#include <liburing.h>
void io_uring_prep_sendmsg(struct io_uring_sqe *sqe,
int fd,
const struct msghdr *msg,
unsigned flags);
void io_uring_prep_sendmsg_zc(struct io_uring_sqe *sqe,
int fd,
const struct msghdr *msg,
unsigned flags);
π¦ DESCRIPTION π¦
So io_uring_prep_sendmsg(3) preps a sendmsg request for you π. The submission queue entry sqe gets set up to use the file descriptor fd, and it starts sending the data that msg points at, using the sendmsg(2)-defined flags you dropped into the flags argument.
Then there's io_uring_prep_sendmsg_zc(3) β she takes the exact same parameters as io_uring_prep_sendmsg(3) but preps a zerocopy sendmsg request instead. iconique β¨
Pop over to io_uring_prep_send(3) for the rundown on flags you can set in the SQE ioprio field. On top of those, the zero-copy send also supports setting IORING_SEND_ZC_REPORT_USAGE. If you set it, the notification CQE res field will report the number of bytes that got copied rather than sent with zero copy. A value of 0 means success π. If the value is IORING_NOTIF_USAGE_ZC_COPIED, then yeah β data was copied.
Now here's the tea β: unlike non-zerocopy send requests, a zerocopy send will usually generate two CQEs.
- The first CQE holds the result of the send operation itself. If that CQE has
IORING_CQE_F_MOREset in the CQE flags field, then a second notification CQE will be posted for the operation. - That second notification CQE tells the application that the memory associated with the send is safe to get reused. It'll have
IORING_CQE_F_NOTIFset in the CQE flags field.
Also go read the io_uring_enter(2) man page for a fuller description of the notification CQE, iykyk.
β οΈ Heads up bestie: usingIOSQE_IO_LINKwith this request type requires you to setMSG_WAITALLin theflagsargument, because a short send isn't considered an error condition without that being set. Don't skip this one π
And fr fr, this function prepares an async sendmsg(2) request β see that man page for the deets.
π« RETURN VALUE π«
None. Literally nothing, she's just prepping π«Ά
π ERRORS π
The CQE res field will contain the result of the operation. Check out the related man page for possible values, bestie.
π Important: where synchronous system calls will return-1on failure and seterrnoto the actual error value, io_uring never useserrno. Instead it returns the negatederrnodirectly in the CQEresfield.
Some common error cases are:
-ENOMEMβ theulimit(1) -lsetting is too low to support the size of the attempted zero copy send. Increasing the limit may help.-ENOMEMβ the kernel ran out of memory.
π NOTES π
As with any request that passes in data in a struct, that data must remain valid until the request has been successfully submitted. It does not need to remain valid until completion. Once a request has been submitted, the in-kernel state is stable. Very early kernels (5.4 and earlier) required state to be stable until the completion occurred. Applications can test for this behavior by inspecting the IORING_FEAT_SUBMIT_STABLE flag passed back from io_uring_queue_init_params(3). slay π
π₯ SEE ALSO π₯
io_uring_get_sqe(3), io_uring_submit(3), io_uring_buf_ring_init(3), io_uring_buf_ring_add(3), sendmsg(2)
mwah π that's the whole page, you're officially fluent in zerocopy sendmsg now. This was liburing-2.2, dated March 12, 2022, and it lives in the liburing manual under io_uring_prep_sendmsg(3). go forth and submit your SQEs, main character π§π
π¦ where this page comes from
- alpine 3.24: liburing-doc 2.14-r0 Β· LGPL-2.1-or-later OR MIT
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- nixpkgs unstable: liburing 2.14
- ubuntu resolute: liburing-dev 2.14-1
- π the page's license: LGPL-2.0-or-later
- Copyright (C) 2022 Jens Axboe <axboe@kernel.dk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms