tevent_queue_tutorial(3)
π NAME π
tevent_queue_tutorial β bestie, this is the tevent_queue tutorial, and it's in section 3 of the library functions manual π
β¨ Introduction β¨
okay so picture this: a tevent_queue is what you use to queue up async requests that have to be serialized. like, they cannot overlap, they gotta take turns, no cutting in line πΆβοΈπΆβοΈπΆβοΈ
the classic example? writing buffers into a socket. that has to be serialized, periodt. because writing a big lump of data into a socket can need multiple write(2) or send(2) system calls β it's not always one and done π
and here's the thing: if more than one async request is outstanding, all trying to write large buffers into a socket, then every request must individually be completed before the next one begins β even if multiple syscalls are required for it. no interleaving, no mixing, not ever π βοΈ
to make that happen, every socket gets assigned a tevent_queue struct. one queue per socket, that's the vibe π«Ά
π¦ how you actually make one of these π¦
creating a serialized async request follows the usual convention: you return a tevent_req structure with an embedded state structure. iconic, love that for us β¨
but here's the plot twist β to serialize the work that the request is about to do, instead of directly starting or doing that work, you have to call tevent_queue_add. that's the move π
then, when it's finally time for the serialized async request to do its thing, the trigger callback function that you gave to tevent_queue_add gets called. in the writing-to-a-socket example, that trigger fires when the write request is allowed to begin accessing the socket π₯
πΈ the lore: how this engine works behind the scenes πΈ
okay bestie, sit down, because this part is lowkey genius π§ β¨
- when the queue is empty,
tevent_queue_addschedules an immediate call to the trigger callback. - the trigger callback starts its work β and it'll probably do that by starting other async subrequests.
- while those async subrequests are busy working, more requests can accumulate in the queue via
tevent_queue_add. they just pile up, patiently, like a group chat when you're asleep π΄ - and here's the wild part: there is no function to explicitly trigger the next waiter in line. none. doesn't exist. and yet?? it still works π
- because when the active request in the queue is done, it gets destroyed by
talloc_free. - and
talloc_freeof a serialized async request that had been added to a queue will trigger the next request in the queue β via a talloc destructor attached to a child of the serialized request. yeah. a destructor. doing queue management. main character energy fr fr π
so that's how the queue stays busy whenever an async request finishes. it's giving "the next one up, automatically" π
π Example π
Metze: Please add a code example here.
(that's it. that's the whole example section. we're waiting on Metze, bestie π if you got a code example, the queue is literally right there β no pressure tho π)
and that's the whole page!! π this was tevent_queue_tutorial(3) from the tevent crew, Version 0.9.8 β go serialize something responsibly, ily, bye bestie ππ¦β¨
π¦ where this page comes from
- centos-stream 10: libtevent-devel 0.17.1-100.el10 Β· LGPL-3.0-or-later
- fedora 43: libtevent-devel 0.17.1-3.fc43 Β· LGPL-3.0-or-later
- fedora 43: libtevent-devel 0.17.1-3.fc43 Β· LGPL-3.0-or-later
- fedora 44: libtevent-devel 0.17.1-4.fc44 Β· LGPL-3.0-or-later
- fedora 44: libtevent-devel 0.17.1-4.fc44 Β· LGPL-3.0-or-later
- opensuse-leap 16.0: tevent-man 0.16.2-160000.2.2 Β· LGPL-3.0-or-later
- opensuse-leap 16.0: tevent-man 0.16.2-160000.2.2 Β· LGPL-3.0-or-later
- opensuse-leap 16.0: tevent-man 0.16.2-160000.2.2 Β· LGPL-3.0-or-later
- opensuse-leap 16.0: tevent-man 0.16.2-160000.2.2 Β· LGPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms