implement irc_queue for irc_conn, and add missing irc_queue_destroy, fix irc_conn_destroy
--- a/src/irc_conn.c Mon Mar 30 16:31:24 2009 +0300
+++ b/src/irc_conn.c Mon Mar 30 16:44:00 2009 +0300
@@ -267,6 +267,10 @@
if (line_proto_create(&conn->lp, sock, IRC_LINE_MAX * 1.5, &irc_conn_lp_callbacks, conn, err))
goto error;
+ // create the outgoing line queue
+ if (irc_queue_create(&conn->out_queue, conn->lp, err))
+ goto error;
+
// ok
*conn_ptr = conn;
@@ -284,9 +288,14 @@
// the line_proto
if (conn->lp)
line_proto_release(conn->lp);
+
+ // the queue
+ if (conn->out_queue)
+ irc_queue_destroy(conn->out_queue);
// the command handlers
irc_cmd_free(&conn->handlers);
+ irc_cmd_free(&conn->ctcp_handlers);
// additional data
free(conn->nickname);
@@ -324,23 +333,8 @@
err_t irc_conn_send (struct irc_conn *conn, const struct irc_line *line)
{
- char line_buf[IRC_LINE_MAX + 2];
- err_t err;
- int ret;
-
- // format
- if ((err = irc_line_build(line, line_buf)))
- return err;
-
- // log
- log_debug("%s", line_buf);
-
- // add CRLF
- strcat(line_buf, "\r\n");
-
- // send using line_proto
- // XXX: ignore output-buffering
- return (ret = line_proto_send(conn->lp, line_buf)) < 0 ? -ret : SUCCESS;
+ // just proxy off to irc_quuee
+ return irc_queue_process(conn->out_queue, line);
}
err_t irc_conn_NICK (struct irc_conn *conn, const char *nickname)
--- a/src/irc_conn.h Mon Mar 30 16:31:24 2009 +0300
+++ b/src/irc_conn.h Mon Mar 30 16:44:00 2009 +0300
@@ -14,6 +14,7 @@
#include "error.h"
#include "sock.h"
#include "line_proto.h"
+#include "irc_queue.h"
#include "irc_line.h"
#include "irc_cmd.h"
#include <stdbool.h>
@@ -75,6 +76,9 @@
/** We are a line-based protocol, this wraps the given sock_stream */
struct line_proto *lp;
+ /** Outgoing line queue */
+ struct irc_queue *out_queue;
+
/** High-level callbacks */
struct irc_conn_callbacks callbacks;
--- a/src/irc_queue.c Mon Mar 30 16:31:24 2009 +0300
+++ b/src/irc_queue.c Mon Mar 30 16:44:00 2009 +0300
@@ -226,3 +226,20 @@
}
}
+void irc_queue_destroy (struct irc_queue *queue)
+{
+ struct irc_queue_entry *entry, *next;
+
+ // free all entries
+ for (entry = TAILQ_FIRST(&queue->list); entry; entry = next) {
+ next = TAILQ_NEXT(entry, queue_list);
+ free(entry);
+ }
+
+ // the event
+ event_free(queue->ev);
+
+ // the queue itself
+ free(queue);
+}
+
--- a/src/test.c Mon Mar 30 16:31:24 2009 +0300
+++ b/src/test.c Mon Mar 30 16:44:00 2009 +0300
@@ -495,6 +495,9 @@
assert_sock_data(sock, "TEST foo5\r\n");
assert(TAILQ_EMPTY(&queue->list));
assert(!event_pending(queue->ev, EV_TIMEOUT, NULL));
+
+ // cleanup
+ irc_queue_destroy(queue);
}
struct test_conn_ctx {