tevent_context(3)

πŸ“¦
version 0.17.1 Β· 2 versions
, in centos-stream 10, fedora 43, fedora 44, opensuse-leap 16.0

okay bestie, welcome to the tevent_context(3) page from the Library Functions Manual πŸ’–

✨ NAME ✨

tevent_context - Chapter 1: Tevent context. Periodt. πŸ’…

πŸ¦‹ Tevent context πŸ¦‹

The tevent context is an essential logical unit of the tevent library. To work with events, you have to create at least one such context β€” allocated, initialized. Then the events you want caught and handled have to be registered inside that specific context. Why are events subordinated to a tevent context structure? Because several contexts can be created, and each one is processed at a different time. So you could have 1 context holding just file descriptor events, another one handling signal and time events, and a third one keeping information about the rest. πŸ’…

Tevent loops are the part of the library that represents the mechanism where noticing events and triggering handlers actually happens. They accept just one argument β€” the tevent context structure. So theoretically, if an infinity loop (tevent_loop_wait) was called, only those arguments that belong to the passed tevent context structure can be caught and invoked within this call. Even if some more signal events were registered (but within some other context), they will not be noticed. 😭

🌸 Example 🌸

First lines that handle mem_ctx belong to talloc library knowledge, but because tevent uses the talloc library for its mechanisms, it is necessary to understand a bit of talloc as well. For more information about working with talloc, please visit the talloc website where tutorial and documentation are located. 🫢

The tevent context structure *event_ctx represents the unit that will further contain information about registered events. It is created by calling tevent_context_init().

TALLOC_CTX *mem_ctx = talloc_new(NULL);
if (mem_ctx == NULL) {
    // error handling
}

struct tevent_context *ev_ctx = tevent_context_init(mem_ctx);
if(ev_ctx == NULL) {
    // error handling
}

The tevent context has a structure containing lots of information. It includes lists of all events, divided according to their type, and they are in order showing the sequence as they came. ✨

In addition to the lists shown in the diagram, the tevent context also contains many other data (e.g. information about the available system mechanism for triggering callbacks). πŸ‘‘

πŸ”₯ Tevent loops πŸ”₯

Tevent loops are the dispatcher for events. They catch them and trigger the handlers. In the case of longer processes, the program spends most of its time at this point waiting for events, invoking handlers, and waiting for another event again. There are 2 types of loop available for use in the tevent library:

  • int tevent_loop_wait()
  • int tevent_loop_once()

Both of the functions accept just one parameter (tevent context), and the only difference is that the first loop can theoretically last forever, but the second one will wait for just a single event to catch, and then the loop breaks and the program continues. πŸ’–


That's the whole vibe, bestie: tevent, Version 0.9.8, on the tevent_context(3) page. The footer didn't give a date, so I'm not inventing one β€” no cap. πŸ’…πŸŽ€