source: appstream-generator/build/girepo/gio/PollableOutputStreamT.d @ 4841

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

Initial release

File size: 5.1 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 gio.PollableOutputStreamT;
22
23public  import gi.gio;
24public  import gi.giotypes;
25public  import gio.Cancellable;
26public  import glib.ErrorG;
27public  import glib.GException;
28public  import glib.Source;
29
30
31/**
32 * #GPollableOutputStream is implemented by #GOutputStreams that
33 * can be polled for readiness to write. This can be used when
34 * interfacing with a non-GIO API that expects
35 * UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.
36 *
37 * Since: 2.28
38 */
39public template PollableOutputStreamT(TStruct)
40{
41        /** Get the main Gtk struct */
42        public GPollableOutputStream* getPollableOutputStreamStruct()
43        {
44                return cast(GPollableOutputStream*)getStruct();
45        }
46
47
48        /**
49         * Checks if @stream is actually pollable. Some classes may implement
50         * #GPollableOutputStream but have only certain instances of that
51         * class be pollable. If this method returns %FALSE, then the behavior
52         * of other #GPollableOutputStream methods is undefined.
53         *
54         * For any given stream, the value returned by this method is constant;
55         * a stream cannot switch from pollable to non-pollable or vice versa.
56         *
57         * Returns: %TRUE if @stream is pollable, %FALSE if not.
58         *
59         * Since: 2.28
60         */
61        public bool canPoll()
62        {
63                return g_pollable_output_stream_can_poll(getPollableOutputStreamStruct()) != 0;
64        }
65
66        /**
67         * Creates a #GSource that triggers when @stream can be written, or
68         * @cancellable is triggered or an error occurs. The callback on the
69         * source is of the #GPollableSourceFunc type.
70         *
71         * As with g_pollable_output_stream_is_writable(), it is possible that
72         * the stream may not actually be writable even after the source
73         * triggers, so you should use g_pollable_output_stream_write_nonblocking()
74         * rather than g_output_stream_write() from the callback.
75         *
76         * Params:
77         *     cancellable = a #GCancellable, or %NULL
78         *
79         * Returns: a new #GSource
80         *
81         * Since: 2.28
82         */
83        public Source createSource(Cancellable cancellable)
84        {
85                auto p = g_pollable_output_stream_create_source(getPollableOutputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct());
86               
87                if(p is null)
88                {
89                        return null;
90                }
91               
92                return new Source(cast(GSource*) p, true);
93        }
94
95        /**
96         * Checks if @stream can be written.
97         *
98         * Note that some stream types may not be able to implement this 100%
99         * reliably, and it is possible that a call to g_output_stream_write()
100         * after this returns %TRUE would still block. To guarantee
101         * non-blocking behavior, you should always use
102         * g_pollable_output_stream_write_nonblocking(), which will return a
103         * %G_IO_ERROR_WOULD_BLOCK error rather than blocking.
104         *
105         * Returns: %TRUE if @stream is writable, %FALSE if not. If an error
106         *     has occurred on @stream, this will result in
107         *     g_pollable_output_stream_is_writable() returning %TRUE, and the
108         *     next attempt to write will return the error.
109         *
110         * Since: 2.28
111         */
112        public bool isWritable()
113        {
114                return g_pollable_output_stream_is_writable(getPollableOutputStreamStruct()) != 0;
115        }
116
117        /**
118         * Attempts to write up to @count bytes from @buffer to @stream, as
119         * with g_output_stream_write(). If @stream is not currently writable,
120         * this will immediately return %G_IO_ERROR_WOULD_BLOCK, and you can
121         * use g_pollable_output_stream_create_source() to create a #GSource
122         * that will be triggered when @stream is writable.
123         *
124         * Note that since this method never blocks, you cannot actually
125         * use @cancellable to cancel it. However, it will return an error
126         * if @cancellable has already been cancelled when you call, which
127         * may happen if you call this method after a source triggers due
128         * to having been cancelled.
129         *
130         * Params:
131         *     buffer = a buffer to write
132         *         data from
133         *     count = the number of bytes you want to write
134         *     cancellable = a #GCancellable, or %NULL
135         *
136         * Returns: the number of bytes written, or -1 on error (including
137         *     %G_IO_ERROR_WOULD_BLOCK).
138         *
139         * Throws: GException on failure.
140         */
141        public ptrdiff_t writeNonblocking(ubyte[] buffer, Cancellable cancellable)
142        {
143                GError* err = null;
144               
145                auto p = g_pollable_output_stream_write_nonblocking(getPollableOutputStreamStruct(), buffer.ptr, cast(size_t)buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
146               
147                if (err !is null)
148                {
149                        throw new GException( new ErrorG(err) );
150                }
151               
152                return p;
153        }
154}
Note: See TracBrowser for help on using the repository browser.