equal
deleted
inserted
replaced
1 |
1 |
2 #include "line_proto.h" |
2 #include "line_proto.h" |
|
3 #include "log.h" |
3 |
4 |
4 #include <string.h> |
5 #include <string.h> |
5 #include <stdlib.h> |
6 #include <stdlib.h> |
6 #include <assert.h> |
7 #include <assert.h> |
7 |
|
8 #include <err.h> |
|
9 |
8 |
10 /* |
9 /* |
11 * Our state |
10 * Our state |
12 */ |
11 */ |
13 struct line_proto { |
12 struct line_proto { |
52 assert(lp->tail_offset < lp->buf_len); |
51 assert(lp->tail_offset < lp->buf_len); |
53 |
52 |
54 do { |
53 do { |
55 // attempt to read a line |
54 // attempt to read a line |
56 if (line_proto_recv(lp, &line)) |
55 if (line_proto_recv(lp, &line)) |
57 // XXX: fail |
56 // XXX: un-fatalize |
58 errx(1, "line_proto_recv: %s", error_msg(&lp->err)); |
57 FATAL_ERROR(&lp->err, "line_proto_recv"); |
59 |
58 |
60 // got a line? |
59 // got a line? |
61 if (line) |
60 if (line) |
62 lp->cb_read(line, lp->cb_arg); |
61 lp->cb_read(line, lp->cb_arg); |
63 |
62 |
64 } while (line); |
63 } while (line); |
65 |
64 |
66 // reschedule |
65 // reschedule |
67 if (line_proto_schedule_events(lp, EV_READ)) |
66 if (line_proto_schedule_events(lp, EV_READ)) |
68 errx(1, "line_proto_schedule_events: %s", error_msg(&lp->err)); |
67 FATAL_ERROR(&lp->err, "line_proto_schedule_events"); |
69 } |
68 } |
70 |
69 |
71 /* |
70 /* |
72 * Signal for write |
71 * Signal for write |
73 */ |
72 */ |
76 struct line_proto *lp = arg; |
75 struct line_proto *lp = arg; |
77 err_t err; |
76 err_t err; |
78 |
77 |
79 // just flush |
78 // just flush |
80 if ((err = line_proto_flush(lp)) < 0) |
79 if ((err = line_proto_flush(lp)) < 0) |
81 errx(1, "line_proto_flush: %s", error_name(err)); |
80 FATAL_ERR(err, "line_proto_flush"); |
82 } |
81 } |
83 |
82 |
84 /* |
83 /* |
85 * Schedule our sock_stream callback |
84 * Schedule our sock_stream callback |
86 */ |
85 */ |