The high-level GIO API and threading



Hello devs,

I've been browsing the GIO and glib-networking source code for a
while, and I'd like to get some clarification on the usage of the
GIOStream API with respect to threading. It was my understanding that
the API allows running a g_input_stream_read() in one thread while
doing a g_output_stream_write() in another - much like regular socket
programming. Building upon this idea, g_input_stream_read_async() and
g_output_stream_write_async() are implemented by pushing a job to a
GThreadPool and doing the blocking _read() and _write() there. Thus
allowing one to read and write from the same GIOStream in an event
based manner, by calling the following functions in a single go:

GSocketConnection *n; // obtained this from a GSocketClient or GSocketListener
GInputStream *in = g_io_stream_get_input_stream(G_IO_STREAM(n));
GOutputStream *out = g_io_stream_get_output_stream(G_IO_STREAM(n));
g_input_stream_read_async(in, ..);
g_output_stream_write_async(out, ..);

...at least, I thought the API supported that. Browsing through the
code of the gnutls implementation in glib-networking, I see a single
internal state being used for both the read and write functions, with
apparently no synchronisation whatsoever. Am I misinterpreting the
code, or was I assuming things wrongly?

Ayo.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]