equal
deleted
inserted
replaced
38 |
38 |
39 // function prototypes |
39 // function prototypes |
40 static err_t line_proto_schedule_events (struct line_proto *lp, short what); |
40 static err_t line_proto_schedule_events (struct line_proto *lp, short what); |
41 |
41 |
42 /** |
42 /** |
43 * Trigger the on_error callback |
43 * An error occured which we could not recover from; the line_proto should now be considered corrupt. |
44 * |
44 * |
45 * XXX: take error_info as an arg? |
45 * Notify the user callback, which will probably call line_proto_release(). |
46 */ |
46 */ |
47 static void line_proto_handle_error (struct line_proto *lp) |
47 static void line_proto_set_error (struct line_proto *lp) |
48 { |
48 { |
49 // trigger callback |
49 // trigger callback |
50 lp->callbacks.on_error(&lp->err, lp->cb_arg); |
50 lp->callbacks.on_error(&lp->err, lp->cb_arg); |
51 |
|
52 // XXX: do we handle release()? no |
|
53 } |
51 } |
54 |
52 |
55 /** |
53 /** |
56 * Our sock_stream on_read handler |
54 * Our sock_stream on_read handler |
57 */ |
55 */ |
67 |
65 |
68 do { |
66 do { |
69 // attempt to read a line |
67 // attempt to read a line |
70 if (line_proto_recv(lp, &line)) { |
68 if (line_proto_recv(lp, &line)) { |
71 // faaail |
69 // faaail |
72 line_proto_handle_error(lp); |
70 return line_proto_set_error(lp); |
73 |
|
74 return; |
|
75 } |
71 } |
76 |
72 |
77 // got a line? |
73 // got a line? |
78 if (line) |
74 if (line) |
79 lp->callbacks.on_line(line, lp->cb_arg); |
75 lp->callbacks.on_line(line, lp->cb_arg); |
80 |
76 |
81 } while (line); |
77 } while (line); |
82 |
78 |
83 // reschedule |
79 // reschedule |
84 if (line_proto_schedule_events(lp, EV_READ)) |
80 if (line_proto_schedule_events(lp, EV_READ)) |
85 line_proto_handle_error(lp); |
81 line_proto_set_error(lp); |
86 } |
82 } |
87 |
83 |
88 /* |
84 /* |
89 * Signal for write |
85 * Signal for write |
90 */ |
86 */ |
98 // just flush |
94 // just flush |
99 if ((ret = line_proto_flush(lp)) < 0) { |
95 if ((ret = line_proto_flush(lp)) < 0) { |
100 // faaaail |
96 // faaaail |
101 SET_ERROR(&lp->err, -ret); |
97 SET_ERROR(&lp->err, -ret); |
102 |
98 |
103 line_proto_handle_error(lp); |
99 return line_proto_set_error(lp); |
104 } |
100 } |
105 } |
101 } |
106 |
102 |
107 /* |
103 /* |
108 * Schedule our sock_stream callback |
104 * Schedule our sock_stream callback |