How to use Gnome GIO to read a file by chunks in non-blocking way?
<p>What is the right (GIO/Glib/GTK/Gnome) way to process GInputStream in non-blocking manner and chunk-by-chunk?</p>

<p>I have an application which is downloading (through libsoup) and processing a data stream in chunks and doing other actions in parallel. I am calling <code>g_input_stream_read_async</code> on GInputStream (received from <code>soup_session_send_finish</code> and giving it a reasonable size of chunk to read (in my case 2048 bytes). </p>

<p>After I receive a <code>g_input_stream_read_async</code> callback, I want to continue reading bytes. So, the first idea is to recursively call <code>g_input_stream_read_async</code> from the callback handler, passing itself as next callback. But that seems clumsy and not quite right to me (and I'm not sure if it's safe to pass to GIO the callback which is currently still executing).</p>

<p>Alternative could be to spin off a thread and do usual blocking reads in a loop calling <code>g_input_stream_read</code>.</p>

<p>But how it is usually done in GTK / Gnome world? What is the right way? Any simple working example (preferably from developers related to GTK / Gnome) will be appreciated.</p>