gpollable: Clarify that can_poll() must be called before other methods

Both `GPollableInputStream` and `GPollableOutputStream` are dynamic
interfaces, in that their implementation on a class may only be
functional if certain prerequisites are met at runtime. For example,
a `GConverterInputStream` is only pollable if its base stream is
pollable, and that’s determined at runtime rather than compile time.

As such, both interfaces have a `can_poll()` method. If that method
returns `FALSE`, the behaviour of all other methods on the interface is
undefined.

That was mentioned in the documentation for `can_poll()`, but not any of
the other documentation for the interfaces, which made it a bit hard to
find.

Mention it more widely.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Fixes: #2952
This commit is contained in:
Philip Withnall
2023-03-23 12:08:08 +00:00
parent bd63436fad
commit e2d06873f9
2 changed files with 31 additions and 0 deletions

View File

@@ -37,6 +37,11 @@
* interfacing with a non-GIO API that expects
* UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.
*
* Some classes may implement #GPollableInputStream but have only certain
* instances of that class be pollable. If g_pollable_input_stream_can_poll()
* returns %FALSE, then the behavior of other #GPollableInputStream methods is
* undefined.
*
* Since: 2.28
*/
@@ -98,6 +103,9 @@ g_pollable_input_stream_can_poll (GPollableInputStream *stream)
* g_pollable_input_stream_read_nonblocking(), which will return a
* %G_IO_ERROR_WOULD_BLOCK error rather than blocking.
*
* The behaviour of this method is undefined if
* g_pollable_input_stream_can_poll() returns %FALSE for @stream.
*
* Returns: %TRUE if @stream is readable, %FALSE if not. If an error
* has occurred on @stream, this will result in
* g_pollable_input_stream_is_readable() returning %TRUE, and the
@@ -127,6 +135,9 @@ g_pollable_input_stream_is_readable (GPollableInputStream *stream)
* triggers, so you should use g_pollable_input_stream_read_nonblocking()
* rather than g_input_stream_read() from the callback.
*
* The behaviour of this method is undefined if
* g_pollable_input_stream_can_poll() returns %FALSE for @stream.
*
* Returns: (transfer full): a new #GSource
*
* Since: 2.28
@@ -179,6 +190,9 @@ g_pollable_input_stream_default_read_nonblocking (GPollableInputStream *stream,
* may happen if you call this method after a source triggers due
* to having been cancelled.
*
* The behaviour of this method is undefined if
* g_pollable_input_stream_can_poll() returns %FALSE for @stream.
*
* Virtual: read_nonblocking
* Returns: the number of bytes read, or -1 on error (including
* %G_IO_ERROR_WOULD_BLOCK).