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 time-out 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(3)
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 time-out in µs to pass to to poll() or
32 a similar call when waiting for events on the specified bus connection.
33 The returned time-out 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 time-out. Note that the returned
37 time-out should be considered only a maximum sleeping time. It is
38 permissible (and even expected) that shorter time-outs 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(3) instead of
46 plain poll(), which understands time-outs with nano-second
47 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 time-out 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 function 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
66 sd_bus_get_fd() returns the file descriptor used for communication, or
67 a negative errno-style error code on error.
68
69 sd_bus_get_events() returns the I/O event mask to use for I/O event
70 watching, or a negative errno-style error code on error.
71
72 sd_bus_get_timeout() returns zero or positive on success, or a negative
73 errno-style error code on error.
74
75 Errors
76 Returned errors may indicate the following problems:
77
78 -EINVAL
79 An invalid bus object was passed.
80
81 -ECHILD
82 The bus connection was allocated in a parent process and is being
83 reused in a child process after fork().
84
85 -ENOTCONN
86 The bus connection has been terminated.
87
88 -EPERM
89 Two distinct file descriptors were passed for input and output
90 using sd_bus_set_fd(), which sd_bus_get_fd() cannot return.
91
93 These APIs are implemented as a shared library, which can be compiled
94 and linked to with the libsystemd pkg-config(1) file.
95
97 systemd(1), sd-bus(3), sd_bus_set_fd(3), sd_bus_process(3),
98 sd_bus_attach_event(3), sd_bus_wait(3), poll(3)
99
100
101
102systemd 245 SD_BUS_GET_FD(3)