From: Victor Seva Date: Thu, 14 Nov 2013 12:37:08 +0000 (+0100) Subject: use timeval. keep timeout in milliseconds for backwards compatibility. X-Git-Tag: collectd-5.5.0~139^2~9 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=62c2e922094300c4b2ae65866a9ab84d384fc2e0;p=collectd.git use timeval. keep timeout in milliseconds for backwards compatibility. --- diff --git a/src/redis.c b/src/redis.c index dcede599..554ed931 100644 --- a/src/redis.c +++ b/src/redis.c @@ -60,7 +60,7 @@ struct redis_node_s char host[HOST_NAME_MAX]; char passwd[MAX_REDIS_PASSWD_LENGTH]; int port; - int timeout; + struct timeval timeout; redis_node_t *next; }; @@ -115,11 +115,12 @@ static int redis_config_node (oconfig_item_t *ci) /* {{{ */ redis_node_t rn; int i; int status; + int timeout; memset (&rn, 0, sizeof (rn)); sstrncpy (rn.host, REDIS_DEF_HOST, sizeof (rn.host)); rn.port = REDIS_DEF_PORT; - rn.timeout = REDIS_DEF_TIMEOUT; + rn.timeout.tv_usec = REDIS_DEF_TIMEOUT; status = cf_util_get_string_buffer (ci, rn.name, sizeof (rn.name)); if (status != 0) @@ -141,7 +142,10 @@ static int redis_config_node (oconfig_item_t *ci) /* {{{ */ } } else if (strcasecmp ("Timeout", option->key) == 0) - status = cf_util_get_int (option, &rn.timeout); + { + status = cf_util_get_int (option, &timeout); + if (status == 0) rn.timeout.tv_usec = timeout; + } else if (strcasecmp ("Password", option->key) == 0) status = cf_util_get_string_buffer (option, rn.passwd, sizeof (rn.passwd)); else @@ -213,7 +217,8 @@ static int redis_init (void) /* {{{ */ .name = "default", .host = REDIS_DEF_HOST, .port = REDIS_DEF_PORT, - .timeout = REDIS_DEF_TIMEOUT, + .timeout.tv_sec = 0, + .timeout.tv_usec = REDIS_DEF_TIMEOUT, .next = NULL }; @@ -259,14 +264,9 @@ static int redis_read (void) /* {{{ */ redisContext *rh; redisReply *rr; - struct timeval tmout; - - tmout.tv_sec = rn->timeout; - tmout.tv_usec = 0; - DEBUG ("redis plugin: querying info from node `%s' (%s:%d).", rn->name, rn->host, rn->port); - rh = redisConnectWithTimeout ((char *)rn->host, rn->port, tmout); + rh = redisConnectWithTimeout ((char *)rn->host, rn->port, rn->timeout); if (rh == NULL) { ERROR ("redis plugin: unable to connect to node `%s' (%s:%d).", rn->name, rn->host, rn->port);