1<?xml version='1.0'?> 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> 4<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> 5 6<refentry id="sd_event_get_fd" xmlns:xi="http://www.w3.org/2001/XInclude"> 7 8 <refentryinfo> 9 <title>sd_event_get_fd</title> 10 <productname>systemd</productname> 11 </refentryinfo> 12 13 <refmeta> 14 <refentrytitle>sd_event_get_fd</refentrytitle> 15 <manvolnum>3</manvolnum> 16 </refmeta> 17 18 <refnamediv> 19 <refname>sd_event_get_fd</refname> 20 21 <refpurpose>Obtain a file descriptor to poll for event loop events</refpurpose> 22 </refnamediv> 23 24 <refsynopsisdiv> 25 <funcsynopsis> 26 <funcsynopsisinfo>#include <systemd/sd-event.h></funcsynopsisinfo> 27 28 <funcprototype> 29 <funcdef>int <function>sd_event_get_fd</function></funcdef> 30 <paramdef>sd_event *<parameter>event</parameter></paramdef> 31 </funcprototype> 32 33 </funcsynopsis> 34 </refsynopsisdiv> 35 36 <refsect1> 37 <title>Description</title> 38 39 <para><function>sd_event_get_fd()</function> returns the file 40 descriptor that an event loop object returned by the 41 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry> 42 function uses to wait for events. This file descriptor may itself 43 be polled for 44 <constant>POLLIN</constant>/<constant>EPOLLIN</constant> 45 events. This makes it possible to embed an 46 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry> 47 event loop into another, possibly foreign, event loop.</para> 48 49 <para>The returned file descriptor refers to an <citerefentry 50 project='man-pages'><refentrytitle>epoll</refentrytitle><manvolnum>7</manvolnum></citerefentry> 51 object. It is recommended not to alter it by invoking 52 <citerefentry 53 project='man-pages'><refentrytitle>epoll_ctl</refentrytitle><manvolnum>2</manvolnum></citerefentry> 54 on it, in order to avoid interference with the event loop's inner 55 logic and assumptions.</para> 56 </refsect1> 57 58 <refsect1> 59 <title>Return Value</title> 60 61 <para>On success, <function>sd_event_get_fd()</function> returns a non-negative file descriptor. On 62 failure, it returns a negative errno-style error code.</para> 63 64 <refsect2> 65 <title>Errors</title> 66 67 <para>Returned errors may indicate the following problems:</para> 68 69 <variablelist> 70 <varlistentry> 71 <term><constant>-EINVAL</constant></term> 72 73 <listitem><para><parameter>event</parameter> is not a valid pointer to an 74 <structname>sd_event</structname> structure.</para></listitem> 75 </varlistentry> 76 77 <varlistentry> 78 <term><constant>-ECHILD</constant></term> 79 80 <listitem><para>The event loop has been created in a different process.</para></listitem> 81 82 </varlistentry> 83 </variablelist> 84 </refsect2> 85 </refsect1> 86 87 <refsect1> 88 <title>Examples</title> 89 90 <example> 91 <title>Integration in the GLib event loop</title> 92 93 <programlisting><xi:include href="glib-event-glue.c" parse="text" /></programlisting> 94 </example> 95 </refsect1> 96 97 <xi:include href="libsystemd-pkgconfig.xml" /> 98 99 <refsect1> 100 <title>See Also</title> 101 102 <para> 103 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 104 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 105 <citerefentry><refentrytitle>sd_event_wait</refentrytitle><manvolnum>3</manvolnum></citerefentry>, 106 <citerefentry project='man-pages'><refentrytitle>epoll_ctl</refentrytitle><manvolnum>2</manvolnum></citerefentry>, 107 <citerefentry project='man-pages'><refentrytitle>epoll</refentrytitle><manvolnum>7</manvolnum></citerefentry> 108 </para> 109 </refsect1> 110 111</refentry> 112