Move pending lines queue to backend.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 16 Jun 2009 21:01:11 +0000 (23:01 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 16 Jun 2009 21:01:11 +0000 (23:01 +0200)
configure.ac
libirc/python/transport.c
libirc/transport.c
libirc/transport.h
libirc/transport_ioc.c
testsuite/test-transport.c

index a4078fc..6f8eb1b 100644 (file)
@@ -61,7 +61,7 @@ AC_TYPE_SIGNAL
 
 AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, gethostbyname))
 AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
-AC_CHECK_FUNCS([gethostname memset strchr strerror strstr uname backtrace_symbols gettimeofday strrchr daemon fork])
+AC_CHECK_FUNCS([gethostname memset strchr strerror strstr uname backtrace_symbols gettimeofday strrchr daemon fork writev])
 AC_CHECK_FUNC(gcry_control, , AC_CHECK_LIB(gcrypt, gcry_control))
 
 PKG_PROG_PKG_CONFIG
index bd8d37c..a364916 100644 (file)
@@ -154,7 +154,6 @@ static PyObject *py_transport_new(PyTypeObject *type, PyObject *args, PyObject *
 
     self->parent = NULL;
     self->transport = g_new0(struct irc_transport, 1);
-       self->transport->pending_lines = g_queue_new();
     self->transport->backend_data = self;
     self->transport->backend_ops = &py_transport_ops;
 
@@ -166,7 +165,6 @@ struct irc_transport *wrap_py_transport(PyObject *obj)
     struct irc_transport *transport;
 
     transport = g_new0(struct irc_transport, 1);
-       transport->pending_lines = g_queue_new();
     Py_INCREF(obj);
     transport->backend_data = obj;
     transport->backend_ops = &py_transport_ops;
index dc3eae4..d9290a2 100644 (file)
@@ -37,12 +37,6 @@ void irc_transport_disconnect(struct irc_transport *transport)
        transport->callbacks->disconnect(transport);
 }
 
-static void free_pending_line(void *_line, void *userdata)
-{
-       free_line((struct irc_line *)_line);
-}
-
-
 void free_irc_transport(struct irc_transport *transport)
 {
        transport->backend_ops->free_data(transport->backend_data);
@@ -50,10 +44,6 @@ void free_irc_transport(struct irc_transport *transport)
 
        g_free(transport->charset);
 
-       g_assert(transport->pending_lines != NULL);
-       g_queue_foreach(transport->pending_lines, free_pending_line, NULL);
-       g_queue_free(transport->pending_lines);
-
        g_free(transport);
 }
 
index 9d114e0..daac8ff 100644 (file)
@@ -52,7 +52,6 @@ struct irc_transport_ops {
 struct irc_transport {
        const struct irc_transport_ops *backend_ops;
        void *backend_data;
-       GQueue *pending_lines;
        char *charset;
        const struct irc_transport_callbacks *callbacks;
        void *userdata;
index 4dabda3..1c82436 100644 (file)
@@ -33,12 +33,18 @@ struct irc_transport_data_iochannel {
        gint outgoing_id;
        GIConv incoming_iconv;
        GIConv outgoing_iconv;
+       GQueue *pending_lines;
 };
 
 
 static gboolean handle_transport_receive(GIOChannel *c, GIOCondition cond, 
                                                                          void *_transport);
 
+static void free_pending_line(void *_line, void *userdata)
+{
+       free_line((struct irc_line *)_line);
+}
+
 static void irc_transport_iochannel_free_data(void *data)
 {
        struct irc_transport_data_iochannel *backend_data = (struct irc_transport_data_iochannel *)data;
@@ -50,6 +56,9 @@ static void irc_transport_iochannel_free_data(void *data)
        if (backend_data->incoming_iconv != (GIConv)-1)
                g_iconv_close(backend_data->incoming_iconv);
 
+       g_queue_foreach(backend_data->pending_lines, free_pending_line, NULL);
+       g_queue_free(backend_data->pending_lines);
+
        g_free(backend_data);
 }
 
@@ -144,7 +153,7 @@ static gboolean irc_transport_iochannel_send_line(struct irc_transport *transpor
        }
 
        if (backend_data->outgoing_id != 0) {
-               g_queue_push_tail(transport->pending_lines, linedup(l));
+               g_queue_push_tail(backend_data->pending_lines, linedup(l));
                return TRUE;
        }
 
@@ -154,7 +163,7 @@ static gboolean irc_transport_iochannel_send_line(struct irc_transport *transpor
        case G_IO_STATUS_AGAIN:
                backend_data->outgoing_id = g_io_add_watch(backend_data->incoming, G_IO_OUT, 
                                                                                transport_send_queue, transport);
-               g_queue_push_tail(transport->pending_lines, linedup(l));
+               g_queue_push_tail(backend_data->pending_lines, linedup(l));
                break;
        case G_IO_STATUS_EOF:
                transport->callbacks->hangup(transport);
@@ -309,7 +318,7 @@ struct irc_transport *irc_transport_new_iochannel(GIOChannel *iochannel)
        ret->backend_ops = &irc_transport_iochannel_ops;
        ret->backend_data = backend_data;
        backend_data->incoming = iochannel;
-       ret->pending_lines = g_queue_new();
+       backend_data->pending_lines = g_queue_new();
        backend_data->outgoing_iconv = backend_data->incoming_iconv = (GIConv)-1;
        g_io_channel_ref(backend_data->incoming);
 
@@ -330,11 +339,11 @@ static gboolean transport_send_queue(GIOChannel *ioc, GIOCondition cond,
        if (status == G_IO_STATUS_AGAIN)
                ret = TRUE;
 
-       g_assert(transport->pending_lines != NULL);
+       g_assert(backend_data->pending_lines != NULL);
 
-       while (!g_queue_is_empty(transport->pending_lines)) {
+       while (!g_queue_is_empty(backend_data->pending_lines)) {
                GError *error = NULL;
-               struct irc_line *l = g_queue_pop_head(transport->pending_lines);
+               struct irc_line *l = g_queue_pop_head(backend_data->pending_lines);
 
                g_assert(backend_data->incoming != NULL);
                status = irc_send_line(backend_data->incoming, 
@@ -342,7 +351,7 @@ static gboolean transport_send_queue(GIOChannel *ioc, GIOCondition cond,
 
                switch (status) {
                case G_IO_STATUS_AGAIN:
-                       g_queue_push_head(transport->pending_lines, l);
+                       g_queue_push_head(backend_data->pending_lines, l);
                        return TRUE;
                case G_IO_STATUS_ERROR:
                        transport->callbacks->log(transport, l, error);
index ab368a6..4d53e57 100644 (file)
@@ -50,8 +50,7 @@ START_TEST(test_send)
                char *str;
                char buf[120];
                g_snprintf(buf, sizeof(buf), "PRIVMSG foo :bar: %d\r\n", i);
-               if (!g_queue_is_empty(t->pending_lines))
-                       g_main_iteration(FALSE);
+               g_main_iteration(FALSE);
                g_io_channel_read_line(ch2, &str, NULL, NULL, NULL);
                fail_if(strcmp(str, buf));
        }