--- a/src/irc_conn.c Tue Mar 10 03:38:20 2009 +0200
+++ b/src/irc_conn.c Tue Mar 10 03:48:00 2009 +0200
@@ -44,7 +44,7 @@
{ NULL, NULL, },
};
-/*
+/**
* Incoming line handler
*/
void irc_conn_on_line (char *line_buf, void *arg)
@@ -80,8 +80,22 @@
}
}
+/**
+ * Transport failed
+ */
+void irc_conn_on_error (struct error_info *err, void *arg)
+{
+ struct irc_conn *conn = arg;
+
+ // log
+ log_err_info(err, "line_proto error");
+
+ // XXX: notify user
+}
+
static struct line_proto_callbacks _lp_callbacks = {
.on_line = &irc_conn_on_line,
+ .on_error = &irc_conn_on_error,
};
err_t irc_conn_create (struct irc_conn **conn_ptr, struct sock_stream *sock, const struct irc_conn_callbacks *callbacks,
--- a/src/line_proto.c Tue Mar 10 03:38:20 2009 +0200
+++ b/src/line_proto.c Tue Mar 10 03:48:00 2009 +0200
@@ -39,7 +39,20 @@
// function prototypes
static err_t line_proto_schedule_events (struct line_proto *lp, short what);
-/*
+/**
+ * Trigger the on_error callback
+ *
+ * XXX: take error_info as an arg?
+ */
+static void line_proto_handle_error (struct line_proto *lp)
+{
+ // trigger callback
+ lp->callbacks.on_error(&lp->err, lp->cb_arg);
+
+ // XXX: do we handle release()? no
+}
+
+/**
* Our sock_stream on_read handler
*/
static void line_proto_on_read (struct sock_stream *sock, void *arg)
@@ -54,10 +67,13 @@
do {
// attempt to read a line
- if (line_proto_recv(lp, &line))
- // XXX: un-fatalize
- FATAL_ERROR(&lp->err, "line_proto_recv");
-
+ if (line_proto_recv(lp, &line)) {
+ // faaail
+ line_proto_handle_error(lp);
+
+ return;
+ }
+
// got a line?
if (line)
lp->callbacks.on_line(line, lp->cb_arg);
@@ -66,7 +82,7 @@
// reschedule
if (line_proto_schedule_events(lp, EV_READ))
- FATAL_ERROR(&lp->err, "line_proto_schedule_events");
+ line_proto_handle_error(lp);
}
/*
@@ -80,8 +96,12 @@
(void) sock;
// just flush
- if ((ret = line_proto_flush(lp)) < 0)
- FATAL_ERR(-ret, "line_proto_flush");
+ if ((ret = line_proto_flush(lp)) < 0) {
+ // faaaail
+ SET_ERROR(&lp->err, -ret);
+
+ line_proto_handle_error(lp);
+ }
}
/*
--- a/src/line_proto.h Tue Mar 10 03:38:20 2009 +0200
+++ b/src/line_proto.h Tue Mar 10 03:48:00 2009 +0200
@@ -20,7 +20,9 @@
struct line_proto_callbacks {
/** Handle received line */
void (*on_line) (char *line, void *arg);
-
+
+ /** Event-based action failed */
+ void (*on_error) (struct error_info *err, void *arg);
};
/**