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

RETURN VALUE

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

NOTES

98       These APIs are implemented as a shared library, which can be compiled
99       and linked to with the libsystemd pkg-config(1) file.
100

SEE ALSO

102       systemd(1), sd-bus(3), sd_bus_process(3), sd_bus_attach_event(3),
103       sd_bus_wait(3), sd_bus_set_fd(3), poll(3)
104
105
106
107systemd 250                                                   SD_BUS_GET_FD(3)
Impressum