Commit 8d3eeed2e9b49c296dfbd9bf29637bdba04d72d2

Con Kolivas 2012-06-23T23:54:05

Merge with master

diff --git a/cgminer.c b/cgminer.c
index 5dbfc76..7b6b436 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1622,7 +1622,7 @@ static bool submit_upstream_work(const struct work *work, CURL *curl)
 	int thr_id = work->thr_id;
 	struct cgpu_info *cgpu = thr_info[thr_id].cgpu;
 	struct pool *pool = work->pool;
-	bool rolltime;
+	int rolltime;
 	uint32_t *hash32;
 	char hashshow[64+1] = "";
 
@@ -2163,6 +2163,9 @@ static bool stale_work(struct work *work, bool share)
 	if (share) {
 		if ((now.tv_sec - work->tv_staged.tv_sec) >= opt_expiry)
 			return true;
+	} else if (work->rolls) {
+		if ((now.tv_sec - work->tv_staged.tv_sec) >= work->rolltime)
+			return true;
 	} else if ((now.tv_sec - work->tv_staged.tv_sec) >= opt_scantime)
 		return true;
 
@@ -3385,7 +3388,7 @@ static bool pool_active(struct pool *pool, bool pinging)
 	bool ret = false;
 	json_t *val;
 	CURL *curl;
-	bool rolltime;
+	int rolltime;
 
 	curl = curl_easy_init();
 	if (unlikely(!curl)) {
@@ -3571,8 +3574,7 @@ static inline bool should_roll(struct work *work)
 
 static inline bool can_roll(struct work *work)
 {
-	return (work->pool && !stale_work(work, false) && work->rolltime &&
-		work->rolls < 11 && !work->clone);
+	return (work->pool && !stale_work(work, false) && work->rolltime && !work->clone);
 }
 
 static void roll_work(struct work *work)
@@ -4022,9 +4024,10 @@ enum {
 };
 
 /* Stage another work item from the work returned in a longpoll */
-static void convert_to_work(json_t *val, bool rolltime, struct pool *pool)
+static void convert_to_work(json_t *val, int rolltime, struct pool *pool)
 {
 	struct work *work, *work_clone;
+	int rolled = 0;
 	bool rc;
 
 	work = make_work();
@@ -4059,7 +4062,7 @@ static void convert_to_work(json_t *val, bool rolltime, struct pool *pool)
 
 	work_clone = make_work();
 	memcpy(work_clone, work, sizeof(struct work));
-	while (reuse_work(work)) {
+	while (reuse_work(work) && rolled++ < mining_threads) {
 		work_clone->clone = true;
 		work_clone->longpoll = false;
 		applog(LOG_DEBUG, "Pushing rolled converted work to stage thread");
@@ -4120,7 +4123,7 @@ static void *longpoll_thread(void *userdata)
 	struct timeval start, end;
 	CURL *curl = NULL;
 	int failures = 0;
-	bool rolltime;
+	int rolltime;
 
 	curl = curl_easy_init();
 	if (unlikely(!curl)) {
diff --git a/miner.h b/miner.h
index 00430db..b1840e9 100644
--- a/miner.h
+++ b/miner.h
@@ -531,7 +531,7 @@ extern pthread_rwlock_t netacc_lock;
 
 extern const uint32_t sha256_init_state[];
 extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
-			     const char *rpc_req, bool, bool, bool *,
+			     const char *rpc_req, bool, bool, int *,
 			     struct pool *pool, bool);
 extern char *bin2hex(const unsigned char *p, size_t len);
 extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
@@ -733,7 +733,7 @@ struct work {
 	bool		mined;
 	bool		clone;
 	bool		cloned;
-	bool		rolltime;
+	int		rolltime;
 	bool		longpoll;
 	bool		stale;
 	bool		mandatory;
diff --git a/util.c b/util.c
index 509d938..703be54 100644
--- a/util.c
+++ b/util.c
@@ -56,7 +56,7 @@ struct upload_buffer {
 
 struct header_info {
 	char		*lp_path;
-	bool		has_rolltime;
+	int		rolltime;
 	char		*reason;
 };
 
@@ -160,8 +160,13 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data)
 		if (!strncasecmp("N", val, 1)) {
 			applog(LOG_DEBUG, "X-Roll-Ntime: N found");
 		} else {
-			applog(LOG_DEBUG, "X-Roll-Ntime found");
-			hi->has_rolltime = true;
+			/* Check to see if expire= is supported and if not, set
+			 * the rolltime to the default scantime */
+			if (strlen(val) > 7 && !strncasecmp("expire=", val, 7))
+				sscanf(val + 7, "%d", &hi->rolltime);
+			else
+				hi->rolltime = opt_scantime;
+			applog(LOG_DEBUG, "X-Roll-Ntime expiry set to %d", hi->rolltime);
 		}
 	}
 
@@ -248,7 +253,7 @@ static void set_nettime(void)
 
 json_t *json_rpc_call(CURL *curl, const char *url,
 		      const char *userpass, const char *rpc_req,
-		      bool probe, bool longpoll, bool *rolltime,
+		      bool probe, bool longpoll, int *rolltime,
 		      struct pool *pool, bool share)
 {
 	json_t *val, *err_val, *res_val;
@@ -260,7 +265,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 	char len_hdr[64], user_agent_hdr[128];
 	char curl_err_str[CURL_ERROR_SIZE];
 	long timeout = longpoll ? (60 * 60) : 60;
-	struct header_info hi = {NULL, false, NULL};
+	struct header_info hi = {NULL, 0, NULL};
 	bool probing = false;
 
 	memset(&err, 0, sizeof(err));
@@ -375,7 +380,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
 		hi.lp_path = NULL;
 	}
 
-	*rolltime = hi.has_rolltime;
+	*rolltime = hi.rolltime;
 
 	val = JSON_LOADS(all_data.buf, &err);
 	if (!val) {