source: appstream-generator/build/girepo/glib/UnixUtils.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 7.7 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.UnixUtils;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.ErrorG;
26private import glib.GException;
27private import glib.Source;
28
29
30/** */
31public struct UnixUtils
32{
33
34        /** */
35        public static GQuark errorQuark()
36        {
37                return g_unix_error_quark();
38        }
39
40        /**
41         * Sets a function to be called when the IO condition, as specified by
42         * @condition becomes true for @fd.
43         *
44         * @function will be called when the specified IO condition becomes
45         * %TRUE.  The function is expected to clear whatever event caused the
46         * IO condition to become true and return %TRUE in order to be notified
47         * when it happens again.  If @function returns %FALSE then the watch
48         * will be cancelled.
49         *
50         * The return value of this function can be passed to g_source_remove()
51         * to cancel the watch at any time that it exists.
52         *
53         * The source will never close the fd -- you must do it yourself.
54         *
55         * Params:
56         *     fd = a file descriptor
57         *     condition = IO conditions to watch for on @fd
58         *     funct = a #GPollFDFunc
59         *     userData = data to pass to @function
60         *
61         * Returns: the ID (greater than 0) of the event source
62         *
63         * Since: 2.36
64         */
65        public static uint fdAdd(int fd, GIOCondition condition, GUnixFDSourceFunc funct, void* userData)
66        {
67                return g_unix_fd_add(fd, condition, funct, userData);
68        }
69
70        /**
71         * Sets a function to be called when the IO condition, as specified by
72         * @condition becomes true for @fd.
73         *
74         * This is the same as g_unix_fd_add(), except that it allows you to
75         * specify a non-default priority and a provide a #GDestroyNotify for
76         * @user_data.
77         *
78         * Params:
79         *     priority = the priority of the source
80         *     fd = a file descriptor
81         *     condition = IO conditions to watch for on @fd
82         *     funct = a #GUnixFDSourceFunc
83         *     userData = data to pass to @function
84         *     notify = function to call when the idle is removed, or %NULL
85         *
86         * Returns: the ID (greater than 0) of the event source
87         *
88         * Since: 2.36
89         */
90        public static uint fdAddFull(int priority, int fd, GIOCondition condition, GUnixFDSourceFunc funct, void* userData, GDestroyNotify notify)
91        {
92                return g_unix_fd_add_full(priority, fd, condition, funct, userData, notify);
93        }
94
95        /**
96         * Creates a #GSource to watch for a particular IO condition on a file
97         * descriptor.
98         *
99         * The source will never close the fd -- you must do it yourself.
100         *
101         * Params:
102         *     fd = a file descriptor
103         *     condition = IO conditions to watch for on @fd
104         *
105         * Returns: the newly created #GSource
106         *
107         * Since: 2.36
108         */
109        public static Source fdSourceNew(int fd, GIOCondition condition)
110        {
111                auto p = g_unix_fd_source_new(fd, condition);
112               
113                if(p is null)
114                {
115                        return null;
116                }
117               
118                return new Source(cast(GSource*) p, true);
119        }
120
121        /**
122         * Similar to the UNIX pipe() call, but on modern systems like Linux
123         * uses the pipe2() system call, which atomically creates a pipe with
124         * the configured flags. The only supported flag currently is
125         * %FD_CLOEXEC. If for example you want to configure %O_NONBLOCK, that
126         * must still be done separately with fcntl().
127         *
128         * This function does not take %O_CLOEXEC, it takes %FD_CLOEXEC as if
129         * for fcntl(); these are different on Linux/glibc.
130         *
131         * Params:
132         *     fds = Array of two integers
133         *     flags = Bitfield of file descriptor flags, as for fcntl()
134         *
135         * Returns: %TRUE on success, %FALSE if not (and errno will be set).
136         *
137         * Since: 2.30
138         *
139         * Throws: GException on failure.
140         */
141        public static bool openPipe(int* fds, int flags)
142        {
143                GError* err = null;
144               
145                auto p = g_unix_open_pipe(fds, flags, &err) != 0;
146               
147                if (err !is null)
148                {
149                        throw new GException( new ErrorG(err) );
150                }
151               
152                return p;
153        }
154
155        /**
156         * Control the non-blocking state of the given file descriptor,
157         * according to @nonblock. On most systems this uses %O_NONBLOCK, but
158         * on some older ones may use %O_NDELAY.
159         *
160         * Params:
161         *     fd = A file descriptor
162         *     nonblock = If %TRUE, set the descriptor to be non-blocking
163         *
164         * Returns: %TRUE if successful
165         *
166         * Since: 2.30
167         *
168         * Throws: GException on failure.
169         */
170        public static bool setFdNonblocking(int fd, bool nonblock)
171        {
172                GError* err = null;
173               
174                auto p = g_unix_set_fd_nonblocking(fd, nonblock, &err) != 0;
175               
176                if (err !is null)
177                {
178                        throw new GException( new ErrorG(err) );
179                }
180               
181                return p;
182        }
183
184        /**
185         * A convenience function for g_unix_signal_source_new(), which
186         * attaches to the default #GMainContext.  You can remove the watch
187         * using g_source_remove().
188         *
189         * Params:
190         *     signum = Signal number
191         *     handler = Callback
192         *     userData = Data for @handler
193         *
194         * Returns: An ID (greater than 0) for the event source
195         *
196         * Since: 2.30
197         */
198        public static uint signalAdd(int signum, GSourceFunc handler, void* userData)
199        {
200                return g_unix_signal_add(signum, handler, userData);
201        }
202
203        /**
204         * A convenience function for g_unix_signal_source_new(), which
205         * attaches to the default #GMainContext.  You can remove the watch
206         * using g_source_remove().
207         *
208         * Params:
209         *     priority = the priority of the signal source. Typically this will be in
210         *         the range between #G_PRIORITY_DEFAULT and #G_PRIORITY_HIGH.
211         *     signum = Signal number
212         *     handler = Callback
213         *     userData = Data for @handler
214         *     notify = #GDestroyNotify for @handler
215         *
216         * Returns: An ID (greater than 0) for the event source
217         *
218         * Since: 2.30
219         */
220        public static uint signalAddFull(int priority, int signum, GSourceFunc handler, void* userData, GDestroyNotify notify)
221        {
222                return g_unix_signal_add_full(priority, signum, handler, userData, notify);
223        }
224
225        /**
226         * Create a #GSource that will be dispatched upon delivery of the UNIX
227         * signal @signum.  In GLib versions before 2.36, only `SIGHUP`, `SIGINT`,
228         * `SIGTERM` can be monitored.  In GLib 2.36, `SIGUSR1` and `SIGUSR2`
229         * were added.
230         *
231         * Note that unlike the UNIX default, all sources which have created a
232         * watch will be dispatched, regardless of which underlying thread
233         * invoked g_unix_signal_source_new().
234         *
235         * For example, an effective use of this function is to handle `SIGTERM`
236         * cleanly; flushing any outstanding files, and then calling
237         * g_main_loop_quit ().  It is not safe to do any of this a regular
238         * UNIX signal handler; your handler may be invoked while malloc() or
239         * another library function is running, causing reentrancy if you
240         * attempt to use it from the handler.  None of the GLib/GObject API
241         * is safe against this kind of reentrancy.
242         *
243         * The interaction of this source when combined with native UNIX
244         * functions like sigprocmask() is not defined.
245         *
246         * The source will not initially be associated with any #GMainContext
247         * and must be added to one with g_source_attach() before it will be
248         * executed.
249         *
250         * Params:
251         *     signum = A signal number
252         *
253         * Returns: A newly created #GSource
254         *
255         * Since: 2.30
256         */
257        public static Source signalSourceNew(int signum)
258        {
259                auto p = g_unix_signal_source_new(signum);
260               
261                if(p is null)
262                {
263                        return null;
264                }
265               
266                return new Source(cast(GSource*) p, true);
267        }
268}
Note: See TracBrowser for help on using the repository browser.