1SD_BUS_GET_FD(3) sd_bus_get_fd SD_BUS_GET_FD(3)
2
3
4
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
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
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 relative and specified
41 in microseconds. When converting this value in order to pass it as
42 third argument to poll() (which expects milliseconds), care should be
43 taken to use a division that rounds up to ensure the I/O polling
44 operation doesn't sleep for shorter than necessary, which might result
45 in unintended busy looping (alternatively, use ppoll(2) instead of
46 plain poll(), which understands timeouts with nano-second granularity).
47
48 These three functions are useful to hook up a bus connection object
49 with an external or manual event loop involving poll() or a similar I/O
50 polling call. Before each invocation of the I/O polling call, all three
51 functions should be invoked: the file descriptor returned by
52 sd_bus_get_fd() should be polled for the events indicated by
53 sd_bus_get_events(), and the I/O call should block for that up to the
54 timeout returned by sd_bus_get_timeout(). After each I/O polling call
55 the bus connection needs to process incoming or outgoing data, by
56 invoking sd_bus_process(3).
57
58 Note that these functions are only one of three supported ways to
59 implement I/O event handling for bus connections. Alternatively use
60 sd_bus_attach_event(3) to attach a bus connection to an sd-event(3)
61 event loop. Or use sd_bus_wait(3) as a simple synchronous, blocking I/O
62 waiting call.
63
65 On success, sd_bus_get_fd() returns the file descriptor used for
66 communication. On failure, it returns a negative errno-style error
67 code.
68
69 On success, sd_bus_get_events() returns the I/O event mask to use for
70 I/O event watching. On failure, it returns a negative errno-style error
71 code.
72
73 On success, sd_bus_get_timeout() returns a non-negative integer. On
74 failure, it returns a negative errno-style error code.
75
76 Errors
77 Returned errors may indicate the following problems:
78
79 -EINVAL
80 An invalid bus object was passed.
81
82 -ECHILD
83 The bus connection was allocated in a parent process and is being
84 reused in a child process after fork().
85
86 -ENOTCONN
87 The bus connection has been terminated.
88
89 -EPERM
90 Two distinct file descriptors were passed for input and output
91 using sd_bus_set_fd(), which sd_bus_get_fd() cannot return.
92
93 -ENOPKG
94 The bus cannot be resolved.
95
97 These APIs are implemented as a shared library, which can be compiled
98 and linked to with the libsystemd pkg-config(1) file.
99
101 systemd(1), sd-bus(3), sd_bus_process(3), sd_bus_attach_event(3),
102 sd_bus_wait(3), sd_bus_set_fd(3), poll(3)
103
104
105
106systemd 249 SD_BUS_GET_FD(3)