]>
Commit | Line | Data |
---|---|---|
514094f9 | 1 | <?xml version='1.0'?> |
3a54a157 ZJS |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
e382c49f | 4 | |
5 | <!-- | |
db9ecf05 | 6 | SPDX-License-Identifier: LGPL-2.1-or-later |
572eb058 | 7 | |
96b2fb93 | 8 | Copyright © 2016 Julian Orth |
e382c49f | 9 | --> |
10 | ||
ffd1a3f6 | 11 | <refentry id="sd_bus_get_fd" xmlns:xi="http://www.w3.org/2001/XInclude"> |
e382c49f | 12 | |
13 | <refentryinfo> | |
14 | <title>sd_bus_get_fd</title> | |
15 | <productname>systemd</productname> | |
e382c49f | 16 | </refentryinfo> |
17 | ||
18 | <refmeta> | |
19 | <refentrytitle>sd_bus_get_fd</refentrytitle> | |
20 | <manvolnum>3</manvolnum> | |
21 | </refmeta> | |
22 | ||
23 | <refnamediv> | |
24 | <refname>sd_bus_get_fd</refname> | |
ffd1a3f6 LP |
25 | <refname>sd_bus_get_events</refname> |
26 | <refname>sd_bus_get_timeout</refname> | |
e382c49f | 27 | |
201632e3 | 28 | <refpurpose>Get the file descriptor, I/O events and timeout to wait for from a message bus |
d4169bf8 | 29 | object</refpurpose> |
e382c49f | 30 | </refnamediv> |
31 | ||
32 | <refsynopsisdiv> | |
33 | <funcsynopsis> | |
34 | <funcsynopsisinfo>#include <systemd/sd-bus.h></funcsynopsisinfo> | |
35 | ||
36 | <funcprototype> | |
37 | <funcdef>int <function>sd_bus_get_fd</function></funcdef> | |
38 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
39 | </funcprototype> | |
ffd1a3f6 LP |
40 | |
41 | <funcprototype> | |
42 | <funcdef>int <function>sd_bus_get_events</function></funcdef> | |
43 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
44 | </funcprototype> | |
45 | ||
46 | <funcprototype> | |
47 | <funcdef>int <function>sd_bus_get_timeout</function></funcdef> | |
48 | <paramdef>sd_bus *<parameter>bus</parameter></paramdef> | |
49 | <paramdef>uint64_t *<parameter>timeout_usec</parameter></paramdef> | |
50 | </funcprototype> | |
e382c49f | 51 | </funcsynopsis> |
52 | </refsynopsisdiv> | |
53 | ||
54 | <refsect1> | |
55 | <title>Description</title> | |
56 | ||
d4169bf8 DDM |
57 | <para><function>sd_bus_get_fd()</function> returns the file descriptor used to communicate from |
58 | a message bus object. This descriptor can be used with | |
59 | <citerefentry project='man-pages'><refentrytitle>poll</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
60 | or a similar function to wait for I/O events on the specified bus connection object. If the bus | |
61 | object was configured with the <function>sd_bus_set_fd()</function> function, then the | |
62 | <parameter>input_fd</parameter> file descriptor used in that call is returned.</para> | |
aaf6c750 | 63 | |
d4169bf8 DDM |
64 | <para><function>sd_bus_get_events()</function> returns the I/O events to wait for, suitable for |
65 | passing to <function>poll()</function> or a similar call. Returns a combination of | |
66 | <constant>POLLIN</constant>, <constant>POLLOUT</constant>, … events, or negative on error. | |
67 | </para> | |
ffd1a3f6 | 68 | |
e503019b | 69 | <para><function>sd_bus_get_timeout()</function> returns the <emphasis>absolute</emphasis> time-out in μs, |
f977356a LP |
70 | from which the relative time-out to pass to <function>poll()</function> (or a similar call) can be |
71 | derived, when waiting for events on the specified bus connection. The returned timeout may be zero, in | |
72 | which case a subsequent I/O polling call should be invoked in non-blocking mode. The returned timeout may | |
73 | be <constant>UINT64_MAX</constant> in which case the I/O polling call may block indefinitely, without any | |
74 | applied timeout. Note that the returned timeout should be considered only a maximum sleeping time. It is | |
75 | permissible (and even expected) that shorter timeouts are used by the calling program, in case other | |
76 | event sources are polled in the same event loop. Note that the returned time-value is absolute, based of | |
77 | <constant>CLOCK_MONOTONIC</constant> and specified in microseconds. When converting this value in order | |
78 | to pass it as third argument to <function>poll()</function> (which expects relative milliseconds), care | |
79 | should be taken to convert to a relative time and use a division that rounds up to ensure the I/O polling | |
80 | operation doesn't sleep for shorter than necessary, which might result in unintended busy looping | |
81 | (alternatively, use <citerefentry | |
82 | project='man-pages'><refentrytitle>ppoll</refentrytitle><manvolnum>2</manvolnum></citerefentry> instead | |
83 | of plain <function>poll()</function>, which understands timeouts with nano-second granularity).</para> | |
d4169bf8 DDM |
84 | |
85 | <para>These three functions are useful to hook up a bus connection object with an external or | |
86 | manual event loop involving <function>poll()</function> or a similar I/O polling call. Before | |
87 | each invocation of the I/O polling call, all three functions should be invoked: the file | |
88 | descriptor returned by <function>sd_bus_get_fd()</function> should be polled for the events | |
89 | indicated by <function>sd_bus_get_events()</function>, and the I/O call should block for that up | |
201632e3 | 90 | to the timeout returned by <function>sd_bus_get_timeout()</function>. After each I/O polling |
ffd1a3f6 | 91 | call the bus connection needs to process incoming or outgoing data, by invoking |
d4169bf8 DDM |
92 | <citerefentry><refentrytitle>sd_bus_process</refentrytitle><manvolnum>3</manvolnum></citerefentry>. |
93 | </para> | |
94 | ||
75358555 | 95 | <para>Note that these functions are only one of three supported ways to implement I/O event |
d4169bf8 DDM |
96 | handling for bus connections. Alternatively use |
97 | <citerefentry><refentrytitle>sd_bus_attach_event</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
98 | to attach a bus connection to an | |
99 | <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
100 | event loop. Or use | |
101 | <citerefentry><refentrytitle>sd_bus_wait</refentrytitle><manvolnum>3</manvolnum></citerefentry> | |
ffd1a3f6 | 102 | as a simple synchronous, blocking I/O waiting call.</para> |
e382c49f | 103 | </refsect1> |
104 | ||
105 | <refsect1> | |
106 | <title>Return Value</title> | |
107 | ||
d4169bf8 DDM |
108 | <para>On success, <function>sd_bus_get_fd()</function> returns the file descriptor used for |
109 | communication. On failure, it returns a negative errno-style error code.</para> | |
aaf6c750 | 110 | |
d4169bf8 DDM |
111 | <para>On success, <function>sd_bus_get_events()</function> returns the I/O event mask to use for |
112 | I/O event watching. On failure, it returns a negative errno-style error code.</para> | |
ffd1a3f6 | 113 | |
d4169bf8 DDM |
114 | <para>On success, <function>sd_bus_get_timeout()</function> returns a non-negative integer. On |
115 | failure, it returns a negative errno-style error code.</para> | |
e382c49f | 116 | |
b1de39de ZJS |
117 | <refsect2> |
118 | <title>Errors</title> | |
ffd1a3f6 | 119 | |
b1de39de | 120 | <para>Returned errors may indicate the following problems:</para> |
ffd1a3f6 | 121 | |
b1de39de ZJS |
122 | <variablelist> |
123 | <varlistentry> | |
124 | <term><constant>-EINVAL</constant></term> | |
ffd1a3f6 | 125 | |
b1de39de ZJS |
126 | <listitem><para>An invalid bus object was passed.</para></listitem> |
127 | </varlistentry> | |
ffd1a3f6 | 128 | |
b1de39de ZJS |
129 | <varlistentry> |
130 | <term><constant>-ECHILD</constant></term> | |
ffd1a3f6 | 131 | |
d4169bf8 DDM |
132 | <listitem><para>The bus connection was allocated in a parent process and is being reused |
133 | in a child process after <function>fork()</function>.</para></listitem> | |
b1de39de | 134 | </varlistentry> |
ffd1a3f6 | 135 | |
b1de39de ZJS |
136 | <varlistentry> |
137 | <term><constant>-ENOTCONN</constant></term> | |
ffd1a3f6 | 138 | |
b1de39de ZJS |
139 | <listitem><para>The bus connection has been terminated.</para></listitem> |
140 | </varlistentry> | |
ffd1a3f6 | 141 | |
b1de39de ZJS |
142 | <varlistentry> |
143 | <term><constant>-EPERM</constant></term> | |
ffd1a3f6 | 144 | |
b1de39de ZJS |
145 | <listitem><para>Two distinct file descriptors were passed for input and output using |
146 | <function>sd_bus_set_fd()</function>, which <function>sd_bus_get_fd()</function> cannot | |
147 | return.</para></listitem> | |
148 | </varlistentry> | |
aaf6c750 | 149 | |
aaf6c750 DDM |
150 | <varlistentry> |
151 | <term><constant>-ENOPKG</constant></term> | |
152 | ||
ec07c3c8 AK |
153 | <listitem><para>The bus cannot be resolved.</para> |
154 | ||
155 | <xi:include href="version-info.xml" xpointer="v246"/></listitem> | |
aaf6c750 | 156 | </varlistentry> |
b1de39de ZJS |
157 | </variablelist> |
158 | </refsect2> | |
ffd1a3f6 LP |
159 | </refsect1> |
160 | ||
161 | <xi:include href="libsystemd-pkgconfig.xml" /> | |
162 | ||
69106f47 AK |
163 | <refsect1> |
164 | <title>History</title> | |
165 | <para><function>sd_bus_get_fd()</function> was added in version 231.</para> | |
00f95506 AK |
166 | <para><function>sd_bus_get_events()</function> and |
167 | <function>sd_bus_get_timeout()</function> were added in version 240.</para> | |
69106f47 AK |
168 | </refsect1> |
169 | ||
e382c49f | 170 | <refsect1> |
171 | <title>See Also</title> | |
172 | ||
173 | <para> | |
174 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
175 | <citerefentry><refentrytitle>sd-bus</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
ffd1a3f6 LP |
176 | <citerefentry><refentrytitle>sd_bus_process</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
177 | <citerefentry><refentrytitle>sd_bus_attach_event</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
178 | <citerefentry><refentrytitle>sd_bus_wait</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
cd6d2111 | 179 | <citerefentry><refentrytitle>sd_bus_set_fd</refentrytitle><manvolnum>3</manvolnum></citerefentry>, |
ffd1a3f6 | 180 | <citerefentry project='man-pages'><refentrytitle>poll</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
e382c49f | 181 | </para> |
182 | </refsect1> | |
183 | ||
184 | </refentry> |