This allows to escape calculating it before calling the function.
ngx_chain_t *
ngx_quic_write_chain(ngx_connection_t *c, ngx_chain_t **chain, ngx_chain_t *in,
- off_t limit, off_t offset)
+ off_t limit, off_t offset, size_t *size)
{
off_t n;
u_char *p;
ngx_buf_t *b;
ngx_chain_t *cl, *sl;
+ if (size) {
+ *size = 0;
+ }
+
while (in && limit) {
cl = *chain;
in->buf->pos += n;
offset += n;
limit -= n;
+
+ if (size) {
+ *size += n;
+ }
}
if (b->sync && p == b->last) {
ngx_chain_t *ngx_quic_read_chain(ngx_connection_t *c, ngx_chain_t **chain,
off_t limit);
ngx_chain_t *ngx_quic_write_chain(ngx_connection_t *c, ngx_chain_t **chain,
- ngx_chain_t *in, off_t limit, off_t offset);
+ ngx_chain_t *in, off_t limit, off_t offset, size_t *size);
#if (NGX_DEBUG)
void ngx_quic_log_frame(ngx_log_t *log, ngx_quic_frame_t *f, ngx_uint_t tx);
if (f->offset > ctx->crypto_received) {
if (ngx_quic_write_chain(c, &ctx->crypto, frame->data, f->length,
- f->offset - ctx->crypto_received)
+ f->offset - ctx->crypto_received, NULL)
== NGX_CHAIN_ERROR)
{
return NGX_ERROR;
static ngx_chain_t *
ngx_quic_stream_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
{
- off_t n, flow;
+ off_t flow;
+ size_t n;
ngx_event_t *wev;
- ngx_chain_t *out, *cl;
+ ngx_chain_t *out;
ngx_connection_t *pc;
ngx_quic_frame_t *frame;
ngx_quic_stream_t *qs;
limit = flow;
}
- n = 0;
-
- for (cl = in; cl; cl = cl->next) {
- n += cl->buf->last - cl->buf->pos;
- if (n >= limit) {
- n = limit;
- break;
- }
- }
-
- in = ngx_quic_write_chain(pc, &qs->out, in, limit, 0);
+ in = ngx_quic_write_chain(pc, &qs->out, in, limit, 0, &n);
if (in == NGX_CHAIN_ERROR) {
return NGX_CHAIN_ERROR;
}
}
if (ngx_quic_write_chain(c, &qs->in, frame->data, f->length,
- f->offset - qs->recv_offset)
+ f->offset - qs->recv_offset, NULL)
== NGX_CHAIN_ERROR)
{
return NGX_ERROR;