Re: Gio::SocketConnection new data
- From: Chris Vine <chris cvine freeserve co uk>
- To: José Alburquerque <jaalburquerque cox net>
- Cc: teofil camarasu <teofilcamarasu gmail com>, gtkmm-list gnome org
- Subject: Re: Gio::SocketConnection new data
- Date: Sat, 30 Oct 2010 13:25:10 +0100
On Fri, 29 Oct 2010 16:53:45 -0400
José Alburquerque <jaalburquerque cox net> wrote:
> On Fri, 2010-10-29 at 20:08 +0100, teofil camarasu wrote:
> > Is there a way to call a function every time a new peice of data
> > arives to the Gio::SocketConnection (like in Qt's readyRead signal).
>
> By using Gio::ThreadedSocketService[1] and connecting to its
> signal_run() signal, it is possible for the slot to perform blocking
> IO indefinitely on the socket connection until the connection is
> closed.
That is often the best solution, but if the OP wants to send output
from the socket thread managing the new connection to the main loop
thread, say because he wants to address GTK+ widgets in some way with
the output, this solution is somewhat problematic because the glibmm's
idle implementation is not thread safe (there is a long-standing bug
report by me on that), and there is no asynchronous queue class that
can be used in conjunction with Glib::Dispatcher to pass the data (one
was posted in a bug report by someone three or so years ago, but it was
rejected as unnecessary I believe.)
If the OP really does want to avoid threads for that or for some other
reason, and therefore wants to plumb the socket into the main loop, he
will probably have to get the socket from the socket connection with
Gio::SocketConnection::get_socket(), and then get the socket file
descriptor from that with Gio::Socket::get_fd(). He can then
connect that descriptor into the main loop with
Glib::signal_io().connect(): there are two overloaded connect()
functions, one of which takes a file descriptor.
So the most literal answer to the OP's question - whether there is
something equivalent to Qt's readyRead signal - is to use
Glib::signal_io().connect() on the socket's file descriptor.
Another solution is to use glib's C interface with an idle handler
(which is thread safe), with or without some c++ wrappers which are
available for it, which is what I tend to do.
Chris
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]