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