|
@@ -54,6 +54,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;
|
|
|
|
|
|
|
@@ -1403,7 +1405,7 @@ bool _stratum_send(struct pool *pool, char *s, ssize_t len, bool force)
|
|
|
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;
|
|
@@ -1412,10 +1414,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 = 60;
|
|
|
|
|
- else
|
|
|
|
|
- timeout.tv_sec = 1;
|
|
|
|
|
|
|
+ timeout.tv_sec = wait;
|
|
|
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;
|
|
@@ -1427,7 +1426,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)
|
|
@@ -1476,14 +1475,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;
|
|
|
}
|
|
}
|
|
@@ -1500,11 +1500,13 @@ 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) {
|
|
|
//Save errno from being overweitten bei socket_ commands
|
|
//Save errno from being overweitten bei socket_ commands
|
|
|
int socket_recv_errno;
|
|
int socket_recv_errno;
|
|
|
socket_recv_errno = SOCKERR;
|
|
socket_recv_errno = SOCKERR;
|
|
|
- if (!sock_blocks() || !socket_full(pool, true)) {
|
|
|
|
|
|
|
+ if (!sock_blocks() || !socket_full(pool, DEFAULT_SOCKWAIT - waited)) {
|
|
|
applog(LOG_DEBUG, "Failed to recv sock in recv_line: %s", bfg_strerror(socket_recv_errno, BST_SOCKET));
|
|
applog(LOG_DEBUG, "Failed to recv sock in recv_line: %s", bfg_strerror(socket_recv_errno, BST_SOCKET));
|
|
|
suspend_stratum(pool);
|
|
suspend_stratum(pool);
|
|
|
break;
|
|
break;
|
|
@@ -1514,8 +1516,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 (tdiff(&now, &rstart) < 60 && !strstr(pool->sockbuf, "\n"));
|
|
|
|
|
|
|
+ } while (waited < DEFAULT_SOCKWAIT && !strstr(pool->sockbuf, "\n"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
buflen = strlen(pool->sockbuf);
|
|
buflen = strlen(pool->sockbuf);
|
|
@@ -2133,7 +2134,7 @@ resend:
|
|
|
|
|
|
|
|
recvd = true;
|
|
recvd = true;
|
|
|
|
|
|
|
|
- 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;
|
|
|
}
|
|
}
|