diff --git a/src/mpdclient.c b/src/mpdclient.c
index 870839fd27dbb69ee8abd1d4b65e79d8c8567ee4..1801ad2dc7973b94e927131f5bdd1c3a95127f7d 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 const struct mpd_settings *
+mpdclient_get_settings(const struct mpdclient *c)
+{
+#ifndef WIN32
+ if (c->connecting2)
+ return c->settings2;
+#endif
+
+ return c->settings;
+}
+
static void
mpdclient_connect_success(struct mpd_connection *connection, void *ctx)
{
assert(c->async_connect != NULL);
c->async_connect = NULL;
+ const char *password =
+ mpd_settings_get_password(mpdclient_get_settings(c));
+ if (password != NULL && !mpd_run_password(connection, password)) {
+ mpdclient_error_callback(mpd_connection_get_error_message(connection));
+ mpd_connection_free(connection);
+ mpdclient_failed_callback();
+ return;
+ }
+
mpdclient_connected(c, connection);
}
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 */
c->idle = false;
mpd_glib_leave(c->source);
- mpdclient_schedule_enter_idle(c);
+ if (c->source != NULL)
+ mpdclient_schedule_enter_idle(c);
}
return c->connection;