GNOME Bugzilla – Bug 673997
pollable stream additions
Last modified: 2012-04-17 16:34:26 UTC
This (in particular, making GConverterInputStream pollable) is needed for some upcoming libsoup stuff. The last patch is also a nice general cleanup. (I thought about adding "skip_nonblocking" and "flush_nonblocking" to GPollableInput/OutputStream, and likewise reimplementing skip_async and flush_async on top of them when possible... ?) Not totally sure about the naming of g_pollable_stream_read() / g_pollable_stream_write(). Calling it "g_pollable_input_stream_read()" seemed wrong, since the argument doesn't have to be a GPollableInputStream. Maybe "g_input_stream_pollable_read()" would be better? or "g_input_stream_read_with_blocking()" to match "g_socket_receive_with_blocking()", but I never liked that name anyway... I'll add a test for the converter stream pollable implementations before committing.
Created attachment 211937 [details] [review] gio: minor GPollableInputStream / GPollableOutputStream fixes Make g_pollable_input_stream_read() and g_pollable_output_stream_write() look a little bit more like the non-pollable versions in terms of error handling, etc. Also, use the read_fn and write_fn virtual methods directly rather than calling g_input_stream_read()/g_output_stream_write(), to avoid problems with re-entrancy involving the "pending" flag. Also belatedly add single-include guards to the header files.
Created attachment 211938 [details] [review] gpollableutils: utility functions for pollable stream implementations Move g_pollable_source_new() here from gpollableinputstream.c, add g_pollable_source_new_full(), and add some new methods to do either blocking or nonblocking reads depending on a boolean argument.
Created attachment 211939 [details] [review] gio: implement GPollableInput/OutputStream in more stream types Implement GPollableInputStream in GMemoryInputStream and GConverterInputStream, and likewise implement GPollableOutputStream in the corresponding output streams.
Created attachment 211940 [details] [review] gio: use GPollable* to implement fallback read_async/write_async If a GInputStream does not provide a read_async() implementation, but does implement GPollableInputStream, then instead of doing read-synchronously-in-a-thread, just use g_pollable_input_stream_read_nonblocking() and g_pollable_input_stream_create_source() to implement an async read in the same thread. Similarly for GOutputStream. Remove a bunch of existing read_async()/write_async() implementations that are basically equivalent to the new fallback method.
Review of attachment 211938 [details] [review]: ::: gio/gpollableutils.h @@ +54,3 @@ + gsize *bytes_written, + GCancellable *cancellable, + GError **error); G_AVAILABLE_IN_2_34 ?
Review of attachment 211937 [details] [review]: looks fine to me
Review of attachment 211939 [details] [review]: Looks ok to me
Review of attachment 211940 [details] [review]: nice
pushed with GLIB_AVAILABLE_IN_2_34 and a GConverterInputStream pollability test (and a fix for a pre-existing GConverterInputStream bug that it uncovered)