1SD_BUS_GET_FD(3)                 sd_bus_get_fd                SD_BUS_GET_FD(3)
2
3
4

NAME

6       sd_bus_get_fd, sd_bus_get_events, sd_bus_get_timeout - Get the file
7       descriptor, I/O events and timeout to wait for from a message bus
8       object
9

SYNOPSIS

11       #include <systemd/sd-bus.h>
12
13       int sd_bus_get_fd(sd_bus *bus);
14
15       int sd_bus_get_events(sd_bus *bus);
16
17       int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec);
18

DESCRIPTION

20       sd_bus_get_fd() returns the file descriptor used to communicate from a
21       message bus object. This descriptor can be used with poll(3) or a
22       similar function to wait for I/O events on the specified bus connection
23       object. If the bus object was configured with the sd_bus_set_fd()
24       function, then the input_fd file descriptor used in that call is
25       returned.
26
27       sd_bus_get_events() returns the I/O events to wait for, suitable for
28       passing to poll() or a similar call. Returns a combination of POLLIN,
29       POLLOUT, ... events, or negative on error.
30
31       sd_bus_get_timeout() returns the absolute time-out in μs, from which
32       the relative time-out to pass to poll() (or a similar call) can be
33       derived, when waiting for events on the specified bus connection. The
34       returned timeout may be zero, in which case a subsequent I/O polling
35       call should be invoked in non-blocking mode. The returned timeout may
36       be UINT64_MAX in which case the I/O polling call may block
37       indefinitely, without any applied timeout. Note that the returned
38       timeout should be considered only a maximum sleeping time. It is
39       permissible (and even expected) that shorter timeouts are used by the
40       calling program, in case other event sources are polled in the same
41       event loop. Note that the returned time-value is absolute, based of
42       CLOCK_MONOTONIC and specified in microseconds. When converting this
43       value in order to pass it as third argument to poll() (which expects
44       relative milliseconds), care should be taken to convert to a relative
45       time and use a division that rounds up to ensure the I/O polling
46       operation doesn't sleep for shorter than necessary, which might result
47       in unintended busy looping (alternatively, use ppoll(2) instead of
48       plain poll(), which understands timeouts with nano-second granularity).
49
50       These three functions are useful to hook up a bus connection object
51       with an external or manual event loop involving poll() or a similar I/O
52       polling call. Before each invocation of the I/O polling call, all three
53       functions should be invoked: the file descriptor returned by
54       sd_bus_get_fd() should be polled for the events indicated by
55       sd_bus_get_events(), and the I/O call should block for that up to the
56       timeout returned by sd_bus_get_timeout(). After each I/O polling call
57       the bus connection needs to process incoming or outgoing data, by
58       invoking sd_bus_process(3).
59
60       Note that these functions are only one of three supported ways to
61       implement I/O event handling for bus connections. Alternatively use
62       sd_bus_attach_event(3) to attach a bus connection to an sd-event(3)
63       event loop. Or use sd_bus_wait(3) as a simple synchronous, blocking I/O
64       waiting call.
65

RETURN VALUE

67       On success, sd_bus_get_fd() returns the file descriptor used for
68       communication. On failure, it returns a negative errno-style error
69       code.
70
71       On success, sd_bus_get_events() returns the I/O event mask to use for
72       I/O event watching. On failure, it returns a negative errno-style error
73       code.
74
75       On success, sd_bus_get_timeout() returns a non-negative integer. On
76       failure, it returns a negative errno-style error code.
77
78   Errors
79       Returned errors may indicate the following problems:
80
81       -EINVAL
82           An invalid bus object was passed.
83
84       -ECHILD
85           The bus connection was allocated in a parent process and is being
86           reused in a child process after fork().
87
88       -ENOTCONN
89           The bus connection has been terminated.
90
91       -EPERM
92           Two distinct file descriptors were passed for input and output
93           using sd_bus_set_fd(), which sd_bus_get_fd() cannot return.
94
95       -ENOPKG
96           The bus cannot be resolved.
97

NOTES

99       Functions described here are available as a shared library, which can
100       be compiled against and linked to with the libsystemd pkg-config(1)
101       file.
102
103       The code described here uses getenv(3), which is declared to be not
104       multi-thread-safe. This means that the code calling the functions
105       described here must not call setenv(3) from a parallel thread. It is
106       recommended to only do calls to setenv() from an early phase of the
107       program when no other threads have been started.
108

SEE ALSO

110       systemd(1), sd-bus(3), sd_bus_process(3), sd_bus_attach_event(3),
111       sd_bus_wait(3), sd_bus_set_fd(3), poll(3)
112
113
114
115systemd 254                                                   SD_BUS_GET_FD(3)
Impressum