예제 #1
0
int nghttp2_stream_dep_remove(nghttp2_stream *stream) {
  nghttp2_stream *dep_prev, *si;
  int32_t sum_dep_weight_delta;
  int rv;

  DEBUGF(fprintf(stderr, "stream: dep_remove stream(%p)=%d\n", stream,
                 stream->stream_id));

  /* Distribute weight of |stream| to direct descendants */
  sum_dep_weight_delta = -stream->weight;

  for (si = stream->dep_next; si; si = si->sib_next) {
    si->weight = nghttp2_stream_dep_distributed_weight(stream, si->weight);

    sum_dep_weight_delta += si->weight;

    if (si->queued) {
      rv = stream_obq_move(stream->dep_prev, stream, si);
      if (rv != 0) {
        return rv;
      }
    }
  }

  assert(stream->dep_prev);

  dep_prev = stream->dep_prev;

  dep_prev->sum_dep_weight += sum_dep_weight_delta;

  if (stream->queued) {
    stream_obq_remove(stream);
  }

  if (stream->sib_prev) {
    unlink_sib(stream);
  } else {
    unlink_dep(stream);
  }

  stream->sum_dep_weight = 0;

  stream->dep_prev = NULL;
  stream->dep_next = NULL;
  stream->sib_prev = NULL;
  stream->sib_next = NULL;

  validate_tree(dep_prev);

  return 0;
}
예제 #2
0
void nghttp2_stream_dep_remove(nghttp2_stream *stream) {
  nghttp2_stream *prev, *next, *dep_prev, *si, *root_stream;
  int32_t sum_dep_weight_delta;

  root_stream = NULL;

  DEBUGF(fprintf(stderr, "stream: dep_remove stream(%p)=%d\n", stream,
                 stream->stream_id));

  /* Distribute weight of |stream| to direct descendants */
  sum_dep_weight_delta = -stream->weight;

  for (si = stream->dep_next; si; si = si->sib_next) {
    si->weight = nghttp2_stream_dep_distributed_weight(stream, si->weight);

    sum_dep_weight_delta += si->weight;
  }

  prev = stream_first_sib(stream);

  dep_prev = prev->dep_prev;

  if (dep_prev) {
    root_stream = stream_update_dep_length(dep_prev, -1);

    dep_prev->sum_dep_weight += sum_dep_weight_delta;
  }

  if (stream->sib_prev) {
    unlink_sib(stream);
  } else if (stream->dep_prev) {
    unlink_dep(stream);
  } else {
    nghttp2_stream_roots_remove(stream->roots, stream);

    /* stream is a root of tree.  Removing stream makes its
       descendants a root of its own subtree. */

    for (si = stream->dep_next; si;) {
      next = si->sib_next;

      si->dep_prev = NULL;
      si->sib_prev = NULL;
      si->sib_next = NULL;

      /* We already distributed weight of |stream| to this. */
      si->effective_weight = si->weight;

      nghttp2_stream_roots_add(si->roots, si);

      si = next;
    }
  }

  if (root_stream) {
    stream_update_dep_sum_norest_weight(root_stream);
    stream_update_dep_effective_weight(root_stream);
  }

  stream->num_substreams = 1;
  stream->sum_dep_weight = 0;

  stream->dep_prev = NULL;
  stream->dep_next = NULL;
  stream->sib_prev = NULL;
  stream->sib_next = NULL;

  --stream->roots->num_streams;
}