@@ -27,7 +27,7 @@ static void qc_stream_buf_free(struct qc_stream_desc *stream,
2727
2828 eb64_delete (& (* stream_buf )-> offset_node );
2929
30- if (* stream_buf == stream -> buf ) {
30+ if (* stream_buf == stream -> buf && !( stream -> flags & QC_SD_FL_FINALIZED ) ) {
3131 /* Reset current buffer ptr. */
3232 stream -> buf = NULL ;
3333 room = b_size (buf );
@@ -130,7 +130,7 @@ void qc_stream_desc_release(struct qc_stream_desc *stream,
130130 */
131131 if (!b_data (buf ))
132132 qc_stream_buf_free (stream , & stream_buf );
133- else
133+ else if (!( stream -> flags & QC_SD_FL_FINALIZED ))
134134 qc_stream_buf_release (stream );
135135 }
136136
@@ -231,8 +231,10 @@ static int qc_stream_buf_store_ack(struct qc_stream_buf *buf,
231231 }
232232
233233 buf -> room += newly_acked ;
234- if (stream -> notify_room && qc_stream_buf_is_released (buf , stream ))
234+ if (stream -> notify_room &&
235+ (qc_stream_buf_is_released (buf , stream ) || stream -> flags & QC_SD_FL_FINALIZED )) {
235236 stream -> notify_room (stream , newly_acked );
237+ }
236238
237239 end :
238240 return newly_acked ;
@@ -262,7 +264,8 @@ static struct qc_stream_buf *qc_stream_buf_ack(struct qc_stream_buf *buf,
262264 bdata_ctr_del (& stream -> data , diff );
263265
264266 /* notify room from acked data if buffer has been released. */
265- if (stream -> notify_room && qc_stream_buf_is_released (buf , stream )) {
267+ if (stream -> notify_room &&
268+ (qc_stream_buf_is_released (buf , stream ) || stream -> flags & QC_SD_FL_FINALIZED )) {
266269 if (diff >= buf -> room ) {
267270 diff -= buf -> room ;
268271 buf -> room = 0 ;
@@ -516,6 +519,8 @@ void qc_stream_buf_release(struct qc_stream_desc *stream)
516519 /* current buffer already released */
517520 BUG_ON (!stream -> buf );
518521
522+ BUG_ON (stream -> flags & QC_SD_FL_FINALIZED );
523+
519524 room = b_room (& stream -> buf -> buf ) + stream -> buf -> room ;
520525 stream -> buf = NULL ;
521526 stream -> buf_offset = 0 ;
@@ -526,3 +531,16 @@ void qc_stream_buf_release(struct qc_stream_desc *stream)
526531 if (stream -> notify_room && room )
527532 stream -> notify_room (stream , room );
528533}
534+
535+ void qc_stream_buf_finalize (struct qc_stream_desc * stream )
536+ {
537+ uint64_t room ;
538+
539+ /* current buffer already released */
540+ BUG_ON (!stream -> buf );
541+
542+ room = b_room (& stream -> buf -> buf ) + stream -> buf -> room ;
543+ if (stream -> notify_room && room )
544+ stream -> notify_room (stream , room );
545+ stream -> flags |= QC_SD_FL_FINALIZED ;
546+ }
0 commit comments