On Mon, 23 Jan 2017 18:10:46 -1000 (HST)
rbd <r...@soest.hawaii.edu> wrote:
> Eric (cecas...@aol.com) sent me the following earlier today in
> response to another discussion thread I started a few days ago re:
> GSubProcess:
> 
> > I put together a test example of GSubprocess. ...
> >
> > 
> > https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Pipes/gnuplot5.c
> >   
> 
> In an amazing bit of coincidence, Eric's example contains the
> following bit of code which would seem to have some bearing on this
> file descriptor watch discussion thread:
> 
> >  GSource
> > *source=g_pollable_input_stream_create_source((GPollableInputStream*)err_stream,
> >    
> NULL);
> >  g_source_attach(source, NULL);
> >  g_source_set_callback(source, (GSourceFunc)read_err, NULL, NULL);  
> 
> Could this be yet another way to skin my cat? Perhaps better than the 
> GIOChannel, if not the g_source_add_unix_fd() solution? Looks like I
> could create my own GInputStream with
> 
>    GInputStream *gis= g_unix_input_stream_new(mypipefd, FALSE);
> 
> and then use that stream (which should also be a
> GPollableInputStream, yes?) in the call to
> g_pollable_input_stream_create_source(). I had not intended to use
> stream (i.e., buffered) i/o, but there's probably no harm in doing
> so. This seems like a perspiration-free way to create the GSource I
> need.

I didn't know about that.  Yes, that looks as if it will do what you
want.  GInputStream is not buffered by the way.  GIO streams are based
on the class heirarchy of the java.io package, so for buffering you
would need to instantiate an object of the GBufferedInputStream type
(which is derived from GInputStream).  GPollableInputStream is an
interface which is implemented by any pollable GInputStream (which in
practice seems to mean any input stream for a device represented by a
file descriptor).

If you are not going to use any of the GInputStream methods to read
from the file descriptor that could be regarded as a somewhat heavy
weight way of doing it, but if it is convenient for you, why not, and
you could say something of the same for GIOChannel.  Given what you want
to do and what we now know to be your four options (GIOChannel,
GPollableInputStream, using g_source_add_unix_fd() directly or using
GPollFD directly) on reflection I think I would probably go for
GIOChannel for ease of use, but that is just a matter of impression.

Chris
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to