summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 0236c33)
raw | patch | inline | side by side (parent: 0236c33)
author | Max Kellermann <max.kellermann@gmail.com> | |
Sat, 25 Mar 2017 19:09:57 +0000 (20:09 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Sat, 25 Mar 2017 19:54:28 +0000 (20:54 +0100) |
This is what libmpdclient does internally, and when ncmpc copied some
code from libmpdclient, it did not replicate this implementation
detail.
https://bugs.musicpd.org/view.php?id=4672
code from libmpdclient, it did not replicate this implementation
detail.
https://bugs.musicpd.org/view.php?id=4672
NEWS | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history |
index 6956a1e50443562172eabd17bdf14393924718c8..5b3a4d036e7a08809284248673c13ce5205e28ad 100644 (file)
--- a/NEWS
+++ b/NEWS
ncmpc 0.27 - not yet released
+* work around connect failure if /var/run/mpd/socket does not exist
* remove the status bar clock (option "display-time")
* fix assertion failure after connect failure
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 870839fd27dbb69ee8abd1d4b65e79d8c8567ee4..ffa1a5d84408e86757b82d2dbde1617dbf07c583 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
return false;
}
+#ifdef ENABLE_ASYNC_CONNECT
+#ifndef WIN32
+
+static bool
+is_local_socket(const char *host)
+{
+ return *host == '/' || *host == '@';
+}
+
+static bool
+settings_is_local_socket(const struct mpd_settings *settings)
+{
+ const char *host = mpd_settings_get_host(settings);
+ return host != NULL && is_local_socket(host);
+}
+
+#endif
+#endif
+
struct mpdclient *
mpdclient_new(const gchar *host, unsigned port,
unsigned timeout_ms, const gchar *password)
NULL, NULL);
if (c->settings == NULL)
g_error("Out of memory");
+
+#ifndef WIN32
+ c->settings2 = host == NULL && port == 0 &&
+ settings_is_local_socket(c->settings)
+ ? mpd_settings_new(host, 6600, timeout_ms, NULL, NULL)
+ : NULL;
+#endif
+
#else
c->host = host;
c->port = port;
#ifdef ENABLE_ASYNC_CONNECT
mpd_settings_free(c->settings);
+
+#ifndef WIN32
+ if (c->settings2 != NULL)
+ mpd_settings_free(c->settings2);
+#endif
#endif
g_free(c);
#ifdef ENABLE_ASYNC_CONNECT
+static void
+mpdclient_aconnect_start(struct mpdclient *c,
+ const struct mpd_settings *settings);
+
static void
mpdclient_connect_success(struct mpd_connection *connection, void *ctx)
{
assert(c->async_connect != NULL);
c->async_connect = NULL;
+#ifndef WIN32
+ if (!c->connecting2 && c->settings2 != NULL) {
+ c->connecting2 = true;
+ mpdclient_aconnect_start(c, c->settings2);
+ return;
+ }
+#endif
+
mpdclient_error_callback(message);
mpdclient_failed_callback();
}
mpdclient_disconnect(c);
#ifdef ENABLE_ASYNC_CONNECT
+#ifndef WIN32
+ c->connecting2 = false;
+#endif
mpdclient_aconnect_start(c, c->settings);
#else
/* connect to MPD */
diff --git a/src/mpdclient.h b/src/mpdclient.h
index d51013fc8c4176b29b4b23e1b1ccf1a74c9a3573..1d3b6e0b547d61f292480d6eff9da533230e4a03 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
struct mpdclient {
#ifdef ENABLE_ASYNC_CONNECT
+ /**
+ * These settings are used to connect to MPD asynchronously.
+ */
struct mpd_settings *settings;
+
+#ifndef WIN32
+ /**
+ * A second set of settings, just in case #settings did not
+ * work. This is only used if #settings refers to a local
+ * socket path, and this one is supposed to be a fallback to
+ * IP on the default port (6600).
+ */
+ struct mpd_settings *settings2;
+#endif
+
#else
const char *host;
unsigned port;
*/
enum mpd_idle events;
+#if defined(ENABLE_ASYNC_CONNECT) && !defined(WIN32)
+ bool connecting2;
+#endif
+
/**
* This attribute is true when the connection is currently in
* "idle" mode, and the #mpd_glib_source waits for an event.