mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-22 20:44:19 +00:00
Provide locking around stratum send operations to avoid races.
This commit is contained in:
parent
8baac0d66d
commit
b5617734fa
@ -2759,7 +2759,7 @@ static void *submit_work_thread(void *userdata)
|
|||||||
|
|
||||||
applog(LOG_INFO, "Submitting share %08lx to pool %d", (unsigned long)(hash32[6]), pool->pool_no);
|
applog(LOG_INFO, "Submitting share %08lx to pool %d", (unsigned long)(hash32[6]), pool->pool_no);
|
||||||
|
|
||||||
sock_send(pool->sock, s, strlen(s));
|
stratum_send(pool, s, strlen(s));
|
||||||
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
21
util.c
21
util.c
@ -843,9 +843,11 @@ bool extract_sockaddr(struct pool *pool, char *url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Send a single command across a socket, appending \n to it */
|
/* Send a single command across a socket, appending \n to it */
|
||||||
bool sock_send(int sock, char *s, ssize_t len)
|
bool stratum_send(struct pool *pool, char *s, ssize_t len)
|
||||||
{
|
{
|
||||||
|
SOCKETTYPE sock = pool->sock;
|
||||||
ssize_t sent = 0;
|
ssize_t sent = 0;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
if (opt_protocol)
|
if (opt_protocol)
|
||||||
applog(LOG_DEBUG, "SEND: %s", s);
|
applog(LOG_DEBUG, "SEND: %s", s);
|
||||||
@ -853,15 +855,20 @@ bool sock_send(int sock, char *s, ssize_t len)
|
|||||||
strcat(s, "\n");
|
strcat(s, "\n");
|
||||||
len++;
|
len++;
|
||||||
|
|
||||||
|
mutex_lock(&pool->pool_lock);
|
||||||
while (len > 0 ) {
|
while (len > 0 ) {
|
||||||
sent = send(sock, s + sent, len, 0);
|
sent = send(sock, s + sent, len, 0);
|
||||||
if (SOCKETFAIL(sent))
|
if (SOCKETFAIL(sent)) {
|
||||||
return false;
|
ret = false;
|
||||||
|
goto out_unlock;
|
||||||
|
}
|
||||||
len -= sent;
|
len -= sent;
|
||||||
}
|
}
|
||||||
|
ret = true;
|
||||||
fsync(sock);
|
fsync(sock);
|
||||||
|
out_unlock:
|
||||||
return true;
|
mutex_unlock(&pool->pool_lock);
|
||||||
|
return ret;;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RECVSIZE 8192
|
#define RECVSIZE 8192
|
||||||
@ -1129,7 +1136,7 @@ bool auth_stratum(struct pool *pool)
|
|||||||
free(sret);
|
free(sret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sock_send(pool->sock, s, strlen(s)))
|
if (!stratum_send(pool, s, strlen(s)))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
sret = recv_line(pool->sock);
|
sret = recv_line(pool->sock);
|
||||||
@ -1184,7 +1191,7 @@ bool initiate_stratum(struct pool *pool)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sock_send(pool->sock, s, strlen(s))) {
|
if (!stratum_send(pool, s, strlen(s))) {
|
||||||
applog(LOG_DEBUG, "Failed to send s in initiate_stratum");
|
applog(LOG_DEBUG, "Failed to send s in initiate_stratum");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
2
util.h
2
util.h
@ -116,7 +116,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct pool;
|
struct pool;
|
||||||
bool sock_send(int sock, char *s, ssize_t len);
|
bool stratum_send(struct pool *pool, char *s, ssize_t len);
|
||||||
char *recv_line(SOCKETTYPE sock);
|
char *recv_line(SOCKETTYPE sock);
|
||||||
bool parse_method(struct pool *pool, char *s);
|
bool parse_method(struct pool *pool, char *s);
|
||||||
bool extract_sockaddr(struct pool *pool, char *url);
|
bool extract_sockaddr(struct pool *pool, char *url);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user