1 <?xml version='
1.0'
?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 This file is part of systemd.
8 Copyright 2015 Zbigniew Jędrzejewski-Szmek
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 <refentry id=
"sd_event_wait">
27 <title>sd_event_wait
</title>
28 <productname>systemd
</productname>
32 <contrib>Developer
</contrib>
33 <firstname>Tom
</firstname>
34 <surname>Gundersen
</surname>
35 <email>teg@jklm.no
</email>
41 <refentrytitle>sd_event_wait
</refentrytitle>
42 <manvolnum>3</manvolnum>
46 <refname>sd_event_wait
</refname>
47 <refname>sd_event_prepare
</refname>
48 <refname>sd_event_dispatch
</refname>
50 <refpurpose>Run parts of the libsystemd event loop
</refpurpose>
55 <funcsynopsisinfo>#include
<systemd/sd-event.h
></funcsynopsisinfo>
58 <funcdef>int
<function>sd_event_prepare
</function></funcdef>
59 <paramdef>sd_event *
<parameter>event
</parameter></paramdef>
63 <funcdef>int
<function>sd_event_wait
</function></funcdef>
64 <paramdef>sd_event *
<parameter>event
</parameter></paramdef>
65 <paramdef>uint64_t
<parameter>timeout
</parameter></paramdef>
69 <funcdef>int
<function>sd_event_dispatch
</function></funcdef>
70 <paramdef>sd_event *
<parameter>event
</parameter></paramdef>
77 <title>Description
</title>
79 <para>Functions described here form parts of an event loop.
</para>
81 <para><function>sd_event_prepare
</function> checks for pending
82 events and arms necessary timers. If any events are ready to be
83 processed, it returns a positive value, and the events should be
84 processed with
<function>sd_event_dispatch
</function>.
85 <function>sd_event_dispatch
</function> runs a handler for one of
86 the events from the sources with the highest priority. On success,
87 <function>sd_event_dispatch
</function> returns either
0, which
88 means that the loop is finished, or a positive value, which means
89 that the loop is again in the initial state and
90 <function>sd_event_prepare
</function> should be called again.
93 <para>In case
<function>sd_event_prepare
</function> returned
0,
94 <function>sd_event_wait
</function> should be called to wait for
95 events or a timeout. If any events are ready to be processed, it
96 returns a positive value, and the events should be processed with
97 <function>sd_event_dispatch
</function>. Otherwise, the loop is
98 back in the initial state and
<function>sd_event_prepare
</function>
99 should be called again.
</para>
103 │ initial ├──←←←←←←←←←←←←←←←←←←←─┐
106 sd_event_prepare ┌─────────┐ ↑
107 ├
0 →→→→→→→──┤ armed │ ↑
111 ├───←←←←←←←───
1 ┴─
0 →→→→→→→─┘
118 ├
1 ──────────→→→→→→→─────────┘
126 <para>All three functions take, as the first argument, the event
127 loop object
<parameter>event
</parameter> that is created with
128 <function>sd_event_new
</function>. The timeout for
129 <function>sd_event_wait
</function> is specified with
130 <parameter>timeout
</parameter> in milliseconds.
131 <constant>(uint64_t) -
1</constant> may be used to specify an
132 infinite timeout.
</para>
136 <title>Return Value
</title>
138 <para>On success, these functions return
0 or a positive integer.
139 On failure, they return a negative errno-style error code. In case
140 of
<function>sd_event_prepare
</function> and
141 <function>sd_event_wait
</function>, a positive value means that
142 events are ready to be processed and
0 means that no events are
143 ready. In case of
<function>sd_event_dispatch
</function>, a
144 positive value means that the loop is again in the initial state
145 and
0 means the loop is finished. For any of these functions, a
146 negative return value means the loop must be aborted.
</para>
150 <title>Errors
</title>
152 <para>Returned errors may indicate the following problems:
</para>
156 <term><constant>-EINVAL
</constant></term>
158 <listitem><para>The
<parameter>event
</parameter> parameter is
159 <constant>NULL
</constant>.
</para></listitem>
163 <term><constant>-EBUSY
</constant></term>
165 <listitem><para>The event loop object is not in the right
166 state.
</para></listitem>
170 <term><constant>-ESTALE
</constant></term>
172 <listitem><para>The event loop is already terminated.
</para></listitem>
177 <term><constant>-ECHILD
</constant></term>
179 <listitem><para>The event loop has been created in a different process.
</para></listitem>
185 <para>Other errors are possible, too.
</para>
191 <para>Functions described here are available
192 as a shared library, which can be compiled and linked to with the
193 <constant>libsystemd
</constant> <citerefentry project='die-net'
><refentrytitle>pkg-config
</refentrytitle><manvolnum>1</manvolnum></citerefentry>
198 <title>See Also
</title>
201 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
202 <citerefentry><refentrytitle>sd_event_new
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
203 <citerefentry><refentrytitle>sd_event_run
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
204 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
205 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
206 <citerefentry><refentrytitle>sd_event_add_signal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
207 <citerefentry><refentrytitle>sd_event_add_defer
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
208 <citerefentry><refentrytitle>sd_event_add_exit
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
209 <citerefentry><refentrytitle>sd_event_add_post
</refentrytitle><manvolnum>3</manvolnum></citerefentry>.