|
|
@ -555,24 +555,36 @@ static void add_bufline(connsock_t *cs, const char *readbuf, const int len) |
|
|
|
|
|
|
|
|
|
|
|
static int read_cs_length(connsock_t *cs, float *timeout, int len) |
|
|
|
static int read_cs_length(connsock_t *cs, float *timeout, int len) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
tv_t start, now; |
|
|
|
int ret = len; |
|
|
|
int ret = len; |
|
|
|
|
|
|
|
float diff; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tv_time(&start); |
|
|
|
|
|
|
|
|
|
|
|
while (cs->bufofs < len) { |
|
|
|
while (cs->bufofs < len) { |
|
|
|
char readbuf[PAGESIZE]; |
|
|
|
char readbuf[PAGESIZE]; |
|
|
|
int readlen; |
|
|
|
int readlen; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (*timeout < 0) { |
|
|
|
|
|
|
|
LOGDEBUG("Timed out in read_cs_length"); |
|
|
|
|
|
|
|
ret = 0; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
ret = wait_read_select(cs->fd, *timeout); |
|
|
|
ret = wait_read_select(cs->fd, *timeout); |
|
|
|
if (ret < 1) |
|
|
|
if (ret < 1) |
|
|
|
goto out; |
|
|
|
break; |
|
|
|
readlen = len - cs->bufofs; |
|
|
|
readlen = len - cs->bufofs; |
|
|
|
if (readlen >= PAGESIZE) |
|
|
|
if (readlen >= PAGESIZE) |
|
|
|
readlen = PAGESIZE - 4; |
|
|
|
readlen = PAGESIZE - 4; |
|
|
|
ret = recv(cs->fd, readbuf, readlen, MSG_DONTWAIT); |
|
|
|
ret = recv(cs->fd, readbuf, readlen, MSG_DONTWAIT); |
|
|
|
if (ret < 1) |
|
|
|
if (ret < 1) |
|
|
|
goto out; |
|
|
|
break; |
|
|
|
add_bufline(cs, readbuf, ret); |
|
|
|
add_bufline(cs, readbuf, ret); |
|
|
|
|
|
|
|
tv_time(&now); |
|
|
|
|
|
|
|
diff = tvdiff(&now, &start); |
|
|
|
|
|
|
|
copy_tv(&start, &now); |
|
|
|
|
|
|
|
*timeout -= diff; |
|
|
|
} |
|
|
|
} |
|
|
|
out: |
|
|
|
|
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|