/** * g_pollable_input_stream_can_poll: * @stream: a #GPollableInputStream. * * Checks if @stream is actually pollable. Some classes may implement * #GPollableInputStream but have only certain instances of that class * be pollable. If this method returns %FALSE, then the behavior of * other #GPollableInputStream methods is undefined. * * For any given stream, the value returned by this method is constant; * a stream cannot switch from pollable to non-pollable or vice versa. * * Returns: %TRUE if @stream is pollable, %FALSE if not. * * Since: 2.28 */ gboolean g_pollable_input_stream_can_poll (GPollableInputStream *stream) { g_return_val_if_fail (G_IS_POLLABLE_INPUT_STREAM (stream), FALSE); return G_POLLABLE_INPUT_STREAM_GET_INTERFACE (stream)->can_poll (stream); }
/** * g_pollable_input_stream_create_source: * @stream: a #GPollableInputStream. * @cancellable: (allow-none): a #GCancellable, or %NULL * * Creates a #GSource that triggers when @stream can be read, or * @cancellable is triggered or an error occurs. The callback on the * source is of the #GPollableSourceFunc type. * * As with g_pollable_input_stream_is_readable(), it is possible that * the stream may not actually be readable even after the source * triggers, so you should use g_pollable_input_stream_read_nonblocking() * rather than g_input_stream_read() from the callback. * * Returns: (transfer full): a new #GSource * * Since: 2.28 */ GSource * g_pollable_input_stream_create_source (GPollableInputStream *stream, GCancellable *cancellable) { g_return_val_if_fail (G_IS_POLLABLE_INPUT_STREAM (stream), NULL); return G_POLLABLE_INPUT_STREAM_GET_INTERFACE (stream)-> create_source (stream, cancellable); }
/** * g_pollable_input_stream_read_nonblocking: * @stream: a #GPollableInputStream * @buffer: a buffer to read data into (which should be at least @size * bytes long). * @size: the number of bytes you want to read * @cancellable: (allow-none): a #GCancellable, or %NULL * @error: #GError for error reporting, or %NULL to ignore. * * Attempts to read up to @size bytes from @stream into @buffer, as * with g_input_stream_read(). If @stream is not currently readable, * this will immediately return %G_IO_ERROR_WOULD_BLOCK, and you can * use g_pollable_input_stream_create_source() to create a #GSource * that will be triggered when @stream is readable. * * Note that since this method never blocks, you cannot actually * use @cancellable to cancel it. However, it will return an error * if @cancellable has already been cancelled when you call, which * may happen if you call this method after a source triggers due * to having been cancelled. * * Virtual: read_nonblocking * Return value: the number of bytes read, or -1 on error (including * %G_IO_ERROR_WOULD_BLOCK). */ gssize g_pollable_input_stream_read_nonblocking (GPollableInputStream *stream, void *buffer, gsize size, GCancellable *cancellable, GError **error) { g_return_val_if_fail (G_IS_POLLABLE_INPUT_STREAM (stream), -1); if (g_cancellable_set_error_if_cancelled (cancellable, error)) return -1; return G_POLLABLE_INPUT_STREAM_GET_INTERFACE (stream)-> read_nonblocking (stream, buffer, size, error); }
/** * g_pollable_input_stream_read_nonblocking: * @stream: a #GPollableInputStream * @buffer: a buffer to read data into (which should be at least @count * bytes long). * @count: the number of bytes you want to read * @cancellable: (allow-none): a #GCancellable, or %NULL * @error: #GError for error reporting, or %NULL to ignore. * * Attempts to read up to @count bytes from @stream into @buffer, as * with g_input_stream_read(). If @stream is not currently readable, * this will immediately return %G_IO_ERROR_WOULD_BLOCK, and you can * use g_pollable_input_stream_create_source() to create a #GSource * that will be triggered when @stream is readable. * * Note that since this method never blocks, you cannot actually * use @cancellable to cancel it. However, it will return an error * if @cancellable has already been cancelled when you call, which * may happen if you call this method after a source triggers due * to having been cancelled. * * Virtual: read_nonblocking * Returns: the number of bytes read, or -1 on error (including * %G_IO_ERROR_WOULD_BLOCK). */ gssize g_pollable_input_stream_read_nonblocking (GPollableInputStream *stream, void *buffer, gsize count, GCancellable *cancellable, GError **error) { gssize res; g_return_val_if_fail (G_IS_POLLABLE_INPUT_STREAM (stream), -1); g_return_val_if_fail (buffer != NULL, 0); if (g_cancellable_set_error_if_cancelled (cancellable, error)) return -1; if (count == 0) return 0; if (((gssize) count) < 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Too large count value passed to %s"), G_STRFUNC); return -1; } if (cancellable) g_cancellable_push_current (cancellable); res = G_POLLABLE_INPUT_STREAM_GET_INTERFACE (stream)-> read_nonblocking (stream, buffer, count, error); if (cancellable) g_cancellable_pop_current (cancellable); return res; }