1tevent_context(3) tevent tevent_context(3)
2
3
4
6 tevent_context - Chapter 1: Tevent context
7
8
10 Tevent context is an essential logical unit of tevent library. For
11 working with events at least one such context has to be created -
12 allocated, initialized. Then, events which are meant to be caught and
13 handled have to be registered within this specific context. Reason for
14 subordinating events to a tevent context structure rises from the fact
15 that several context can be created and each of them is processed at
16 different time. So, there can be 1 context containing just file
17 descriptor events, another one taking care of signal and time events
18 and the third one which keeps information about the rest.
19
20 Tevent loops are the part of the library which represents the mechanism
21 where noticing events and triggering handlers actually happens. They
22 accept just one argument - tevent context structure. Therefore if
23 theoretically an infinity loop (tevent_loop_wait) was called, only
24 those arguments which belong to the passed tevent context structure can
25 be caught and invoked within this call. Although some more signal
26 events were registered (but within some other context) they will not be
27 noticed.
28
29 Example
30 First lines which handle mem_ctx belong to talloc library knowledge but
31 because of the fact that tevent uses the talloc library for its
32 mechanisms it is necessary to understand a bit talloc as well. For more
33 information about working with talloc, please visit talloc website
34 where tutorial and documentation are located.
35
36 Tevent context structure *event_ctx represents the unit which will
37 further contain information about registered events. It is created via
38 calling tevent_context_init().
39
40 TALLOC_CTX *mem_ctx = talloc_new(NULL);
41 if (mem_ctx == NULL) {
42 // error handling
43 }
44
45 struct tevent_context *ev_ctx = tevent_context_init(mem_ctx);
46 if(ev_ctx == NULL) {
47 // error handling
48 }
49
50 Tevent context has a structure containing lots of information. It
51 include lists of all events which are divided according their type and
52 are in order showing the sequence as they came.
53
54 In addition to the lists shown in the diagram, the tevent context also
55 contains many other data (e.g. information about the available system
56 mechanism for triggering callbacks).
57
59 Tevent loops are the dispatcher for events. They catch them and trigger
60 the handlers. In the case of longer processes, the program spends most
61 of its time at this point waiting for events, invoking handlers and
62 waiting for another event again. There are 2 types of loop available
63 for use in tevent library:
64
65 · int tevent_loop_wait()
66 · int tevent_loop_once()
67 Both of functions accept just one parameter (tevent context) and the
68 only difference lies in the fact that the first loop can theoretically
69 last for ever but the second one will wait just for a single one event
70 to catch and then the loop breaks and the program continue.
71
72
73
74Version 0.9.8 Wed Mar 6 2019 tevent_context(3)