io_uring_prep_send(3)
πΈ io_uring_prep_send β prepare a send request π
okay bestie so this is a liburing manual page, and it's literally all about getting a send request ready to go. no cap, it's giving "networking but make it async" β¨
π SYNOPSIS π
#include <liburing.h>
void io_uring_prep_send(struct io_uring_sqe *sqe,
int sockfd,
const void *buf,
size_t len,
int flags);
void io_uring_prep_sendto(struct io_uring_sqe *sqe,
int sockfd,
const void *buf,
size_t len,
int flags,
const struct sockaddr *addr,
socklen_t addrlen);
void io_uring_prep_send_bundle(struct io_uring_sqe *sqe,
int sockfd,
size_t len,
int flags);
like, three whole flavors π pick your fighter fr fr
π DESCRIPTION π
π io_uring_prep_send(3)
so io_uring_prep_send(3) preps a send request, periodt. the submission queue entry sqe gets set up to use the file descriptor sockfd to start sending the data from buf β that's len bytes of it β with modifier flags flags. iconic.
π‘ after you call this function, additional io_uring internal modifier flags may be set in the SQEiopriofield. yes,ioprio. it's multi-purpose, she contains multitudes π
here's the flag lineup, the ones that are supported:
IORING_RECVSEND_POLL_FIRSTβ if you set this, io_uring will assume the socket is currently full and that attempting to send data will be unsuccessful. in that case, io_uring arms internal poll and triggers a send of the data when the socket has space available. and if poll does indicate that space is available in the socket, the operation will proceed immediately. no extra waiting, we love to see it πIORING_RECVSEND_BUNDLEβ if set, the send operation will attempt to fill multiple buffers rather than just pick a single buffer to fill. to send multiple buffers in a single send, the buffer group ID set in the SQE must be of the ring provided type. if set, the CQEresfield indicates the total number of bytes sent, and the buffer ID returned in the CQEflagsfield indicates the first buffer in the send operation. the application must process the indicated initial buffer ID and keep going until allresbytes have been seen, so it knows which one is the last buffer in the send operation. the buffers consumed will be contiguous from the initial buffer, in the order in which they appear in the buffer ring. the CQE struct does not contain the position of the buffer in the buffer ring, so to identify the buffers contained by the bundle, it's advised to maintain the cached head index per buffer ring. thisuint16_tindex represents the position of the next buffer to be consumed within the ring. upon completion of a bundle send operation, the cached head index should be incremented accordingly. sending in bundles can improve performance when more than one chunk of data is available, by eliminating redundant round trips through the networking stack. chef's kiss honestly π₯IORING_SEND_VECTORIZEDβ if set,addrmust point to an array ofstruct iovecandlenmust be the number of vectors in that array. this enables use of vectorized IO for a normal send operation, rather than needing asendmsgvariant to accomplish that. cute shortcut fr π¦
β οΈ okay important: usingIOSQE_IO_LINKwith this request type requires the setting ofMSG_WAITALLin theflagsargument, because a short send isn't considered an error condition without that being set. like, that's the whole deal. don't skip it π
this function prepares an async send(2) request. see that man page for details, iykyk.
β¨ io_uring_prep_sendto(3) β¨
io_uring_prep_sendto(3) preps a sendto request. the submission queue entry sqe is set up to use the file descriptor sockfd to start sending the data from buf of size len bytes, with modifier flags flags. the destination address is specified by addr and addrlen, and it must be a valid address for the socket type. no cap, gotta be valid π«Ά
this function prepares an async sendto(2) request. see that man page for details.
π§ provided buffers moment π§
both of the above send variants may be used with provided buffers β where instead of passing a buffer in directly with the request, you set IOSQE_BUFFER_SELECT in the SQE flags field, and additionally set a buffer group ID in the SQE buf_group field. by using provided buffers with send requests, the application can prevent any kind of reordering of the outgoing data, which can otherwise occur if the application has more than one send request inflight for a single socket. this gives better pipelining of data, where previously the app needed to manually serialize sends. main character energy for real π
π the bundle version π
the bundle version lets the application issue a single send request, with a buffer group ID given in the SQE buf_group field, which keeps sending from that buffer group until it runs out of buffers. as with any other request using provided buffers, IOSQE_BUFFER_SELECT must also be set in the SQE flags before submission.
currently len must be given as 0 β otherwise the request will be errored with -EINVAL as the result code. future versions may allow setting it to limit the transfer size. a single CQE is posted for the send, with the result being how many bytes were sent, on success.
when used with provided buffers, send or send bundle will contain the starting buffer group ID in the CQE flags field. the number of bytes sent starts from there, and will be in contiguous buffer IDs after that.
send bundle β and send with provided buffers in general β are available since kernel 6.10, and can be further identified by checking for the IORING_FEAT_SEND_BUF_SELECT flag returned when using io_uring_init_queue_params(3) to setup the ring. slay π
β RETURN VALUE β
None. that's it. that's the whole section. literally nothing returned π
π ERRORS π
the CQE res field will contain the result of the operation. see the related man page for details on possible values.
π¨ and here's the thing bestie: where synchronous system calls return-1on failure and seterrnoto the actual error value, io_uring never useserrno. instead it returns the negated errno directly in the CQEresfield. so don't go checkingerrno, it's not gonna help you π
πΈ SEE ALSO πΈ
io_uring_get_sqe(3), io_uring_submit(3), io_uring_buf_ring_init(3), io_uring_buf_ring_add(3), send(2) sendto(2)
okay that's the whole page bestie, go send some bytes πβ¨
this was brought to you by liburing-2.2, dated March 12, 2022 β vintage! a classic! π
π¦ where this page comes from
- alpine 3.23: liburing-doc 2.12-r0 Β· LGPL-2.1-or-later OR MIT
- centos-stream 10: liburing-devel 2.12-1.el10 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) 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)
- π 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-1017 on : a language model's rewrite of the original, under its terms