[glibmm] examples/network: Use SocketSource and SignalSocket.



commit 517785fddc76b10d0087f7c3de510a29844ca3e8
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date:   Thu May 15 13:18:23 2014 +0200

    examples/network: Use SocketSource and SignalSocket.
    
    * examples/network/socket-client.cc: Use Gio::Socket::create_source().
    * examples/network/socket-server.cc: Use Gio::signal_socket().connect().
    Bug #725281.

 examples/network/socket-client.cc |   17 +++++------------
 examples/network/socket-server.cc |   15 +++------------
 2 files changed, 8 insertions(+), 24 deletions(-)
---
diff --git a/examples/network/socket-client.cc b/examples/network/socket-client.cc
index 2912257..1276e37 100644
--- a/examples/network/socket-client.cc
+++ b/examples/network/socket-client.cc
@@ -44,8 +44,7 @@ socket_address_to_string (const Glib::RefPtr<Gio::SocketAddress>& address)
 }
 
 static bool
-source_ready (gpointer /*data*/,
-              GIOCondition /*condition*/)
+source_ready(Glib::IOCondition /*condition*/)
 {
   loop->quit ();
   return false;
@@ -57,21 +56,15 @@ ensure_condition (const Glib::RefPtr<Gio::Socket>& socket,
                   const Glib::RefPtr<Gio::Cancellable>& cancellable,
                   Glib::IOCondition condition)
 {
-    GSource *source;
-
     if (!non_blocking)
         return;
 
     if (use_source)
     {
-        source = g_socket_create_source (socket->gobj (),
-                                         (GIOCondition) condition,
-                                         cancellable->gobj ());
-        g_source_set_callback (source,
-                               (GSourceFunc) source_ready,
-                               NULL, NULL);
-        g_source_attach (source, NULL);
-        loop->run ();
+      Glib::RefPtr<Gio::SocketSource> source = socket->create_source(condition, cancellable);
+      source->connect(sigc::ptr_fun(&source_ready));
+      source->attach();
+      loop->run();
     }
     else
     {
diff --git a/examples/network/socket-server.cc b/examples/network/socket-server.cc
index d507859..2bf9d2b 100644
--- a/examples/network/socket-server.cc
+++ b/examples/network/socket-server.cc
@@ -49,8 +49,7 @@ socket_address_to_string (const Glib::RefPtr<Gio::SocketAddress>& address)
 }
 
 static bool
-source_ready (gpointer /*data*/,
-              GIOCondition /*condition*/)
+source_ready(Glib::IOCondition /*condition*/)
 {
   loop->quit ();
   return false;
@@ -62,21 +61,13 @@ ensure_condition (const Glib::RefPtr<Gio::Socket>& socket,
                   const Glib::RefPtr<Gio::Cancellable>& cancellable,
                   Glib::IOCondition condition)
 {
-    GSource *source;
-
     if (!non_blocking)
         return;
 
     if (use_source)
     {
-        source = g_socket_create_source (socket->gobj (),
-                                         (GIOCondition) condition,
-                                         cancellable->gobj ());
-        g_source_set_callback (source,
-                               (GSourceFunc) source_ready,
-                               NULL, NULL);
-        g_source_attach (source, NULL);
-        loop->run ();
+      Gio::signal_socket().connect(sigc::ptr_fun(&source_ready), socket, condition);
+      loop->run();
     }
     else
     {


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