Browse Source

Merge commit 'fc5d3a0' into cg_merges_20121203

Luke Dashjr 13 years ago
parent
commit
e9d4b5e7bb
3 changed files with 47 additions and 0 deletions
  1. 38 0
      miner.c
  2. 8 0
      util.c
  3. 1 0
      util.h

+ 38 - 0
miner.c

@@ -5449,6 +5449,28 @@ static void clear_stratum_shares(struct pool *pool)
 	}
 }
 
+/* We only need to maintain a secondary pool connection when we need the
+ * capacity to get work from the backup pools while still on the primary */
+static bool cnx_needed(struct pool *pool)
+{
+	struct pool *cp;
+
+	if (pool_strategy == POOL_BALANCE)
+		return true;
+	if (pool_strategy == POOL_LOADBALANCE)
+		return true;
+	if (opt_fail_only)
+		return true;
+	cp = current_pool();
+	if (cp == pool)
+		return true;
+	if (!cp->has_gbt && !cp->has_stratum)
+		return true;
+	return false;
+}
+
+static void wait_lpcurrent(struct pool *pool);
+
 /* One stratum thread per pool that has stratum waits on the socket checking
  * for new messages and for the integrity of the socket connection. We reset
  * the connection based on the integrity of the receive side only as the send
@@ -5469,6 +5491,22 @@ static void *stratum_thread(void *userdata)
 		if (unlikely(!pool->has_stratum))
 			break;
 
+		/* Check to see whether we need to maintain this connection
+		 * indefinitely or just bring it up when we switch to this
+		 * pool */
+		if (!cnx_needed(pool)) {
+			suspend_stratum(pool);
+			wait_lpcurrent(pool);
+			if (!initiate_stratum(pool) || !auth_stratum(pool)) {
+				pool_died(pool);
+				while (!initiate_stratum(pool) || !auth_stratum(pool)) {
+					if (pool->removed)
+						goto out;
+					sleep(30);
+				}
+			}
+		}
+
 		FD_ZERO(&rd);
 		FD_SET(pool->sock, &rd);
 		timeout.tv_sec = 120;

+ 8 - 0
util.c

@@ -1406,6 +1406,14 @@ out:
 	return ret;
 }
 
+void suspend_stratum(struct pool *pool)
+{
+	applog(LOG_INFO, "Closing socket for stratum pool %d", pool->pool_no);
+	mutex_lock(&pool->stratum_lock);
+	pool->stratum_active = false;
+	mutex_unlock(&pool->stratum_lock);
+	CLOSESOCKET(pool->sock);
+}
 
 void dev_error(struct cgpu_info *dev, enum dev_reason reason)
 {

+ 1 - 0
util.h

@@ -51,6 +51,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);
+void suspend_stratum(struct pool *pool);
 void dev_error(struct cgpu_info *dev, enum dev_reason reason);
 void *realloc_strcat(char *ptr, char *s);
 void RenameThread(const char* name);