in flood_socket_keepalive.c [279:337]
static apr_status_t keepalive_load_resp(response_t *resp,
keepalive_socket_t *sock,
apr_size_t remaining, apr_pool_t *pool)
{
/* Ugh, we want everything. */
int currentalloc, remain;
apr_size_t i;
char *cp, *op, b[MAX_DOC_LENGTH];
apr_status_t status;
if (remaining > 0)
{
remain = 1;
currentalloc = remaining + resp->rbufsize;
}
else
{
remain = 0;
currentalloc = MAX_DOC_LENGTH + resp->rbufsize;
}
cp = apr_palloc(pool, currentalloc);
memcpy(cp, resp->rbuf, resp->rbufsize);
resp->rbuf = cp;
cp = resp->rbuf + resp->rbufsize;
do
{
if (!remain)
i = MAX_DOC_LENGTH - 1;
else
{
if (remaining > MAX_DOC_LENGTH - 1)
i = MAX_DOC_LENGTH - 1;
else
i = remaining;
}
status = ksock_read_socket(sock, b, &i);
if (resp->rbufsize + i > currentalloc)
{
/* You can think why this always work. */
currentalloc *= 2;
op = resp->rbuf;
resp->rbuf = apr_palloc(pool, currentalloc);
memcpy(resp->rbuf, op, cp - op);
cp = resp->rbuf + (cp - op);
}
memcpy(cp, b, i);
resp->rbufsize += i;
cp += i;
remaining -= i;
}
while (status != APR_EGENERAL && status != APR_EOF &&
status != APR_TIMEUP && (!remain || remaining));
return status;
}