Async connecting *almost* works. For some reason the G_IO_OUT condition
[cascardo/gnio.git] / test / test-tcp-client.c
index 467d172..8620ba4 100644 (file)
@@ -3,29 +3,28 @@
 
 GMainLoop *loop;
 
-/*
-void
-accept_callback (GSocket *socket, GAsyncResult *result, gpointer data)
+static void
+connect_callback (GObject *source, GAsyncResult *result, gpointer data)
 {
+       GTcpClient *client = G_TCP_CLIENT (source);
        GError *error = NULL;
 
-       if (!g_socket_connect_finish (socket, result, &error)) {
+       if (!g_tcp_client_connect_finish (client, result, &error)) {
                g_warning (error->message);
                return;
        }
 
        g_print ("successfully connected\n");
 }
-*/
 
 int main (int argc, char *argv[])
 {
        GTcpClient *client;
-       GInputStream *input;
+/*     GInputStream *input;
        GOutputStream *output;
-       GError *error = NULL;
        gchar buffer[512] = {0};
        gssize count;
+       GError *error = NULL;*/
 
        g_thread_init (NULL);
 
@@ -33,10 +32,14 @@ int main (int argc, char *argv[])
 
        loop = g_main_loop_new (NULL, FALSE);
 
-       client = g_tcp_client_new ("www.google.com", 80);
+       client = g_tcp_client_new ("localhost", 80);
 
        g_print ("connecting to www.google.com:80\n");
 
+       g_tcp_client_connect_async (client, NULL, connect_callback, NULL);
+
+       g_print ("connecting seems to have begun\n");
+/*
        if (!g_tcp_client_connect (client, NULL, &error)) {
                g_warning (error->message);
                return 1;
@@ -65,8 +68,8 @@ int main (int argc, char *argv[])
        g_print ("read %d bytes: %s\n", count, buffer);
 
        g_object_unref (G_OBJECT (client));
-
-//     g_main_loop_run (loop);
+*/
+       g_main_loop_run (loop);
 
        return 0;
 }