mirror of
https://github.com/nginx/nginx.git
synced 2024-12-21 01:27:48 +08:00
QUIC: return written size from ngx_quic_write_chain().
This allows to escape calculating it before calling the function.
This commit is contained in:
parent
2f28342e08
commit
2ba20e3451
@ -478,13 +478,17 @@ ngx_quic_copy_buf(ngx_connection_t *c, u_char *data, size_t len)
|
||||
|
||||
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;
|
||||
|
||||
@ -549,6 +553,10 @@ ngx_quic_write_chain(ngx_connection_t *c, ngx_chain_t **chain, ngx_chain_t *in,
|
||||
in->buf->pos += n;
|
||||
offset += n;
|
||||
limit -= n;
|
||||
|
||||
if (size) {
|
||||
*size += n;
|
||||
}
|
||||
}
|
||||
|
||||
if (b->sync && p == b->last) {
|
||||
|
@ -31,7 +31,7 @@ void ngx_quic_free_chain(ngx_connection_t *c, ngx_chain_t *in);
|
||||
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);
|
||||
|
@ -370,7 +370,7 @@ ngx_quic_handle_crypto_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
|
||||
|
||||
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;
|
||||
|
@ -824,9 +824,10 @@ ngx_quic_stream_send(ngx_connection_t *c, u_char *buf, size_t size)
|
||||
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;
|
||||
@ -851,17 +852,7 @@ ngx_quic_stream_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
|
||||
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;
|
||||
}
|
||||
@ -1099,7 +1090,7 @@ ngx_quic_handle_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
|
||||
}
|
||||
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user