Browse Source

[multiple] inline chunkqueue_length()

master
Glenn Strauss 10 months ago
parent
commit
97e314fc9e
  1. 13
      src/chunk.c
  2. 5
      src/chunk.h
  3. 8
      src/connections.c
  4. 4
      src/gw_backend.c
  5. 10
      src/h2.c
  6. 2
      src/http_chunk.c
  7. 4
      src/mod_cgi.c
  8. 2
      src/mod_fastcgi.c
  9. 2
      src/mod_proxy.c
  10. 7
      src/mod_scgi.c
  11. 2
      src/mod_webdav.c

13
src/chunk.c

@ -362,7 +362,7 @@ void chunkqueue_append_chunkqueue(chunkqueue * const restrict cq, chunkqueue * c
cq->last->next = src->first;
}
cq->last = src->last;
cq->bytes_in += (src->bytes_in - src->bytes_out);
cq->bytes_in += chunkqueue_length(src);
src->first = NULL;
src->last = NULL;
@ -709,17 +709,6 @@ int chunkqueue_steal_with_tempfiles(chunkqueue * const restrict dest, chunkqueue
return 0;
}
off_t chunkqueue_length(chunkqueue *cq) {
off_t len = 0;
chunk *c;
for (c = cq->first; c; c = c->next) {
len += chunk_remaining_length(c);
}
return len;
}
void chunkqueue_mark_written(chunkqueue *cq, off_t len) {
cq->bytes_out += len;

5
src/chunk.h

@ -124,7 +124,10 @@ void chunkqueue_compact_mem(chunkqueue *cq, size_t clen);
void chunkqueue_small_resp_optim (chunkqueue * restrict cq);
__attribute_pure__
off_t chunkqueue_length(chunkqueue *cq);
static inline off_t chunkqueue_length(const chunkqueue *cq);
static inline off_t chunkqueue_length(const chunkqueue *cq) {
return cq->bytes_in - cq->bytes_out;
}
void chunkqueue_free(chunkqueue *cq);
void chunkqueue_reset(chunkqueue *cq);

8
src/connections.c

@ -1240,7 +1240,7 @@ connection_state_machine_h2 (request_st * const h2r, connection * const con)
&& (r->resp_body_finished || r->conf.stream_response_body)) {
chunkqueue * const cq = r->write_queue;
off_t avail = cq->bytes_in - cq->bytes_out;
off_t avail = chunkqueue_length(cq);
if (avail > max_bytes) avail = max_bytes;
if (avail > fsize) avail = fsize;
if (avail > r->h2_swin) avail = r->h2_swin;
@ -1625,7 +1625,7 @@ connection_handle_read_post_chunked (request_st * const r, chunkqueue * const cq
const off_t max_request_size = (off_t)r->conf.max_request_size << 10;
off_t te_chunked = r->te_chunked;
do {
off_t len = cq->bytes_in - cq->bytes_out;
off_t len = chunkqueue_length(cq);
while (0 == te_chunked) {
char *p;
@ -1714,7 +1714,7 @@ connection_handle_read_post_chunked (request_st * const r, chunkqueue * const cq
/* consume HTTP chunked header */
chunkqueue_mark_written(cq, (size_t)hsz);
len = cq->bytes_in - cq->bytes_out;
len = chunkqueue_length(cq);
if (0 !=max_request_size
&& (max_request_size < te_chunked
@ -1757,7 +1757,7 @@ connection_handle_read_post_chunked (request_st * const r, chunkqueue * const cq
return http_response_reqbody_read_error(r, 500);
}
te_chunked -= len;
len = cq->bytes_in - cq->bytes_out;
len = chunkqueue_length(cq);
}
if (len < te_chunked) break;

4
src/gw_backend.c

@ -1968,7 +1968,7 @@ static handler_t gw_write_request(gw_handler_ctx * const hctx, request_st * cons
fdevent_fdnode_event_clr(hctx->ev, hctx->fdn, FDEVENT_OUT);
gw_set_state(hctx, GW_STATE_READ);
} else {
off_t wblen = hctx->wb->bytes_in - hctx->wb->bytes_out;
off_t wblen = chunkqueue_length(hctx->wb);
if ((hctx->wb->bytes_in < hctx->wb_reqlen || hctx->wb_reqlen < 0)
&& wblen < 65536 - 16384) {
/*(r->conf.stream_request_body & FDEVENT_STREAM_REQUEST)*/
@ -2064,7 +2064,7 @@ handler_t gw_handle_subrequest(request_st * const r, void *p_d) {
* buffered to disk if too large and backend can not keep up */
/*(64k - 4k to attempt to avoid temporary files
* in conjunction with FDEVENT_STREAM_REQUEST_BUFMIN)*/
if (hctx->wb->bytes_in - hctx->wb->bytes_out > 65536 - 4096) {
if (chunkqueue_length(hctx->wb) > 65536 - 4096) {
if (r->conf.stream_request_body & FDEVENT_STREAM_REQUEST_BUFMIN) {
r->conf.stream_request_body &= ~FDEVENT_STREAM_REQUEST_POLLIN;
}

10
src/h2.c

@ -665,7 +665,7 @@ h2_recv_data (connection * const con, const uint8_t * const s, const uint32_t le
/*(similar decision logic to that in http_chunk_uses_tempfile())*/
const chunk * const c = dst->last;
if ((c && c->type == FILE_CHUNK && c->file.is_temp)
|| dst->bytes_in - dst->bytes_out + alen > 65536) {
|| chunkqueue_length(dst) + alen > 65536) {
log_error_st * const errh = r->conf.errh;
if (0 != chunkqueue_steal_with_tempfiles(dst, cq, (off_t)alen, errh)) {
h2_send_rst_stream(r, con, H2_E_INTERNAL_ERROR);
@ -816,10 +816,12 @@ h2_recv_continuation (uint32_t n, uint32_t clen, const off_t cqlen, chunkqueue *
/* (alternatively, could memmove() 9 bytes of frame header over the
* pad length octet, remove PADDED flag, add 1 to c->offset,
* add 1 to s, subtract 1 from clen and substract 1 from cqlen,
* substract 1 from n) */
* substract 1 from n, add 1 to cq->bytes_out) */
s[9] = 0;
/* set offset to beginning of padding at end of first frame */
m -= plen;
/* XXX: layer violation; adjusts chunk.c internal accounting */
cq->bytes_out += plen;
}
do {
@ -828,6 +830,8 @@ h2_recv_continuation (uint32_t n, uint32_t clen, const off_t cqlen, chunkqueue *
memmove(s+m, s+n+9, flen);
m += flen;
n += 9+flen;
/* XXX: layer violation; adjusts chunk.c internal accounting */
cq->bytes_out += 9;
} while (!(flags & H2_FLAG_END_HEADERS));
/* overwrite frame size */
m -= 9; /*(temporarily remove frame header from len)*/
@ -1317,7 +1321,7 @@ h2_want_read (connection * const con)
if (chunkqueue_is_empty(cq)) return 1;
/* check for partial frame */
const off_t cqlen = cq->bytes_in - cq->bytes_out; /*chunkqueue_length(cq);*/
const off_t cqlen = chunkqueue_length(cq);
if (cqlen < 9) return 1;
chunk *c = cq->first;
uint32_t clen = buffer_string_length(c->mem) - c->offset;

2
src/http_chunk.c

@ -198,7 +198,7 @@ static int http_chunk_uses_tempfile(const request_st * const r, const chunkqueue
const chunk * const c = cq->last;
return
((c && c->type == FILE_CHUNK && c->file.is_temp)
|| cq->bytes_in - cq->bytes_out + len
|| chunkqueue_length(cq) + len
> ((r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN)
? 128*1024
: 64*1024));

4
src/mod_cgi.c

@ -711,7 +711,7 @@ static int cgi_write_request(handler_ctx *hctx, int fd) {
cgi_connection_close_fdtocgi(hctx); /*(closes only hctx->fdtocgi)*/
}
} else {
off_t cqlen = cq->bytes_in - cq->bytes_out;
off_t cqlen = chunkqueue_length(cq);
if (cq->bytes_in != r->reqbody_length && cqlen < 65536 - 16384) {
/*(r->conf.stream_request_body & FDEVENT_STREAM_REQUEST)*/
if (!(r->conf.stream_request_body & FDEVENT_STREAM_REQUEST_POLLIN)) {
@ -962,7 +962,7 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) {
if (cq->bytes_in != (off_t)r->reqbody_length) {
/*(64k - 4k to attempt to avoid temporary files
* in conjunction with FDEVENT_STREAM_REQUEST_BUFMIN)*/
if (cq->bytes_in - cq->bytes_out > 65536 - 4096
if (chunkqueue_length(cq) > 65536 - 4096
&& (r->conf.stream_request_body & FDEVENT_STREAM_REQUEST_BUFMIN)){
r->conf.stream_request_body &= ~FDEVENT_STREAM_REQUEST_POLLIN;
if (-1 != hctx->fd) return HANDLER_WAIT_FOR_EVENT;

2
src/mod_fastcgi.c

@ -221,7 +221,7 @@ static handler_t fcgi_stdin_append(handler_ctx *hctx) {
FCGI_Header header;
chunkqueue * const req_cq = hctx->r->reqbody_queue;
off_t offset, weWant;
const off_t req_cqlen = req_cq->bytes_in - req_cq->bytes_out;
const off_t req_cqlen = chunkqueue_length(req_cq);
int request_id = hctx->request_id;
/* something to send ? */

2
src/mod_proxy.c

@ -824,7 +824,7 @@ static void proxy_set_Forwarded(connection * const con, request_st * const r, co
static handler_t proxy_stdin_append(gw_handler_ctx *hctx) {
/*handler_ctx *hctx = (handler_ctx *)gwhctx;*/
chunkqueue * const req_cq = hctx->r->reqbody_queue;
const off_t req_cqlen = req_cq->bytes_in - req_cq->bytes_out;
const off_t req_cqlen = chunkqueue_length(req_cq);
if (req_cqlen) {
/* XXX: future: use http_chunk_len_append() */
buffer * const tb = hctx->r->tmp_buf;

7
src/mod_scgi.c

@ -259,12 +259,9 @@ static handler_t scgi_create_env(handler_ctx *hctx) {
hctx->wb_reqlen = buffer_string_length(b) - offset;
chunkqueue_prepend_buffer_commit(hctx->wb);
#if 0
hctx->wb->first->offset += (off_t)offset;
hctx->wb->bytes_in -= (off_t)offset;
#else
chunkqueue_mark_written(hctx->wb, offset);
#endif
hctx->wb->bytes_in -= (off_t)offset;
hctx->wb->bytes_out -= (off_t)offset;
if (r->reqbody_length) {
chunkqueue_append_chunkqueue(hctx->wb, r->reqbody_queue);

2
src/mod_webdav.c

@ -3449,7 +3449,7 @@ webdav_parse_chunkqueue (request_st * const r,
| XML_PARSE_PEDANTIC| XML_PARSE_NONET);
char *xmlstr;
chunkqueue * const cq = r->reqbody_queue;
size_t weWant = cq->bytes_in - cq->bytes_out;
size_t weWant = chunkqueue_length(cq);
int err = XML_ERR_OK;
while (weWant) {

Loading…
Cancel
Save