comparison src/event/quic/ngx_event_quic_streams.c @ 8856:f9c788f3f5cc quic

QUIC: ngx_quic_buffer_t object. The object is used instead of ngx_chain_t pointer for buffer operations like ngx_quic_write_chain() and ngx_quic_read_chain(). These functions are renamed to ngx_quic_write_buffer() and ngx_quic_read_buffer().
author Roman Arutyunyan <arut@nginx.com>
date Mon, 14 Feb 2022 15:27:59 +0300
parents a5aebd51e4c7
children 489c2dcb3180
comparison
equal deleted inserted replaced
8855:a5aebd51e4c7 8856:f9c788f3f5cc
259 frame->u.reset_stream.error_code = err; 259 frame->u.reset_stream.error_code = err;
260 frame->u.reset_stream.final_size = qs->send_offset; 260 frame->u.reset_stream.final_size = qs->send_offset;
261 261
262 ngx_quic_queue_frame(qc, frame); 262 ngx_quic_queue_frame(qc, frame);
263 263
264 ngx_quic_free_chain(pc, qs->out); 264 ngx_quic_free_buffer(pc, &qs->send);
265 qs->out = NULL;
266 265
267 return NGX_OK; 266 return NGX_OK;
268 } 267 }
269 268
270 269
758 757
759 if (size == 0) { 758 if (size == 0) {
760 return 0; 759 return 0;
761 } 760 }
762 761
763 in = ngx_quic_read_chain(pc, &qs->in, size); 762 in = ngx_quic_read_buffer(pc, &qs->recv, size);
764 if (in == NGX_CHAIN_ERROR) { 763 if (in == NGX_CHAIN_ERROR) {
765 return NGX_ERROR; 764 return NGX_ERROR;
766 } 765 }
767 766
768 len = 0; 767 len = 0;
833 832
834 833
835 static ngx_chain_t * 834 static ngx_chain_t *
836 ngx_quic_stream_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) 835 ngx_quic_stream_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
837 { 836 {
838 off_t flow; 837 uint64_t n, flow;
839 size_t n;
840 ngx_event_t *wev; 838 ngx_event_t *wev;
841 ngx_connection_t *pc; 839 ngx_connection_t *pc;
842 ngx_quic_stream_t *qs; 840 ngx_quic_stream_t *qs;
843 ngx_quic_connection_t *qc; 841 ngx_quic_connection_t *qc;
844 842
861 if (flow == 0) { 859 if (flow == 0) {
862 wev->ready = 0; 860 wev->ready = 0;
863 return in; 861 return in;
864 } 862 }
865 863
866 if (limit == 0 || limit > flow) { 864 if (limit == 0 || limit > (off_t) flow) {
867 limit = flow; 865 limit = flow;
868 } 866 }
869 867
870 in = ngx_quic_write_chain(pc, &qs->out, in, limit, 868 n = qs->send.size;
871 c->sent - qs->send_offset, &n); 869
870 in = ngx_quic_write_buffer(pc, &qs->send, in, limit, c->sent);
872 if (in == NGX_CHAIN_ERROR) { 871 if (in == NGX_CHAIN_ERROR) {
873 return NGX_CHAIN_ERROR; 872 return NGX_CHAIN_ERROR;
874 } 873 }
875 874
875 n = qs->send.size - n;
876 c->sent += n; 876 c->sent += n;
877 qc->streams.sent += n; 877 qc->streams.sent += n;
878 878
879 if (flow == (off_t) n) { 879 if (flow == n) {
880 wev->ready = 0; 880 wev->ready = 0;
881 } 881 }
882 882
883 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, 883 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
884 "quic send_chain sent:%uz", n); 884 "quic send_chain sent:%uL", n);
885 885
886 if (ngx_quic_stream_flush(qs) != NGX_OK) { 886 if (ngx_quic_stream_flush(qs) != NGX_OK) {
887 return NGX_CHAIN_ERROR; 887 return NGX_CHAIN_ERROR;
888 } 888 }
889 889
892 892
893 893
894 static ngx_int_t 894 static ngx_int_t
895 ngx_quic_stream_flush(ngx_quic_stream_t *qs) 895 ngx_quic_stream_flush(ngx_quic_stream_t *qs)
896 { 896 {
897 off_t limit; 897 off_t limit, len;
898 size_t len;
899 ngx_uint_t last; 898 ngx_uint_t last;
900 ngx_chain_t *out, *cl; 899 ngx_chain_t *out;
901 ngx_quic_frame_t *frame; 900 ngx_quic_frame_t *frame;
902 ngx_connection_t *pc; 901 ngx_connection_t *pc;
903 ngx_quic_connection_t *qc; 902 ngx_quic_connection_t *qc;
904 903
905 if (qs->send_state != NGX_QUIC_STREAM_SEND_SEND) { 904 if (qs->send_state != NGX_QUIC_STREAM_SEND_SEND) {
917 qs->send_max_data - qs->send_offset); 916 qs->send_max_data - qs->send_offset);
918 917
919 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0, 918 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, pc->log, 0,
920 "quic stream id:0x%xL flush limit:%O", qs->id, limit); 919 "quic stream id:0x%xL flush limit:%O", qs->id, limit);
921 920
922 out = ngx_quic_read_chain(pc, &qs->out, limit); 921 len = qs->send.offset;
922
923 out = ngx_quic_read_buffer(pc, &qs->send, limit);
923 if (out == NGX_CHAIN_ERROR) { 924 if (out == NGX_CHAIN_ERROR) {
924 return NGX_ERROR; 925 return NGX_ERROR;
925 } 926 }
926 927
927 len = 0; 928 len = qs->send.offset - len;
928 last = 0; 929 last = 0;
929 930
930 for (cl = out; cl; cl = cl->next) {
931 len += cl->buf->last - cl->buf->pos;
932 }
933
934 if (qs->send_final_size != (uint64_t) -1 931 if (qs->send_final_size != (uint64_t) -1
935 && qs->send_final_size == qs->send_offset + len) 932 && qs->send_final_size == qs->send.offset)
936 { 933 {
937 qs->send_state = NGX_QUIC_STREAM_SEND_DATA_SENT; 934 qs->send_state = NGX_QUIC_STREAM_SEND_DATA_SENT;
938 last = 1; 935 last = 1;
939 } 936 }
940 937
963 960
964 qs->send_offset += len; 961 qs->send_offset += len;
965 qc->streams.send_offset += len; 962 qc->streams.send_offset += len;
966 963
967 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pc->log, 0, 964 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, pc->log, 0,
968 "quic stream id:0x%xL flush len:%uz last:%ui", 965 "quic stream id:0x%xL flush len:%O last:%ui",
969 qs->id, len, last); 966 qs->id, len, last);
970 967
971 if (qs->connection == NULL) { 968 if (qs->connection == NULL) {
972 return ngx_quic_close_stream(qs); 969 return ngx_quic_close_stream(qs);
973 } 970 }
1024 } 1021 }
1025 1022
1026 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0, 1023 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0,
1027 "quic stream id:0x%xL close", qs->id); 1024 "quic stream id:0x%xL close", qs->id);
1028 1025
1029 ngx_quic_free_chain(pc, qs->in); 1026 ngx_quic_free_buffer(pc, &qs->send);
1030 ngx_quic_free_chain(pc, qs->out); 1027 ngx_quic_free_buffer(pc, &qs->recv);
1031 1028
1032 ngx_rbtree_delete(&qc->streams.tree, &qs->node); 1029 ngx_rbtree_delete(&qc->streams.tree, &qs->node);
1033 ngx_queue_insert_tail(&qc->streams.free, &qs->queue); 1030 ngx_queue_insert_tail(&qc->streams.free, &qs->queue);
1034 1031
1035 if (qc->closing) { 1032 if (qc->closing) {
1069 1066
1070 ngx_int_t 1067 ngx_int_t
1071 ngx_quic_handle_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, 1068 ngx_quic_handle_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt,
1072 ngx_quic_frame_t *frame) 1069 ngx_quic_frame_t *frame)
1073 { 1070 {
1074 size_t size;
1075 uint64_t last; 1071 uint64_t last;
1076 ngx_quic_stream_t *qs; 1072 ngx_quic_stream_t *qs;
1077 ngx_quic_connection_t *qc; 1073 ngx_quic_connection_t *qc;
1078 ngx_quic_stream_frame_t *f; 1074 ngx_quic_stream_frame_t *f;
1079 1075
1138 1134
1139 qs->recv_final_size = last; 1135 qs->recv_final_size = last;
1140 qs->recv_state = NGX_QUIC_STREAM_RECV_SIZE_KNOWN; 1136 qs->recv_state = NGX_QUIC_STREAM_RECV_SIZE_KNOWN;
1141 } 1137 }
1142 1138
1143 if (ngx_quic_write_chain(c, &qs->in, frame->data, f->length, 1139 if (ngx_quic_write_buffer(c, &qs->recv, frame->data, f->length, f->offset)
1144 f->offset - qs->recv_offset, &size)
1145 == NGX_CHAIN_ERROR) 1140 == NGX_CHAIN_ERROR)
1146 { 1141 {
1147 return NGX_ERROR; 1142 return NGX_ERROR;
1148 } 1143 }
1149 1144
1150 qs->recv_size += size;
1151
1152 if (qs->recv_state == NGX_QUIC_STREAM_RECV_SIZE_KNOWN 1145 if (qs->recv_state == NGX_QUIC_STREAM_RECV_SIZE_KNOWN
1153 && qs->recv_size == qs->recv_final_size) 1146 && qs->recv.size == qs->recv_final_size)
1154 { 1147 {
1155 qs->recv_state = NGX_QUIC_STREAM_RECV_DATA_RECVD; 1148 qs->recv_state = NGX_QUIC_STREAM_RECV_DATA_RECVD;
1156 } 1149 }
1157 1150
1158 if (qs->connection == NULL) { 1151 if (qs->connection == NULL) {