diff --git a/src/mpdclient.c b/src/mpdclient.c
index 8c18a0c81ab60044db6df587af04e87abc3d2e46..ffa1a5d84408e86757b82d2dbde1617dbf07c583 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
return false;
}
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)
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");
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;
#else
c->host = host;
c->port = port;
#ifdef ENABLE_ASYNC_CONNECT
mpd_settings_free(c->settings);
#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);
#endif
g_free(c);
#ifdef ENABLE_ASYNC_CONNECT
#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)
{
static void
mpdclient_connect_success(struct mpd_connection *connection, void *ctx)
{
assert(c->async_connect != NULL);
c->async_connect = NULL;
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_error_callback(message);
mpdclient_failed_callback();
}
.error = mpdclient_connect_error,
};
.error = mpdclient_connect_error,
};
+static void
+mpdclient_aconnect_start(struct mpdclient *c,
+ const struct mpd_settings *settings)
+{
+ aconnect_start(&c->async_connect,
+ mpd_settings_get_host(settings),
+ mpd_settings_get_port(settings),
+ &mpdclient_connect_handler, c);
+}
+
#endif
void
#endif
void
mpdclient_disconnect(c);
#ifdef ENABLE_ASYNC_CONNECT
mpdclient_disconnect(c);
#ifdef ENABLE_ASYNC_CONNECT
- aconnect_start(&c->async_connect,
- mpd_settings_get_host(c->settings),
- mpd_settings_get_port(c->settings),
- &mpdclient_connect_handler, c);
+#ifndef WIN32
+ c->connecting2 = false;
+#endif
+ mpdclient_aconnect_start(c, c->settings);
#else
/* connect to MPD */
struct mpd_connection *connection =
#else
/* connect to MPD */
struct mpd_connection *connection =