5 #include <string.h> |
5 #include <string.h> |
6 #include <event.h> |
6 #include <event.h> |
7 #include <assert.h> |
7 #include <assert.h> |
8 |
8 |
9 #include <err.h> |
9 #include <err.h> |
|
10 #include <event2/event.h> |
10 |
11 |
11 #include "sock.h" |
12 #include "sock.h" |
12 #include "line_proto.h" |
13 #include "line_proto.h" |
13 |
14 |
14 #define CONNECT_HOST "irc.fixme.fi" |
15 #define CONNECT_HOST "irc.fixme.fi" |
15 #define CONNECT_SERV "6697" |
16 #define CONNECT_SERV "6697" |
16 #define LINE_LENGTH 512 |
17 #define LINE_LENGTH 512 |
17 |
18 |
18 int main (int argc, char **argv) { |
19 int main (int argc, char **argv) { |
|
20 struct event_base *ev_base; |
19 struct sock_stream *sock; |
21 struct sock_stream *sock; |
20 struct line_proto *lp; |
22 struct line_proto *lp; |
21 char line_buf[LINE_LENGTH + 1]; |
23 char line_buf[LINE_LENGTH + 1]; |
22 struct error_info err; |
24 struct error_info _err; |
23 |
25 |
24 // initialize |
26 // initialize libevent |
25 if (sock_init(&err)) |
27 if ((ev_base = event_base_new()) == NULL) |
26 errx(1, "sock_init: %s", error_msg(&err)); |
28 err(1, "event_base_new"); |
|
29 |
|
30 // initialize sock module |
|
31 if (sock_init(ev_base, &_err)) |
|
32 errx(1, "sock_init: %s", error_msg(&_err)); |
27 |
33 |
28 // over-simplified connect |
34 // over-simplified connect |
29 if (sock_gnutls_connect(&sock, CONNECT_HOST, CONNECT_SERV, &err)) |
35 if (sock_gnutls_connect(&sock, CONNECT_HOST, CONNECT_SERV, &_err)) |
30 errx(1, "sock_gnutls_connect: %s", error_msg(&err)); |
36 errx(1, "sock_gnutls_connect: %s", error_msg(&_err)); |
31 |
37 |
32 // line protocol |
38 // line protocol |
33 if (line_proto_create(&lp, sock, &err)) |
39 if (line_proto_create(&lp, sock, &_err)) |
34 errx(1, "line_proto_create: %s", error_msg(&err)); |
40 errx(1, "line_proto_create: %s", error_msg(&_err)); |
35 |
41 |
36 // read lines and dump them out |
42 // read lines and dump them out |
37 do { |
43 do { |
38 // recv |
44 // recv |
39 if (line_proto_read(lp, line_buf, sizeof(line_buf))) |
45 if (line_proto_read(lp, line_buf, sizeof(line_buf))) |