1SD_BUS_GET_FD(3) sd_bus_get_fd SD_BUS_GET_FD(3)
2
3
4
6 sd_bus_get_fd, sd_bus_set_fd, sd_bus_get_events, sd_bus_get_timeout -
7 Get the file descriptor, I/O events and timeout to wait for from a
8 message bus object
9
11 #include <systemd/sd-bus.h>
12
13 int sd_bus_get_fd(sd_bus *bus);
14
15 int sd_bus_set_fd(sd_bus *bus, int input_fd, int output_fd);
16
17 int sd_bus_get_events(sd_bus *bus);
18
19 int sd_bus_get_timeout(sd_bus *bus, uint64_t *timeout_usec);
20
22 sd_bus_get_fd() returns the file descriptor used to communicate from a
23 message bus object. This descriptor can be used with poll(3) or a
24 similar function to wait for I/O events on the specified bus connection
25 object. If the bus object was configured with the sd_bus_set_fd()
26 function, then the input_fd file descriptor used in that call is
27 returned.
28
29 sd_bus_set_fd() sets the file descriptors used to communicate from a
30 message bus object. Both input_fd and output_fd must be valid file
31 descriptors. The same file descriptor may be used as both the input and
32 the output file descriptor. This function must be called before the bus
33 is started.
34
35 sd_bus_get_events() returns the I/O events to wait for, suitable for
36 passing to poll() or a similar call. Returns a combination of POLLIN,
37 POLLOUT, ... events, or negative on error.
38
39 sd_bus_get_timeout() returns the timeout in µs to pass to poll() or a
40 similar call when waiting for events on the specified bus connection.
41 The returned timeout may be zero, in which case a subsequent I/O
42 polling call should be invoked in non-blocking mode. The returned
43 timeout may be UINT64_MAX in which case the I/O polling call may block
44 indefinitely, without any applied timeout. Note that the returned
45 timeout should be considered only a maximum sleeping time. It is
46 permissible (and even expected) that shorter timeouts are used by the
47 calling program, in case other event sources are polled in the same
48 event loop. Note that the returned time-value is relative and specified
49 in microseconds. When converting this value in order to pass it as
50 third argument to poll() (which expects milliseconds), care should be
51 taken to use a division that rounds up to ensure the I/O polling
52 operation doesn't sleep for shorter than necessary, which might result
53 in unintended busy looping (alternatively, use ppoll(3) instead of
54 plain poll(), which understands timeouts with nano-second granularity).
55
56 These three functions are useful to hook up a bus connection object
57 with an external or manual event loop involving poll() or a similar I/O
58 polling call. Before each invocation of the I/O polling call, all three
59 functions should be invoked: the file descriptor returned by
60 sd_bus_get_fd() should be polled for the events indicated by
61 sd_bus_get_events(), and the I/O call should block for that up to the
62 timeout returned by sd_bus_get_timeout(). After each I/O polling call
63 the bus connection needs to process incoming or outgoing data, by
64 invoking sd_bus_process(3).
65
66 Note that these functions are only one of three supported ways to
67 implement I/O event handling for bus connections. Alternatively use
68 sd_bus_attach_event(3) to attach a bus connection to an sd-event(3)
69 event loop. Or use sd_bus_wait(3) as a simple synchronous, blocking I/O
70 waiting call.
71
73 On success, sd_bus_get_fd() returns the file descriptor used for
74 communication. On failure, it returns a negative errno-style error
75 code.
76
77 On success, sd_bus_set_fd() returns a non-negative integer. On failure,
78 it returns a negative errno-style error code.
79
80 On success, sd_bus_get_events() returns the I/O event mask to use for
81 I/O event watching. On failure, it returns a negative errno-style error
82 code.
83
84 On success, sd_bus_get_timeout() returns a non-negative integer. On
85 failure, it returns a negative errno-style error code.
86
87 Errors
88 Returned errors may indicate the following problems:
89
90 -EINVAL
91 An invalid bus object was passed.
92
93 -ECHILD
94 The bus connection was allocated in a parent process and is being
95 reused in a child process after fork().
96
97 -ENOTCONN
98 The bus connection has been terminated.
99
100 -EPERM
101 Two distinct file descriptors were passed for input and output
102 using sd_bus_set_fd(), which sd_bus_get_fd() cannot return.
103
104 -EBADF
105 An invalid file descriptor was passed to sd_bus_set_fd().
106
107 -ENOPKG
108 The bus cannot be resolved.
109
111 These APIs are implemented as a shared library, which can be compiled
112 and linked to with the libsystemd pkg-config(1) file.
113
115 systemd(1), sd-bus(3), sd_bus_process(3), sd_bus_attach_event(3),
116 sd_bus_wait(3), poll(3)
117
118
119
120systemd 246 SD_BUS_GET_FD(3)