Append \n in the sock_send function instead of adding it when constructing json in stratum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
diff --git a/util.c b/util.c
index db100ec..d97fc90 100644
--- a/util.c
+++ b/util.c
@@ -846,6 +846,7 @@ bool extract_sockaddr(struct pool *pool, char *url)
return true;
}
+/* Send a single command across a socket, appending \n to it */
static bool sock_send(int sock, char *s, ssize_t len)
{
ssize_t sent = 0;
@@ -853,6 +854,9 @@ static bool sock_send(int sock, char *s, ssize_t len)
if (opt_protocol)
applog(LOG_DEBUG, "SEND: %s", s);
+ strcat(s, "\n");
+ len++;
+
while (len > 0 ) {
sent = send(sock, s + sent, len, 0);
if (SOCKETFAIL(sent))
@@ -1006,7 +1010,7 @@ bool auth_stratum(struct pool *pool)
bool ret = false;
s = alloca(RECVSIZE);
- sprintf(s, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}\n",
+ sprintf(s, "{\"id\": %d, \"method\": \"mining.authorize\", \"params\": [\"%s\", \"%s\"]}",
pool->swork.id++, pool->rpc_user, pool->rpc_pass);
while (sock_full(pool->sock, false)) {
@@ -1033,7 +1037,7 @@ bool initiate_stratum(struct pool *pool)
bool ret = false;
s = alloca(RECVSIZE);
- sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}\n", pool->swork.id++);
+ sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", pool->swork.id++);
pool->sock = socket(AF_INET, SOCK_STREAM, 0);
if (pool->sock == INVSOCK)