From 7919090d6bc9685dffdb308c7dc70b1dac45ab0b Mon Sep 17 00:00:00 2001 From: Jon Sailor Date: Thu, 22 Dec 2011 12:08:00 +0100 Subject: [PATCH] options: configurable timeout for MPD connections --- NEWS | 1 + doc/ncmpc.1 | 6 ++++++ src/conf.c | 4 ++++ src/defaults.h | 2 ++ src/main.c | 2 +- src/options.c | 4 ++++ src/options.h | 1 + 7 files changed, 19 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 4e0180b..068baf2 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ ncmpc 0.20 - not yet released range * add a doxygen configuration file. Documentation will be generated if the configure script is called with --enable-documentation +* configurable timeout for MPD connections ncmpc 0.19 - (07/23/2011) diff --git a/doc/ncmpc.1 b/doc/ncmpc.1 index 6f48734..78c082e 100644 --- a/doc/ncmpc.1 +++ b/doc/ncmpc.1 @@ -76,6 +76,12 @@ Connect to mpd on the specified port. .TP .B password = PASSWORD Connect to mpd using the specified password. +.TP +.B timeout = TIMEOUT +Attempt to reconnect to mpd if a response to a command is not received within +TIMEOUT seconds. Specifying a value in the configuration file overrides the +"MPD_TIMEOUT" environment variable. If no timeout is specified in the +configuration file or in the environment, the default is 1.5 seconds. .SS Interface .TP .B enable\-mouse = yes|no diff --git a/src/conf.c b/src/conf.c index 9d1f882..9754fbd 100644 --- a/src/conf.c +++ b/src/conf.c @@ -68,6 +68,7 @@ #define CONF_HOST "host" #define CONF_PORT "port" #define CONF_PASSWORD "password" +#define CONF_TIMEOUT "timeout" #define CONF_LYRICS_TIMEOUT "lyrics-timeout" #define CONF_SCROLL "scroll" #define CONF_SCROLL_SEP "scroll-sep" @@ -489,6 +490,9 @@ parse_line(char *line) options.port = atoi(get_format(value)); else if (!strcasecmp(CONF_PASSWORD, name)) options.password = get_format(value); + else if (!strcasecmp(CONF_TIMEOUT, name)) + options.timeout_ms = atoi(get_format(value)) + * 1000 /* seconds -> milliseconds */; else if (!strcasecmp(CONF_LYRICS_TIMEOUT, name)) #ifdef ENABLE_LYRICS_SCREEN options.lyrics_timeout = atoi(get_format(value)); diff --git a/src/defaults.h b/src/defaults.h index fac784d..b8bc81a 100644 --- a/src/defaults.h +++ b/src/defaults.h @@ -36,6 +36,8 @@ #define DEFAULT_TEXT_EDITOR "editor" +#define DEFAULT_MPD_TIMEOUT 5000 /* 5 seconds */ + #define DEFAULT_SCROLL TRUE #define DEFAULT_SCROLL_SEP " *** " diff --git a/src/main.c b/src/main.c index 7e3e3df..1581e78 100644 --- a/src/main.c +++ b/src/main.c @@ -320,7 +320,7 @@ timer_reconnect(G_GNUC_UNUSED gpointer data) mpdclient_disconnect(mpd); success = mpdclient_connect(mpd, options.host, options.port, - 5000, + options.timeout_ms, options.password); if (!success) { /* try again in 5 seconds */ diff --git a/src/options.c b/src/options.c index 47fc3b9..1b3e9af 100644 --- a/src/options.c +++ b/src/options.c @@ -60,6 +60,7 @@ options_t options = { .audible_bell = true, .bell_on_wrap = true, .status_message_time = 3, + .timeout_ms = DEFAULT_MPD_TIMEOUT, #ifndef NCMPC_MINI .scroll = DEFAULT_SCROLL, .welcome_screen_list = true, @@ -374,6 +375,9 @@ options_init(void) #ifndef NCMPC_MINI options.scroll_sep = g_strdup(DEFAULT_SCROLL_SEP); #endif + if (getenv("MPD_TIMEOUT") != NULL) + /* let libmpdclient parse the environment variable */ + options.timeout_ms = 0; } void diff --git a/src/options.h b/src/options.h index fc9f7a1..6b1da8b 100644 --- a/src/options.h +++ b/src/options.h @@ -40,6 +40,7 @@ typedef struct { char **screen_list; bool display_remaining_time; int port; + int timeout_ms; int crossfade_time; int search_mode; int hide_cursor; -- 2.30.2