]> git.proxmox.com Git - systemd.git/blob - man/sd_event_get_fd.3
Imported Upstream version 219
[systemd.git] / man / sd_event_get_fd.3
1 '\" t
2 .TH "SD_EVENT_GET_FD" "3" "" "systemd 219" "sd_event_get_fd"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_event_get_fd \- Obtain a file descriptor to poll for event loop events
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-bus\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_event_get_fd('u
32 .BI "int sd_event_get_fd(sd_bus\ *" "event" ");"
33 .SH "DESCRIPTION"
34 .PP
35 \fBsd_event_get_fd()\fR
36 returns the file descriptor that the event loop object returned by the
37 \fBsd_event_new\fR(3)
38 function uses to wait for events\&. This file descriptor can be polled for events\&. This makes it possible to embed the
39 \fBsd-event\fR(3)
40 event loop inside of another event loop\&.
41 .SH "RETURN VALUE"
42 .PP
43 On success,
44 \fBsd_event_get_fd()\fR
45 returns a non\-negative integer\&. On failure, it returns a negative errno\-style error code\&.
46 .SH "ERRORS"
47 .PP
48 Returned errors may indicate the following problems:
49 .PP
50 \fB\-EINVAL\fR
51 .RS 4
52 \fIevent\fR
53 is not a valid pointer to an
54 sd_event
55 structure\&.
56 .RE
57 .PP
58 \fB\-ECHILD\fR
59 .RS 4
60 The event loop has been created in a different process\&.
61 .RE
62 .SH "EXAMPLES"
63 .PP
64 \fBExample\ \&1.\ \&Integration in glib event loop\fR
65 .sp
66 .if n \{\
67 .RS 4
68 .\}
69 .nf
70 /***
71 Copyright 2014 Tom Gundersen
72
73 Permission is hereby granted, free of charge, to any person
74 obtaining a copy of this software and associated documentation files
75 (the "Software"), to deal in the Software without restriction,
76 including without limitation the rights to use, copy, modify, merge,
77 publish, distribute, sublicense, and/or sell copies of the Software,
78 and to permit persons to whom the Software is furnished to do so,
79 subject to the following conditions:
80
81 The above copyright notice and this permission notice shall be
82 included in all copies or substantial portions of the Software\&.
83
84 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
86 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
87 NONINFRINGEMENT\&. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
88 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
89 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
90 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
91 SOFTWARE\&.
92 ***/
93
94 #include <stdlib\&.h>
95
96 typedef struct SDEventSource {
97 GSource source;
98 GPollFD pollfd;
99 sd_event *event;
100 } SDEventSource;
101
102 static gboolean event_prepare(GSource *source, gint *timeout_) {
103 return sd_event_prepare(((SDEventSource *)source)\->event) > 0;
104 }
105
106 static gboolean event_check(GSource *source) {
107 return sd_event_wait(((SDEventSource *)source)\->event, 0) > 0;
108 }
109
110 static gboolean event_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
111 return sd_event_dispatch(((SDEventSource *)source)\->event) > 0;
112 }
113
114 static void event_finalize(GSource *source) {
115 sd_event_unref(((SDEventSource *)source)\->event);
116 }
117
118 static GSourceFuncs event_funcs = {
119 \&.prepare = event_prepare,
120 \&.check = event_check,
121 \&.dispatch = event_dispatch,
122 \&.finalize = event_finalize,
123 };
124
125 GSource *g_sd_event_create_source(sd_event *event) {
126 SDEventSource *source;
127
128 source = (SDEventSource *)g_source_new(&event_funcs, sizeof(SDEventSource));
129
130 source\->event = sd_event_ref(event);
131 source\->pollfd\&.fd = sd_event_get_fd(event);
132 source\->pollfd\&.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
133
134 g_source_add_poll((GSource *)source, &source\->pollfd);
135
136 return (GSource *)source;
137 }
138 .fi
139 .if n \{\
140 .RE
141 .\}
142 .SH "NOTES"
143 .PP
144 \fBsd_event_get_fd()\fR
145 is available as a shared library, which can be compiled and linked to with the
146 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
147 file\&.
148 .SH "SEE ALSO"
149 .PP
150 \fBsd-event\fR(3),
151 \fBsd_event_new\fR(3),
152 \fBsd_event_ref\fR(3)