1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-10 14:58:01 +00:00

Adjust socket wait timeout in recv_line according to how long we've already waited to avoid a 60 second wait dropping to 1 second due to a blocked socket.

This commit is contained in:
ckolivas 2013-07-19 19:09:23 +10:00
parent fa92ff8cfe
commit f2ae7fadb2

25
util.c
View File

@ -42,6 +42,8 @@
#include "compat.h" #include "compat.h"
#include "util.h" #include "util.h"
#define DEFAULT_SOCKWAIT 60
bool successful_connect = false; bool successful_connect = false;
struct timeval nettime; struct timeval nettime;
@ -1025,7 +1027,7 @@ bool stratum_send(struct pool *pool, char *s, ssize_t len)
return (ret == SEND_OK); return (ret == SEND_OK);
} }
static bool socket_full(struct pool *pool, bool wait) static bool socket_full(struct pool *pool, int wait)
{ {
SOCKETTYPE sock = pool->sock; SOCKETTYPE sock = pool->sock;
struct timeval timeout; struct timeval timeout;
@ -1034,10 +1036,7 @@ static bool socket_full(struct pool *pool, bool wait)
FD_ZERO(&rd); FD_ZERO(&rd);
FD_SET(sock, &rd); FD_SET(sock, &rd);
timeout.tv_usec = 0; timeout.tv_usec = 0;
if (wait) timeout.tv_sec = wait;
timeout.tv_sec = 60;
else
timeout.tv_sec = 1;
if (select(sock + 1, &rd, NULL, NULL, &timeout) > 0) if (select(sock + 1, &rd, NULL, NULL, &timeout) > 0)
return true; return true;
return false; return false;
@ -1049,7 +1048,7 @@ bool sock_full(struct pool *pool)
if (strlen(pool->sockbuf)) if (strlen(pool->sockbuf))
return true; return true;
return (socket_full(pool, false)); return (socket_full(pool, 0));
} }
static void clear_sockbuf(struct pool *pool) static void clear_sockbuf(struct pool *pool)
@ -1098,14 +1097,15 @@ static void recalloc_sock(struct pool *pool, size_t len)
* from the socket and returns that as a malloced char */ * from the socket and returns that as a malloced char */
char *recv_line(struct pool *pool) char *recv_line(struct pool *pool)
{ {
ssize_t len, buflen;
char *tok, *sret = NULL; char *tok, *sret = NULL;
ssize_t len, buflen;
int waited = 0;
if (!strstr(pool->sockbuf, "\n")) { if (!strstr(pool->sockbuf, "\n")) {
struct timeval rstart, now; struct timeval rstart, now;
cgtime(&rstart); cgtime(&rstart);
if (!socket_full(pool, true)) { if (!socket_full(pool, DEFAULT_SOCKWAIT)) {
applog(LOG_DEBUG, "Timed out waiting for data on socket_full"); applog(LOG_DEBUG, "Timed out waiting for data on socket_full");
goto out; goto out;
} }
@ -1122,8 +1122,10 @@ char *recv_line(struct pool *pool)
suspend_stratum(pool); suspend_stratum(pool);
break; break;
} }
cgtime(&now);
waited = tdiff(&now, &rstart);
if (n < 0) { if (n < 0) {
if (!sock_blocks() || !socket_full(pool, false)) { if (!sock_blocks() || !socket_full(pool, DEFAULT_SOCKWAIT - waited)) {
applog(LOG_DEBUG, "Failed to recv sock in recv_line"); applog(LOG_DEBUG, "Failed to recv sock in recv_line");
suspend_stratum(pool); suspend_stratum(pool);
break; break;
@ -1133,8 +1135,7 @@ char *recv_line(struct pool *pool)
recalloc_sock(pool, slen); recalloc_sock(pool, slen);
strcat(pool->sockbuf, s); strcat(pool->sockbuf, s);
} }
cgtime(&now); } while (waited < DEFAULT_SOCKWAIT && !strstr(pool->sockbuf, "\n"));
} while (tdiff(&now, &rstart) < 60 && !strstr(pool->sockbuf, "\n"));
} }
buflen = strlen(pool->sockbuf); buflen = strlen(pool->sockbuf);
@ -1646,7 +1647,7 @@ resend:
goto out; goto out;
} }
if (!socket_full(pool, true)) { if (!socket_full(pool, DEFAULT_SOCKWAIT)) {
applog(LOG_DEBUG, "Timed out waiting for response in initiate_stratum"); applog(LOG_DEBUG, "Timed out waiting for response in initiate_stratum");
goto out; goto out;
} }