1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.PollableOutputStreamT; 26 27 public import gio.Cancellable; 28 public import gio.c.functions; 29 public import gio.c.types; 30 public import glib.ErrorG; 31 public import glib.GException; 32 public import glib.Source; 33 34 35 /** 36 * #GPollableOutputStream is implemented by #GOutputStreams that 37 * can be polled for readiness to write. This can be used when 38 * interfacing with a non-GIO API that expects 39 * UNIX-file-descriptor-style asynchronous I/O rather than GIO-style. 40 * 41 * Since: 2.28 42 */ 43 public template PollableOutputStreamT(TStruct) 44 { 45 /** Get the main Gtk struct */ 46 public GPollableOutputStream* getPollableOutputStreamStruct(bool transferOwnership = false) 47 { 48 if (transferOwnership) 49 ownedRef = false; 50 return cast(GPollableOutputStream*)getStruct(); 51 } 52 53 54 /** 55 * Checks if @stream is actually pollable. Some classes may implement 56 * #GPollableOutputStream but have only certain instances of that 57 * class be pollable. If this method returns %FALSE, then the behavior 58 * of other #GPollableOutputStream methods is undefined. 59 * 60 * For any given stream, the value returned by this method is constant; 61 * a stream cannot switch from pollable to non-pollable or vice versa. 62 * 63 * Returns: %TRUE if @stream is pollable, %FALSE if not. 64 * 65 * Since: 2.28 66 */ 67 public bool canPoll() 68 { 69 return g_pollable_output_stream_can_poll(getPollableOutputStreamStruct()) != 0; 70 } 71 72 /** 73 * Creates a #GSource that triggers when @stream can be written, or 74 * @cancellable is triggered or an error occurs. The callback on the 75 * source is of the #GPollableSourceFunc type. 76 * 77 * As with g_pollable_output_stream_is_writable(), it is possible that 78 * the stream may not actually be writable even after the source 79 * triggers, so you should use g_pollable_output_stream_write_nonblocking() 80 * rather than g_output_stream_write() from the callback. 81 * 82 * Params: 83 * cancellable = a #GCancellable, or %NULL 84 * 85 * Returns: a new #GSource 86 * 87 * Since: 2.28 88 */ 89 public Source createSource(Cancellable cancellable) 90 { 91 auto __p = g_pollable_output_stream_create_source(getPollableOutputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct()); 92 93 if(__p is null) 94 { 95 return null; 96 } 97 98 return new Source(cast(GSource*) __p, true); 99 } 100 101 /** 102 * Checks if @stream can be written. 103 * 104 * Note that some stream types may not be able to implement this 100% 105 * reliably, and it is possible that a call to g_output_stream_write() 106 * after this returns %TRUE would still block. To guarantee 107 * non-blocking behavior, you should always use 108 * g_pollable_output_stream_write_nonblocking(), which will return a 109 * %G_IO_ERROR_WOULD_BLOCK error rather than blocking. 110 * 111 * Returns: %TRUE if @stream is writable, %FALSE if not. If an error 112 * has occurred on @stream, this will result in 113 * g_pollable_output_stream_is_writable() returning %TRUE, and the 114 * next attempt to write will return the error. 115 * 116 * Since: 2.28 117 */ 118 public bool isWritable() 119 { 120 return g_pollable_output_stream_is_writable(getPollableOutputStreamStruct()) != 0; 121 } 122 123 /** 124 * Attempts to write up to @count bytes from @buffer to @stream, as 125 * with g_output_stream_write(). If @stream is not currently writable, 126 * this will immediately return %G_IO_ERROR_WOULD_BLOCK, and you can 127 * use g_pollable_output_stream_create_source() to create a #GSource 128 * that will be triggered when @stream is writable. 129 * 130 * Note that since this method never blocks, you cannot actually 131 * use @cancellable to cancel it. However, it will return an error 132 * if @cancellable has already been cancelled when you call, which 133 * may happen if you call this method after a source triggers due 134 * to having been cancelled. 135 * 136 * Also note that if %G_IO_ERROR_WOULD_BLOCK is returned some underlying 137 * transports like D/TLS require that you re-send the same @buffer and 138 * @count in the next write call. 139 * 140 * Params: 141 * buffer = a buffer to write 142 * data from 143 * cancellable = a #GCancellable, or %NULL 144 * 145 * Returns: the number of bytes written, or -1 on error (including 146 * %G_IO_ERROR_WOULD_BLOCK). 147 * 148 * Throws: GException on failure. 149 */ 150 public ptrdiff_t writeNonblocking(ubyte[] buffer, Cancellable cancellable) 151 { 152 GError* err = null; 153 154 auto __p = g_pollable_output_stream_write_nonblocking(getPollableOutputStreamStruct(), buffer.ptr, cast(size_t)buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 155 156 if (err !is null) 157 { 158 throw new GException( new ErrorG(err) ); 159 } 160 161 return __p; 162 } 163 164 /** 165 * Attempts to write the bytes contained in the @n_vectors @vectors to @stream, 166 * as with g_output_stream_writev(). If @stream is not currently writable, 167 * this will immediately return %@G_POLLABLE_RETURN_WOULD_BLOCK, and you can 168 * use g_pollable_output_stream_create_source() to create a #GSource 169 * that will be triggered when @stream is writable. @error will *not* be 170 * set in that case. 171 * 172 * Note that since this method never blocks, you cannot actually 173 * use @cancellable to cancel it. However, it will return an error 174 * if @cancellable has already been cancelled when you call, which 175 * may happen if you call this method after a source triggers due 176 * to having been cancelled. 177 * 178 * Also note that if %G_POLLABLE_RETURN_WOULD_BLOCK is returned some underlying 179 * transports like D/TLS require that you re-send the same @vectors and 180 * @n_vectors in the next write call. 181 * 182 * Params: 183 * vectors = the buffer containing the #GOutputVectors to write. 184 * bytesWritten = location to store the number of bytes that were 185 * written to the stream 186 * cancellable = a #GCancellable, or %NULL 187 * 188 * Returns: %@G_POLLABLE_RETURN_OK on success, %G_POLLABLE_RETURN_WOULD_BLOCK 189 * if the stream is not currently writable (and @error is *not* set), or 190 * %G_POLLABLE_RETURN_FAILED if there was an error in which case @error will 191 * be set. 192 * 193 * Since: 2.60 194 * 195 * Throws: GException on failure. 196 */ 197 public GPollableReturn writevNonblocking(GOutputVector[] vectors, out size_t bytesWritten, Cancellable cancellable) 198 { 199 GError* err = null; 200 201 auto __p = g_pollable_output_stream_writev_nonblocking(getPollableOutputStreamStruct(), vectors.ptr, cast(size_t)vectors.length, &bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 202 203 if (err !is null) 204 { 205 throw new GException( new ErrorG(err) ); 206 } 207 208 return __p; 209 } 210 }