Commit 4cde791e9f484f724f5dfe5f0f69e2a53d4f413f

Con Kolivas 2013-02-15T21:31:44

Provide basic framework for restarting stratum depending on whether resume support exists or not.

diff --git a/cgminer.c b/cgminer.c
index 47496df..a896cfc 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4720,9 +4720,9 @@ static void *stratum_thread(void *userdata)
 			clear_pool_work(pool);
 
 			wait_lpcurrent(pool);
-			if (!initiate_stratum(pool) || !auth_stratum(pool)) {
+			if (!restart_stratum(pool)) {
 				pool_died(pool);
-				while (!initiate_stratum(pool) || !auth_stratum(pool)) {
+				while (!restart_stratum(pool)) {
 					if (pool->removed)
 						goto out;
 					sleep(30);
@@ -4757,11 +4757,11 @@ static void *stratum_thread(void *userdata)
 			if (pool == current_pool())
 				restart_threads();
 
-			if (initiate_stratum(pool) && auth_stratum(pool))
+			if (restart_stratum(pool))
 				continue;
 
 			pool_died(pool);
-			while (!initiate_stratum(pool) || !auth_stratum(pool)) {
+			while (!restart_stratum(pool)) {
 				if (pool->removed)
 					goto out;
 				sleep(30);
diff --git a/util.c b/util.c
index 77f5b36..48d3bd9 100644
--- a/util.c
+++ b/util.c
@@ -1513,6 +1513,34 @@ out:
 	return ret;
 }
 
+/* Placeholder for real resume function in the future */
+static bool resume_stratum(struct pool *pool)
+{
+	mutex_lock(&pool->pool_lock);
+	free(pool->sessionid);
+	pool->sessionid = NULL;
+	mutex_unlock(&pool->pool_lock);
+
+	return false;
+}
+
+bool restart_stratum(struct pool *pool)
+{
+	bool resume;
+
+	mutex_lock(&pool->pool_lock);
+	resume = pool->sessionid != NULL;
+	mutex_unlock(&pool->pool_lock);
+
+	if (resume && !resume_stratum(pool))
+		return false;
+	else if (!initiate_stratum(pool))
+		return false;
+	if (!auth_stratum(pool))
+		return false;
+	return true;
+}
+
 void suspend_stratum(struct pool *pool)
 {
 	applog(LOG_INFO, "Closing socket for stratum pool %d", pool->pool_no);
diff --git a/util.h b/util.h
index ade0b2e..9093b76 100644
--- a/util.h
+++ b/util.h
@@ -52,6 +52,7 @@ bool parse_method(struct pool *pool, char *s);
 bool extract_sockaddr(struct pool *pool, char *url);
 bool auth_stratum(struct pool *pool);
 bool initiate_stratum(struct pool *pool);
+bool restart_stratum(struct pool *pool);
 void suspend_stratum(struct pool *pool);
 void dev_error(struct cgpu_info *dev, enum dev_reason reason);
 void *realloc_strcat(char *ptr, char *s);