summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d3d8af3)
raw | patch | inline | side by side (parent: d3d8af3)
author | Max Kellermann <max.kellermann@gmail.com> | |
Fri, 17 Mar 2017 22:33:49 +0000 (23:33 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Fri, 17 Mar 2017 22:33:49 +0000 (23:33 +0100) |
More preparations for asynchronous connect.
src/callbacks.h | patch | blob | history | |
src/main.c | patch | blob | history | |
src/mpdclient.c | patch | blob | history |
diff --git a/src/callbacks.h b/src/callbacks.h
index c4f1cf929f4c47f2ba86e148f24b1b59bd573981..6c315e45649396063003924ab5c48a13766623b0 100644 (file)
--- a/src/callbacks.h
+++ b/src/callbacks.h
struct mpdclient;
+/**
+ * A connection to MPD has been established.
+ */
+void
+mpdclient_connected_callback(void);
+
+/**
+ * An attempt to connect to MPD has failed.
+ * mpdclient_error_callback() has been called already.
+ */
+void
+mpdclient_failed_callback(void);
+
/**
* The connection to MPD was lost. If this was due to an error, then
* mpdclient_error_callback() has already been called.
diff --git a/src/main.c b/src/main.c
index ec051f4a8c83de04a54b1e9983910a3847614662..12bee3d733a2e9733ab27f8a8feb37c4079500e5 100644 (file)
--- a/src/main.c
+++ b/src/main.c
doupdate();
mpdclient_disconnect(mpd);
- if (!mpdclient_connect(mpd, options.host, options.port,
- options.timeout_ms,
- options.password)) {
- /* try again in 5 seconds */
- reconnect_source_id = g_timeout_add(5000,
- timer_reconnect, NULL);
- return FALSE;
- }
+ mpdclient_connect(mpd, options.host, options.port,
+ options.timeout_ms,
+ options.password);
+
+ return FALSE;
+}
+
+static void
+check_reconnect(void)
+{
+ if (mpdclient_is_dead(mpd) && reconnect_source_id == 0)
+ /* reconnect when the connection is lost */
+ reconnect_source_id = g_timeout_add(1000, timer_reconnect,
+ NULL);
+}
+
+void
+mpdclient_connected_callback(void)
+{
+ assert(reconnect_source_id == 0);
#ifndef NCMPC_MINI
/* quit if mpd is pre 0.14 - song id not supported by mpd */
/* try again after 30 seconds */
reconnect_source_id = g_timeout_add(30000,
timer_reconnect, NULL);
- return FALSE;
+ return;
}
#endif
do_mpd_update();
auto_update_timer();
-
- return FALSE;
}
-static void
-check_reconnect(void)
+void
+mpdclient_failed_callback(void)
{
- if (mpdclient_is_dead(mpd) && reconnect_source_id == 0)
- /* reconnect when the connection is lost */
- reconnect_source_id = g_timeout_add(1000, timer_reconnect,
- NULL);
+ assert(reconnect_source_id == 0);
+
+ /* try again in 5 seconds */
+ reconnect_source_id = g_timeout_add(5000,
+ timer_reconnect, NULL);
}
void
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 0209d6464bf8287ab4294ded44d35995ab05043b..3db559b3640c4872fe592159ea430b2667c707f3 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
if (mpd_connection_get_error(c->connection) != MPD_ERROR_SUCCESS) {
mpdclient_handle_error(c);
mpdclient_disconnect(c);
+ mpdclient_failed_callback();
return false;
}
if (password != NULL && !mpd_run_password(c->connection, password)) {
mpdclient_handle_error(c);
mpdclient_disconnect(c);
+ mpdclient_failed_callback();
return false;
}
++c->connection_id;
+ mpdclient_connected_callback();
+
return true;
}