Support delaying disconnects until all lines are sent.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 16 Jun 2009 22:51:35 +0000 (00:51 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 16 Jun 2009 22:51:35 +0000 (00:51 +0200)
libirc/transport_ioc.c
testsuite/test-client.c
testsuite/test-linestack.c
testsuite/test-network.c

index 1c82436..ea702ae 100644 (file)
@@ -29,6 +29,7 @@
 
 struct irc_transport_data_iochannel {
        GIOChannel *incoming;
+       gboolean pending_disconnect;
        gint incoming_id;
        gint outgoing_id;
        GIConv incoming_iconv;
@@ -49,7 +50,7 @@ static void irc_transport_iochannel_free_data(void *data)
 {
        struct irc_transport_data_iochannel *backend_data = (struct irc_transport_data_iochannel *)data;
 
-       g_assert(backend_data->incoming == NULL);
+       g_assert(backend_data->pending_disconnect);
 
        if (backend_data->outgoing_iconv != (GIConv)-1)
                g_iconv_close(backend_data->outgoing_iconv);
@@ -126,9 +127,8 @@ static gboolean irc_transport_iochannel_set_charset(struct irc_transport *transp
        return TRUE;
 }
 
-static void irc_transport_iochannel_disconnect(void *data)
+static void really_disconnect(struct irc_transport_data_iochannel *backend_data)
 {
-       struct irc_transport_data_iochannel *backend_data = (struct irc_transport_data_iochannel *)data;
        g_io_channel_unref(backend_data->incoming);
 
        g_source_remove(backend_data->incoming_id);
@@ -138,6 +138,16 @@ static void irc_transport_iochannel_disconnect(void *data)
        backend_data->incoming = NULL;
 }
 
+static void irc_transport_iochannel_disconnect(void *data)
+{
+       struct irc_transport_data_iochannel *backend_data = (struct irc_transport_data_iochannel *)data;
+
+       backend_data->pending_disconnect = TRUE;
+
+       if (backend_data->outgoing_id == 0) 
+               really_disconnect(backend_data);
+}
+
 static gboolean transport_send_queue(GIOChannel *ioc, GIOCondition cond, 
                                                                          void *_transport);
 
@@ -389,7 +399,9 @@ static gboolean transport_send_queue(GIOChannel *ioc, GIOCondition cond,
 
        if (!ret)
                backend_data->outgoing_id = 0;
-       return ret;
-}
 
+       if (!ret && backend_data->pending_disconnect)
+               really_disconnect(backend_data);
 
+       return ret;
+}
index a0539ba..ccc083a 100644 (file)
@@ -46,6 +46,8 @@ START_TEST(test_network_first)
                                "USER a a a a\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
        fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
        g_main_iteration(FALSE);
+       g_main_iteration(FALSE);
+       g_main_iteration(FALSE);
        g_io_channel_read_to_end(ch2, &raw, NULL, NULL);
        fail_unless(!strcmp(raw, "ERROR :Please select a network first, or specify one in your configuration file\r\n"), "Got: %s", raw);
 END_TEST
@@ -108,6 +110,8 @@ START_TEST(test_disconnect)
        client = client_init_iochannel(NULL, ch1, "desc");
        g_io_channel_unref(ch1);
        client_disconnect(client, "Because");
+       g_main_iteration(FALSE);
+       g_main_iteration(FALSE);
        g_io_channel_read_to_end(ch2, &raw, &length, &error);
        fail_unless(!strcmp(raw, "ERROR :Because\r\n"));
 END_TEST
index a520f15..9f4beb9 100644 (file)
@@ -258,13 +258,14 @@ START_TEST(test_join_part)
        g_io_channel_unref(ch1);
 
        linestack_send(ctx, lm, NULL, cl, FALSE, FALSE, 0);
+       g_main_iteration(FALSE);
        client_disconnect(cl, "foo");
-
+       g_main_iteration(FALSE);
        g_io_channel_read_to_end(ch2, &raw, NULL, NULL);
 
        fail_unless(!strcmp(raw, ":bla!Gebruikersnaam@Computernaam JOIN #bla\r\n"
                                                     ":bla!Gebruikersnaam@Computernaam PART #bla :hihi\r\n"
-                                                        "ERROR :foo\r\n"));
+                                                        "ERROR :foo\r\n"), "Got %s", raw);
 END_TEST
 
 
index d9616ec..ecbccf4 100644 (file)
@@ -61,6 +61,7 @@ START_TEST(test_login)
        g_io_channel_set_close_on_unref(ch1, TRUE);
        g_io_channel_unref(ch1);
        disconnect_network(n);
+       g_main_iteration(FALSE);
        g_io_channel_read_to_end(ch2, &raw, NULL, &error);
        fail_unless(error == NULL);
        fail_unless(!strcmp(raw, "NICK foo\r\nUSER blah a a :bloeh \r\nQUIT\r\n"), raw);