18 |
18 |
19 int main (int argc, char **argv) { |
19 int main (int argc, char **argv) { |
20 struct event_base *ev_base; |
20 struct event_base *ev_base; |
21 struct sock_stream *sock; |
21 struct sock_stream *sock; |
22 struct line_proto *lp; |
22 struct line_proto *lp; |
23 char line_buf[LINE_LENGTH + 1]; |
23 char *line; |
24 struct error_info _err; |
24 struct error_info _err; |
25 |
25 |
26 // initialize libevent |
26 // initialize libevent |
27 if ((ev_base = event_base_new()) == NULL) |
27 if ((ev_base = event_base_new()) == NULL) |
28 err(1, "event_base_new"); |
28 err(1, "event_base_new"); |
34 // over-simplified connect |
34 // over-simplified connect |
35 if (sock_gnutls_connect(&sock, CONNECT_HOST, CONNECT_SERV, &_err)) |
35 if (sock_gnutls_connect(&sock, CONNECT_HOST, CONNECT_SERV, &_err)) |
36 errx(1, "sock_gnutls_connect: %s", error_msg(&_err)); |
36 errx(1, "sock_gnutls_connect: %s", error_msg(&_err)); |
37 |
37 |
38 // line protocol |
38 // line protocol |
39 if (line_proto_create(&lp, sock, &_err)) |
39 if (line_proto_create(&lp, sock, LINE_LENGTH, NULL, NULL, &_err)) |
40 errx(1, "line_proto_create: %s", error_msg(&_err)); |
40 errx(1, "line_proto_create: %s", error_msg(&_err)); |
41 |
41 |
42 // read lines and dump them out |
42 // read lines and dump them out |
43 do { |
43 do { |
44 // recv |
44 // recv |
45 if (line_proto_read(lp, line_buf, sizeof(line_buf))) |
45 if (line_proto_read(lp, &line)) |
46 errx(1, "line_proto_read: %s", error_msg(line_proto_error(lp))); |
46 errx(1, "line_proto_read: %s", error_msg(line_proto_error(lp))); |
47 |
47 |
48 // printf |
48 // printf |
49 printf("<<< %s\n", line_buf); |
49 printf("<<< %s\n", line); |
50 |
50 |
51 } while (1); |
51 } while (1); |
52 |
52 |
53 // ok |
53 // ok |
54 return 0; |
54 return 0; |