Browse Source

Merge commit '6d3c880' into stratum

Luke Dashjr 13 years ago
parent
commit
8bcd17d477
2 changed files with 19 additions and 12 deletions
  1. 2 2
      miner.h
  2. 17 10
      util.c

+ 2 - 2
miner.h

@@ -884,8 +884,8 @@ struct stratum_work {
 	int diff;
 	int diff;
 };
 };
 
 
-#define RECVSIZE 8191
-#define RBUFSIZE (RECVSIZE + 1)
+#define RECVSIZE 8192
+#define RBUFSIZE (RECVSIZE + 4)
 
 
 struct pool {
 struct pool {
 	int pool_no;
 	int pool_no;

+ 17 - 10
util.c

@@ -850,7 +850,8 @@ bool extract_sockaddr(struct pool *pool, char *url)
 	return true;
 	return true;
 }
 }
 
 
-/* Send a single command across a socket, appending \n to it */
+/* Send a single command across a socket, appending \n to it. This should all
+ * be done under stratum lock except when first establishing the socket */
 static bool __stratum_send(struct pool *pool, char *s, ssize_t len)
 static bool __stratum_send(struct pool *pool, char *s, ssize_t len)
 {
 {
 	SOCKETTYPE sock = pool->sock;
 	SOCKETTYPE sock = pool->sock;
@@ -864,6 +865,7 @@ static bool __stratum_send(struct pool *pool, char *s, ssize_t len)
 
 
 	while (len > 0 ) {
 	while (len > 0 ) {
 		struct timeval timeout = {0, 0};
 		struct timeval timeout = {0, 0};
+		CURLcode rc = CURLE_SEND_ERROR;
 		size_t sent = 0;
 		size_t sent = 0;
 		fd_set wd;
 		fd_set wd;
 
 
@@ -873,7 +875,9 @@ static bool __stratum_send(struct pool *pool, char *s, ssize_t len)
 			applog(LOG_DEBUG, "Write select failed on pool %d sock", pool->pool_no);
 			applog(LOG_DEBUG, "Write select failed on pool %d sock", pool->pool_no);
 			return false;
 			return false;
 		}
 		}
-		if (curl_easy_send(pool->stratum_curl, s + ssent, len, &sent) != CURLE_OK) {
+		if (likely(pool->stratum_curl))
+			rc = curl_easy_send(pool->stratum_curl, s + ssent, len, &sent);
+		if (rc != CURLE_OK) {
 			applog(LOG_DEBUG, "Failed to curl_easy_send in stratum_send");
 			applog(LOG_DEBUG, "Failed to curl_easy_send in stratum_send");
 			return false;
 			return false;
 		}
 		}
@@ -898,14 +902,16 @@ bool stratum_send(struct pool *pool, char *s, ssize_t len)
 	return ret;
 	return ret;
 }
 }
 
 
-#define RECVSIZE 8191
-#define RBUFSIZE (RECVSIZE + 1)
-
 static void clear_sock(struct pool *pool)
 static void clear_sock(struct pool *pool)
 {
 {
-	SOCKETTYPE sock = pool->sock;
+	size_t n = 0;
 
 
-	recv(sock, pool->sockbuf, RECVSIZE, MSG_DONTWAIT);
+	mutex_lock(&pool->stratum_lock);
+	/* Ignore return code of curl_easy_recv since we're just clearing
+	 * anything in the socket if it's still alive */
+	if (likely(pool->stratum_curl))
+		curl_easy_recv(pool->stratum_curl, pool->sockbuf, RECVSIZE, &n);
+	mutex_unlock(&pool->stratum_lock);
 	strcpy(pool->sockbuf, "");
 	strcpy(pool->sockbuf, "");
 }
 }
 
 
@@ -937,12 +943,12 @@ char *recv_line(struct pool *pool)
 {
 {
 	ssize_t len, buflen;
 	ssize_t len, buflen;
 	char *tok, *sret = NULL;
 	char *tok, *sret = NULL;
-	size_t n;
+	size_t n = 0;
 
 
 	if (!strstr(pool->sockbuf, "\n")) {
 	if (!strstr(pool->sockbuf, "\n")) {
+		CURLcode rc = CURLE_RECV_ERROR;
 		char s[RBUFSIZE];
 		char s[RBUFSIZE];
 		size_t sspace;
 		size_t sspace;
-		CURLcode rc;
 
 
 		if (!sock_full(pool, true)) {
 		if (!sock_full(pool, true)) {
 			applog(LOG_DEBUG, "Timed out waiting for data on sock_full");
 			applog(LOG_DEBUG, "Timed out waiting for data on sock_full");
@@ -951,7 +957,8 @@ char *recv_line(struct pool *pool)
 		memset(s, 0, RBUFSIZE);
 		memset(s, 0, RBUFSIZE);
 
 
 		mutex_lock(&pool->stratum_lock);
 		mutex_lock(&pool->stratum_lock);
-		rc = curl_easy_recv(pool->stratum_curl, s, RECVSIZE, &n);
+		if (likely(pool->stratum_curl))
+			rc = curl_easy_recv(pool->stratum_curl, s, RECVSIZE, &n);
 		mutex_unlock(&pool->stratum_lock);
 		mutex_unlock(&pool->stratum_lock);
 
 
 		if (rc != CURLE_OK) {
 		if (rc != CURLE_OK) {