io_uring_sub...wait_timeout(3)
β¨ io_uring_submit_and_wait_timeout β from the liburing manual β¨
okay bestie, pull up a chair, we're learning io_uring_submit_and_wait_timeout(3) and honestly? it's giving main character energy. it's a liburing thing. let's go π
πΈ NAME πΈ
io_uring_submit_and_wait_timeout β submit requests to the submission queue and wait for the completion, but with a timeout clock ticking, so you're never just sitting there forever like a girl waiting for a text back π
π¦ SYNOPSIS π¦
#include <liburing.h>
int io_uring_submit_and_wait_timeout(struct io_uring *ring,
struct io_uring_cqe **cqe_ptr,
unsigned wait_nr,
struct __kernel_timespec *ts,
sigset_t *sigmask);
yes that's a whole lot of parameters. she's high maintenance but she delivers β¨
π DESCRIPTION π
so here's the tea, bestie. io_uring_submit_and_wait_timeout(3) does two things at once and it's lowkey iconic for it:
- it submits the next requests from the submission queue that belong to the ring
- it waits for
wait_nrcompletion events β or until the timeouttsexpires, whichever comes first π
the completion events get stored in the cqe_ptr array. cute, right? no cap.
π the sigmask situation π
the sigmask parameter specifies the set of signals to block. if you set it, it's equivalent to atomically executing these calls:
sigset_t origmask;
pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
ret = io_uring_submit_and_wait_timeout(ring, cqe, wait_nr, ts, NULL);
pthread_sigmask(SIG_SETMASK, &origmask, NULL);
so it's the "block the signals, do the thing, put the signals back" dance, except it happens atomically so nothing sneaks in between π§
π how you actually use her π
after you grab a submission queue entry (SQE) with io_uring_get_sqe(3) and get that SQE all prepped and ready, you can submit it with io_uring_submit_and_wait_timeout(3). that's the flow, periodt.
π the pro-tip setup π
ideally you run this with a ring set up using IORING_SETUP_SINGLE_ISSUER|IORING_SETUP_DEFER_TASKRUN, because that will greatly reduce the number of context switches your app sees when it's waiting on multiple requests. fewer context switches = happier app = slay π₯
β RETURN VALUE β
on success, io_uring_submit_and_wait_timeout(3) returns the number of submitted submission queue entries. on failure it returns -errno.
β οΈ heads up though: in earlier versions of the liburing library, the return value was0on success. so if you're reading old code and it's checking for0, that's why. don't come for me, come for the changelog π
the most common failure case? not getting a completion within the specified timeout. when that happens, -ETIME gets returned. your vibe check timed out, bestie, it's literally in the name π
π SEE ALSO π
go read these next, they're all part of the same friend group:
io_uring_queue_init_params(3)io_uring_get_sqe(3)io_uring_submit(3)io_uring_submit_and_wait(3)io_uring_wait_cqe(3)
and that's the whole page, bestie π«Ά this one came from liburing-2.1, dated November 15, 2021. go forth, submit, wait, time out gracefully. i'm obsessed with you. mwah π
π¦ where this page comes from
- alpine 3.22: liburing-doc 2.9-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.23: liburing-doc 2.12-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.24: liburing-doc 2.14-r0 Β· LGPL-2.1-or-later OR MIT
- arch rolling: liburing 2.15-1 Β· GPL-2.0-only WITH Linux-syscall-note OR MIT AND LGPL-2.0-or-later AND 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
- debian trixie: liburing-dev 2.9-1
- fedora 43: liburing-devel 2.9-2.fc43 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 43: liburing-devel 2.9-2.fc43 Β· (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)
- 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
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- ubuntu questing: liburing-dev 2.11-1
- ubuntu resolute: liburing-dev 2.14-1
- ubuntu stonking: liburing-dev 2.15-1
- π the page's license: LGPL-2.0-or-later
- Copyright (C) 2021 Stefan Roesch <shr@fb.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms