1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>GPollableOutputStream</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="GIO Reference Manual">
8 <link rel="up" href="streaming.html" title="Streaming I/O">
9 <link rel="prev" href="GPollableInputStream.html" title="GPollableInputStream">
10 <link rel="next" href="types.html" title="File types and applications">
11 <meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
17 <td><a accesskey="p" href="GPollableInputStream.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18 <td><a accesskey="u" href="streaming.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20 <th width="100%" align="center">GIO Reference Manual</th>
21 <td><a accesskey="n" href="types.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
23 <tr><td colspan="5" class="shortcuts">
24 <a href="#GPollableOutputStream.synopsis" class="shortcut">Top</a>
26 <a href="#GPollableOutputStream.description" class="shortcut">Description</a>
28 <a href="#GPollableOutputStream.object-hierarchy" class="shortcut">Object Hierarchy</a>
30 <a href="#GPollableOutputStream.prerequisites" class="shortcut">Prerequisites</a>
32 <a href="#GPollableOutputStream.implementations" class="shortcut">Known Implementations</a>
35 <div class="refentry">
36 <a name="GPollableOutputStream"></a><div class="titlepage"></div>
37 <div class="refnamediv"><table width="100%"><tr>
39 <h2><span class="refentrytitle"><a name="GPollableOutputStream.top_of_page"></a>GPollableOutputStream</span></h2>
40 <p>GPollableOutputStream — Interface for pollable output streams</p>
42 <td valign="top" align="right"></td>
44 <div class="refsynopsisdiv">
45 <a name="GPollableOutputStream.synopsis"></a><h2>Synopsis</h2>
46 <pre class="synopsis">
47 #include <gio/gio.h>
49 <a class="link" href="GPollableOutputStream.html#GPollableOutputStream-struct" title="GPollableOutputStream">GPollableOutputStream</a>;
50 struct <a class="link" href="GPollableOutputStream.html#GPollableOutputStreamInterface" title="struct GPollableOutputStreamInterface">GPollableOutputStreamInterface</a>;
52 <a href="./../glib/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-can-poll" title="g_pollable_output_stream_can_poll ()">g_pollable_output_stream_can_poll</a> (<em class="parameter"><code><a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> *stream</code></em>);
53 <a href="./../glib/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-is-writable" title="g_pollable_output_stream_is_writable ()">g_pollable_output_stream_is_writable</a>
54 (<em class="parameter"><code><a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> *stream</code></em>);
55 <a href="./../glib/glib/glib-The-Main-Event-Loop.html#GSource"><span class="returnvalue">GSource</span></a> * <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-create-source" title="g_pollable_output_stream_create_source ()">g_pollable_output_stream_create_source</a>
56 (<em class="parameter"><code><a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> *stream</code></em>,
57 <em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>);
58 <a href="./../glib/glib/glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a> <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-write-nonblocking" title="g_pollable_output_stream_write_nonblocking ()">g_pollable_output_stream_write_nonblocking</a>
59 (<em class="parameter"><code><a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> *stream</code></em>,
60 <em class="parameter"><code>const <span class="type">void</span> *buffer</code></em>,
61 <em class="parameter"><code><a href="./../glib/glib/glib-Basic-Types.html#gsize"><span class="type">gsize</span></a> size</code></em>,
62 <em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
63 <em class="parameter"><code><a href="./../glib/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);
66 <div class="refsect1">
67 <a name="GPollableOutputStream.object-hierarchy"></a><h2>Object Hierarchy</h2>
68 <pre class="synopsis">
70 +----GPollableOutputStream
73 <div class="refsect1">
74 <a name="GPollableOutputStream.prerequisites"></a><h2>Prerequisites</h2>
76 GPollableOutputStream requires
77 <a class="link" href="GOutputStream.html" title="GOutputStream">GOutputStream</a>.</p>
79 <div class="refsect1">
80 <a name="GPollableOutputStream.implementations"></a><h2>Known Implementations</h2>
82 GPollableOutputStream is implemented by
83 <a class="link" href="GUnixOutputStream.html" title="GUnixOutputStream">GUnixOutputStream</a>.</p>
85 <div class="refsect1">
86 <a name="GPollableOutputStream.description"></a><h2>Description</h2>
88 <a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> is implemented by <a class="link" href="GOutputStream.html" title="GOutputStream"><span class="type">GOutputStream</span></a>s that
89 can be polled for readiness to write. This can be used when
90 interfacing with a non-GIO API that expects
91 UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.
94 <div class="refsect1">
95 <a name="GPollableOutputStream.details"></a><h2>Details</h2>
96 <div class="refsect2">
97 <a name="GPollableOutputStream-struct"></a><h3>GPollableOutputStream</h3>
98 <pre class="programlisting">typedef struct _GPollableOutputStream GPollableOutputStream;</pre>
100 An interface for a <a class="link" href="GOutputStream.html" title="GOutputStream"><span class="type">GOutputStream</span></a> that can be polled for readability.
102 <p class="since">Since 2.28</p>
105 <div class="refsect2">
106 <a name="GPollableOutputStreamInterface"></a><h3>struct GPollableOutputStreamInterface</h3>
107 <pre class="programlisting">struct GPollableOutputStreamInterface {
108 GTypeInterface g_iface;
111 gboolean (*can_poll) (GPollableOutputStream *stream);
113 gboolean (*is_writable) (GPollableOutputStream *stream);
114 GSource * (*create_source) (GPollableOutputStream *stream,
115 GCancellable *cancellable);
116 gssize (*write_nonblocking) (GPollableOutputStream *stream,
123 The interface for pollable output streams.
126 The default implementation of <em class="parameter"><code>can_poll</code></em> always returns <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>.
129 The default implementation of <em class="parameter"><code>write_nonblocking</code></em> calls
130 <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-is-writable" title="g_pollable_output_stream_is_writable ()"><code class="function">g_pollable_output_stream_is_writable()</code></a>, and then calls
131 <a class="link" href="GOutputStream.html#g-output-stream-write" title="g_output_stream_write ()"><code class="function">g_output_stream_write()</code></a> if it returns <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>. This means you only
132 need to override it if it is possible that your <em class="parameter"><code>is_writable</code></em>
133 implementation may return <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> when the stream is not actually
136 <div class="variablelist"><table border="0">
137 <col align="left" valign="top">
140 <td><p><span class="term"><a href="./../gobject/gobject/gobject-Type-Information.html#GTypeInterface"><span class="type">GTypeInterface</span></a> <em class="structfield"><code><a name="GPollableOutputStreamInterface.g-iface"></a>g_iface</code></em>;</span></p></td>
141 <td>The parent interface.</td>
144 <td><p><span class="term"><em class="structfield"><code><a name="GPollableOutputStreamInterface.can-poll"></a>can_poll</code></em> ()</span></p></td>
145 <td>Checks if the <a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> instance is actually pollable</td>
148 <td><p><span class="term"><em class="structfield"><code><a name="GPollableOutputStreamInterface.is-writable"></a>is_writable</code></em> ()</span></p></td>
149 <td>Checks if the stream is writable</td>
152 <td><p><span class="term"><em class="structfield"><code><a name="GPollableOutputStreamInterface.create-source"></a>create_source</code></em> ()</span></p></td>
153 <td>Creates a <a href="./../glib/glib/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a> to poll the stream</td>
156 <td><p><span class="term"><em class="structfield"><code><a name="GPollableOutputStreamInterface.write-nonblocking"></a>write_nonblocking</code></em> ()</span></p></td>
157 <td>Does a non-blocking write or returns
158 <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a>
163 <p class="since">Since 2.28</p>
166 <div class="refsect2">
167 <a name="g-pollable-output-stream-can-poll"></a><h3>g_pollable_output_stream_can_poll ()</h3>
168 <pre class="programlisting"><a href="./../glib/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> g_pollable_output_stream_can_poll (<em class="parameter"><code><a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> *stream</code></em>);</pre>
170 Checks if <em class="parameter"><code>stream</code></em> is actually pollable. Some classes may implement
171 <a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> but have only certain instances of that
172 class be pollable. If this method returns <a href="./../glib/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>, then the behavior
173 of other <a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> methods is undefined.
176 For any given stream, the value returned by this method is constant;
177 a stream cannot switch from pollable to non-pollable or vice versa.
179 <div class="variablelist"><table border="0">
180 <col align="left" valign="top">
183 <td><p><span class="term"><em class="parameter"><code>stream</code></em> :</span></p></td>
184 <td>a <a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a>.</td>
187 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
189 <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if <em class="parameter"><code>stream</code></em> is pollable, <a href="./../glib/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if not.</td>
193 <p class="since">Since 2.28</p>
196 <div class="refsect2">
197 <a name="g-pollable-output-stream-is-writable"></a><h3>g_pollable_output_stream_is_writable ()</h3>
198 <pre class="programlisting"><a href="./../glib/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a> g_pollable_output_stream_is_writable
199 (<em class="parameter"><code><a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> *stream</code></em>);</pre>
201 Checks if <em class="parameter"><code>stream</code></em> can be written.
204 Note that some stream types may not be able to implement this 100%
205 reliably, and it is possible that a call to <a class="link" href="GOutputStream.html#g-output-stream-write" title="g_output_stream_write ()"><code class="function">g_output_stream_write()</code></a>
206 after this returns <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> would still block. To guarantee
207 non-blocking behavior, you should always use
208 <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-write-nonblocking" title="g_pollable_output_stream_write_nonblocking ()"><code class="function">g_pollable_output_stream_write_nonblocking()</code></a>, which will return a
209 <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a> error rather than blocking.
211 <div class="variablelist"><table border="0">
212 <col align="left" valign="top">
215 <td><p><span class="term"><em class="parameter"><code>stream</code></em> :</span></p></td>
216 <td>a <a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a>.</td>
219 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
221 <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if <em class="parameter"><code>stream</code></em> is writable, <a href="./../glib/glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if not. If an error
222 has occurred on <em class="parameter"><code>stream</code></em>, this will result in
223 <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-is-writable" title="g_pollable_output_stream_is_writable ()"><code class="function">g_pollable_output_stream_is_writable()</code></a> returning <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, and the
224 next attempt to write will return the error.</td>
228 <p class="since">Since 2.28</p>
231 <div class="refsect2">
232 <a name="g-pollable-output-stream-create-source"></a><h3>g_pollable_output_stream_create_source ()</h3>
233 <pre class="programlisting"><a href="./../glib/glib/glib-The-Main-Event-Loop.html#GSource"><span class="returnvalue">GSource</span></a> * g_pollable_output_stream_create_source
234 (<em class="parameter"><code><a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> *stream</code></em>,
235 <em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>);</pre>
237 Creates a <a href="./../glib/glib/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a> that triggers when <em class="parameter"><code>stream</code></em> can be written, or
238 <em class="parameter"><code>cancellable</code></em> is triggered or an error occurs. The callback on the
239 source is of the <a class="link" href="GPollableInputStream.html#GPollableSourceFunc" title="GPollableSourceFunc ()"><span class="type">GPollableSourceFunc</span></a> type.
242 As with <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-is-writable" title="g_pollable_output_stream_is_writable ()"><code class="function">g_pollable_output_stream_is_writable()</code></a>, it is possible that
243 the stream may not actually be writable even after the source
244 triggers, so you should use <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-write-nonblocking" title="g_pollable_output_stream_write_nonblocking ()"><code class="function">g_pollable_output_stream_write_nonblocking()</code></a>
245 rather than <a class="link" href="GOutputStream.html#g-output-stream-write" title="g_output_stream_write ()"><code class="function">g_output_stream_write()</code></a> from the callback.
247 <div class="variablelist"><table border="0">
248 <col align="left" valign="top">
251 <td><p><span class="term"><em class="parameter"><code>stream</code></em> :</span></p></td>
252 <td>a <a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a>.</td>
255 <td><p><span class="term"><em class="parameter"><code>cancellable</code></em> :</span></p></td>
256 <td>a <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a>, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
260 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
261 <td>a new <a href="./../glib/glib/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a>. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
266 <p class="since">Since 2.28</p>
269 <div class="refsect2">
270 <a name="g-pollable-output-stream-write-nonblocking"></a><h3>g_pollable_output_stream_write_nonblocking ()</h3>
271 <pre class="programlisting"><a href="./../glib/glib/glib-Basic-Types.html#gssize"><span class="returnvalue">gssize</span></a> g_pollable_output_stream_write_nonblocking
272 (<em class="parameter"><code><a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a> *stream</code></em>,
273 <em class="parameter"><code>const <span class="type">void</span> *buffer</code></em>,
274 <em class="parameter"><code><a href="./../glib/glib/glib-Basic-Types.html#gsize"><span class="type">gsize</span></a> size</code></em>,
275 <em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
276 <em class="parameter"><code><a href="./../glib/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
278 Attempts to write up to <em class="parameter"><code>size</code></em> bytes from <em class="parameter"><code>buffer</code></em> to <em class="parameter"><code>stream</code></em>, as
279 with <a class="link" href="GOutputStream.html#g-output-stream-write" title="g_output_stream_write ()"><code class="function">g_output_stream_write()</code></a>. If <em class="parameter"><code>stream</code></em> is not currently writable,
280 this will immediately return <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a>, and you can
281 use <a class="link" href="GPollableOutputStream.html#g-pollable-output-stream-create-source" title="g_pollable_output_stream_create_source ()"><code class="function">g_pollable_output_stream_create_source()</code></a> to create a <a href="./../glib/glib/glib-The-Main-Event-Loop.html#GSource"><span class="type">GSource</span></a>
282 that will be triggered when <em class="parameter"><code>stream</code></em> is writable.
285 Note that since this method never blocks, you cannot actually
286 use <em class="parameter"><code>cancellable</code></em> to cancel it. However, it will return an error
287 if <em class="parameter"><code>cancellable</code></em> has already been cancelled when you call, which
288 may happen if you call this method after a source triggers due
289 to having been cancelled.
292 Virtual: write_nonblocking
294 <div class="variablelist"><table border="0">
295 <col align="left" valign="top">
298 <td><p><span class="term"><em class="parameter"><code>stream</code></em> :</span></p></td>
299 <td>a <a class="link" href="GPollableOutputStream.html" title="GPollableOutputStream"><span class="type">GPollableOutputStream</span></a>
303 <td><p><span class="term"><em class="parameter"><code>buffer</code></em> :</span></p></td>
304 <td>a buffer to write
305 data from. <span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=size][<acronym title="Generics and defining elements of containers and arrays."><span class="acronym">element-type</span></acronym> guint8]</span>
309 <td><p><span class="term"><em class="parameter"><code>size</code></em> :</span></p></td>
310 <td>the number of bytes you want to write</td>
313 <td><p><span class="term"><em class="parameter"><code>cancellable</code></em> :</span></p></td>
314 <td>a <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a>, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
318 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
320 <a href="./../glib/glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for error reporting, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> to ignore.</td>
323 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
324 <td>the number of bytes written, or -1 on error (including
325 <a class="link" href="gio-GIOError.html#G-IO-ERROR-WOULD-BLOCK:CAPS"><code class="literal">G_IO_ERROR_WOULD_BLOCK</code></a>).</td>
331 <div class="refsect1">
332 <a name="GPollableOutputStream.see-also"></a><h2>See Also</h2>
333 <a class="link" href="GOutputStream.html" title="GOutputStream"><span class="type">GOutputStream</span></a>, <a class="link" href="GFileDescriptorBased.html" title="GFileDescriptorBased"><span class="type">GFileDescriptorBased</span></a>, <a class="link" href="GPollableInputStream.html" title="GPollableInputStream"><span class="type">GPollableInputStream</span></a>
338 Generated by GTK-Doc V1.18</div>