mirror of
https://github.com/nghttp2/nghttp2.git
synced 2025-12-07 02:28:53 +08:00
Add stream public API
The intention of this stream API is give server application about stream dependency information, so that it can utilize it for better scheduling of stream processing. We have no plan to add object oriented API based on stream object.
This commit is contained in:
@@ -3907,6 +3907,134 @@ NGHTTP2_EXTERN ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater,
|
||||
NGHTTP2_EXTERN int
|
||||
nghttp2_hd_inflate_end_headers(nghttp2_hd_inflater *inflater);
|
||||
|
||||
struct nghttp2_stream;
|
||||
|
||||
/**
|
||||
* @struct
|
||||
*
|
||||
* The structure to represent HTTP/2 stream. The details of this
|
||||
* structure are intentionally hidden from the public API.
|
||||
*/
|
||||
typedef struct nghttp2_stream nghttp2_stream;
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns pointer to :type:`nghttp2_stream` object denoted by
|
||||
* |stream_id|. If stream was not found, returns NULL.
|
||||
*
|
||||
* Returns imaginary root stream (see
|
||||
* `nghttp2_session_get_root_stream()`) if 0 is given in |stream_id|.
|
||||
*
|
||||
* Unless |stream_id| == 0, the returned pointer is valid until next
|
||||
* call of `nghttp2_session_send()`, `nghttp2_session_mem_send()`,
|
||||
* `nghttp2_session_recv()`, and `nghttp2_session_mem_recv()`.
|
||||
*/
|
||||
nghttp2_stream *nghttp2_session_find_stream(nghttp2_session *session,
|
||||
int32_t stream_id);
|
||||
|
||||
/**
|
||||
* @enum
|
||||
*
|
||||
* State of stream as described in RFC 7540.
|
||||
*/
|
||||
typedef enum {
|
||||
/**
|
||||
* idle state.
|
||||
*/
|
||||
NGHTTP2_STREAM_STATE_IDLE = 1,
|
||||
/**
|
||||
* open state.
|
||||
*/
|
||||
NGHTTP2_STREAM_STATE_OPEN,
|
||||
/**
|
||||
* reserved (local) state.
|
||||
*/
|
||||
NGHTTP2_STREAM_STATE_RESERVED_LOCAL,
|
||||
/**
|
||||
* reserved (remote) state.
|
||||
*/
|
||||
NGHTTP2_STREAM_STATE_RESERVED_REMOTE,
|
||||
/**
|
||||
* half closed (local) state.
|
||||
*/
|
||||
NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL,
|
||||
/**
|
||||
* half closed (remote) state.
|
||||
*/
|
||||
NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE,
|
||||
/**
|
||||
* closed state.
|
||||
*/
|
||||
NGHTTP2_STREAM_STATE_CLOSED
|
||||
} nghttp2_stream_proto_state;
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns state of |stream|. The root stream retrieved by
|
||||
* `nghttp2_session_get_root_stream()` will have stream state
|
||||
* :enum:`NGHTTP2_STREAM_STATE_IDLE`.
|
||||
*/
|
||||
nghttp2_stream_proto_state nghttp2_stream_get_state(nghttp2_stream *stream);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns root of dependency tree, which is imaginary stream with
|
||||
* stream ID 0. The returned pointer is valid until |session| is
|
||||
* freed by `nghttp2_session_del()`.
|
||||
*/
|
||||
nghttp2_stream *nghttp2_session_get_root_stream(nghttp2_session *session);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns the parent stream of |stream| in dependency tree. Returns
|
||||
* NULL if there is no such stream.
|
||||
*/
|
||||
nghttp2_stream *nghttp2_stream_get_parent(nghttp2_stream *stream);
|
||||
|
||||
int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns the next sibling stream of |stream| in dependency tree.
|
||||
* Returns NULL if there is no such stream.
|
||||
*/
|
||||
nghttp2_stream *nghttp2_stream_get_next_sibling(nghttp2_stream *stream);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns the previous sibling stream of |stream| in dependency tree.
|
||||
* Returns NULL if there is no such stream.
|
||||
*/
|
||||
nghttp2_stream *nghttp2_stream_get_previous_sibling(nghttp2_stream *stream);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns the first child stream of |stream| in dependency tree.
|
||||
* Returns NULL if there is no such stream.
|
||||
*/
|
||||
nghttp2_stream *nghttp2_stream_get_first_child(nghttp2_stream *stream);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns dependency weight to the parent stream of |stream|.
|
||||
*/
|
||||
int32_t nghttp2_stream_get_weight(nghttp2_stream *stream);
|
||||
|
||||
/**
|
||||
* @function
|
||||
*
|
||||
* Returns the sum of the weight for |stream|'s children.
|
||||
*/
|
||||
int32_t nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -338,8 +338,8 @@ static int session_new(nghttp2_session **session_ptr,
|
||||
}
|
||||
|
||||
nghttp2_stream_init(&(*session_ptr)->root, 0, NGHTTP2_STREAM_FLAG_NONE,
|
||||
NGHTTP2_STREAM_INITIAL, NGHTTP2_DEFAULT_WEIGHT, 0, 0,
|
||||
NULL, mem);
|
||||
NGHTTP2_STREAM_IDLE, NGHTTP2_DEFAULT_WEIGHT, 0, 0, NULL,
|
||||
mem);
|
||||
|
||||
(*session_ptr)->remote_window_size = NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE;
|
||||
(*session_ptr)->recv_window_size = 0;
|
||||
@@ -6527,3 +6527,12 @@ uint32_t nghttp2_session_get_next_stream_id(nghttp2_session *session) {
|
||||
int32_t nghttp2_session_get_last_proc_stream_id(nghttp2_session *session) {
|
||||
return session->last_proc_stream_id;
|
||||
}
|
||||
|
||||
nghttp2_stream *nghttp2_session_find_stream(nghttp2_session *session,
|
||||
int32_t stream_id) {
|
||||
return nghttp2_session_get_stream_raw(session, stream_id);
|
||||
}
|
||||
|
||||
nghttp2_stream *nghttp2_session_get_root_stream(nghttp2_session *session) {
|
||||
return &session->root;
|
||||
}
|
||||
|
||||
@@ -856,3 +856,61 @@ nghttp2_stream_next_outbound_item(nghttp2_stream *stream) {
|
||||
stream = nghttp2_struct_of(ent, nghttp2_stream, pq_entry);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -131,10 +131,6 @@ typedef enum {
|
||||
NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE = 1 << 13
|
||||
} nghttp2_http_flag;
|
||||
|
||||
struct nghttp2_stream;
|
||||
|
||||
typedef struct nghttp2_stream nghttp2_stream;
|
||||
|
||||
struct nghttp2_stream {
|
||||
/* Intrusive Map */
|
||||
nghttp2_map_entry map_entry;
|
||||
|
||||
Reference in New Issue
Block a user