man-pages/man3/sd_event_add_defer.3.html
2021-03-31 01:06:50 +01:00

202 lines
6.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of SD_EVENT_ADD_DEFER</TITLE>
</HEAD><BODY>
<H1>SD_EVENT_ADD_DEFER</H1>
Section: sd_event_add_defer (3)<BR>Updated: <BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
sd_event_add_defer, sd_event_add_post, sd_event_add_exit, sd_event_handler_t - Add static event sources to an event loop
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<P>
<B>
</B><PRE>
#include &lt;<A HREF="file:///usr/include/systemd/sd-event.h">systemd/sd-event.h</A>&gt;
</PRE>
<P>
<B>
</B><PRE>
typedef struct sd_event_source sd_event_source;
</PRE>
<DL COMPACT>
<DT id="1">
<B>typedef int (*sd_event_handler_t)(sd_event_source&nbsp;*</B><I>s</I><B>, void&nbsp;*</B><I>userdata</I><B>);</B>
<DT id="2">
<B>int sd_event_add_defer(sd_event&nbsp;*</B><I>event</I><B>, sd_event_source&nbsp;**</B><I>source</I><B>, sd_event_handler_t&nbsp;</B><I>handler</I><B>, void&nbsp;*</B><I>userdata</I><B>);</B>
<DT id="3">
<B>int sd_event_add_post(sd_event&nbsp;*</B><I>event</I><B>, sd_event_source&nbsp;**</B><I>source</I><B>, sd_event_handler_t&nbsp;</B><I>handler</I><B>, void&nbsp;*</B><I>userdata</I><B>);</B>
<DT id="4">
<B>int sd_event_add_exit(sd_event&nbsp;*</B><I>event</I><B>, sd_event_source&nbsp;**</B><I>source</I><B>, sd_event_handler_t&nbsp;</B><I>handler</I><B>, void&nbsp;*</B><I>userdata</I><B>);</B>
</DL>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<P>
<DD>These three functions add new static event sources to an event loop. The event loop object is specified in the
<I>event</I>
parameter, the event source object is returned in the
<I>source</I>
parameter. The event sources are enabled statically and will &quot;fire&quot; when the event loop is run and the conditions described below are met. The handler function will be passed the
<I>userdata</I>
pointer, which may be chosen freely by the caller.
<P>
<B>sd_event_add_defer()</B>
adds a new event source that will be dispatched instantly, before the event loop goes to sleep again and waits for new events. By default, the handler will be called once (<B>SD_EVENT_ONESHOT</B>). Note that if the event source is set to
<B>SD_EVENT_ON</B>
the event loop will never go to sleep again, but continuously call the handler, possibly interleaved with other event sources.
<P>
<B>sd_event_add_post()</B>
adds a new event source that is run before the event loop will sleep and wait for new events, but only after at least one other non-post event source was dispatched. By default, the source is enabled permanently (<B>SD_EVENT_ON</B>). Note that this event source type will still allow the event loop to go to sleep again, even if set to
<B>SD_EVENT_ON</B>, as long as no other event source is ever triggered.
<P>
<B>sd_event_add_exit()</B>
adds a new event source that will be dispatched when the event loop is terminated with
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_exit">sd_event_exit</A></B>(3).
<P>
The
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_source_set_enabled">sd_event_source_set_enabled</A></B>(3)
function may be used to enable the event source permanently (<B>SD_EVENT_ON</B>) or to make it fire just once (<B>SD_EVENT_ONESHOT</B>).
<P>
If the handler function returns a negative error code, it will be disabled after the invocation, even if the
<B>SD_EVENT_ON</B>
mode was requested before.
<P>
To destroy an event source object use
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_source_unref">sd_event_source_unref</A></B>(3), but note that the event source is only removed from the event loop when all references to the event source are dropped. To make sure an event source does not fire anymore, even when there's still a reference to it kept, consider setting the event source to
<B>SD_EVENT_OFF</B>
with
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_source_set_enabled">sd_event_source_set_enabled</A></B>(3).
<P>
If the second parameter of these functions is passed as NULL no reference to the event source object is returned. In this case the event source is considered &quot;floating&quot;, and will be destroyed implicitly when the event loop itself is destroyed.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<P>
On success, these functions return 0 or a positive integer. On failure, they return a negative errno-style error code.
<A NAME="lbAF">&nbsp;</A>
<H3>Errors</H3>
<P>
Returned errors may indicate the following problems:
<P>
<B>-ENOMEM</B>
<DL COMPACT><DT id="5"><DD>
Not enough memory to allocate an object.
</DL>
<P>
<B>-EINVAL</B>
<DL COMPACT><DT id="6"><DD>
An invalid argument has been passed.
</DL>
<P>
<B>-ESTALE</B>
<DL COMPACT><DT id="7"><DD>
The event loop is already terminated.
</DL>
<P>
<B>-ECHILD</B>
<DL COMPACT><DT id="8"><DD>
The event loop has been created in a different process.
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>NOTES</H2>
<P>
These APIs are implemented as a shared library, which can be compiled and linked to with the
<B>libsystemd</B>&nbsp;<B><A HREF="/cgi-bin/man/man2html?1+pkg-config">pkg-config</A></B>(1)
file.
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<P>
<B><A HREF="/cgi-bin/man/man2html?1+systemd">systemd</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?3+sd-event">sd-event</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_new">sd_event_new</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_now">sd_event_now</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_add_io">sd_event_add_io</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_add_time">sd_event_add_time</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_add_signal">sd_event_add_signal</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_add_child">sd_event_add_child</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_add_inotify">sd_event_add_inotify</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_source_set_enabled">sd_event_source_set_enabled</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_source_set_priority">sd_event_source_set_priority</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_source_set_userdata">sd_event_source_set_userdata</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_source_set_description">sd_event_source_set_description</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_source_set_floating">sd_event_source_set_floating</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+sd_event_exit">sd_event_exit</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="9"><A HREF="#lbAB">NAME</A><DD>
<DT id="10"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="11"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="12"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DL>
<DT id="13"><A HREF="#lbAF">Errors</A><DD>
</DL>
<DT id="14"><A HREF="#lbAG">NOTES</A><DD>
<DT id="15"><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:55 GMT, March 31, 2021
</BODY>
</HTML>