/* Updates effective_weight of descendant streams in subtree of |stream|. We assume that stream->effective_weight is already set right. */ static void stream_update_dep_effective_weight(nghttp2_stream *stream) { nghttp2_stream *si; DEBUGF(fprintf(stderr, "stream: update_dep_effective_weight " "stream(%p)=%d, weight=%d, sum_norest_weight=%d, " "sum_top_weight=%d\n", stream, stream->stream_id, stream->weight, stream->sum_norest_weight, stream->sum_top_weight)); /* stream->sum_norest_weight == 0 means there is no NGHTTP2_STREAM_DPRI_TOP under stream */ if (stream->dpri != NGHTTP2_STREAM_DPRI_NO_DATA || stream->sum_norest_weight == 0) { return; } /* If there is no direct descendant whose dpri is NGHTTP2_STREAM_DPRI_TOP, indirect descendants have the chance to send data, so recursively set weight for descendants. */ if (stream->sum_top_weight == 0) { for (si = stream->dep_next; si; si = si->sib_next) { if (si->dpri != NGHTTP2_STREAM_DPRI_REST) { si->effective_weight = nghttp2_stream_dep_distributed_effective_weight(stream, si->weight); } stream_update_dep_effective_weight(si); } return; } /* If there is at least one direct descendant whose dpri is NGHTTP2_STREAM_DPRI_TOP, we won't give a chance to indirect descendants, since closed or blocked stream's weight is distributed among its siblings */ for (si = stream->dep_next; si; si = si->sib_next) { if (si->dpri == NGHTTP2_STREAM_DPRI_TOP) { si->effective_weight = stream_dep_distributed_top_effective_weight(stream, si->weight); DEBUGF(fprintf(stderr, "stream: stream=%d top eweight=%d\n", si->stream_id, si->effective_weight)); continue; } if (si->dpri == NGHTTP2_STREAM_DPRI_NO_DATA) { DEBUGF(fprintf(stderr, "stream: stream=%d no_data, ignored\n", si->stream_id)); /* Since we marked NGHTTP2_STREAM_DPRI_TOP under si, we make them NGHTTP2_STREAM_DPRI_REST again. */ stream_update_dep_set_rest(si->dep_next); } else { DEBUGF( fprintf(stderr, "stream: stream=%d rest, ignored\n", si->stream_id)); } } }
/* Updates effective_weight of descendant streams in subtree of |stream|. We assume that stream->effective_weight is already set right. */ static void stream_update_dep_effective_weight(nghttp2_stream *stream) { nghttp2_stream *si; DEBUGF(fprintf(stderr, "stream: update_dep_effective_weight " "stream(%p)=%d, weight=%d, sum_norest_weight=%d\n", stream, stream->stream_id, stream->weight, stream->sum_norest_weight)); /* stream->sum_norest_weight == 0 means there is no NGHTTP2_STREAM_DPRI_TOP under stream */ if (stream->dpri != NGHTTP2_STREAM_DPRI_NO_ITEM || stream->sum_norest_weight == 0) { return; } for (si = stream->dep_next; si; si = si->sib_next) { if (si->dpri != NGHTTP2_STREAM_DPRI_REST) { si->effective_weight = nghttp2_stream_dep_distributed_effective_weight(stream, si->weight); } stream_update_dep_effective_weight(si); } }