|
|
|
@ -1029,6 +1029,12 @@ static void recalloc_sock(struct pool *pool, size_t len)
@@ -1029,6 +1029,12 @@ static void recalloc_sock(struct pool *pool, size_t len)
|
|
|
|
|
pool->sockbuf_size = new; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum recv_ret { |
|
|
|
|
RECV_OK, |
|
|
|
|
RECV_CLOSED, |
|
|
|
|
RECV_RECVFAIL |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/* Peeks at a socket to find the first end of line and then reads just that
|
|
|
|
|
* from the socket and returns that as a malloced char */ |
|
|
|
|
char *recv_line(struct pool *pool) |
|
|
|
@ -1037,6 +1043,7 @@ char *recv_line(struct pool *pool)
@@ -1037,6 +1043,7 @@ char *recv_line(struct pool *pool)
|
|
|
|
|
char *tok, *sret = NULL; |
|
|
|
|
|
|
|
|
|
if (!strstr(pool->sockbuf, "\n")) { |
|
|
|
|
enum recv_ret ret = RECV_OK; |
|
|
|
|
struct timeval rstart, now; |
|
|
|
|
|
|
|
|
|
gettimeofday(&rstart, NULL); |
|
|
|
@ -1054,11 +1061,11 @@ char *recv_line(struct pool *pool)
@@ -1054,11 +1061,11 @@ char *recv_line(struct pool *pool)
|
|
|
|
|
memset(s, 0, RBUFSIZE); |
|
|
|
|
n = recv(pool->sock, s, RECVSIZE, 0); |
|
|
|
|
if (!n) { |
|
|
|
|
applog(LOG_DEBUG, "Socket closed waiting in recv_line"); |
|
|
|
|
ret = RECV_CLOSED; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
if (n < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { |
|
|
|
|
applog(LOG_DEBUG, "Failed to recv sock in recv_line"); |
|
|
|
|
ret = RECV_RECVFAIL; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
slen = strlen(s); |
|
|
|
@ -1067,6 +1074,18 @@ char *recv_line(struct pool *pool)
@@ -1067,6 +1074,18 @@ char *recv_line(struct pool *pool)
|
|
|
|
|
gettimeofday(&now, NULL); |
|
|
|
|
} while (tdiff(&now, &rstart) < 60 && !strstr(pool->sockbuf, "\n")); |
|
|
|
|
mutex_unlock(&pool->stratum_lock); |
|
|
|
|
|
|
|
|
|
switch (ret) { |
|
|
|
|
default: |
|
|
|
|
case RECV_OK: |
|
|
|
|
break; |
|
|
|
|
case RECV_CLOSED: |
|
|
|
|
applog(LOG_DEBUG, "Socket closed waiting in recv_line"); |
|
|
|
|
break; |
|
|
|
|
case RECV_RECVFAIL: |
|
|
|
|
applog(LOG_DEBUG, "Failed to recv sock in recv_line"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
buflen = strlen(pool->sockbuf); |
|
|
|
|