Merge branch 'master' into errorstate
authorSamuel Cormier-Iijima <sciyoshi@gmail.com>
Sun, 2 Mar 2008 01:21:49 +0000 (20:21 -0500)
committerSamuel Cormier-Iijima <sciyoshi@gmail.com>
Sun, 2 Mar 2008 01:21:49 +0000 (20:21 -0500)
Conflicts:

gnio/gnio.h

18 files changed:
gnio/Makefile.am
gnio/ginet6address.h
gnio/ginetaddress.h
gnio/ginetsocketaddress.h
gnio/gnetworkinputstream.c
gnio/gnetworkinputstream.h
gnio/gnetworkoutputstream.c
gnio/gnetworkoutputstream.h
gnio/gnio.h
gnio/gresolver.c
gnio/gresolver.h
gnio/gsocket.h
gnio/gtcpclient.c
gnio/gtcpclient.h
gnio/gtcpserver.c
gnio/gtcpserver.h
test/Makefile.am
test/test-tcp-client.c [new file with mode: 0644]

index 780cef5..91a72b7 100644 (file)
@@ -1,11 +1,20 @@
 NULL =
 
-INCLUDES =                                     \
-       $(SAMBA_CFLAGS)                         \
-       -I$(top_srcdir)                         \
-       -I$(top_builddir)                       \
-       $(GLIB_CFLAGS)                          \
-       -DG_DISABLE_DEPRECATED
+#INCLUDES =                                    \
+#      $(SAMBA_CFLAGS)                         \
+#      -I$(top_srcdir)                         \
+#      -I$(top_builddir)                       \
+#      $(GLIB_CFLAGS)                          \
+#      -DG_DISABLE_DEPRECATED
+
+AM_CPPFLAGS = \
+        -DG_LOG_DOMAIN=\"GLib-GIO\"                     \
+        -I$(top_builddir)                               \
+        -I$(top_srcdir)                                 \
+       $(GLIB_CFLAGS)                                  \
+        $(GLIB_DEBUG_FLAGS)                             \
+        -DG_DISABLE_DEPRECATED                          \
+        -DGIO_COMPILATION
 
 lib_LTLIBRARIES=libgnio.la
 
index ba791b6..d615426 100644 (file)
@@ -25,7 +25,7 @@
 #define G_INET6_ADDRESS_H
 
 #include <glib-object.h>
-#include <ginetaddress.h>
+#include <gnio/ginetaddress.h>
 
 G_BEGIN_DECLS
 
index 19bb313..31d247d 100644 (file)
@@ -25,7 +25,6 @@
 #define G_INET_ADDRESS_H
 
 #include <glib-object.h>
-#include <gio/gio.h>
 
 G_BEGIN_DECLS
 
index fc44062..27f80ee 100644 (file)
@@ -25,8 +25,8 @@
 #define G_INET_SOCKET_ADDRESS_H
 
 #include <glib-object.h>
-#include "gsocketaddress.h"
-#include "ginetaddress.h"
+#include <gnio/gsocketaddress.h>
+#include <gnio/ginetaddress.h>
 
 G_BEGIN_DECLS
 
index 50eb1a6..a7bdbb6 100644 (file)
 #include <glib.h>
 #include <gio/gio.h>
 
-#include <string.h>
-#ifndef G_OS_WIN32
-# include <netinet/in.h>
-# include <arpa/inet.h>
-# include <netdb.h>
-#else
-# include <winsock2.h>
-# include <winerror.h>
-# include <ws2tcpip.h>
-# undef HAVE_GETADDRINFO
-# define HAVE_GETHOSTBYNAME_THREADSAFE 1
-#endif
-#include <errno.h>
-
-#include "ginetaddress.h"
-#include "ginet4address.h"
-#include "ginet6address.h"
 #include "gnetworkinputstream.h"
-#include "gnioerror.h"
 
 G_DEFINE_TYPE (GNetworkInputStream, g_network_input_stream, G_TYPE_INPUT_STREAM);
 
index 06df919..9d6d42e 100644 (file)
@@ -27,8 +27,6 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include "gsocket.h"
-
 G_BEGIN_DECLS
 
 #define G_TYPE_NETWORK_INPUT_STREAM         (g_socket_get_type ())
@@ -53,9 +51,8 @@ struct _GNetworkInputStreamClass
 
 GType                 g_network_input_stream_get_type (void) G_GNUC_CONST;
 
-GNetworkInputStream * g_network_input_stream_new      (GSocket *socket);
+GNetworkInputStream * g_network_input_stream_new      (void);
 
 G_END_DECLS
 
 #endif /* G_NETWORK_INPUT_STREAM_H */
-
index eecd2db..c32a470 100644 (file)
 #include <glib.h>
 #include <gio/gio.h>
 
-#include <string.h>
-#ifndef G_OS_WIN32
-# include <netinet/in.h>
-# include <arpa/inet.h>
-# include <netdb.h>
-#else
-# include <winsock2.h>
-# include <winerror.h>
-# include <ws2tcpip.h>
-# undef HAVE_GETADDRINFO
-# define HAVE_GETHOSTBYNAME_THREADSAFE 1
-#endif
-#include <errno.h>
-
-#include "ginetaddress.h"
-#include "ginet4address.h"
-#include "ginet6address.h"
 #include "gnetworkoutputstream.h"
-#include "gnioerror.h"
 
 G_DEFINE_TYPE (GNetworkOutputStream, g_network_output_stream, G_TYPE_OUTPUT_STREAM);
 
index b3dfee0..84615e8 100644 (file)
@@ -27,8 +27,6 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include "gsocket.h"
-
 G_BEGIN_DECLS
 
 #define G_TYPE_NETWORK_OUTPUT_STREAM         (g_socket_get_type ())
@@ -53,7 +51,7 @@ struct _GNetworkOutputStreamClass
 
 GType                  g_network_output_stream_get_type (void) G_GNUC_CONST;
 
-GNetworkOutputStream * g_network_output_stream_new      (GSocket *socket);
+GNetworkOutputStream * g_network_output_stream_new      (void);
 
 G_END_DECLS
 
index f1d0e93..6eb16a6 100644 (file)
@@ -33,6 +33,7 @@
 #include <gnio/ginetsocketaddress.h>
 #include <gnio/gresolver.h>
 #include <gnio/gsocket.h>
+#include <gnio/gnioerror.h>
 #include <gnio/gtcpclient.h>
 #include <gnio/gtcpserver.h>
 #include <gnio/gnioenumtypes.h>
index 5a74b7c..014be9a 100644 (file)
 #endif
 #include <errno.h>
 
+#include "gresolver.h"
 #include "ginetaddress.h"
 #include "ginet4address.h"
 #include "ginet6address.h"
-#include "gresolver.h"
 #include "gnioerror.h"
 
 G_DEFINE_TYPE (GResolver, g_resolver, G_TYPE_OBJECT);
@@ -405,6 +405,12 @@ g_resolver_init (GResolver *address)
 
 }
 
+GResolver *
+g_resolver_new ()
+{
+  return G_RESOLVER (g_object_new (G_TYPE_RESOLVER, NULL));
+}
+
 typedef struct {
   GList       *list;
   const gchar *host;
index e91ced8..9484511 100644 (file)
@@ -27,7 +27,7 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include "ginetaddress.h"
+#include <gnio/ginetaddress.h>
 
 G_BEGIN_DECLS
 
@@ -53,6 +53,8 @@ struct _GResolverClass
 
 GType          g_resolver_get_type                  (void) G_GNUC_CONST;
 
+GResolver *    g_resolver_new                       (void);
+
 GInetAddress * g_resolver_resolve                   (GResolver     *resolver,
                                                      const char    *host,
                                                      GCancellable  *cancellable,
index e1eca71..350ff8b 100644 (file)
@@ -27,8 +27,7 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include "ginetaddress.h"
-#include "gsocketaddress.h"
+#include <gnio/gsocketaddress.h>
 
 G_BEGIN_DECLS
 
index ae8de6d..60822a3 100644 (file)
 #include <config.h>
 #include <glib.h>
 #include <gio/gio.h>
-#include <gio/gasynchelper.h>
+#include <gnio/gnio.h>
 
 #include <string.h>
 #include <errno.h>
 
-#include "ginetaddress.h"
-#include "ginet4address.h"
-#include "ginet6address.h"
-#include "gsocket.h"
-#include "gtcpclient.h"
-#include "gnioerror.h"
-#include "ginetsocketaddress.h"
-
 G_DEFINE_TYPE (GTcpClient, g_tcp_client, G_TYPE_OBJECT);
 
 enum
 {
   PROP_0,
-  PROP_ADDRESS
+  PROP_ADDRESS,
+  PROP_HOSTNAME,
+  PROP_PORT
 };
 
 struct _GTcpClientPrivate
 {
-  GSocketAddress *address;
+  GInetSocketAddress *address;
+  gchar              *hostname;
+  gushort             port;
+  GSocket            *socket;
 };
 
 static void
-g_tcp_client_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+g_tcp_client_constructed (GObject *object)
+{
+  GTcpClient *client = G_TCP_CLIENT (object);
+
+  if (client->priv->address)
+    {
+      // we've been constructed with an address, extract hostname+port
+      client->priv->hostname = g_inet_address_to_string (g_inet_socket_address_get_address (client->priv->address));
+      client->priv->port = g_inet_socket_address_get_port (client->priv->address);
+      return;
+    }
+}
+
+static void
+g_tcp_client_get_property (GObject    *object,
+                           guint       prop_id,
+                           GValue     *value,
+                           GParamSpec *pspec)
 {
   GTcpClient *client = G_TCP_CLIENT (object);
 
@@ -61,18 +75,44 @@ g_tcp_client_get_property (GObject *object, guint prop_id, GValue *value, GParam
         g_value_set_object (value, client->priv->address);
         break;
 
+      case PROP_HOSTNAME:
+        g_value_set_string (value, client->priv->hostname);
+        break;
+
+      case PROP_PORT:
+        g_value_set_uint (value, client->priv->port);
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
 }
 
 static void
-g_tcp_client_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+g_tcp_client_set_property (GObject      *object,
+                           guint         prop_id,
+                           const GValue *value,
+                           GParamSpec   *pspec)
 {
   GTcpClient *client = G_TCP_CLIENT (object);
 
   switch (prop_id)
     {
+      case PROP_ADDRESS:
+        // sink the address' floating reference
+        client->priv->address = G_INET_SOCKET_ADDRESS (g_value_get_object (value));
+        if (client->priv->address)
+          g_object_ref_sink (client->priv->address);
+        break;
+
+      case PROP_HOSTNAME:
+        client->priv->hostname = g_value_dup_string (value);
+        break;
+
+      case PROP_PORT:
+        client->priv->port = g_value_get_uint (value);
+        break;
+
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -83,6 +123,8 @@ g_tcp_client_finalize (GObject *object)
 {
   GTcpClient *client = G_TCP_CLIENT (object);
 
+  g_object_unref (client->priv->address);
+
   if (G_OBJECT_CLASS (g_tcp_client_parent_class)->finalize)
     (*G_OBJECT_CLASS (g_tcp_client_parent_class)->finalize) (object);
 }
@@ -92,6 +134,8 @@ g_tcp_client_dispose (GObject *object)
 {
   GTcpClient *client = G_TCP_CLIENT (object);
 
+  g_free (client->priv->hostname);
+
   if (G_OBJECT_CLASS (g_tcp_client_parent_class)->dispose)
     (*G_OBJECT_CLASS (g_tcp_client_parent_class)->dispose) (object);
 }
@@ -105,6 +149,7 @@ g_tcp_client_class_init (GTcpClientClass *klass)
 
   gobject_class->finalize = g_tcp_client_finalize;
   gobject_class->dispose = g_tcp_client_dispose;
+  gobject_class->constructed = g_tcp_client_constructed;
   gobject_class->set_property = g_tcp_client_set_property;
   gobject_class->get_property = g_tcp_client_get_property;
 
@@ -112,35 +157,107 @@ g_tcp_client_class_init (GTcpClientClass *klass)
                                    g_param_spec_object ("address",
                                                         "address",
                                                         "the remote address the socket will connect to",
-                                                        G_TYPE_SOCKET_ADDRESS,
-                                                        G_TYPE_CONSTRUCT_ONLY | G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
+                                                        G_TYPE_INET_SOCKET_ADDRESS,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
+
+  g_object_class_install_property (gobject_class, PROP_HOSTNAME,
+                                   g_param_spec_string ("hostname",
+                                                        "hostname",
+                                                        "the hostname of the remote address the socket will connect to",
+                                                        NULL,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
+
+  g_object_class_install_property (gobject_class, PROP_PORT,
+                                   g_param_spec_uint ("port",
+                                                      "port",
+                                                      "the remote port the socket will connect to",
+                                                      0,
+                                                      G_MAXUSHORT,
+                                                      0,
+                                                      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK));
 }
 
 static void
 g_tcp_client_init (GTcpClient *client)
 {
   client->priv = G_TYPE_INSTANCE_GET_PRIVATE (client, G_TYPE_TCP_CLIENT, GTcpClientPrivate);
+
+  client->priv->address = NULL;
+  client->priv->hostname = NULL;
+  client->priv->port = 0;
+  client->priv->socket = NULL;
 }
 
 GTcpClient *
-g_tcp_client_new (GInetSocketAddress *address,
-                  GError **error)
+g_tcp_client_new (const gchar *hostname,
+                  gushort      port)
 {
-  return NULL;
+  return G_TCP_CLIENT (g_object_new (G_TYPE_TCP_CLIENT, "hostname", hostname, "port", port, NULL));
+}
+
+GTcpClient *
+g_tcp_client_new_from_address (GInetSocketAddress *address)
+{
+  return G_TCP_CLIENT (g_object_new (G_TYPE_TCP_CLIENT, "address", address, NULL));
 }
 
 gboolean
-g_tcp_client_connect (GTcpClient *client,
-                      GError **error)
+g_tcp_client_connect (GTcpClient    *client,
+                      GCancellable  *cancellable,
+                      GError       **error)
 {
-  return FALSE;
+  GInetAddress *address;
+
+  g_return_val_if_fail (G_IS_TCP_CLIENT (client), FALSE);
+
+  if (!client->priv->address)
+    {
+      // we've been constructed with just hostname+port, resolve
+      GResolver *resolver = g_resolver_new ();
+
+      address = g_resolver_resolve (resolver, client->priv->hostname, cancellable, error);
+
+      if (!address)
+        return FALSE;
+
+      client->priv->address = g_inet_socket_address_new (address, client->priv->port);
+
+      g_object_unref (resolver);
+
+      g_object_ref_sink (client->priv->address);
+    }
+  else
+    {
+     address = g_inet_socket_address_get_address (client->priv->address);
+    }
+
+  if (G_IS_INET4_ADDRESS (address))
+    client->priv->socket = g_socket_new (G_SOCKET_DOMAIN_INET, G_SOCKET_TYPE_STREAM, NULL);
+  else if (G_IS_INET6_ADDRESS (address))
+    client->priv->socket = g_socket_new (G_SOCKET_DOMAIN_INET6, G_SOCKET_TYPE_STREAM, NULL);
+  else
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "unsupported address domain");
+      return FALSE;
+    }
+
+  if (g_socket_has_error (client->priv->socket, error))
+    return FALSE;
+
+  if (g_cancellable_set_error_if_cancelled (cancellable, error))
+    return FALSE;
+
+  if (!g_socket_connect (client->priv->socket, G_SOCKET_ADDRESS (client->priv->address), error))
+    return FALSE;
+
+  return TRUE;
 }
 
 typedef struct {
   GAsyncReadyCallback  callback;
   GCancellable        *cancellable;
   gpointer             user_data;
-  GSocket             *socket;
+  GTcpClient          *client;
   gchar                address_buffer[256];
   gsize                address_length;
 } ConnectData;
@@ -150,106 +267,33 @@ connect_callback (ConnectData *data,
                   GIOCondition condition,
                   gint fd)
 {
-  GSocket *socket;
-  GSimpleAsyncResult *result = NULL;
-  gint sockerr = 0;
-  gsize sockerr_size = 1;
-
-  socket = data->socket;
-
-  if (condition & G_IO_OUT)
-    {
-      result = g_simple_async_result_new (G_OBJECT (socket), data->callback, data->user_data, g_socket_connect_async);
-    }
-  else if (condition & G_IO_ERR)
-    {
-      if (getsockopt (fd, SOL_SOCKET, SO_ERROR, (gpointer) &sockerr, &sockerr_size) < 0)
-        g_warning ("getsockopt: %s", g_strerror (errno));
-
-      if (sockerr != 0)
-        result = g_simple_async_result_new_error (G_OBJECT (socket), data->callback, data->user_data, G_IO_ERROR, g_io_error_from_errno (sockerr), "error connecting: %s", g_strerror (sockerr));
-      else
-        g_warning ("getsockopt SO_ERROR returned no error, with sockerr = %d", sockerr);
-    }
-
-  g_simple_async_result_complete (result);
-
-  g_object_unref (result);
-
   return FALSE;
 }
 
 void
-g_socket_connect_async (GTcpClient          *client,
-                        GCancellable        *cancellable,
-                        GAsyncReadyCallback  callback,
-                        gpointer             user_data)
+g_tcp_client_connect_async (GTcpClient          *client,
+                            GCancellable        *cancellable,
+                            GAsyncReadyCallback  callback,
+                            gpointer             user_data)
 {
-  GSource *source;
-  GSimpleAsyncResult *result;
-  ConnectData *data;
-  gint ret;
-  gchar buffer[256];
-  gsize len;
-
-  g_return_if_fail (G_IS_SOCKET (socket) && G_IS_SOCKET_ADDRESS (address));
-
-  if (g_socket_get_blocking (socket))
-    g_socket_set_blocking (socket, FALSE);
 
-  g_socket_address_to_native (address, buffer);
-
-  len = g_socket_address_native_size (address);
-
-  if ((ret = connect (socket->priv->fd, (struct sockaddr *) buffer, len)) < 0)
-    {
-      if (errno == EINPROGRESS)
-        {
-          source = _g_fd_source_new (socket->priv->fd, G_IO_OUT | G_IO_ERR, cancellable);
-
-          data = g_new (ConnectData, 1);
-
-          data->socket = socket;
-          data->callback = callback;
-          data->cancellable = cancellable;
-          data->user_data = user_data;
-          data->address_length = len;
-          memcpy (data->address_buffer, buffer, len);
-
-          g_source_set_callback (source, (GSourceFunc) connect_callback, data, g_free);
-
-          g_source_attach (source, NULL);
-        }
-      else
-        {
-          g_simple_async_report_error_in_idle (G_OBJECT (socket), callback, user_data, G_IO_ERROR, g_io_error_from_errno (errno), "error connecting: %s", g_strerror (errno));
-        }
-    }
-  else
-    {
-      result = g_simple_async_result_new (G_OBJECT (socket), callback, user_data, g_socket_connect_async);
-
-      g_simple_async_result_complete_in_idle (result);
-
-      g_object_unref (result);
-    }
 }
 
 gboolean
-g_socket_connect_finish (GSocket       *socket,
-                         GAsyncResult  *result,
-                         GError       **error)
+g_tcp_client_connect_finish (GTcpClient    *client,
+                             GAsyncResult  *result,
+                             GError       **error)
 {
   GSimpleAsyncResult *simple;
 
-  g_return_val_if_fail (G_IS_SOCKET (socket), FALSE);
+  g_return_val_if_fail (G_IS_TCP_CLIENT (client), FALSE);
 
   simple = G_SIMPLE_ASYNC_RESULT (result);
 
   if (g_simple_async_result_propagate_error (simple, error))
     return FALSE;
 
-  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_socket_connect_async);
+  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_tcp_client_connect_async);
 
   return TRUE;
 }
index 8a1bf7f..dd87d63 100644 (file)
@@ -27,9 +27,9 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include "ginetsocketaddress.h"
-#include "gnetworkinputstream.h"
-#include "gnetworkoutputstream.h"
+#include <gnio/ginetsocketaddress.h>
+#include <gnio/gnetworkinputstream.h>
+#include <gnio/gnetworkoutputstream.h>
 
 G_BEGIN_DECLS
 
@@ -56,29 +56,32 @@ struct _GTcpClientClass
   GObjectClass parent_class;
 };
 
-GType            g_tcp_client_get_type         (void) G_GNUC_CONST;
+GType                  g_tcp_client_get_type          (void) G_GNUC_CONST;
 
-GTcpClient *     g_tcp_client_new              (const gchar *hostname,
-                                                gushort      port);
+GTcpClient *           g_tcp_client_new               (const gchar *hostname,
+                                                       gushort      port);
 
-GTcpClient *     g_tcp_client_new_from_address (GInetSocketAddress *address);
+GTcpClient *           g_tcp_client_new_from_address  (GInetSocketAddress *address);
 
-gboolean         g_tcp_client_connect          (GTcpClient      *clientt,
-                                                GCancellable    *cancellable,
-                                                GError         **error);
+GNetworkInputStream *  g_tcp_client_get_input_stream  (GTcpClient *client);
 
-void             g_tcp_client_connect_async    (GTcpClient          *client,
-                                                GCancellable        *cancellable,
-                                                GAsyncReadyCallback  callback,
-                                                gpointer             user_data);
+GNetworkOutputStream * g_tcp_client_get_output_stream (GTcpClient *client);
 
-gboolean         g_tcp_client_connect_finish   (GTcpClient    *client,
-                                                GAsyncResult  *result,
-                                                GError       **error);
+gboolean               g_tcp_client_connect           (GTcpClient    *client,
+                                                       GCancellable  *cancellable,
+                                                       GError       **error);
 
-void             g_tcp_client_close            (GTcpClient    *client);
+void                   g_tcp_client_connect_async     (GTcpClient          *client,
+                                                       GCancellable        *cancellable,
+                                                       GAsyncReadyCallback  callback,
+                                                       gpointer             user_data);
+
+gboolean               g_tcp_client_connect_finish    (GTcpClient    *client,
+                                                       GAsyncResult  *result,
+                                                       GError       **error);
+
+void                   g_tcp_client_close             (GTcpClient    *client);
 
 G_END_DECLS
 
 #endif /* G_TCP_CLIENT_H */
-
index 6b7349b..aab8c1c 100644 (file)
 #include <config.h>
 #include <glib.h>
 #include <gio/gio.h>
-#include <gio/gasynchelper.h>
 
 #include <string.h>
 #include <errno.h>
 
-#include "ginetaddress.h"
-#include "ginet4address.h"
-#include "ginet6address.h"
-#include "gsocket.h"
 #include "gtcpserver.h"
-#include "gnioerror.h"
-#include "ginetsocketaddress.h"
 
 G_DEFINE_TYPE (GTcpServer, g_tcp_server, G_TYPE_OBJECT);
 
@@ -52,7 +45,7 @@ struct _GTcpServerPrivate
 static void
 g_tcp_server_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
 {
-  GTcpServer *server = G_TCP_SERVER (object);
+  GTcpServer *server G_GNUC_UNUSED = G_TCP_SERVER (object);
 
   switch (prop_id)
     {
@@ -64,7 +57,7 @@ g_tcp_server_get_property (GObject *object, guint prop_id, GValue *value, GParam
 static void
 g_tcp_server_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
 {
-  GTcpServer *server = G_TCP_SERVER (object);
+  GTcpServer *server G_GNUC_UNUSED = G_TCP_SERVER (object);
 
   switch (prop_id)
     {
@@ -76,7 +69,7 @@ g_tcp_server_set_property (GObject *object, guint prop_id, const GValue *value,
 static void
 g_tcp_server_finalize (GObject *object)
 {
-  GTcpServer *server = G_TCP_SERVER (object);
+  GTcpServer *server G_GNUC_UNUSED = G_TCP_SERVER (object);
 
   if (G_OBJECT_CLASS (g_tcp_server_parent_class)->finalize)
     (*G_OBJECT_CLASS (g_tcp_server_parent_class)->finalize) (object);
@@ -85,7 +78,7 @@ g_tcp_server_finalize (GObject *object)
 static void
 g_tcp_server_dispose (GObject *object)
 {
-  GTcpServer *server = G_TCP_SERVER (object);
+  GTcpServer *server G_GNUC_UNUSED = G_TCP_SERVER (object);
 
   if (G_OBJECT_CLASS (g_tcp_server_parent_class)->dispose)
     (*G_OBJECT_CLASS (g_tcp_server_parent_class)->dispose) (object);
index 5cb8d63..42048cc 100644 (file)
 #include <glib-object.h>
 #include <gio/gio.h>
 
-#include "ginetsocketaddress.h"
-#include "gtcpclient.h"
-#include "gnetworkinputstream.h"
-#include "gnetworkoutputstream.h"
-
 G_BEGIN_DECLS
 
 #define G_TYPE_TCP_SERVER         (g_tcp_server_get_type ())
@@ -45,6 +40,9 @@ typedef struct _GTcpServer          GTcpServer;
 typedef struct _GTcpServerClass     GTcpServerClass;
 typedef struct _GTcpServerPrivate   GTcpServerPrivate;
 
+#include <gnio/gnio.h>
+#include <gnio/gtcpclient.h>
+
 struct _GTcpServer
 {
   GObject parent;
index 9e32d5f..f450c7a 100644 (file)
@@ -13,6 +13,7 @@ noinst_PROGRAMS = \
        test-stuff \
        test-server \
        test-client \
+       test-tcp-client \
        $(NULL)
 
 EXTRA_DIST = 
diff --git a/test/test-tcp-client.c b/test/test-tcp-client.c
new file mode 100644 (file)
index 0000000..f13aae8
--- /dev/null
@@ -0,0 +1,48 @@
+#include <gio/gio.h>
+#include <gnio/gnio.h>
+
+GMainLoop *loop;
+
+/*
+void
+accept_callback (GSocket *socket, GAsyncResult *result, gpointer data)
+{
+       GError *error = NULL;
+
+       if (!g_socket_connect_finish (socket, result, &error)) {
+               g_warning (error->message);
+               return;
+       }
+
+       g_print ("successfully connected\n");
+}
+*/
+
+int main (int argc, char *argv[])
+{
+       GTcpClient *client;
+       GError *error = NULL;
+
+       g_thread_init (NULL);
+
+       g_type_init ();
+
+       loop = g_main_loop_new (NULL, FALSE);
+
+       client = g_tcp_client_new ("localhost", 90);
+
+       g_print ("connecting to www.google.com:80\n");
+
+       if (!g_tcp_client_connect (client, NULL, &error)) {
+               g_warning (error->message);
+               return 1;
+       }
+
+       g_print ("connected!\n");
+
+       g_object_unref (G_OBJECT (client));
+
+//     g_main_loop_run (loop);
+
+       return 0;
+}