Fix really stupid bug in create_source
authorSamuel Cormier-Iijima <sciyoshi@gmail.com>
Mon, 3 Mar 2008 00:23:42 +0000 (19:23 -0500)
committerSamuel Cormier-Iijima <sciyoshi@gmail.com>
Mon, 3 Mar 2008 00:23:42 +0000 (19:23 -0500)
gnio/gsocket.c
test/test-tcp-client.c

index 1d54f1c..9b3c285 100644 (file)
@@ -24,7 +24,7 @@
 #include <config.h>
 #include <glib.h>
 #include <gio/gio.h>
-#include <gio/gasynchelper.h>
+#include "gasynchelper.h"
 
 #include <string.h>
 #ifndef G_OS_WIN32
@@ -581,5 +581,5 @@ g_socket_create_source (GSocket      *socket,
 {
   g_return_val_if_fail (G_IS_SOCKET (socket) && (cancellable == NULL || G_IS_CANCELLABLE (cancellable)), NULL);
 
-  return _g_fd_source_new (socket->priv->fd, G_IO_IN | G_IO_HUP | G_IO_ERR, cancellable);
+  return _g_fd_source_new (socket->priv->fd, condition, cancellable);
 }
index 8620ba4..9ef6560 100644 (file)
@@ -7,6 +7,10 @@ static void
 connect_callback (GObject *source, GAsyncResult *result, gpointer data)
 {
        GTcpClient *client = G_TCP_CLIENT (source);
+       GInputStream *input;
+       GOutputStream *output;
+       gchar buffer[512] = {0};
+       gssize count;
        GError *error = NULL;
 
        if (!g_tcp_client_connect_finish (client, result, &error)) {
@@ -15,16 +19,31 @@ connect_callback (GObject *source, GAsyncResult *result, gpointer data)
        }
 
        g_print ("successfully connected\n");
+
+       output = G_OUTPUT_STREAM (g_tcp_client_get_output_stream (client));
+
+       input = G_INPUT_STREAM (g_tcp_client_get_input_stream (client));
+
+       g_print ("writing...\n");
+
+       if ((count = g_output_stream_write (output, "GET / HTTP/1.0\r\n\r\n", 19, NULL, &error)) < 0) {
+               g_warning (error->message);
+               return 1;
+       }
+
+       g_print ("wrote %d bytes\n", count);
+
+       if ((count = g_input_stream_read (input, buffer, 512, NULL, &error)) < 0) {
+               g_warning (error->message);
+               return 1;
+       }
+
+       g_print ("read %d bytes: %s\n", count, buffer);
 }
 
 int main (int argc, char *argv[])
 {
        GTcpClient *client;
-/*     GInputStream *input;
-       GOutputStream *output;
-       gchar buffer[512] = {0};
-       gssize count;
-       GError *error = NULL;*/
 
        g_thread_init (NULL);
 
@@ -32,7 +51,7 @@ int main (int argc, char *argv[])
 
        loop = g_main_loop_new (NULL, FALSE);
 
-       client = g_tcp_client_new ("localhost", 80);
+       client = g_tcp_client_new ("localhost", 31882);
 
        g_print ("connecting to www.google.com:80\n");
 
@@ -47,29 +66,11 @@ int main (int argc, char *argv[])
 
        g_print ("connected!\n");
 
-       output = G_OUTPUT_STREAM (g_tcp_client_get_output_stream (client));
-
-       input = G_INPUT_STREAM (g_tcp_client_get_input_stream (client));
-
-       g_print ("writing...\n");
-
-       if ((count = g_output_stream_write (output, "GET / HTTP/1.0\r\n\r\n", 19, NULL, &error)) < 0) {
-               g_warning (error->message);
-               return 1;
-       }
-
-       g_print ("wrote %d bytes\n", count);
-
-       if ((count = g_input_stream_read (input, buffer, 512, NULL, &error)) < 0) {
-               g_warning (error->message);
-               return 1;
-       }
-
-       g_print ("read %d bytes: %s\n", count, buffer);
-
        g_object_unref (G_OBJECT (client));
 */
+
        g_main_loop_run (loop);
 
        return 0;
 }
+