aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-08-18 16:45:53 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-08-18 16:45:53 +0200
commit64275e09a21aa78076c1aaefc015e96c2864847b (patch)
tree321dffe5e388ebe86ab92be7f48fa6d7028532d3
parentd1778a5beb18331b9e521527a66218fa468c9005 (diff)
downloadirc-64275e09a21aa78076c1aaefc015e96c2864847b.zip
irc-64275e09a21aa78076c1aaefc015e96c2864847b.tar.bz2
Attempts to deal with timeouts.
libircclient does not seem to detect any issue when the connection has been dropped due to external causes. I added a test (getting the current channel topic)that should trigger if 5min go by without anything happening, hopefully this will cause libircclient to detect the connection problem, if not, implement a timeout from the lack of replies concerning the topic should not be too hard.
-rw-r--r--src/irc/irc.c26
-rw-r--r--src/irc/irc.h2
-rw-r--r--src/main.c21
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],
diff --git a/src/main.c b/src/main.c
index 2646809..becd6a3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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)
{