2 #include "log.h" |
2 #include "log.h" |
3 |
3 |
4 #include <stdlib.h> |
4 #include <stdlib.h> |
5 #include <string.h> |
5 #include <string.h> |
6 |
6 |
|
7 /** |
|
8 * Something happaned which caused our irc_conn to fail. Destroy it, and recover. XXX: somehow |
|
9 */ |
|
10 static void irc_net_error (struct irc_net *net, struct error_info *err) |
|
11 { |
|
12 struct irc_chan *chan = NULL; |
|
13 |
|
14 // log an error |
|
15 log_err_info(err, "irc_conn failed"); |
|
16 |
|
17 // destroy connection and set NULL |
|
18 irc_conn_destroy(net->conn); |
|
19 net->conn = NULL; |
|
20 |
|
21 // update channel state |
|
22 TAILQ_FOREACH(chan, &net->channels, node) { |
|
23 // XXX: notify channel somehow |
|
24 } |
|
25 |
|
26 // XXX: reconnect? |
|
27 } |
|
28 |
|
29 /** |
|
30 * Our irc_conn has registered. Join our channels |
|
31 */ |
7 static void irc_net_conn_registered (struct irc_conn *conn, void *arg) |
32 static void irc_net_conn_registered (struct irc_conn *conn, void *arg) |
8 { |
33 { |
9 struct irc_net *net = arg; |
34 struct irc_net *net = arg; |
10 struct irc_chan *chan = NULL; |
35 struct irc_chan *chan = NULL; |
11 err_t err; |
36 struct error_info err; |
12 |
37 |
13 (void) conn; |
38 (void) conn; |
14 |
39 |
15 // join our channels |
40 // join our channels |
16 TAILQ_FOREACH(chan, &net->channels, node) { |
41 TAILQ_FOREACH(chan, &net->channels, node) { |
17 if ((err = irc_chan_join(chan))) |
42 if ((ERROR_CODE(&err) = irc_chan_join(chan))) |
18 // XXX: fuck... |
43 // XXX: this should be some kind of irc_chan_error instead |
19 FATAL_ERR(err, "irc_chan_join failed"); |
44 irc_net_error(net, &err); |
20 } |
45 } |
21 } |
46 } |
22 |
47 |
|
48 /** |
|
49 * Our irc_conn has spontaneously failed, destroy it |
|
50 */ |
23 static void irc_net_conn_error (struct irc_conn *conn, struct error_info *err, void *arg) |
51 static void irc_net_conn_error (struct irc_conn *conn, struct error_info *err, void *arg) |
24 { |
52 { |
25 struct irc_net *net = arg; |
53 struct irc_net *net = arg; |
26 |
54 |
27 // log an error |
55 (void) conn; |
28 log_err_info(err, "irc_conn failed"); |
56 |
29 |
57 irc_net_error(net, err); |
30 // destroy and set NULL |
|
31 irc_conn_destroy(conn); |
|
32 net->conn = NULL; |
|
33 |
|
34 // XXX: reconnect? |
|
35 } |
58 } |
36 |
59 |
37 /** |
60 /** |
38 * Our irc_conn_callbacks list |
61 * Our irc_conn_callbacks list |
39 */ |
62 */ |