src/line_proto.c
changeset 33 e5139b339b18
parent 32 ae66e9ae4afb
child 41 40f7aa051acb
--- 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);
+    }
 }
 
 /*