@@ -3441,12 +3441,22 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
34413441 }
34423442
34433443 switch ((* pfrc )-> fr .type ) {
3444+ case NGTCP2_FRAME_RESET_STREAM :
3445+ strm =
3446+ ngtcp2_conn_find_stream (conn , (* pfrc )-> fr .reset_stream .stream_id );
3447+ if (strm == NULL ||
3448+ !ngtcp2_strm_require_retransmit_reset_stream (strm )) {
3449+ frc = * pfrc ;
3450+ * pfrc = (* pfrc )-> next ;
3451+ ngtcp2_frame_chain_objalloc_del (frc , & conn -> frc_objalloc , conn -> mem );
3452+ continue ;
3453+ }
3454+ break ;
34443455 case NGTCP2_FRAME_STOP_SENDING :
34453456 strm =
34463457 ngtcp2_conn_find_stream (conn , (* pfrc )-> fr .stop_sending .stream_id );
34473458 if (strm == NULL ||
3448- ((strm -> flags & NGTCP2_STRM_FLAG_SHUT_RD ) &&
3449- ngtcp2_strm_rx_offset (strm ) == strm -> rx .last_offset )) {
3459+ !ngtcp2_strm_require_retransmit_stop_sending (strm )) {
34503460 frc = * pfrc ;
34513461 * pfrc = (* pfrc )-> next ;
34523462 ngtcp2_frame_chain_objalloc_del (frc , & conn -> frc_objalloc , conn -> mem );
@@ -3476,10 +3486,8 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
34763486 case NGTCP2_FRAME_MAX_STREAM_DATA :
34773487 strm = ngtcp2_conn_find_stream (conn ,
34783488 (* pfrc )-> fr .max_stream_data .stream_id );
3479- if (strm == NULL ||
3480- (strm -> flags &
3481- (NGTCP2_STRM_FLAG_SHUT_RD | NGTCP2_STRM_FLAG_STOP_SENDING )) ||
3482- (* pfrc )-> fr .max_stream_data .max_stream_data < strm -> rx .max_offset ) {
3489+ if (strm == NULL || !ngtcp2_strm_require_retransmit_max_stream_data (
3490+ strm , & (* pfrc )-> fr .max_stream_data )) {
34833491 frc = * pfrc ;
34843492 * pfrc = (* pfrc )-> next ;
34853493 ngtcp2_frame_chain_objalloc_del (frc , & conn -> frc_objalloc , conn -> mem );
@@ -3497,8 +3505,8 @@ static ngtcp2_ssize conn_write_pkt(ngtcp2_conn *conn, ngtcp2_pkt_info *pi,
34973505 case NGTCP2_FRAME_STREAM_DATA_BLOCKED :
34983506 strm = ngtcp2_conn_find_stream (
34993507 conn , (* pfrc )-> fr .stream_data_blocked .stream_id );
3500- if (strm == NULL || ( strm -> flags & NGTCP2_STRM_FLAG_SHUT_WR ) ||
3501- (* pfrc )-> fr .stream_data_blocked . offset != strm -> tx . max_offset ) {
3508+ if (strm == NULL || ! ngtcp2_strm_require_retransmit_stream_data_blocked (
3509+ strm , & (* pfrc )-> fr .stream_data_blocked ) ) {
35023510 frc = * pfrc ;
35033511 * pfrc = (* pfrc )-> next ;
35043512 ngtcp2_frame_chain_objalloc_del (frc , & conn -> frc_objalloc , conn -> mem );
@@ -7145,7 +7153,7 @@ static int conn_recv_stream(ngtcp2_conn *conn, const ngtcp2_stream *fr) {
71457153 return rv ;
71467154 }
71477155 }
7148- } else if (fr -> datacnt ) {
7156+ } else if (fr -> datacnt && !( strm -> flags & NGTCP2_STRM_FLAG_STOP_SENDING ) ) {
71497157 rv = ngtcp2_strm_recv_reordering (strm , fr -> data [0 ].base , fr -> data [0 ].len ,
71507158 fr -> offset );
71517159 if (rv != 0 ) {
@@ -7304,27 +7312,20 @@ static int conn_recv_reset_stream(ngtcp2_conn *conn,
73047312 }
73057313
73067314 /* Stream is reset before we create ngtcp2_strm object. */
7307- conn -> rx . offset += fr -> final_size ;
7308- ngtcp2_conn_extend_max_offset ( conn , fr -> final_size );
7309-
7310- rv = conn_call_stream_reset ( conn , fr -> stream_id , fr -> final_size ,
7311- fr -> app_error_code , NULL );
7315+ strm = ngtcp2_objalloc_strm_get ( & conn -> strm_objalloc ) ;
7316+ if ( strm == NULL ) {
7317+ return NGTCP2_ERR_NOMEM ;
7318+ }
7319+ rv = ngtcp2_conn_init_stream ( conn , strm , fr -> stream_id , NULL );
73127320 if (rv != 0 ) {
7321+ ngtcp2_objalloc_strm_release (& conn -> strm_objalloc , strm );
73137322 return rv ;
73147323 }
73157324
7316- /* There will be no activity in this stream because we got
7317- RESET_STREAM and don't write stream data any further. This
7318- effectively allows another new stream for peer. */
7319- if (bidi ) {
7320- handle_max_remote_streams_extension (& conn -> remote .bidi .unsent_max_streams ,
7321- 1 );
7322- } else {
7323- handle_max_remote_streams_extension (& conn -> remote .uni .unsent_max_streams ,
7324- 1 );
7325+ rv = conn_call_stream_open (conn , strm );
7326+ if (rv != 0 ) {
7327+ return rv ;
73257328 }
7326-
7327- return 0 ;
73287329 }
73297330
73307331 if ((strm -> flags & NGTCP2_STRM_FLAG_SHUT_RD )) {
@@ -7461,15 +7462,16 @@ static int conn_recv_stop_sending(ngtcp2_conn *conn,
74617462 been acknowledged. */
74627463 if (!ngtcp2_strm_is_all_tx_data_fin_acked (strm ) &&
74637464 !(strm -> flags & NGTCP2_STRM_FLAG_RESET_STREAM )) {
7465+ strm -> flags |= NGTCP2_STRM_FLAG_RESET_STREAM ;
7466+
74647467 rv = conn_reset_stream (conn , strm , fr -> app_error_code );
74657468 if (rv != 0 ) {
74667469 return rv ;
74677470 }
74687471 }
74697472
7470- strm -> flags |= NGTCP2_STRM_FLAG_SHUT_WR |
7471- NGTCP2_STRM_FLAG_STOP_SENDING_RECVED |
7472- NGTCP2_STRM_FLAG_RESET_STREAM ;
7473+ strm -> flags |=
7474+ NGTCP2_STRM_FLAG_SHUT_WR | NGTCP2_STRM_FLAG_STOP_SENDING_RECVED ;
74737475
74747476 ngtcp2_strm_streamfrq_clear (strm );
74757477
@@ -12533,14 +12535,15 @@ static int conn_shutdown_stream_read(ngtcp2_conn *conn, ngtcp2_strm *strm,
1253312535
1253412536 /* Extend connection flow control window for the amount of data
1253512537 which are not passed to application. */
12536- if (!(strm -> flags & (NGTCP2_STRM_FLAG_STOP_SENDING |
12537- NGTCP2_STRM_FLAG_RESET_STREAM_RECVED ))) {
12538+ if (!(strm -> flags & NGTCP2_STRM_FLAG_RESET_STREAM_RECVED )) {
1253812539 ngtcp2_conn_extend_max_offset (conn , strm -> rx .last_offset -
1253912540 ngtcp2_strm_rx_offset (strm ));
1254012541 }
1254112542
1254212543 strm -> flags |= NGTCP2_STRM_FLAG_STOP_SENDING ;
1254312544
12545+ ngtcp2_strm_discard_reordered_data (strm );
12546+
1254412547 return conn_stop_sending (conn , strm , app_error_code );
1254512548}
1254612549
0 commit comments