2018-07-03 00:15:39 +03:00
<?xml version='1.0'?>
2019-03-14 16:40:58 +03:00
< !DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
2023-12-25 17:48:33 +03:00
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
2016-06-21 18:52:32 +03:00
<!--
2020-11-09 07:23:58 +03:00
SPDX-License-Identifier: LGPL-2.1-or-later
2017-11-18 19:22:32 +03:00
2018-06-12 20:00:24 +03:00
Copyright © 2016 Julian Orth
2016-06-21 18:52:32 +03:00
-->
2018-12-12 14:31:05 +03:00
<refentry id= "sd_bus_get_fd" xmlns:xi= "http://www.w3.org/2001/XInclude" >
2016-06-21 18:52:32 +03:00
<refentryinfo >
<title > sd_bus_get_fd</title>
<productname > systemd</productname>
</refentryinfo>
<refmeta >
<refentrytitle > sd_bus_get_fd</refentrytitle>
<manvolnum > 3</manvolnum>
</refmeta>
<refnamediv >
<refname > sd_bus_get_fd</refname>
2018-12-12 14:31:05 +03:00
<refname > sd_bus_get_events</refname>
<refname > sd_bus_get_timeout</refname>
2016-06-21 18:52:32 +03:00
2020-05-22 10:39:36 +03:00
<refpurpose > Get the file descriptor, I/O events and timeout to wait for from a message bus
2020-04-20 21:59:27 +03:00
object</refpurpose>
2016-06-21 18:52:32 +03:00
</refnamediv>
<refsynopsisdiv >
<funcsynopsis >
<funcsynopsisinfo > #include < systemd/sd-bus.h> </funcsynopsisinfo>
<funcprototype >
<funcdef > int <function > sd_bus_get_fd</function> </funcdef>
<paramdef > sd_bus *<parameter > bus</parameter> </paramdef>
</funcprototype>
2018-12-12 14:31:05 +03:00
<funcprototype >
<funcdef > int <function > sd_bus_get_events</function> </funcdef>
<paramdef > sd_bus *<parameter > bus</parameter> </paramdef>
</funcprototype>
<funcprototype >
<funcdef > int <function > sd_bus_get_timeout</function> </funcdef>
<paramdef > sd_bus *<parameter > bus</parameter> </paramdef>
<paramdef > uint64_t *<parameter > timeout_usec</parameter> </paramdef>
</funcprototype>
2016-06-21 18:52:32 +03:00
</funcsynopsis>
</refsynopsisdiv>
<refsect1 >
<title > Description</title>
2020-04-20 21:59:27 +03:00
<para > <function > sd_bus_get_fd()</function> returns the file descriptor used to communicate from
a message bus object. This descriptor can be used with
<citerefentry project= 'man-pages' > <refentrytitle > poll</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
or a similar function to wait for I/O events on the specified bus connection object. If the bus
object was configured with the <function > sd_bus_set_fd()</function> function, then the
<parameter > input_fd</parameter> file descriptor used in that call is returned.</para>
2020-03-15 23:10:37 +03:00
2020-04-20 21:59:27 +03:00
<para > <function > sd_bus_get_events()</function> returns the I/O events to wait for, suitable for
passing to <function > poll()</function> or a similar call. Returns a combination of
<constant > POLLIN</constant> , <constant > POLLOUT</constant> , … events, or negative on error.
</para>
2018-12-12 14:31:05 +03:00
2024-11-05 20:47:54 +03:00
<para > <function > sd_bus_get_timeout()</function> returns the <emphasis > absolute</emphasis> timeout in μs,
from which the relative timeout to pass to <function > poll()</function> (or a similar call) can be
2023-01-09 14:58:09 +03:00
derived, when waiting for events on the specified bus connection. The returned timeout may be zero, in
which case a subsequent I/O polling call should be invoked in non-blocking mode. The returned timeout may
be <constant > UINT64_MAX</constant> in which case the I/O polling call may block indefinitely, without any
applied timeout. Note that the returned timeout should be considered only a maximum sleeping time. It is
permissible (and even expected) that shorter timeouts are used by the calling program, in case other
event sources are polled in the same event loop. Note that the returned time-value is absolute, based of
<constant > CLOCK_MONOTONIC</constant> and specified in microseconds. When converting this value in order
to pass it as third argument to <function > poll()</function> (which expects relative milliseconds), care
should be taken to convert to a relative time and use a division that rounds up to ensure the I/O polling
operation doesn't sleep for shorter than necessary, which might result in unintended busy looping
(alternatively, use <citerefentry
project='man-pages'><refentrytitle > ppoll</refentrytitle> <manvolnum > 2</manvolnum> </citerefentry> instead
of plain <function > poll()</function> , which understands timeouts with nano-second granularity).</para>
2020-04-20 21:59:27 +03:00
<para > These three functions are useful to hook up a bus connection object with an external or
manual event loop involving <function > poll()</function> or a similar I/O polling call. Before
each invocation of the I/O polling call, all three functions should be invoked: the file
descriptor returned by <function > sd_bus_get_fd()</function> should be polled for the events
indicated by <function > sd_bus_get_events()</function> , and the I/O call should block for that up
2020-05-22 10:39:36 +03:00
to the timeout returned by <function > sd_bus_get_timeout()</function> . After each I/O polling
2018-12-12 14:31:05 +03:00
call the bus connection needs to process incoming or outgoing data, by invoking
2020-04-20 21:59:27 +03:00
<citerefentry > <refentrytitle > sd_bus_process</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> .
</para>
2020-04-20 22:32:35 +03:00
<para > Note that these functions are only one of three supported ways to implement I/O event
2020-04-20 21:59:27 +03:00
handling for bus connections. Alternatively use
<citerefentry > <refentrytitle > sd_bus_attach_event</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
to attach a bus connection to an
<citerefentry > <refentrytitle > sd-event</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
event loop. Or use
<citerefentry > <refentrytitle > sd_bus_wait</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry>
2018-12-12 14:31:05 +03:00
as a simple synchronous, blocking I/O waiting call.</para>
2016-06-21 18:52:32 +03:00
</refsect1>
<refsect1 >
<title > Return Value</title>
2020-04-20 21:59:27 +03:00
<para > On success, <function > sd_bus_get_fd()</function> returns the file descriptor used for
communication. On failure, it returns a negative errno-style error code.</para>
2020-03-15 23:10:37 +03:00
2020-04-20 21:59:27 +03:00
<para > On success, <function > sd_bus_get_events()</function> returns the I/O event mask to use for
I/O event watching. On failure, it returns a negative errno-style error code.</para>
2018-12-12 14:31:05 +03:00
2020-04-20 21:59:27 +03:00
<para > On success, <function > sd_bus_get_timeout()</function> returns a non-negative integer. On
failure, it returns a negative errno-style error code.</para>
2016-06-21 18:52:32 +03:00
2019-03-21 16:53:00 +03:00
<refsect2 >
<title > Errors</title>
2018-12-12 14:31:05 +03:00
2019-03-21 16:53:00 +03:00
<para > Returned errors may indicate the following problems:</para>
2018-12-12 14:31:05 +03:00
2019-03-21 16:53:00 +03:00
<variablelist >
<varlistentry >
<term > <constant > -EINVAL</constant> </term>
2018-12-12 14:31:05 +03:00
2019-03-21 16:53:00 +03:00
<listitem > <para > An invalid bus object was passed.</para> </listitem>
</varlistentry>
2018-12-12 14:31:05 +03:00
2019-03-21 16:53:00 +03:00
<varlistentry >
<term > <constant > -ECHILD</constant> </term>
2018-12-12 14:31:05 +03:00
2020-04-20 21:59:27 +03:00
<listitem > <para > The bus connection was allocated in a parent process and is being reused
in a child process after <function > fork()</function> .</para> </listitem>
2019-03-21 16:53:00 +03:00
</varlistentry>
2018-12-12 14:31:05 +03:00
2019-03-21 16:53:00 +03:00
<varlistentry >
<term > <constant > -ENOTCONN</constant> </term>
2018-12-12 14:31:05 +03:00
2019-03-21 16:53:00 +03:00
<listitem > <para > The bus connection has been terminated.</para> </listitem>
</varlistentry>
2018-12-12 14:31:05 +03:00
2019-03-21 16:53:00 +03:00
<varlistentry >
<term > <constant > -EPERM</constant> </term>
2018-12-12 14:31:05 +03:00
2019-03-21 16:53:00 +03:00
<listitem > <para > Two distinct file descriptors were passed for input and output using
<function > sd_bus_set_fd()</function> , which <function > sd_bus_get_fd()</function> cannot
return.</para> </listitem>
</varlistentry>
2020-03-15 23:10:37 +03:00
<varlistentry >
<term > <constant > -ENOPKG</constant> </term>
2024-04-18 03:45:51 +03:00
<listitem > <para > The bus cannot be resolved.</para> </listitem>
2020-03-15 23:10:37 +03:00
</varlistentry>
2019-03-21 16:53:00 +03:00
</variablelist>
</refsect2>
2018-12-12 14:31:05 +03:00
</refsect1>
<xi:include href= "libsystemd-pkgconfig.xml" />
2023-09-04 15:46:35 +03:00
<refsect1 >
<title > History</title>
2024-04-18 03:45:51 +03:00
<para > <function > sd_bus_get_fd()</function> ,
<function > sd_bus_get_events()</function> , and
<function > sd_bus_get_timeout()</function> were added in version 221.</para>
2023-09-04 15:46:35 +03:00
</refsect1>
2016-06-21 18:52:32 +03:00
<refsect1 >
<title > See Also</title>
2023-12-22 21:09:32 +03:00
<para > <simplelist type= "inline" >
<member > <citerefentry > <refentrytitle > systemd</refentrytitle> <manvolnum > 1</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd-bus</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd_bus_process</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd_bus_attach_event</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd_bus_wait</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry > <refentrytitle > sd_bus_set_fd</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
<member > <citerefentry project= 'man-pages' > <refentrytitle > poll</refentrytitle> <manvolnum > 3</manvolnum> </citerefentry> </member>
</simplelist> </para>
2016-06-21 18:52:32 +03:00
</refsect1>
</refentry>