This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch main
in repository elaro.
View the commit online.
commit bedc29df1509bb3646fe605495af078a901ff3a7
Author: Alastair Poole <[email protected]>
AuthorDate: Tue Nov 24 12:00:46 2026 +0000
ui: handle reconnect when we disconnect
---
data/meson.build | 2 +-
data/themes/view-refresh.svg | 3 ++
data/themes/widgets.edc | 19 ++++++--
src/core/servers.c | 8 +--
src/core/servers.h | 2 +
src/engine/elaro_engine.c | 87 +++++++++++++++++++++++++++++----
src/engine/elaro_engine.h | 3 ++
src/fe-efl/ui/elaro_ui.c | 20 ++++++++
src/fe-efl/ui/elaro_ui_private.h | 2 +-
tests/fe-efl/meson.build | 2 +-
tests/fe-efl/reconnect.py | 14 ++++--
tests/fe-efl/test-reconnect.c | 102 ++++++++++++++++++++++++++++++++++-----
12 files changed, 229 insertions(+), 35 deletions(-)
diff --git a/data/meson.build b/data/meson.build
index 00b8f22..ad081f5 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -21,7 +21,7 @@ foreach name : ['midnight', 'porcelain', 'verdigris', 'ember']
elaro_assets += custom_target(name + '.edj',
input : 'themes' / name / (name + '.edc'),
output : name + '.edj',
- depend_files : theme_icons + files('themes/widgets.edc', 'themes/progress.edc', 'themes/window-shadow.png', 'themes/add.svg'),
+ depend_files : theme_icons + files('themes/widgets.edc', 'themes/progress.edc', 'themes/window-shadow.png', 'themes/add.svg', 'themes/view-refresh.svg'),
command : [edje_cc, '-id', meson.current_source_dir() / 'themes' / name,
'-id', meson.current_source_dir() / 'themes', '@INPUT@', '@OUTPUT@'],
build_by_default : true,
diff --git a/data/themes/view-refresh.svg b/data/themes/view-refresh.svg
new file mode 100644
index 0000000..48d028d
--- /dev/null
+++ b/data/themes/view-refresh.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <path d="M18.5 11a6.6 6.6 0 1 0-.8 4.5M18.5 6v5h-5" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>
diff --git a/data/themes/widgets.edc b/data/themes/widgets.edc
index f0fba11..9445fae 100644
--- a/data/themes/widgets.edc
+++ b/data/themes/widgets.edc
@@ -69,6 +69,15 @@ group { name: "elaro/icons/add"; min: 15 15;
}
}
}
+group { name: "elaro/icons/view-refresh"; min: 15 15;
+ images.image: "view-refresh.svg" COMP;
+ parts {
+ part { name: "icon"; type: IMAGE; mouse_events: 0;
+ description { state: "default" 0.0; color: ACCENT;
+ aspect: 1 1; aspect_preference: BOTH; image.normal: "view-refresh.svg"; }
+ }
+ }
+}
/* Quiet title-bar controls shared by windows and popup close buttons. */
group { name: "elm/button/base/elaro/window-control";
min: 30 30;
@@ -79,7 +88,11 @@ group { name: "elm/button/base/elaro/window-control";
description { state: "over" 0.0; color: EDGE; }
description { state: "pressed" 0.0; color: PANEL; }
}
- part { name: "elm.swallow.content"; type: SWALLOW;
+ part { name: "content_clip"; type: RECT; mouse_events: 0;
+ description { state: "default" 0.0; }
+ description { state: "disabled" 0.0; inherit: "default" 0.0; color: 255 255 255 110; }
+ }
+ part { name: "elm.swallow.content"; type: SWALLOW; clip_to: "content_clip";
scale: 1;
description { state: "default" 0.0; offset_scale: 1;
rel1.offset: 5 5; rel2.offset: -5 -5; }
@@ -97,8 +110,8 @@ group { name: "elm/button/base/elaro/window-control";
program { signal: "mouse,up,1"; source: "event"; action: SIGNAL_EMIT "elm,action,unpress" "elm"; after: "release"; }
program { name: "release"; action: STATE_SET "over" 0.0; target: "surface"; }
program { signal: "mouse,clicked,1"; source: "event"; action: SIGNAL_EMIT "elm,action,click" "elm"; }
- program { signal: "elm,state,disabled"; source: "elm"; action: STATE_SET "disabled" 0.0; target: "event"; }
- program { signal: "elm,state,enabled"; source: "elm"; action: STATE_SET "default" 0.0; target: "event"; }
+ program { signal: "elm,state,disabled"; source: "elm"; action: STATE_SET "disabled" 0.0; target: "event"; target: "content_clip"; }
+ program { signal: "elm,state,enabled"; source: "elm"; action: STATE_SET "default" 0.0; target: "event"; target: "content_clip"; }
program { signal: "elm,action,focus_highlight,show"; source: "elm"; action: STATE_SET "over" 0.0; target: "surface"; }
program { signal: "elm,action,focus_highlight,hide"; source: "elm"; action: STATE_SET "default" 0.0; target: "surface"; }
}
diff --git a/src/core/servers.c b/src/core/servers.c
index fd3a1cf..9f2bd83 100644
--- a/src/core/servers.c
+++ b/src/core/servers.c
@@ -98,7 +98,7 @@ static char *server_create_address_tag(const char *address)
/* create unique tag for server. prefer ircnet's name or
generate it from server's address */
-static char *server_create_tag(SERVER_CONNECT_REC *conn)
+char *server_create_tag(SERVER_CONNECT_REC *conn, gboolean (*reserved)(const char *tag))
{
GString *str;
char *tag;
@@ -112,6 +112,7 @@ static char *server_create_tag(SERVER_CONNECT_REC *conn)
if (conn->tag != NULL && server_find_tag(conn->tag) == NULL &&
server_find_lookup_tag(conn->tag) == NULL &&
+ (reserved == NULL || !reserved(conn->tag)) &&
strncmp(conn->tag, tag, strlen(tag)) == 0) {
/* use the existing tag if it begins with the same ID -
this is useful when you have several connections to
@@ -128,7 +129,8 @@ static char *server_create_tag(SERVER_CONNECT_REC *conn)
num = 2;
while (server_find_tag(str->str) != NULL ||
- server_find_lookup_tag(str->str) != NULL) {
+ server_find_lookup_tag(str->str) != NULL ||
+ (reserved != NULL && reserved(str->str))) {
g_string_printf(str, "%s%d", tag, num);
num++;
}
@@ -387,7 +389,7 @@ void server_connect_init(SERVER_REC *server)
server->connrec->realname = g_strdup(str);
}
- server->tag = server_create_tag(server->connrec);
+ server->tag = server_create_tag(server->connrec, NULL);
server->connect_tag = -1;
}
diff --git a/src/core/servers.h b/src/core/servers.h
index fa10b32..70e247e 100644
--- a/src/core/servers.h
+++ b/src/core/servers.h
@@ -56,6 +56,8 @@ void server_connect_unref(SERVER_CONNECT_REC *conn);
SERVER_REC *server_connect(SERVER_CONNECT_REC *conn);
+/* Allocate a tag, optionally excluding tags owned by disconnected sessions. */
+char *server_create_tag(SERVER_CONNECT_REC *conn, gboolean (*reserved)(const char *tag));
/* initializes server record but doesn't start connecting */
void server_connect_init(SERVER_REC *server);
/* Connection to server finished, fill the rest of the fields */
diff --git a/src/engine/elaro_engine.c b/src/engine/elaro_engine.c
index 1143ae7..0a0e0f3 100644
--- a/src/engine/elaro_engine.c
+++ b/src/engine/elaro_engine.c
@@ -32,7 +32,7 @@ typedef struct
SERVER_REC *server;
char *tag, *profile_nick;
guint retry_timer, timeout_timer, attempts;
- gboolean enabled, registered;
+ gboolean auto_reconnect, enabled, registered, closed;
} Connection;
struct _Elaro_Engine
@@ -41,6 +41,7 @@ struct _Elaro_Engine
int command_pipe[2], event_pipe[2];
GThread *thread;
GSList *connections;
+ bool reconnect_available;
GMainLoop *loop;
char *binary, *selected_server, *selected_target, *last_nicks;
GHashTable *whois_presence;
@@ -316,6 +317,36 @@ _connection_timers_cancel(Connection *connection)
connection->retry_timer = connection->timeout_timer = 0;
}
+static bool
+_connection_can_reconnect(const Connection *connection)
+{
+ return !connection->closed && !connection->server;
+}
+
+static bool
+_reconnect_available(void)
+{
+ for (GSList *node = active->connections; node; node = node->next)
+ if (_connection_can_reconnect(node->data)) return true;
+ return false;
+}
+
+static void
+_reconnect_availability_update(void)
+{
+ bool available = _reconnect_available();
+ if (active->reconnect_available == available) return;
+
+ active->reconnect_available = available;
+ Elaro_Engine_Event *event = g_new0(Elaro_Engine_Event, 1);
+ event->type = ELARO_ENGINE_RECONNECT_AVAILABLE;
+ event->server = g_strdup("Status");
+ event->target = g_strdup("");
+ event->text = g_strdup("");
+ event->reconnect_available = available;
+ elaro_engine_event_push(event);
+}
+
static void
_connection_start(Connection *connection);
@@ -339,6 +370,7 @@ _connection_schedule(Connection *connection)
{
_connection_timers_cancel(connection);
connection->server = NULL;
+ _reconnect_availability_update();
if (!connection->enabled) return;
if (connection->attempts >= 5)
{
@@ -381,6 +413,7 @@ _connection_start(Connection *connection)
/* The adapter owns retry timing and limits; suppress Irssi's retry queue. */
server->no_reconnect = TRUE;
connection->server = server;
+ _reconnect_availability_update();
g_free(connection->tag);
connection->tag = g_strdup(server->tag);
g_free(connection->conn->tag);
@@ -449,7 +482,7 @@ _disconnected(SERVER_REC *s)
if (g_str_has_prefix(presence_key, prefix)) g_hash_table_iter_remove(&presence_iter);
g_free(prefix);
if (!connection) return;
- if (connection->registered && s->connection_lost)
+ if (connection->registered && !connection->closed)
{
char *channels = irc_server_get_channels(IRC_SERVER(s), REJOIN_CHANNELS_MODE_ON);
g_free(connection->conn->channels);
@@ -742,6 +775,17 @@ _clean_field(const char *s)
return s && !strpbrk(s, "\r\n");
}
+static gboolean
+_connection_tag_reserved(const char *tag)
+{
+ for (GSList *node = active->connections; node; node = node->next)
+ {
+ Connection *connection = node->data;
+ if (!connection->closed && !g_ascii_strcasecmp(connection->tag, tag)) return TRUE;
+ }
+ return FALSE;
+}
+
static void
_connect_command(Elaro_Engine_Command *c)
{
@@ -799,11 +843,31 @@ _connect_command(Elaro_Engine_Command *c)
connection = g_new0(Connection, 1);
connection->conn = conn; /* Own the creation reference through retries. */
connection->profile_nick = g_strdup(c->nick);
- connection->enabled = c->auto_reconnect;
+ connection->auto_reconnect = connection->enabled = c->auto_reconnect;
+ char *tag = server_create_tag(conn, _connection_tag_reserved);
+ g_free(conn->tag);
+ conn->tag = tag;
+ connection->tag = g_strdup(tag);
active->connections = g_slist_append(active->connections, connection);
_connection_start(connection);
}
+static void
+_reconnect_command(void)
+{
+ for (GSList *node = active->connections; node; node = node->next)
+ {
+ Connection *connection = node->data;
+ if (!_connection_can_reconnect(connection)) continue;
+
+ _connection_timers_cancel(connection);
+ connection->attempts = 0;
+ connection->enabled = connection->auto_reconnect;
+ _emit_event(ELARO_ENGINE_LINE, connection->tag, "", "Reconnecting…");
+ _connection_start(connection);
+ }
+}
+
static void
_open_query(const char *server_tag, const char *nick)
{
@@ -837,18 +901,19 @@ _open_query(const char *server_tag, const char *nick)
}
static void
-_connection_cancel(const char *server_tag)
+_connection_cancel(const char *server_tag, gboolean close)
{
GSList *node;
for (node = active->connections; node; node = node->next)
{
Connection *connection = node->data;
- if (g_ascii_strcasecmp(connection->tag ? connection->tag : "",
- server_tag ? server_tag : ""))
+ if (connection->closed || g_ascii_strcasecmp(connection->tag, server_tag ? server_tag : ""))
continue;
connection->enabled = FALSE;
+ if (close) connection->closed = TRUE;
_connection_timers_cancel(connection);
}
+ _reconnect_availability_update();
}
static void
@@ -861,7 +926,7 @@ _close_server(const char *server_tag)
if (!server_tag || !*server_tag || !strcmp(server_tag, "Status")) return;
- _connection_cancel(server_tag);
+ _connection_cancel(server_tag, TRUE);
/* Queries survive ordinary disconnects; explicitly close them here. */
for (node = queries; node; node = next)
{
@@ -916,8 +981,7 @@ _connection_forget_channel(const char *server_tag, const char *target)
GString *channels, *passwords;
guint i, key_count;
- if (g_ascii_strcasecmp(connection->tag ? connection->tag : "",
- server_tag ? server_tag : ""))
+ if (connection->closed || g_ascii_strcasecmp(connection->tag, server_tag ? server_tag : ""))
continue;
parts = g_strsplit(connection->conn->channels ? connection->conn->channels : "", " ", 2);
if (!parts[0])
@@ -1005,7 +1069,7 @@ _input_command(Elaro_Engine_Command *c)
if (!g_ascii_strncasecmp(c->text, "/quit", 5)
&& (!c->text[5] || c->text[5] == ' ' || c->text[5] == '\t'))
{
- _connection_cancel(c->server);
+ _connection_cancel(c->server, FALSE);
if (!s) s = server_find_lookup_tag(c->server ? c->server : "");
if (s)
{
@@ -1175,6 +1239,9 @@ _dispatch(gint fd, GIOCondition condition, gpointer data)
case ELARO_ENGINE_CONNECT:
_connect_command(c);
break;
+ case ELARO_ENGINE_RECONNECT:
+ _reconnect_command();
+ break;
case ELARO_ENGINE_INPUT:
_input_command(c);
break;
diff --git a/src/engine/elaro_engine.h b/src/engine/elaro_engine.h
index 00d381d..1794e61 100644
--- a/src/engine/elaro_engine.h
+++ b/src/engine/elaro_engine.h
@@ -8,6 +8,7 @@
typedef enum
{
ELARO_ENGINE_CONNECT,
+ ELARO_ENGINE_RECONNECT,
ELARO_ENGINE_INPUT,
ELARO_ENGINE_SELECT,
ELARO_ENGINE_QUERY,
@@ -39,6 +40,7 @@ typedef enum
{
ELARO_ENGINE_LINE,
ELARO_ENGINE_CONNECTION,
+ ELARO_ENGINE_RECONNECT_AVAILABLE,
ELARO_ENGINE_NICKS,
ELARO_ENGINE_JOINED,
ELARO_ENGINE_QUERY_OPENED,
@@ -91,6 +93,7 @@ typedef struct
char *host, *nick;
int port;
bool connected;
+ bool reconnect_available; /* RECONNECT_AVAILABLE payload. */
bool disconnected; /* Status line also shown in the selected conversation. */
bool channel_message; /* Channel chat or action, excluding protocol/status events. */
/* Channel text formatting uses the nickname and casemapping at receipt. */
diff --git a/src/fe-efl/ui/elaro_ui.c b/src/fe-efl/ui/elaro_ui.c
index bfdecab..b073272 100644
--- a/src/fe-efl/ui/elaro_ui.c
+++ b/src/fe-efl/ui/elaro_ui.c
@@ -1,6 +1,17 @@
#include "elaro_ui_private.h"
#include <locale.h>
+static void
+_reconnect_cb(void *data, Evas_Object *obj, void *info)
+{
+ Elaro_Ui *ui = data;
+ Elaro_Engine_Command *command = calloc(1, sizeof(*command));
+
+ if (!command) return;
+ command->type = ELARO_ENGINE_RECONNECT;
+ elaro_engine_submit(ui->engine, command);
+}
+
static void
_last_connected_save(Elaro_Config *config, const Elaro_Engine_Event *event)
{
@@ -75,6 +86,9 @@ _receive_events_cb(void *data, Ecore_Fd_Handler *handler)
elaro_ui_buffer_event(ui, event);
if (event->connected) _last_connected_save(ui->config, event);
break;
+ case ELARO_ENGINE_RECONNECT_AVAILABLE:
+ elm_object_disabled_set(ui->reconnect, !event->reconnect_available);
+ break;
case ELARO_ENGINE_NICKS:
if (ui->current && !strcmp(event->server, ui->current->server)
@@ -295,6 +309,12 @@ elaro_ui_run(int argc, char **argv)
elaro_ui_window_control_style_set(settings, EINA_FALSE);
elm_box_pack_end(bar, settings);
+ ui.reconnect = elaro_ui_icon_button_add(ui.win, "view-refresh", _("Reconnect disconnected servers"),
+ _reconnect_cb, &ui);
+ elaro_ui_window_control_style_set(ui.reconnect, EINA_FALSE);
+ elm_object_disabled_set(ui.reconnect, EINA_TRUE);
+ elm_box_pack_end(bar, ui.reconnect);
+
/* A dedicated title region leaves the channel heading clickable. */
icon = elm_label_add(bar);
elm_object_style_set(icon, "elaro/title");
diff --git a/src/fe-efl/ui/elaro_ui_private.h b/src/fe-efl/ui/elaro_ui_private.h
index f9cdc5c..98edb49 100644
--- a/src/fe-efl/ui/elaro_ui_private.h
+++ b/src/fe-efl/ui/elaro_ui_private.h
@@ -53,7 +53,7 @@ struct _Elaro_Ui
Ecore_Event_Handler *theme_config_handler;
Evas_Object *resize_grips[8];
Evas_Object *frame, *app_menu, *theme_buttons[4], *theme_status;
- Evas_Object *content;
+ Evas_Object *content, *reconnect;
Evas_Object *buffer_panes, *user_panes;
Ecore_Animator *user_panel_animator;
double user_panel_animation_from;
diff --git a/tests/fe-efl/meson.build b/tests/fe-efl/meson.build
index 5d58318..bc417bc 100644
--- a/tests/fe-efl/meson.build
+++ b/tests/fe-efl/meson.build
@@ -136,7 +136,7 @@ reconnect_test = executable('test-reconnect', 'test-reconnect.c',
link_with : [engine_lib, libconfig_a, libcore_a, libirc_a],
dependencies : dep + [threads_dep],
export_dynamic : true)
-foreach scenario : ['success', 'limit', 'timeout', 'cancel', 'quit', 'disabled', 'quit-message', 'quit-default', 'quit-blank']
+foreach scenario : ['success', 'manual', 'all', 'limit', 'timeout', 'cancel', 'quit', 'disabled', 'quit-message', 'quit-default', 'quit-blank']
test('IRC reconnect ' + scenario, python,
args : [files('reconnect.py'), reconnect_test, scenario], timeout : 90)
endforeach
diff --git a/tests/fe-efl/reconnect.py b/tests/fe-efl/reconnect.py
index e2508ce..7364940 100644
--- a/tests/fe-efl/reconnect.py
+++ b/tests/fe-efl/reconnect.py
@@ -56,7 +56,7 @@ with socket.socket() as listener, tempfile.TemporaryDirectory() as home:
for channel in line.split()[1].split(','):
current.add(channel)
peer.sendall(f':tester!u@host JOIN :{channel}\r\n'.encode())
- if current == {'#saved', '#later'} and len(accepted) == 1 and not mode.startswith('quit-'):
+ if current == {'#saved', '#later'} and len(accepted) == 1 and mode != 'manual' and not mode.startswith('quit-'):
joined.append(current)
break
if line.startswith('QUIT'):
@@ -77,15 +77,19 @@ with socket.socket() as listener, tempfile.TemporaryDirectory() as home:
stopped.set()
thread.join(timeout=2)
assert not errors, errors
- expected = 2 if mode == 'success' else 6 if mode in ('limit', 'timeout') else 1
+ expected = 4 if mode == 'all' else 2 if mode in ('success', 'manual') else 6 if mode in ('limit', 'timeout') else 1
assert len(accepted) == expected, accepted
- for before, after in zip(accepted, accepted[1:]):
- assert after - before >= 4.8, accepted
+ if mode not in ('manual', 'all'):
+ for before, after in zip(accepted, accepted[1:]):
+ assert after - before >= 4.8, accepted
if mode == 'timeout':
assert accepted[1] - accepted[0] >= 34.8, accepted
- if mode == 'success':
+ if mode in ('success', 'manual'):
assert joined == [{'#saved', '#later'}, {'#saved', '#later'}], joined
+ if mode == 'all':
+ assert joined == [{'#saved', '#first'}, {'#saved', '#second'}] * 2, joined
+
if mode.startswith('quit-'):
reason = 'Gone fishing — back soon' if mode == 'quit-message' else 'Leaving'
assert quits == ['QUIT :' + reason], quits
diff --git a/tests/fe-efl/test-reconnect.c b/tests/fe-efl/test-reconnect.c
index e77d23b..1b94a0c 100644
--- a/tests/fe-efl/test-reconnect.c
+++ b/tests/fe-efl/test-reconnect.c
@@ -12,25 +12,90 @@ static void submit(Elaro_Engine *engine, Elaro_Engine_Command_Type type,
elaro_engine_submit(engine, c);
}
+static void connect_server(Elaro_Engine *engine, int port, gboolean auto_reconnect)
+{
+ Elaro_Engine_Command *c = g_new0(Elaro_Engine_Command, 1);
+ c->type = ELARO_ENGINE_CONNECT;
+ c->host = g_strdup("127.0.0.1");
+ c->port = port;
+ c->nick = g_strdup("tester");
+ c->password = g_strdup("");
+ c->channels = g_strdup("#saved secret");
+ c->auto_reconnect = auto_reconnect;
+ elaro_engine_submit(engine, c);
+}
+
+static void reconnect_all(Elaro_Engine *engine, int port)
+{
+ char *tags[2] = { NULL };
+ guint joined[2] = { 0 };
+ guint registered = 0, disconnected = 0, closed = 0, changes = 0;
+ gint64 deadline = g_get_monotonic_time() + 45 * G_TIME_SPAN_SECOND;
+
+ connect_server(engine, port, FALSE);
+ while (closed < 2 && g_get_monotonic_time() < deadline) {
+ Elaro_Engine_Event *event = elaro_engine_poll(engine);
+ if (!event) { g_usleep(1000); continue; }
+
+ if (event->type == ELARO_ENGINE_CONNECTION && event->connected && registered < 2)
+ tags[registered++] = g_strdup(event->server);
+ if (event->type == ELARO_ENGINE_RECONNECT_AVAILABLE) {
+ changes++;
+ g_assert_cmpuint(changes, <=, 2);
+ g_assert_cmpint(event->reconnect_available, ==, changes == 1);
+ }
+ if (event->type == ELARO_ENGINE_JOINED) {
+ guint index = g_strcmp0(tags[0], event->server) == 0 ? 0 : 1;
+ g_assert_cmpstr(event->server, ==, tags[index]);
+ const char *channel = index == 0 ? "#first" : "#second";
+ g_assert_true(!strcmp(event->target, "#saved") || !strcmp(event->target, channel));
+ joined[index]++;
+ if (joined[index] == 1) {
+ char *join = g_strdup_printf("/join %s", channel);
+ submit(engine, ELARO_ENGINE_INPUT, event->server, join);
+ g_free(join);
+ } else {
+ if (joined[index] == 2)
+ submit(engine, ELARO_ENGINE_INPUT, event->server, "/quit");
+ if (joined[index] == 4)
+ submit(engine, ELARO_ENGINE_CLOSE, event->server, NULL);
+ }
+ }
+ if (!strcmp(event->text, "Auto-reconnect cancelled")) {
+ disconnected++;
+ if (disconnected == 1) connect_server(engine, port, FALSE);
+ if (disconnected == 2) submit(engine, ELARO_ENGINE_RECONNECT, NULL, NULL);
+ }
+ if (event->type == ELARO_ENGINE_BUFFER_CLOSED) closed++;
+ elaro_engine_event_free(event);
+ }
+ g_assert_cmpuint(closed, ==, 2);
+ g_assert_cmpuint(changes, ==, 2);
+ g_assert_cmpstr(tags[0], !=, tags[1]);
+ g_free(tags[0]);
+ g_free(tags[1]);
+}
+
int main(int argc, char **argv)
{
g_assert_cmpint(argc, ==, 3);
const char *mode = argv[2];
+ int port = atoi(argv[1]);
+ gboolean manual = !strcmp(mode, "manual");
const char *quit_text = !strcmp(mode, "quit-message") ? "/QuIt \tGone fishing — back soon"
: !strcmp(mode, "quit-default") ? "/quit"
: !strcmp(mode, "quit-blank") ? "/quit \t " : NULL;
Elaro_Engine *engine = elaro_engine_start(argv[0]);
- Elaro_Engine_Command *c = g_new0(Elaro_Engine_Command, 1);
- c->type = ELARO_ENGINE_CONNECT;
- c->host = g_strdup("127.0.0.1");
- c->port = atoi(argv[1]);
- c->nick = g_strdup("tester");
- c->password = g_strdup("");
- c->channels = g_strdup("#saved secret");
- c->auto_reconnect = strcmp(mode, "disabled") != 0;
- elaro_engine_submit(engine, c);
+ if (!strcmp(mode, "all")) {
+ reconnect_all(engine, port);
+ elaro_engine_stop(engine);
+ return 0;
+ }
+ connect_server(engine, port, !manual && strcmp(mode, "disabled") != 0);
guint retries = 0, saved = 0, later = 0;
gboolean done = FALSE, closing = FALSE;
+ gboolean requested = FALSE, disconnected = FALSE;
+ guint availability_changes = 0;
char *tag = NULL;
gint64 deadline = g_get_monotonic_time() + 75 * G_TIME_SPAN_SECOND;
while (g_get_monotonic_time() < deadline) {
@@ -54,8 +119,10 @@ int main(int argc, char **argv)
submit(engine, ELARO_ENGINE_INPUT, event->server, quit_text);
closing = TRUE;
}
+ if (manual && saved == 1 && later == 1 && !requested)
+ submit(engine, ELARO_ENGINE_INPUT, event->server, "/quit");
if (saved == 2 && later == 2) {
- g_assert_cmpuint(retries, ==, 1);
+ g_assert_cmpuint(retries, ==, manual ? 0 : 1);
submit(engine, ELARO_ENGINE_CLOSE, event->server, NULL);
closing = TRUE;
}
@@ -68,11 +135,23 @@ int main(int argc, char **argv)
submit(engine, ELARO_ENGINE_CLOSE, event->server, NULL);
closing = TRUE;
}
+ if (manual && event->disconnected && !closing) disconnected = TRUE;
+ if (manual && event->type == ELARO_ENGINE_RECONNECT_AVAILABLE) {
+ g_assert_true(disconnected);
+ availability_changes++;
+ g_assert_cmpint(event->reconnect_available, ==, availability_changes == 1);
+ if (event->reconnect_available) {
+ g_assert_false(requested);
+ requested = TRUE;
+ submit(engine, ELARO_ENGINE_RECONNECT, NULL, NULL);
+ submit(engine, ELARO_ENGINE_RECONNECT, NULL, NULL);
+ }
+ }
if ((!strcmp(mode, "disabled") && !strcmp(event->text, "Disconnected")) ||
(closing && event->type == ELARO_ENGINE_BUFFER_CLOSED) ||
((!strcmp(mode, "quit") || quit_text) && !strcmp(event->text, "Auto-reconnect cancelled")) ||
!strcmp(event->text, "Auto-reconnect stopped after 5 retries")) {
- if (!closing && strcmp(mode, "disabled")) g_assert_cmpuint(retries, ==, 5);
+ if (!closing && !manual && strcmp(mode, "disabled")) g_assert_cmpuint(retries, ==, 5);
done = TRUE;
deadline = g_get_monotonic_time() + 6 * G_TIME_SPAN_SECOND;
}
@@ -81,5 +160,6 @@ int main(int argc, char **argv)
elaro_engine_stop(engine);
g_free(tag);
g_assert_true(done);
+ if (manual) g_assert_cmpuint(availability_changes, ==, 2);
return 0;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.