equal
deleted
inserted
replaced
37 }; |
37 }; |
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 |
|
44 * |
|
45 * XXX: take error_info as an arg? |
|
46 */ |
|
47 static void line_proto_handle_error (struct line_proto *lp) |
|
48 { |
|
49 // trigger callback |
|
50 lp->callbacks.on_error(&lp->err, lp->cb_arg); |
|
51 |
|
52 // XXX: do we handle release()? no |
|
53 } |
|
54 |
|
55 /** |
43 * Our sock_stream on_read handler |
56 * Our sock_stream on_read handler |
44 */ |
57 */ |
45 static void line_proto_on_read (struct sock_stream *sock, void *arg) |
58 static void line_proto_on_read (struct sock_stream *sock, void *arg) |
46 { |
59 { |
47 struct line_proto *lp = arg; |
60 struct line_proto *lp = arg; |
52 // sanity-check |
65 // sanity-check |
53 assert(lp->tail_offset < lp->buf_len); |
66 assert(lp->tail_offset < lp->buf_len); |
54 |
67 |
55 do { |
68 do { |
56 // attempt to read a line |
69 // attempt to read a line |
57 if (line_proto_recv(lp, &line)) |
70 if (line_proto_recv(lp, &line)) { |
58 // XXX: un-fatalize |
71 // faaail |
59 FATAL_ERROR(&lp->err, "line_proto_recv"); |
72 line_proto_handle_error(lp); |
60 |
73 |
|
74 return; |
|
75 } |
|
76 |
61 // got a line? |
77 // got a line? |
62 if (line) |
78 if (line) |
63 lp->callbacks.on_line(line, lp->cb_arg); |
79 lp->callbacks.on_line(line, lp->cb_arg); |
64 |
80 |
65 } while (line); |
81 } while (line); |
66 |
82 |
67 // reschedule |
83 // reschedule |
68 if (line_proto_schedule_events(lp, EV_READ)) |
84 if (line_proto_schedule_events(lp, EV_READ)) |
69 FATAL_ERROR(&lp->err, "line_proto_schedule_events"); |
85 line_proto_handle_error(lp); |
70 } |
86 } |
71 |
87 |
72 /* |
88 /* |
73 * Signal for write |
89 * Signal for write |
74 */ |
90 */ |
78 int ret; |
94 int ret; |
79 |
95 |
80 (void) sock; |
96 (void) sock; |
81 |
97 |
82 // just flush |
98 // just flush |
83 if ((ret = line_proto_flush(lp)) < 0) |
99 if ((ret = line_proto_flush(lp)) < 0) { |
84 FATAL_ERR(-ret, "line_proto_flush"); |
100 // faaaail |
|
101 SET_ERROR(&lp->err, -ret); |
|
102 |
|
103 line_proto_handle_error(lp); |
|
104 } |
85 } |
105 } |
86 |
106 |
87 /* |
107 /* |
88 * Schedule our sock_stream callback |
108 * Schedule our sock_stream callback |
89 */ |
109 */ |