From 003b65b7b168f022d14ffc892b701d75323a7ed0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 11 Jan 2014 09:32:16 +1100 Subject: [PATCH] Change stratum strings under stratum_lock in reconnect and free old strings. Conflicts resolved: util.c --- util.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/util.c b/util.c index 8baa480b..4e03ea38 100644 --- a/util.c +++ b/util.c @@ -1661,8 +1661,18 @@ static bool parse_diff(struct pool *pool, json_t *val) return true; } +static void __suspend_stratum(struct pool *pool) +{ + clear_sockbuf(pool); + pool->stratum_active = pool->stratum_notify = false; + if (pool->sock) + CLOSESOCKET(pool->sock); + pool->sock = 0; +} + static bool parse_reconnect(struct pool *pool, json_t *val) { + char *sockaddr_url, *stratum_port, *tmp; char *url, *port, address[256]; memset(address, 0, 255); @@ -1676,13 +1686,22 @@ static bool parse_reconnect(struct pool *pool, json_t *val) sprintf(address, "%s:%s", url, port); - if (!extract_sockaddr(address, &pool->sockaddr_url, &pool->stratum_port)) + if (!extract_sockaddr(address, &sockaddr_url, &stratum_port)) return false; - pool->stratum_url = pool->sockaddr_url; - applog(LOG_NOTICE, "Reconnect requested from %s to %s", pool->poolname, address); + mutex_lock(&pool->stratum_lock); + __suspend_stratum(pool); + tmp = pool->sockaddr_url; + pool->sockaddr_url = sockaddr_url; + pool->stratum_url = pool->sockaddr_url; + free(tmp); + tmp = pool->stratum_port; + pool->stratum_port = stratum_port; + free(tmp); + mutex_unlock(&pool->stratum_lock); + if (!restart_stratum(pool)) return false; @@ -2268,14 +2287,10 @@ out: void suspend_stratum(struct pool *pool) { - clear_sockbuf(pool); applog(LOG_INFO, "Closing socket for stratum %s", pool->poolname); mutex_lock(&pool->stratum_lock); - pool->stratum_active = pool->stratum_notify = false; - if (pool->sock) - CLOSESOCKET(pool->sock); - pool->sock = 0; + __suspend_stratum(pool); mutex_unlock(&pool->stratum_lock); }