2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-01-24 14:02:24 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
#include "nghttp2_stream.h"
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-02-19 15:42:25 +01:00
|
|
|
#include <assert.h>
|
2014-03-25 18:04:24 +01:00
|
|
|
#include <stdio.h>
|
2012-02-19 15:42:25 +01:00
|
|
|
|
2014-11-11 16:26:23 +01:00
|
|
|
#include "nghttp2_session.h"
|
2014-03-31 15:51:33 +02:00
|
|
|
#include "nghttp2_helper.h"
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
static int stream_weight_less(const void *lhsx, const void *rhsx) {
|
|
|
|
const nghttp2_stream *lhs, *rhs;
|
|
|
|
|
|
|
|
lhs = nghttp2_struct_of(lhsx, nghttp2_stream, pq_entry);
|
|
|
|
rhs = nghttp2_struct_of(rhsx, nghttp2_stream, pq_entry);
|
|
|
|
|
2015-08-17 17:12:04 +02:00
|
|
|
return lhs->cycle < rhs->cycle;
|
2015-08-16 12:01:10 +02:00
|
|
|
}
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id,
|
2014-11-27 15:39:04 +01:00
|
|
|
uint8_t flags, nghttp2_stream_state initial_state,
|
2015-08-13 16:32:13 +02:00
|
|
|
int32_t weight, int32_t remote_initial_window_size,
|
2013-08-08 14:12:49 +02:00
|
|
|
int32_t local_initial_window_size,
|
2015-08-16 12:01:10 +02:00
|
|
|
void *stream_user_data, nghttp2_mem *mem) {
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_map_entry_init(&stream->map_entry, stream_id);
|
2015-08-16 12:01:10 +02:00
|
|
|
nghttp2_pq_init(&stream->obq, stream_weight_less, mem);
|
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
stream->stream_id = stream_id;
|
2012-01-25 15:46:07 +01:00
|
|
|
stream->flags = flags;
|
2012-01-25 17:04:01 +01:00
|
|
|
stream->state = initial_state;
|
2013-07-12 17:19:03 +02:00
|
|
|
stream->shut_flags = NGHTTP2_SHUT_NONE;
|
2012-02-03 17:37:21 +01:00
|
|
|
stream->stream_user_data = stream_user_data;
|
2014-12-20 11:53:57 +01:00
|
|
|
stream->item = NULL;
|
2013-08-08 14:12:49 +02:00
|
|
|
stream->remote_window_size = remote_initial_window_size;
|
|
|
|
stream->local_window_size = local_initial_window_size;
|
2012-02-25 16:12:32 +01:00
|
|
|
stream->recv_window_size = 0;
|
2014-07-25 14:26:03 +02:00
|
|
|
stream->consumed_size = 0;
|
2013-10-12 10:02:37 +02:00
|
|
|
stream->recv_reduction = 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
|
|
|
stream->dep_prev = NULL;
|
|
|
|
stream->dep_next = NULL;
|
|
|
|
stream->sib_prev = NULL;
|
|
|
|
stream->sib_next = NULL;
|
|
|
|
|
2014-11-07 16:36:47 +01:00
|
|
|
stream->closed_prev = NULL;
|
2014-03-30 10:41:54 +02:00
|
|
|
stream->closed_next = NULL;
|
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
stream->weight = weight;
|
|
|
|
stream->sum_dep_weight = 0;
|
2014-04-17 14:15:14 +02:00
|
|
|
|
2015-02-19 16:01:15 +01:00
|
|
|
stream->http_flags = NGHTTP2_HTTP_FLAG_NONE;
|
|
|
|
stream->content_length = -1;
|
|
|
|
stream->recv_content_length = 0;
|
|
|
|
stream->status_code = -1;
|
2015-08-16 12:01:10 +02:00
|
|
|
|
|
|
|
stream->queued = 0;
|
|
|
|
stream->descendant_last_cycle = 0;
|
|
|
|
stream->cycle = 0;
|
2015-09-09 14:16:53 +02:00
|
|
|
stream->last_writelen = 0;
|
2012-01-24 14:02:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
void nghttp2_stream_free(nghttp2_stream *stream) {
|
|
|
|
nghttp2_pq_free(&stream->obq);
|
2014-12-20 11:53:57 +01:00
|
|
|
/* We don't free stream->item. If it is assigned to aob, then
|
2015-08-16 12:01:10 +02:00
|
|
|
active_outbound_item_reset() will delete it. Otherwise,
|
|
|
|
nghttp2_stream_close() or session_del() will delete it. */
|
2012-02-02 13:51:52 +01:00
|
|
|
}
|
2012-01-28 16:08:51 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void nghttp2_stream_shutdown(nghttp2_stream *stream, nghttp2_shut_flag flag) {
|
2012-01-28 16:08:51 +01:00
|
|
|
stream->shut_flags |= flag;
|
|
|
|
}
|
2012-02-02 13:51:52 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
/*
|
|
|
|
* Returns nonzero if |stream| is active. This function does not take
|
|
|
|
* into account its descendants.
|
|
|
|
*/
|
|
|
|
static int stream_active(nghttp2_stream *stream) {
|
|
|
|
return stream->item &&
|
|
|
|
(stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) == 0;
|
2014-03-31 16:01:05 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
/*
|
|
|
|
* Returns nonzero if |stream| or one of its descendants is active
|
2015-08-13 16:32:13 +02:00
|
|
|
*/
|
2015-08-16 12:01:10 +02:00
|
|
|
static int stream_subtree_active(nghttp2_stream *stream) {
|
|
|
|
return stream_active(stream) || !nghttp2_pq_empty(&stream->obq);
|
2015-08-13 16:32:13 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
/*
|
|
|
|
* Returns next cycle for |stream|.
|
|
|
|
*/
|
|
|
|
static uint64_t stream_next_cycle(nghttp2_stream *stream, uint64_t last_cycle) {
|
|
|
|
return last_cycle +
|
2015-09-09 14:20:59 +02:00
|
|
|
(stream->last_writelen + 1) * NGHTTP2_MAX_WEIGHT / stream->weight;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
static int stream_obq_push(nghttp2_stream *dep_stream, nghttp2_stream *stream) {
|
|
|
|
int rv;
|
2014-03-31 15:51:33 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
for (; dep_stream && !stream->queued;
|
|
|
|
stream = dep_stream, dep_stream = dep_stream->dep_prev) {
|
|
|
|
stream->cycle =
|
|
|
|
stream_next_cycle(stream, dep_stream->descendant_last_cycle);
|
2014-03-31 15:51:33 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
DEBUGF(fprintf(stderr, "stream: stream=%d obq push cycle=%ld\n",
|
|
|
|
stream->stream_id, stream->cycle));
|
2014-10-08 15:44:02 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
DEBUGF(fprintf(stderr, "stream: push stream %d to stream %d\n",
|
|
|
|
stream->stream_id, dep_stream->stream_id));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
rv = nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
stream->queued = 1;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
return 0;
|
2015-08-13 16:32:13 +02:00
|
|
|
}
|
2014-10-08 15:44:02 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
/*
|
|
|
|
* Removes |stream| from parent's obq. If removal of |stream| makes
|
|
|
|
* parent's obq empty, and parent is not active, then parent is also
|
|
|
|
* removed. This process is repeated recursively.
|
|
|
|
*/
|
|
|
|
static void stream_obq_remove(nghttp2_stream *stream) {
|
|
|
|
nghttp2_stream *dep_stream;
|
2014-10-08 15:44:02 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
dep_stream = stream->dep_prev;
|
2014-10-08 15:44:02 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
if (!stream->queued) {
|
|
|
|
return;
|
2014-10-08 15:44:02 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
for (; dep_stream; stream = dep_stream, dep_stream = dep_stream->dep_prev) {
|
|
|
|
DEBUGF(fprintf(stderr, "stream: remove stream %d from stream %d\n",
|
|
|
|
stream->stream_id, dep_stream->stream_id));
|
2015-08-13 16:32:13 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
nghttp2_pq_remove(&dep_stream->obq, &stream->pq_entry);
|
2015-08-13 16:32:13 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
assert(stream->queued);
|
2015-08-13 16:32:13 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
stream->queued = 0;
|
|
|
|
stream->cycle = 0;
|
|
|
|
stream->descendant_last_cycle = 0;
|
2015-06-19 12:36:24 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
if (stream_subtree_active(dep_stream)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-13 16:32:13 +02:00
|
|
|
}
|
2014-10-08 15:44:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2015-08-16 12:01:10 +02:00
|
|
|
* Moves |stream| from |src|'s obq to |dest|'s obq. Removal from
|
|
|
|
* |src|'s obq is just done calling nghttp2_pq_remove(), so it does
|
|
|
|
* not recursively remove |src| and ancestors, like
|
|
|
|
* stream_obq_remove().
|
2014-03-25 18:04:24 +01:00
|
|
|
*/
|
2015-08-16 12:01:10 +02:00
|
|
|
static int stream_obq_move(nghttp2_stream *dest, nghttp2_stream *src,
|
|
|
|
nghttp2_stream *stream) {
|
|
|
|
if (!stream->queued) {
|
|
|
|
return 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
DEBUGF(fprintf(stderr, "stream: remove stream %d from stream %d (move)\n",
|
|
|
|
stream->stream_id, src->stream_id));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
nghttp2_pq_remove(&src->obq, &stream->pq_entry);
|
|
|
|
stream->queued = 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
return stream_obq_push(dest, stream);
|
2015-08-13 16:32:13 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
void nghttp2_stream_reschedule(nghttp2_stream *stream) {
|
|
|
|
nghttp2_stream *dep_stream;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
assert(stream->queued);
|
2014-04-24 16:37:40 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
dep_stream = stream->dep_prev;
|
2014-04-24 16:37:40 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
for (; dep_stream; stream = dep_stream, dep_stream = dep_stream->dep_prev) {
|
2015-08-29 16:43:54 +02:00
|
|
|
if (nghttp2_pq_size(&dep_stream->obq) == 1) {
|
|
|
|
dep_stream->descendant_last_cycle = 0;
|
|
|
|
stream->cycle = 0;
|
|
|
|
} else {
|
|
|
|
dep_stream->descendant_last_cycle =
|
|
|
|
nghttp2_max(dep_stream->descendant_last_cycle, stream->cycle);
|
|
|
|
|
|
|
|
stream->cycle =
|
|
|
|
stream_next_cycle(stream, dep_stream->descendant_last_cycle);
|
|
|
|
|
|
|
|
nghttp2_pq_remove(&dep_stream->obq, &stream->pq_entry);
|
|
|
|
nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry);
|
|
|
|
}
|
2015-06-19 12:36:24 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
DEBUGF(fprintf(stderr, "stream: stream=%d obq resched cycle=%ld\n",
|
|
|
|
stream->stream_id, stream->cycle));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
dep_stream->last_writelen = stream->last_writelen;
|
2014-03-31 15:51:33 +02:00
|
|
|
}
|
2015-06-19 12:36:24 +02:00
|
|
|
}
|
2014-03-31 15:51:33 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
static nghttp2_stream *stream_last_sib(nghttp2_stream *stream) {
|
|
|
|
for (; stream->sib_next; stream = stream->sib_next)
|
|
|
|
;
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t nghttp2_stream_dep_distributed_weight(nghttp2_stream *stream,
|
|
|
|
int32_t weight) {
|
|
|
|
weight = stream->weight * weight / stream->sum_dep_weight;
|
|
|
|
|
|
|
|
return nghttp2_max(1, weight);
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-06-26 16:02:18 +02:00
|
|
|
#ifdef STREAM_DEP_DEBUG
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
static void ensure_inactive(nghttp2_stream *stream) {
|
2015-06-26 16:02:18 +02:00
|
|
|
nghttp2_stream *si;
|
2015-08-16 12:01:10 +02:00
|
|
|
|
|
|
|
if (stream->queued) {
|
|
|
|
fprintf(stderr, "stream(%p)=%d, stream->queued = 1; want 0\n", stream,
|
|
|
|
stream->stream_id);
|
2015-06-26 16:02:18 +02:00
|
|
|
assert(0);
|
2015-08-16 12:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_active(stream)) {
|
|
|
|
fprintf(stderr, "stream(%p)=%d, stream_active(stream) = 1; want 0\n",
|
|
|
|
stream, stream->stream_id);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nghttp2_pq_empty(&stream->obq)) {
|
|
|
|
fprintf(stderr, "stream(%p)=%d, nghttp2_pq_size() = %zu; want 0\n", stream,
|
|
|
|
stream->stream_id, nghttp2_pq_size(&stream->obq));
|
2015-06-26 16:02:18 +02:00
|
|
|
assert(0);
|
|
|
|
}
|
2015-08-16 12:01:10 +02:00
|
|
|
|
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
|
|
|
ensure_inactive(si);
|
|
|
|
}
|
2015-06-26 16:02:18 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
static void check_queued(nghttp2_stream *stream) {
|
2015-06-26 16:02:18 +02:00
|
|
|
nghttp2_stream *si;
|
2015-08-16 12:01:10 +02:00
|
|
|
int queued;
|
|
|
|
|
|
|
|
if (stream->queued) {
|
|
|
|
if (!stream_subtree_active(stream)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"stream(%p)=%d, stream->queued == 1, but "
|
|
|
|
"stream_active() == %d and nghttp2_pq_size(&stream->obq) = %zu\n",
|
|
|
|
stream, stream->stream_id, stream_active(stream),
|
|
|
|
nghttp2_pq_size(&stream->obq));
|
2015-06-26 16:02:18 +02:00
|
|
|
assert(0);
|
|
|
|
}
|
2015-08-16 12:01:10 +02:00
|
|
|
if (!stream_active(stream)) {
|
|
|
|
queued = 0;
|
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
|
|
|
if (si->queued) {
|
|
|
|
++queued;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (queued == 0) {
|
|
|
|
fprintf(stderr, "stream(%p)=%d, stream->queued == 1, and "
|
|
|
|
"!stream_active(), but no descendants is queued\n",
|
|
|
|
stream, stream->stream_id);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 16:02:18 +02:00
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
2015-08-16 12:01:10 +02:00
|
|
|
check_queued(si);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (stream_active(stream) || !nghttp2_pq_empty(&stream->obq)) {
|
|
|
|
fprintf(stderr, "stream(%p) = %d, stream->queued == 0, but "
|
|
|
|
"stream_active(stream) == %d and "
|
|
|
|
"nghttp2_pq_size(&stream->obq) = %zu\n",
|
|
|
|
stream, stream->stream_id, stream_active(stream),
|
|
|
|
nghttp2_pq_size(&stream->obq));
|
|
|
|
assert(0);
|
2015-06-26 16:02:18 +02:00
|
|
|
}
|
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
2015-08-16 12:01:10 +02:00
|
|
|
ensure_inactive(si);
|
2015-06-26 16:02:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_sum_dep(nghttp2_stream *stream) {
|
|
|
|
nghttp2_stream *si;
|
|
|
|
int32_t n = 0;
|
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
|
|
|
n += si->weight;
|
|
|
|
}
|
|
|
|
if (n != stream->sum_dep_weight) {
|
2015-08-13 16:32:13 +02:00
|
|
|
fprintf(stderr, "stream(%p)=%d, sum_dep_weight = %d; want %d\n", stream,
|
|
|
|
stream->stream_id, n, stream->sum_dep_weight);
|
2015-06-26 16:02:18 +02:00
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
|
|
|
check_sum_dep(si);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_dep_prev(nghttp2_stream *stream) {
|
|
|
|
nghttp2_stream *si;
|
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
|
|
|
if (si->dep_prev != stream) {
|
|
|
|
fprintf(stderr, "si->dep_prev = %p; want %p\n", si->dep_prev, stream);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
check_dep_prev(si);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* STREAM_DEP_DEBUG */
|
|
|
|
|
|
|
|
#ifdef STREAM_DEP_DEBUG
|
2015-06-26 16:21:01 +02:00
|
|
|
static void validate_tree(nghttp2_stream *stream) {
|
2015-08-16 12:01:10 +02:00
|
|
|
nghttp2_stream *si;
|
|
|
|
|
2015-06-26 16:02:18 +02:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; stream->dep_prev; stream = stream->dep_prev)
|
|
|
|
;
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
assert(stream->stream_id == 0);
|
|
|
|
assert(!stream->queued);
|
|
|
|
|
|
|
|
fprintf(stderr, "checking...\n");
|
|
|
|
if (nghttp2_pq_empty(&stream->obq)) {
|
|
|
|
fprintf(stderr, "root obq empty\n");
|
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
|
|
|
ensure_inactive(si);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
|
|
|
check_queued(si);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 16:02:18 +02:00
|
|
|
check_sum_dep(stream);
|
|
|
|
check_dep_prev(stream);
|
|
|
|
}
|
2015-06-26 16:21:01 +02:00
|
|
|
#else /* !STREAM_DEP_DEBUG */
|
|
|
|
static void validate_tree(nghttp2_stream *stream _U_) {}
|
|
|
|
#endif /* !STREAM_DEP_DEBUG*/
|
2015-06-26 16:02:18 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
static int stream_update_dep_on_attach_item(nghttp2_stream *stream) {
|
2015-06-19 12:36:24 +02:00
|
|
|
int rv;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
rv = stream_obq_push(stream->dep_prev, stream);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
2015-06-19 12:36:24 +02:00
|
|
|
}
|
2014-04-24 16:37:40 +02:00
|
|
|
|
2015-06-26 16:02:18 +02:00
|
|
|
validate_tree(stream);
|
2015-06-19 12:36:24 +02:00
|
|
|
return 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
static int stream_update_dep_on_detach_item(nghttp2_stream *stream) {
|
|
|
|
if (nghttp2_pq_empty(&stream->obq)) {
|
|
|
|
stream_obq_remove(stream);
|
2015-06-26 16:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
validate_tree(stream);
|
|
|
|
|
|
|
|
return 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2014-12-20 11:53:57 +01:00
|
|
|
int nghttp2_stream_attach_item(nghttp2_stream *stream,
|
2015-08-16 12:01:10 +02:00
|
|
|
nghttp2_outbound_item *item) {
|
|
|
|
int rv;
|
|
|
|
|
2014-04-02 15:55:49 +02:00
|
|
|
assert((stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) == 0);
|
2014-12-20 11:53:57 +01:00
|
|
|
assert(stream->item == NULL);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-12-20 11:53:57 +01:00
|
|
|
DEBUGF(fprintf(stderr, "stream: stream=%d attach item=%p\n",
|
|
|
|
stream->stream_id, item));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-12-20 11:53:57 +01:00
|
|
|
stream->item = item;
|
2014-04-03 08:52:21 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
rv = stream_update_dep_on_attach_item(stream);
|
|
|
|
if (rv != 0) {
|
|
|
|
/* This may relave stream->queued == 1, but stream->item == NULL.
|
|
|
|
But only consequence of this error is fatal one, and session
|
|
|
|
destruction. In that execution path, these inconsistency does
|
|
|
|
not matter. */
|
|
|
|
stream->item = NULL;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
int nghttp2_stream_detach_item(nghttp2_stream *stream) {
|
2014-12-20 11:53:57 +01:00
|
|
|
DEBUGF(fprintf(stderr, "stream: stream=%d detach item=%p\n",
|
|
|
|
stream->stream_id, stream->item));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-12-20 11:53:57 +01:00
|
|
|
stream->item = NULL;
|
2014-04-02 15:55:49 +02:00
|
|
|
stream->flags &= ~NGHTTP2_STREAM_FLAG_DEFERRED_ALL;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
return stream_update_dep_on_detach_item(stream);
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
int nghttp2_stream_defer_item(nghttp2_stream *stream, uint8_t flags) {
|
2014-12-20 11:53:57 +01:00
|
|
|
assert(stream->item);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-12-20 11:53:57 +01:00
|
|
|
DEBUGF(fprintf(stderr, "stream: stream=%d defer item=%p cause=%02x\n",
|
|
|
|
stream->stream_id, stream->item, flags));
|
2014-04-03 08:48:19 +02:00
|
|
|
|
2014-04-02 15:55:49 +02:00
|
|
|
stream->flags |= flags;
|
2014-04-03 08:48:19 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
return stream_update_dep_on_detach_item(stream);
|
2012-02-19 15:42:25 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
int nghttp2_stream_resume_deferred_item(nghttp2_stream *stream, uint8_t flags) {
|
2014-12-20 11:53:57 +01:00
|
|
|
assert(stream->item);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-12-20 11:53:57 +01:00
|
|
|
DEBUGF(fprintf(stderr, "stream: stream=%d resume item=%p flags=%02x\n",
|
|
|
|
stream->stream_id, stream->item, flags));
|
2014-04-03 08:52:21 +02:00
|
|
|
|
2014-09-26 14:32:17 +02:00
|
|
|
stream->flags &= ~flags;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) {
|
2014-09-26 14:32:17 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
return stream_update_dep_on_attach_item(stream);
|
2014-04-02 15:55:49 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-12-20 11:53:57 +01:00
|
|
|
int nghttp2_stream_check_deferred_item(nghttp2_stream *stream) {
|
|
|
|
return stream->item && (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL);
|
2014-04-02 15:55:49 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int nghttp2_stream_check_deferred_by_flow_control(nghttp2_stream *stream) {
|
2014-12-20 11:53:57 +01:00
|
|
|
return stream->item &&
|
2014-11-27 15:39:04 +01:00
|
|
|
(stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL);
|
2012-02-19 15:42:25 +01:00
|
|
|
}
|
2012-03-09 16:10:11 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
static int update_initial_window_size(int32_t *window_size_ptr,
|
|
|
|
int32_t new_initial_window_size,
|
|
|
|
int32_t old_initial_window_size) {
|
2013-08-08 17:58:52 +02:00
|
|
|
int64_t new_window_size = (int64_t)(*window_size_ptr) +
|
2014-11-27 15:39:04 +01:00
|
|
|
new_initial_window_size - old_initial_window_size;
|
|
|
|
if (INT32_MIN > new_window_size ||
|
|
|
|
new_window_size > NGHTTP2_MAX_WINDOW_SIZE) {
|
2013-08-08 14:12:49 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-06-11 16:37:16 +02:00
|
|
|
*window_size_ptr = (int32_t)new_window_size;
|
2013-08-08 14:12:49 +02:00
|
|
|
return 0;
|
2012-03-09 16:10:11 +01:00
|
|
|
}
|
2013-07-24 18:49:05 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int nghttp2_stream_update_remote_initial_window_size(
|
|
|
|
nghttp2_stream *stream, int32_t new_initial_window_size,
|
|
|
|
int32_t old_initial_window_size) {
|
2013-08-08 17:58:52 +02:00
|
|
|
return update_initial_window_size(&stream->remote_window_size,
|
|
|
|
new_initial_window_size,
|
|
|
|
old_initial_window_size);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int nghttp2_stream_update_local_initial_window_size(
|
|
|
|
nghttp2_stream *stream, int32_t new_initial_window_size,
|
|
|
|
int32_t old_initial_window_size) {
|
2013-08-08 17:58:52 +02:00
|
|
|
return update_initial_window_size(&stream->local_window_size,
|
|
|
|
new_initial_window_size,
|
|
|
|
old_initial_window_size);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void nghttp2_stream_promise_fulfilled(nghttp2_stream *stream) {
|
2013-07-24 18:49:05 +02:00
|
|
|
stream->state = NGHTTP2_STREAM_OPENED;
|
2015-02-09 13:45:55 +01:00
|
|
|
stream->flags &= ~NGHTTP2_STREAM_FLAG_PUSH;
|
2013-07-24 18:49:05 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
int nghttp2_stream_dep_find_ancestor(nghttp2_stream *stream,
|
|
|
|
nghttp2_stream *target) {
|
|
|
|
for (; stream; stream = stream->dep_prev) {
|
|
|
|
if (stream == target) {
|
|
|
|
return 1;
|
2015-08-13 16:32:13 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-16 12:01:10 +02:00
|
|
|
return 0;
|
2015-06-19 12:36:24 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
int nghttp2_stream_dep_insert(nghttp2_stream *dep_stream,
|
|
|
|
nghttp2_stream *stream) {
|
2014-03-25 18:04:24 +01:00
|
|
|
nghttp2_stream *si;
|
2015-08-16 12:01:10 +02:00
|
|
|
int rv;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
|
|
|
DEBUGF(fprintf(stderr,
|
|
|
|
"stream: dep_insert dep_stream(%p)=%d, stream(%p)=%d\n",
|
2014-11-27 15:39:04 +01:00
|
|
|
dep_stream, dep_stream->stream_id, stream, stream->stream_id));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
stream->sum_dep_weight = dep_stream->sum_dep_weight;
|
|
|
|
dep_stream->sum_dep_weight = stream->weight;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (dep_stream->dep_next) {
|
|
|
|
for (si = dep_stream->dep_next; si; si = si->sib_next) {
|
2015-06-19 12:36:24 +02:00
|
|
|
si->dep_prev = stream;
|
2015-08-16 12:01:10 +02:00
|
|
|
if (si->queued) {
|
|
|
|
rv = stream_obq_move(stream, dep_stream, si);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream_subtree_active(stream)) {
|
|
|
|
rv = stream_obq_push(dep_stream, stream);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
2015-06-19 12:36:24 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stream->dep_next = dep_stream->dep_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
dep_stream->dep_next = stream;
|
|
|
|
stream->dep_prev = dep_stream;
|
|
|
|
|
2015-06-26 16:02:18 +02:00
|
|
|
validate_tree(stream);
|
2015-08-16 12:01:10 +02:00
|
|
|
|
|
|
|
return 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-06-19 12:36:24 +02:00
|
|
|
static void set_dep_prev(nghttp2_stream *stream, nghttp2_stream *dep) {
|
|
|
|
for (; stream; stream = stream->sib_next) {
|
|
|
|
stream->dep_prev = dep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
static void link_dep(nghttp2_stream *dep_stream, nghttp2_stream *stream) {
|
2014-10-15 18:12:59 +02:00
|
|
|
dep_stream->dep_next = stream;
|
2015-06-19 12:36:24 +02:00
|
|
|
if (stream) {
|
|
|
|
stream->dep_prev = dep_stream;
|
|
|
|
}
|
2014-10-15 18:12:59 +02:00
|
|
|
}
|
|
|
|
|
2015-06-19 12:36:24 +02:00
|
|
|
static void link_sib(nghttp2_stream *a, nghttp2_stream *b) {
|
|
|
|
a->sib_next = b;
|
|
|
|
if (b) {
|
|
|
|
b->sib_prev = a;
|
|
|
|
}
|
2014-10-15 18:12:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void insert_link_dep(nghttp2_stream *dep_stream,
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_stream *stream) {
|
2014-10-15 18:12:59 +02:00
|
|
|
nghttp2_stream *sib_next;
|
|
|
|
|
|
|
|
assert(stream->sib_prev == NULL);
|
|
|
|
|
|
|
|
sib_next = dep_stream->dep_next;
|
|
|
|
|
|
|
|
link_sib(stream, sib_next);
|
|
|
|
|
|
|
|
link_dep(dep_stream, stream);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
static void unlink_sib(nghttp2_stream *stream) {
|
2014-10-16 14:59:52 +02:00
|
|
|
nghttp2_stream *prev, *next, *dep_next;
|
|
|
|
|
|
|
|
prev = stream->sib_prev;
|
|
|
|
dep_next = stream->dep_next;
|
|
|
|
|
|
|
|
assert(prev);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (dep_next) {
|
2014-10-16 14:59:52 +02:00
|
|
|
/*
|
|
|
|
* prev--stream(--sib_next--...)
|
|
|
|
* |
|
|
|
|
* dep_next
|
|
|
|
*/
|
|
|
|
|
|
|
|
link_sib(prev, dep_next);
|
|
|
|
|
2015-06-19 12:36:24 +02:00
|
|
|
set_dep_prev(dep_next, stream->dep_prev);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream->sib_next) {
|
2014-10-16 14:59:52 +02:00
|
|
|
link_sib(stream_last_sib(dep_next), stream->sib_next);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* prev--stream(--sib_next--...)
|
|
|
|
*/
|
|
|
|
next = stream->sib_next;
|
|
|
|
|
|
|
|
prev->sib_next = next;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (next) {
|
2014-10-16 14:59:52 +02:00
|
|
|
next->sib_prev = prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
static void unlink_dep(nghttp2_stream *stream) {
|
2014-10-16 14:59:52 +02:00
|
|
|
nghttp2_stream *prev, *next, *dep_next;
|
|
|
|
|
|
|
|
prev = stream->dep_prev;
|
|
|
|
dep_next = stream->dep_next;
|
|
|
|
|
|
|
|
assert(prev);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (dep_next) {
|
2014-10-16 14:59:52 +02:00
|
|
|
/*
|
|
|
|
* prev
|
|
|
|
* |
|
|
|
|
* stream(--sib_next--...)
|
|
|
|
* |
|
|
|
|
* dep_next
|
|
|
|
*/
|
|
|
|
link_dep(prev, dep_next);
|
|
|
|
|
2015-06-19 12:36:24 +02:00
|
|
|
set_dep_prev(dep_next, stream->dep_prev);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream->sib_next) {
|
2014-10-16 14:59:52 +02:00
|
|
|
link_sib(stream_last_sib(dep_next), stream->sib_next);
|
|
|
|
}
|
2015-06-19 12:36:24 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
} else if (stream->sib_next) {
|
2014-10-16 14:59:52 +02:00
|
|
|
/*
|
|
|
|
* prev
|
|
|
|
* |
|
|
|
|
* stream--sib_next
|
|
|
|
*/
|
|
|
|
next = stream->sib_next;
|
|
|
|
|
|
|
|
next->sib_prev = NULL;
|
|
|
|
|
|
|
|
link_dep(prev, next);
|
|
|
|
} else {
|
|
|
|
prev->dep_next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 18:04:24 +01:00
|
|
|
void nghttp2_stream_dep_add(nghttp2_stream *dep_stream,
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_stream *stream) {
|
|
|
|
DEBUGF(fprintf(stderr, "stream: dep_add dep_stream(%p)=%d, stream(%p)=%d\n",
|
|
|
|
dep_stream, dep_stream->stream_id, stream, stream->stream_id));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
dep_stream->sum_dep_weight += stream->weight;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (dep_stream->dep_next == NULL) {
|
2014-10-16 14:59:52 +02:00
|
|
|
link_dep(dep_stream, stream);
|
2014-04-14 16:53:54 +02:00
|
|
|
} else {
|
2014-10-15 18:12:59 +02:00
|
|
|
insert_link_dep(dep_stream, stream);
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-06-26 16:02:18 +02:00
|
|
|
validate_tree(stream);
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
int nghttp2_stream_dep_remove(nghttp2_stream *stream) {
|
|
|
|
nghttp2_stream *dep_prev, *si;
|
|
|
|
int32_t sum_dep_weight_delta;
|
|
|
|
int rv;
|
2014-04-24 16:37:40 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
DEBUGF(fprintf(stderr, "stream: dep_remove stream(%p)=%d\n", stream,
|
|
|
|
stream->stream_id));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
/* Distribute weight of |stream| to direct descendants */
|
|
|
|
sum_dep_weight_delta = -stream->weight;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (si = stream->dep_next; si; si = si->sib_next) {
|
2014-04-14 16:53:54 +02:00
|
|
|
si->weight = nghttp2_stream_dep_distributed_weight(stream, si->weight);
|
|
|
|
|
|
|
|
sum_dep_weight_delta += si->weight;
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
if (si->queued) {
|
|
|
|
rv = stream_obq_move(stream->dep_prev, stream, si);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-06-19 12:36:24 +02:00
|
|
|
}
|
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-13 16:32:13 +02:00
|
|
|
assert(stream->dep_prev);
|
2014-04-14 16:53:54 +02:00
|
|
|
|
2015-08-13 16:32:13 +02:00
|
|
|
dep_prev = stream->dep_prev;
|
2014-04-14 16:53:54 +02:00
|
|
|
|
2015-08-13 16:32:13 +02:00
|
|
|
dep_prev->sum_dep_weight += sum_dep_weight_delta;
|
2015-08-16 12:01:10 +02:00
|
|
|
|
|
|
|
if (stream->queued) {
|
|
|
|
stream_obq_remove(stream);
|
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream->sib_prev) {
|
2014-10-16 14:59:52 +02:00
|
|
|
unlink_sib(stream);
|
2014-03-25 18:04:24 +01:00
|
|
|
} else {
|
2015-08-13 16:32:13 +02:00
|
|
|
unlink_dep(stream);
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
stream->sum_dep_weight = 0;
|
|
|
|
|
2014-03-25 18:04:24 +01:00
|
|
|
stream->dep_prev = NULL;
|
|
|
|
stream->dep_next = NULL;
|
|
|
|
stream->sib_prev = NULL;
|
|
|
|
stream->sib_next = NULL;
|
2014-04-17 14:15:14 +02:00
|
|
|
|
2015-08-13 16:32:13 +02:00
|
|
|
validate_tree(dep_prev);
|
2015-08-16 12:01:10 +02:00
|
|
|
|
|
|
|
return 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int nghttp2_stream_dep_insert_subtree(nghttp2_stream *dep_stream,
|
2015-08-16 12:01:10 +02:00
|
|
|
nghttp2_stream *stream) {
|
2014-03-25 18:04:24 +01:00
|
|
|
nghttp2_stream *last_sib;
|
|
|
|
nghttp2_stream *dep_next;
|
2015-06-19 12:36:24 +02:00
|
|
|
nghttp2_stream *si;
|
2015-06-26 16:02:18 +02:00
|
|
|
int rv;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
|
|
|
DEBUGF(fprintf(stderr, "stream: dep_insert_subtree dep_stream(%p)=%d "
|
2014-11-27 15:39:04 +01:00
|
|
|
"stream(%p)=%d\n",
|
|
|
|
dep_stream, dep_stream->stream_id, stream, stream->stream_id));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
stream->sum_dep_weight += dep_stream->sum_dep_weight;
|
|
|
|
dep_stream->sum_dep_weight = stream->weight;
|
2015-06-25 15:31:15 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (dep_stream->dep_next) {
|
2014-04-14 16:53:54 +02:00
|
|
|
dep_next = dep_stream->dep_next;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-10-16 14:59:52 +02:00
|
|
|
link_dep(dep_stream, stream);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream->dep_next) {
|
2014-03-25 18:04:24 +01:00
|
|
|
last_sib = stream_last_sib(stream->dep_next);
|
|
|
|
|
2014-10-16 14:59:52 +02:00
|
|
|
link_sib(last_sib, dep_next);
|
2014-03-25 18:04:24 +01:00
|
|
|
} else {
|
2014-10-16 14:59:52 +02:00
|
|
|
link_dep(stream, dep_next);
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
2015-06-19 12:36:24 +02:00
|
|
|
|
|
|
|
for (si = dep_next; si; si = si->sib_next) {
|
|
|
|
si->dep_prev = stream;
|
2015-08-16 12:01:10 +02:00
|
|
|
if (si->queued) {
|
|
|
|
rv = stream_obq_move(stream, dep_stream, si);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
2015-06-19 12:36:24 +02:00
|
|
|
}
|
2014-03-25 18:04:24 +01:00
|
|
|
} else {
|
2014-10-16 14:59:52 +02:00
|
|
|
link_dep(dep_stream, stream);
|
2015-06-19 12:36:24 +02:00
|
|
|
}
|
2014-03-31 15:51:33 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
if (stream_subtree_active(stream)) {
|
|
|
|
rv = stream_obq_push(dep_stream, stream);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-06-26 16:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
validate_tree(dep_stream);
|
|
|
|
|
|
|
|
return 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream,
|
2015-08-16 12:01:10 +02:00
|
|
|
nghttp2_stream *stream) {
|
2015-06-26 16:02:18 +02:00
|
|
|
int rv;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
|
|
|
DEBUGF(fprintf(stderr, "stream: dep_add_subtree dep_stream(%p)=%d "
|
2014-11-27 15:39:04 +01:00
|
|
|
"stream(%p)=%d\n",
|
|
|
|
dep_stream, dep_stream->stream_id, stream, stream->stream_id));
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
dep_stream->sum_dep_weight += stream->weight;
|
2014-04-14 16:53:54 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
if (dep_stream->dep_next) {
|
2014-10-15 18:12:59 +02:00
|
|
|
insert_link_dep(dep_stream, stream);
|
2014-03-25 18:04:24 +01:00
|
|
|
} else {
|
2014-10-16 14:59:52 +02:00
|
|
|
link_dep(dep_stream, stream);
|
2015-06-19 12:36:24 +02:00
|
|
|
}
|
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
if (stream_subtree_active(stream)) {
|
|
|
|
rv = stream_obq_push(dep_stream, stream);
|
|
|
|
if (rv != 0) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-06-26 16:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
validate_tree(dep_stream);
|
|
|
|
|
|
|
|
return 0;
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void nghttp2_stream_dep_remove_subtree(nghttp2_stream *stream) {
|
2015-08-16 12:01:10 +02:00
|
|
|
nghttp2_stream *next, *dep_prev;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
DEBUGF(fprintf(stderr, "stream: dep_remove_subtree stream(%p)=%d\n", stream,
|
|
|
|
stream->stream_id));
|
2014-03-31 15:51:33 +02:00
|
|
|
|
2015-08-13 16:32:13 +02:00
|
|
|
assert(stream->dep_prev);
|
|
|
|
|
|
|
|
dep_prev = stream->dep_prev;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream->sib_prev) {
|
2015-06-19 12:36:24 +02:00
|
|
|
link_sib(stream->sib_prev, stream->sib_next);
|
2015-08-13 16:32:13 +02:00
|
|
|
} else {
|
2014-03-25 18:04:24 +01:00
|
|
|
next = stream->sib_next;
|
|
|
|
|
2015-06-19 12:36:24 +02:00
|
|
|
link_dep(dep_prev, next);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (next) {
|
2014-03-25 18:04:24 +01:00
|
|
|
next->sib_prev = NULL;
|
|
|
|
}
|
2014-04-14 16:53:54 +02:00
|
|
|
}
|
|
|
|
|
2015-08-13 16:32:13 +02:00
|
|
|
dep_prev->sum_dep_weight -= stream->weight;
|
2015-06-19 12:36:24 +02:00
|
|
|
|
2015-08-16 12:01:10 +02:00
|
|
|
if (stream->queued) {
|
|
|
|
stream_obq_remove(stream);
|
2014-03-25 18:04:24 +01:00
|
|
|
}
|
|
|
|
|
2015-08-13 16:32:13 +02:00
|
|
|
validate_tree(dep_prev);
|
|
|
|
|
2014-03-25 18:04:24 +01:00
|
|
|
stream->sib_prev = NULL;
|
|
|
|
stream->sib_next = NULL;
|
|
|
|
stream->dep_prev = NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int nghttp2_stream_in_dep_tree(nghttp2_stream *stream) {
|
|
|
|
return stream->dep_prev || stream->dep_next || stream->sib_prev ||
|
2015-08-13 16:32:13 +02:00
|
|
|
stream->sib_next;
|
2014-04-17 14:15:14 +02:00
|
|
|
}
|
2015-08-16 12:01:10 +02:00
|
|
|
|
|
|
|
nghttp2_outbound_item *
|
|
|
|
nghttp2_stream_next_outbound_item(nghttp2_stream *stream) {
|
|
|
|
nghttp2_pq_entry *ent;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (stream_active(stream)) {
|
|
|
|
return stream->item;
|
|
|
|
}
|
|
|
|
ent = nghttp2_pq_top(&stream->obq);
|
|
|
|
if (!ent) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
stream = nghttp2_struct_of(ent, nghttp2_stream, pq_entry);
|
|
|
|
}
|
|
|
|
}
|
2015-08-18 15:41:50 +02:00
|
|
|
|
|
|
|
nghttp2_stream_proto_state nghttp2_stream_get_state(nghttp2_stream *stream) {
|
|
|
|
if (stream->flags & NGHTTP2_STREAM_FLAG_CLOSED) {
|
|
|
|
return NGHTTP2_STREAM_STATE_CLOSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->flags & NGHTTP2_STREAM_FLAG_PUSH) {
|
|
|
|
if (stream->shut_flags & NGHTTP2_SHUT_RD) {
|
|
|
|
return NGHTTP2_STREAM_STATE_RESERVED_LOCAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->shut_flags & NGHTTP2_SHUT_WR) {
|
|
|
|
return NGHTTP2_STREAM_STATE_RESERVED_REMOTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->shut_flags & NGHTTP2_SHUT_RD) {
|
|
|
|
return NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->shut_flags & NGHTTP2_SHUT_WR) {
|
|
|
|
return NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->state == NGHTTP2_STREAM_IDLE) {
|
|
|
|
return NGHTTP2_STREAM_STATE_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NGHTTP2_STREAM_STATE_OPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_stream *nghttp2_stream_get_parent(nghttp2_stream *stream) {
|
|
|
|
return stream->dep_prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_stream *nghttp2_stream_get_next_sibling(nghttp2_stream *stream) {
|
|
|
|
return stream->sib_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_stream *nghttp2_stream_get_previous_sibling(nghttp2_stream *stream) {
|
|
|
|
return stream->sib_prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_stream *nghttp2_stream_get_first_child(nghttp2_stream *stream) {
|
|
|
|
return stream->dep_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t nghttp2_stream_get_weight(nghttp2_stream *stream) {
|
|
|
|
return stream->weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream) {
|
|
|
|
return stream->sum_dep_weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream) {
|
|
|
|
return stream->stream_id;
|
|
|
|
}
|