aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-08-23 15:09:16 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-08-23 15:09:16 +0200
commitba71528805f777871f52fc278858f56677307064 (patch)
tree2536578a90bf79918941b5d12b12dca4872d1f14
parent8314e55911cee7c64a94d7e7092b69b51b805c93 (diff)
downloadirc-ba71528805f777871f52fc278858f56677307064.zip
irc-ba71528805f777871f52fc278858f56677307064.tar.bz2
Fixes connection test.
Sending the test request made the connection test be considered valid. Woops.
-rw-r--r--src/irc/irc.c32
-rw-r--r--src/irc/irc.h3
-rw-r--r--src/irc/irc_types.h1
-rw-r--r--src/main.c33
4 files changed, 52 insertions, 17 deletions
diff --git a/src/irc/irc.c b/src/irc/irc.c
index 5779a7a..5d2aba4 100644
--- a/src/irc/irc.c
+++ b/src/irc/irc.c
@@ -45,6 +45,7 @@ int JH_irc_initialize
irc->params = params;
irc->jh_net = jh_net;
+ irc->is_testing_connection = 0;
if (!(irc->session))
{
@@ -139,9 +140,34 @@ void JH_irc_handle_numeric_event
unsigned int count
)
{
+ struct JH_irc * irc;
+
+ irc = irc_get_ctx(session);
+
+ if
+ (
+ (event == LIBIRC_RFC_RPL_NOTOPIC)
+ || (event == LIBIRC_RFC_RPL_TOPIC)
+ )
+ {
+ if (irc->is_testing_connection == 1)
+ {
+ JH_S_DEBUG(stdout, 1, "Connection test successful.");
+
+ irc->is_testing_connection = 0;
+ }
+ }
+}
+
+int JH_irc_is_testing_connection
+(
+ struct JH_irc irc [const restrict static 1]
+)
+{
+ return irc->is_testing_connection;
}
-int JH_irc_test_connection
+int JH_irc_start_connection_test
(
struct JH_irc irc [const restrict static 1]
)
@@ -162,7 +188,9 @@ int JH_irc_test_connection
return -1;
}
- JH_S_DEBUG(stdout, 1, "Testing connection...");
+ irc->is_testing_connection = 1;
+
+ JH_S_DEBUG(stdout, 1, "Connection test started...");
return 0;
}
diff --git a/src/irc/irc.h b/src/irc/irc.h
index 67a4350..28d1481 100644
--- a/src/irc/irc.h
+++ b/src/irc/irc.h
@@ -16,7 +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_start_connection_test (struct JH_irc irc [const restrict static 1]);
+int JH_irc_is_testing_connection (struct JH_irc irc [const restrict static 1]);
int JH_irc_send_message
(
diff --git a/src/irc/irc_types.h b/src/irc/irc_types.h
index f846076..f1db35d 100644
--- a/src/irc/irc_types.h
+++ b/src/irc/irc_types.h
@@ -9,6 +9,7 @@ struct JH_irc
irc_session_t * session;
const struct JH_parameters * params;
struct JH_meta_net * jh_net;
+ int is_testing_connection;
};
#endif
diff --git a/src/main.c b/src/main.c
index a4254bd..dcb8a66 100644
--- a/src/main.c
+++ b/src/main.c
@@ -169,25 +169,30 @@ static int event_handling_loop
timeouts += 1;
/* 1200 timeouts => 5min */
- if ((timeouts == 1200) && (JH_irc_test_connection(irc) != 0))
+ if (timeouts >= 1200)
{
- JH_S_ERROR(stderr, "Timed out due to fail connection test.");
+ if (JH_irc_is_testing_connection(irc))
+ {
+ JH_S_ERROR
+ (
+ stderr,
+ "Timed out due to lack of response to connection test."
+ );
- JH_irc_finalize(irc);
+ JH_irc_finalize(irc);
- return -1;
- }
- else if (timeouts >= 1500)
- {
- JH_S_ERROR
- (
- stderr,
- "Timed out due to lack of response to connection test."
- );
+ return -1;
+ }
+ else if (JH_irc_start_connection_test(irc) < 0)
+ {
+ JH_S_ERROR(stderr, "Timed out due to failed connection test.");
+
+ JH_irc_finalize(irc);
- JH_irc_finalize(irc);
+ return -1;
+ }
- return -1;
+ timeouts = 0;
}
}
else