| summaryrefslogtreecommitdiff |
diff options
| -rw-r--r-- | src/irc/irc.c | 26 | ||||
| -rw-r--r-- | src/irc/irc.h | 2 | ||||
| -rw-r--r-- | src/main.c | 21 |
3 files changed, 49 insertions, 0 deletions
diff --git a/src/irc/irc.c b/src/irc/irc.c index f1290f9..5779a7a 100644 --- a/src/irc/irc.c +++ b/src/irc/irc.c @@ -140,3 +140,29 @@ void JH_irc_handle_numeric_event ) { } + +int JH_irc_test_connection +( + struct JH_irc irc [const restrict static 1] +) +{ + if + ( + irc_cmd_topic + ( + irc->session, + JH_parameters_get_irc_channel(irc->params), + (const char *) NULL + ) + != 0 + ) + { + JH_S_ERROR(stderr, "Could not request IRC topic to test connection."); + + return -1; + } + + JH_S_DEBUG(stdout, 1, "Testing connection..."); + + return 0; +} diff --git a/src/irc/irc.h b/src/irc/irc.h index a6c2df3..67a4350 100644 --- a/src/irc/irc.h +++ b/src/irc/irc.h @@ -16,6 +16,8 @@ int JH_irc_initialize int JH_irc_connect (struct JH_irc irc [const restrict static 1]); +int JH_irc_test_connection (struct JH_irc irc [const restrict static 1]); + int JH_irc_send_message ( struct JH_irc irc [const restrict static 1], @@ -106,6 +106,9 @@ static int event_handling_loop struct timeval tv; fd_set in_set, out_set; int fd_max, error; + int timeouts; + + timeouts = 0; for (;;) { @@ -161,6 +164,24 @@ static int event_handling_loop strerror(error) ); } + else if (error == 0) + { + timeouts += 1; + + /* 1200 timeouts => 5min */ + if ((timeouts >= 1200) && (JH_irc_test_connection(irc) != 0)) + { + JH_S_ERROR(stderr, "Timed out."); + + JH_irc_finalize(irc); + + return -1; + } + } + else + { + timeouts = 0; + } if (JH_irc_post_select(irc, &in_set, &out_set) < 0) { |


