mirror of
https://github.com/JayDDee/cpuminer-opt.git
synced 2025-09-17 23:44:27 +00:00
v3.10.6
This commit is contained in:
66
util.c
66
util.c
@@ -1069,7 +1069,7 @@ double target_to_diff(uint32_t* target)
|
||||
#define socket_blocks() (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
#endif
|
||||
|
||||
static bool send_line(curl_socket_t sock, char *s)
|
||||
static bool send_line( struct stratum_ctx *sctx, char *s )
|
||||
{
|
||||
size_t sent = 0;
|
||||
int len;
|
||||
@@ -1077,24 +1077,35 @@ static bool send_line(curl_socket_t sock, char *s)
|
||||
len = (int) strlen(s);
|
||||
s[len++] = '\n';
|
||||
|
||||
while (len > 0) {
|
||||
while ( len > 0 )
|
||||
{
|
||||
struct timeval timeout = {0, 0};
|
||||
int n;
|
||||
fd_set wd;
|
||||
|
||||
FD_ZERO(&wd);
|
||||
FD_SET(sock, &wd);
|
||||
if (select((int) (sock + 1), NULL, &wd, NULL, &timeout) < 1)
|
||||
FD_ZERO( &wd );
|
||||
FD_SET( sctx->sock, &wd );
|
||||
if ( select( (int) ( sctx->sock + 1 ), NULL, &wd, NULL, &timeout ) < 1 )
|
||||
return false;
|
||||
n = send(sock, s + sent, len, 0);
|
||||
if (n < 0) {
|
||||
if (!socket_blocks())
|
||||
return false;
|
||||
n = 0;
|
||||
}
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x071802
|
||||
|
||||
CURLcode rc = curl_easy_send(sctx->curl, s + sent, len, (size_t *)&n);
|
||||
if ( rc != CURLE_OK )
|
||||
{
|
||||
if ( rc != CURLE_AGAIN )
|
||||
#else
|
||||
n = send(sock, s + sent, len, 0);
|
||||
if ( n < 0 )
|
||||
{
|
||||
if ( !socket_blocks() )
|
||||
#endif
|
||||
return false;
|
||||
n = 0;
|
||||
}
|
||||
sent += n;
|
||||
len -= n;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1107,7 +1118,7 @@ bool stratum_send_line(struct stratum_ctx *sctx, char *s)
|
||||
applog(LOG_DEBUG, "> %s", s);
|
||||
|
||||
pthread_mutex_lock(&sctx->sock_lock);
|
||||
ret = send_line(sctx->sock, s);
|
||||
ret = send_line( sctx, s );
|
||||
pthread_mutex_unlock(&sctx->sock_lock);
|
||||
|
||||
return ret;
|
||||
@@ -1167,14 +1178,27 @@ char *stratum_recv_line(struct stratum_ctx *sctx)
|
||||
ssize_t n;
|
||||
|
||||
memset(s, 0, RBUFSIZE);
|
||||
n = recv(sctx->sock, s, RECVSIZE, 0);
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x071802
|
||||
|
||||
CURLcode rc = curl_easy_recv(sctx->curl, s, RECVSIZE, (size_t *)&n);
|
||||
if (rc == CURLE_OK && !n) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
if (rc != CURLE_OK) {
|
||||
if (rc != CURLE_AGAIN || !socket_full(sctx->sock, 1)) {
|
||||
#else
|
||||
|
||||
n = recv(sctx->sock, s, RECVSIZE, 0);
|
||||
if (!n) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
if (n < 0) {
|
||||
if (!socket_blocks() || !socket_full(sctx->sock, 1)) {
|
||||
ret = false;
|
||||
#endif
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
@@ -1244,7 +1268,9 @@ bool stratum_connect(struct stratum_ctx *sctx, const char *url)
|
||||
}
|
||||
free(sctx->curl_url);
|
||||
sctx->curl_url = (char*) malloc(strlen(url));
|
||||
sprintf(sctx->curl_url, "http%s", strstr(url, "://"));
|
||||
sprintf( sctx->curl_url, "http%s", strstr( url, "s://" )
|
||||
? strstr( url, "s://" )
|
||||
: strstr (url, "://" ) );
|
||||
|
||||
if (opt_protocol)
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||
@@ -1254,7 +1280,9 @@ bool stratum_connect(struct stratum_ctx *sctx, const char *url)
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, sctx->curl_err_str);
|
||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
|
||||
if (opt_proxy) {
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
if (opt_proxy) {
|
||||
curl_easy_setopt(curl, CURLOPT_PROXY, opt_proxy);
|
||||
curl_easy_setopt(curl, CURLOPT_PROXYTYPE, opt_proxy_type);
|
||||
}
|
||||
@@ -1954,7 +1982,9 @@ static bool stratum_reconnect(struct stratum_ctx *sctx, json_t *params)
|
||||
return false;
|
||||
|
||||
url = (char*) malloc(32 + strlen(host));
|
||||
sprintf(url, "stratum+tcp://%s:%d", host, port);
|
||||
|
||||
strncpy( url, sctx->url, 15 );
|
||||
sprintf( strstr( url, "://" ) + 3, "%s:%d", host, port );
|
||||
|
||||
if (!opt_redirect) {
|
||||
applog(LOG_INFO, "Ignoring request to reconnect to %s", url);
|
||||
|
||||
Reference in New Issue
Block a user