systemd/man/sd_event_get_fd.html
2015-02-17 11:22:16 +01:00

108 lines
7.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_event_get_fd</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
a.headerlink {
color: #c60f0f;
font-size: 0.8em;
padding: 0 4px 0 4px;
text-decoration: none;
visibility: hidden;
}
a.headerlink:hover {
background-color: #c60f0f;
color: white;
}
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
visibility: visible;
}
</style><a href="index.html">Index </a>·
<a href="systemd.directives.html">Directives </a>·
<a href="../python-systemd/index.html">Python </a>·
<a href="../libudev/index.html">libudev </a>·
<a href="../libudev/index.html">gudev </a><span style="float:right">systemd 219</span><hr><div class="refentry"><a name="sd_event_get_fd"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_event_get_fd — Obtain a file descriptor to poll for event loop events</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;systemd/sd-bus.h&gt;</pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_event_get_fd</b>(</code></td><td>sd_bus *<var class="pdparam">event</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm139634046162512"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description"></a></h2><p><code class="function">sd_event_get_fd()</code> returns the file
descriptor that the event loop object returned by the
<a href="sd_event_new.html"><span class="citerefentry"><span class="refentrytitle">sd_event_new</span>(3)</span></a>
function uses to wait for events. This file descriptor can be
polled for events. This makes it possible to embed the
<a href="sd-event.html"><span class="citerefentry"><span class="refentrytitle">sd-event</span>(3)</span></a>
event loop inside of another event loop.</p></div><div class="refsect1"><a name="idm139634046186672"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value"></a></h2><p>On success, <code class="function">sd_event_get_fd()</code> returns a
non-negative integer. On failure, it returns a negative
errno-style error code.</p></div><div class="refsect1"><a name="idm139634042349936"></a><h2 id="Errors">Errors<a class="headerlink" title="Permalink to this headline" href="#Errors"></a></h2><p>Returned errors may indicate the following problems:</p><div class="variablelist"><dl class="variablelist"><dt id="-EINVAL"><span class="term"><code class="constant">-EINVAL</code></span><a class="headerlink" title="Permalink to this term" href="#-EINVAL"></a></dt><dd><p><em class="parameter"><code>event</code></em> is not a valid
pointer to an <span class="structname">sd_event</span> structure.
</p></dd><dt id="-ECHILD"><span class="term"><code class="constant">-ECHILD</code></span><a class="headerlink" title="Permalink to this term" href="#-ECHILD"></a></dt><dd><p>The event loop has been created in a different process.</p></dd></dl></div></div><div class="refsect1"><a name="idm139634042344432"></a><h2 id="Examples">Examples<a class="headerlink" title="Permalink to this headline" href="#Examples"></a></h2><div class="example"><a name="idm139634042343760"></a><p class="title"><b>Example 1. Integration in glib event loop</b></p><div class="example-contents"><pre class="programlisting">/***
Copyright 2014 Tom Gundersen
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***/
#include &lt;stdlib.h&gt;
typedef struct SDEventSource {
GSource source;
GPollFD pollfd;
sd_event *event;
} SDEventSource;
static gboolean event_prepare(GSource *source, gint *timeout_) {
return sd_event_prepare(((SDEventSource *)source)-&gt;event) &gt; 0;
}
static gboolean event_check(GSource *source) {
return sd_event_wait(((SDEventSource *)source)-&gt;event, 0) &gt; 0;
}
static gboolean event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
return sd_event_dispatch(((SDEventSource *)source)-&gt;event) &gt; 0;
}
static void event_finalize(GSource *source) {
sd_event_unref(((SDEventSource *)source)-&gt;event);
}
static GSourceFuncs event_funcs = {
.prepare = event_prepare,
.check = event_check,
.dispatch = event_dispatch,
.finalize = event_finalize,
};
GSource *g_sd_event_create_source(sd_event *event) {
SDEventSource *source;
source = (SDEventSource *)g_source_new(&amp;event_funcs, sizeof(SDEventSource));
source-&gt;event = sd_event_ref(event);
source-&gt;pollfd.fd = sd_event_get_fd(event);
source-&gt;pollfd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
g_source_add_poll((GSource *)source, &amp;source-&gt;pollfd);
return (GSource *)source;
}
</pre></div></div><br class="example-break"></div><div class="refsect1"><a name="idm139634042341616"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes"></a></h2><p><code class="function">sd_event_get_fd()</code> is available as a
shared library, which can be compiled and linked to with the
<code class="constant">libsystemd</code> <a href="http://linux.die.net/man/1/pkg-config"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
file.</p></div><div class="refsect1"><a name="idm139634042338160"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also"></a></h2><p>
<a href="sd-event.html"><span class="citerefentry"><span class="refentrytitle">sd-event</span>(3)</span></a>,
<a href="sd_event_new.html"><span class="citerefentry"><span class="refentrytitle">sd_event_new</span>(3)</span></a>,
<a href="sd_event_ref.html"><span class="citerefentry"><span class="refentrytitle">sd_event_ref</span>(3)</span></a>
</p></div></div></body></html>