Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
2d4b92fc
Commit
2d4b92fc
authored
Apr 24, 2014
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'priority'
parents
85190f36
ee26469c
Changes
17
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
1204 additions
and
1264 deletions
+1204
-1264
lib/includes/nghttp2/nghttp2.h
lib/includes/nghttp2/nghttp2.h
+55
-117
lib/nghttp2_frame.c
lib/nghttp2_frame.c
+31
-60
lib/nghttp2_frame.h
lib/nghttp2_frame.h
+2
-1
lib/nghttp2_priority_spec.c
lib/nghttp2_priority_spec.c
+17
-10
lib/nghttp2_session.c
lib/nghttp2_session.c
+107
-251
lib/nghttp2_session.h
lib/nghttp2_session.h
+1
-24
lib/nghttp2_stream.c
lib/nghttp2_stream.c
+319
-192
lib/nghttp2_stream.h
lib/nghttp2_stream.h
+72
-53
lib/nghttp2_submit.c
lib/nghttp2_submit.c
+24
-64
src/app_helper.cc
src/app_helper.cc
+11
-35
src/nghttp.cc
src/nghttp.cc
+17
-14
tests/main.c
tests/main.c
+2
-0
tests/nghttp2_frame_test.c
tests/nghttp2_frame_test.c
+16
-78
tests/nghttp2_session_test.c
tests/nghttp2_session_test.c
+481
-347
tests/nghttp2_session_test.h
tests/nghttp2_session_test.h
+1
-0
tests/nghttp2_test_helper.c
tests/nghttp2_test_helper.c
+41
-18
tests/nghttp2_test_helper.h
tests/nghttp2_test_helper.h
+7
-0
No files found.
lib/includes/nghttp2/nghttp2.h
View file @
2d4b92fc
...
...
@@ -114,21 +114,21 @@ typedef struct {
/**
* @macro
*
* The default weight of
priority group
.
* The default weight of
stream dependency
.
*/
#define NGHTTP2_DEFAULT_WEIGHT 16
/**
* @macro
*
* The maximum weight of
priority group
.
* The maximum weight of
stream dependency
.
*/
#define NGHTTP2_MAX_WEIGHT 256
/**
* @macro
*
* The minimum weight of
priority group
.
* The minimum weight of
stream dependency
.
*/
#define NGHTTP2_MIN_WEIGHT 1
...
...
@@ -482,13 +482,9 @@ typedef enum {
*/
NGHTTP2_FLAG_PAD_HIGH
=
0x10
,
/**
* The PRIORITY
_GROUP
flag.
* The PRIORITY flag.
*/
NGHTTP2_FLAG_PRIORITY_GROUP
=
0x20
,
/**
* The PRIORITY_DEPENDENCY flag.
*/
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
=
0x40
NGHTTP2_FLAG_PRIORITY
=
0x20
}
nghttp2_flag
;
/**
...
...
@@ -731,93 +727,25 @@ typedef enum {
NGHTTP2_HCAT_HEADERS
=
3
}
nghttp2_headers_category
;
/**
* @enum
*
* The type of priority specified in :type:`nghttp2_priority_spec`.
*/
typedef
enum
{
/**
* No priority is given. The default priority will be used.
*/
NGHTTP2_PRIORITY_TYPE_NONE
=
0
,
/**
* Priority group ID and its weight are specified.
*/
NGHTTP2_PRIORITY_TYPE_GROUP
=
1
,
/**
* The stream ID of a stream to depend on and its exclusive flag is
* specified.
*/
NGHTTP2_PRIORITY_TYPE_DEP
=
2
}
nghttp2_priority_type
;
/**
* @struct
*
* Th
is structure stores priority group ID and its weight
.
* Th
e structure to specify stream dependency
.
*/
typedef
struct
{
/**
* The priority group ID
* The stream ID of the stream to depend on. Specifying 0 makes
* stream not depend any other stream.
*/
int32_t
pri_group
_id
;
int32_t
stream
_id
;
/**
* The weight of th
e priority group
* The weight of th
is dependency.
*/
int32_t
weight
;
}
nghttp2_priority_group
;
/**
* @struct
*
* This structure stores stream ID of the stream to depend on and its
* dependency is exclusive or not.
*/
typedef
struct
{
/**
* The stream ID of the stream to depend on.
*/
int32_t
stream_id
;
/**
* nonzero means exclusive dependency
*/
uint8_t
exclusive
;
}
nghttp2_priority_dep
;
/**
* @struct
*
* The structure to specify stream dependency. To specify stream
* dependency, specify |pri_type| and fill the |group| or |dep| member
* according to |pri_type|.
*/
typedef
struct
{
/**
* Type of priority specification. If |pri_type| is
* :enum:`NGHTTP2_PRIORITY_TYPE_GROUP`, fill |group|. If |pri_type|
* is :enum:`NGHTTP2_PRIORITY_TYPE_DEP`, fill |dep|. If |pri_type|
* is :enum:`NGHTTP2_PRIORITY_TYPE_NONE`, the other data members are
* ignored and it means that default priority group ID (which is
* same as the stream ID) and default weight
* :macro:`NGHTTP2_DEFAULT_WEIGHT` are specified.
*/
nghttp2_priority_type
pri_type
;
union
{
/**
* Specify priority group ID and its weight. This field is
* interpreted only when |pri_type| member is
* :enum:`NGHTTP2_PRIORITY_TYPE_GROUP`.
*/
nghttp2_priority_group
group
;
/**
* Specify stream ID of a stream to depend on and exclusive flag.
* This field is interpreted only when |pri_type| member is
* :enum:`NGHTTP2_PRIORITY_TYPE_DEP`.
*/
nghttp2_priority_dep
dep
;
}
spec
;
}
nghttp2_priority_spec
;
/**
...
...
@@ -2153,32 +2081,32 @@ const char* nghttp2_strerror(int lib_error_code);
/**
* @function
*
* Initializes |pri_spec| with priority group ID |pri_group_id| and
* its weight |weight|.
* Initializes |pri_spec| with the |stream_id| of the stream to depend
* on with |weight| and its exclusive flag. If |exclusive| is
* nonzero, exclusive flag is set.
*
* The |weight| must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
* :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If |weight| is strictly
* less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
* :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
* :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
* :enum:`NGHTTP2_MAX_WEIGHT`], inclusive.
*/
void
nghttp2_priority_spec_init
(
nghttp2_priority_spec
*
pri_spec
,
int32_t
stream_id
,
int32_t
weight
,
int
exclusive
);
/**
* @function
*
* To specify weight for the default priority group (which is the same
* as the stream ID of the stream) in `nghttp2_submit_request()` and
* `nghttp2_submit_headers()` and its stream ID is not known in
* advance, specify -1 to |pri_group_id|.
* Initializes |pri_spec| with the default values. The default values
* are: stream_id = 0, weight = :macro:`NGHTTP2_DEFAULT_WEIGHT` and
* exclusive = 0.
*/
void
nghttp2_priority_spec_group_init
(
nghttp2_priority_spec
*
pri_spec
,
int32_t
pri_group_id
,
int32_t
weight
);
void
nghttp2_priority_spec_default_init
(
nghttp2_priority_spec
*
pri_spec
);
/**
* @function
*
* Initializes |pri_spec| with the |stream_id| of the stream to depend
* on and its exclusive flag. If |exclusive| is nonzero, exclusive
* flag is set.
* Returns nonzero if the |pri_spec| is filled with default values.
*/
void
nghttp2_priority_spec_dep_init
(
nghttp2_priority_spec
*
pri_spec
,
int32_t
stream_id
,
int
exclusive
);
int
nghttp2_priority_spec_check_default
(
const
nghttp2_priority_spec
*
pri_spec
);
/**
* @function
...
...
@@ -2186,12 +2114,17 @@ void nghttp2_priority_spec_dep_init(nghttp2_priority_spec *pri_spec,
* Submits HEADERS frame and optionally one or more DATA frames.
*
* The |pri_spec| is priority specification of this request. ``NULL``
* means the default priority (priority group ID becomes its stream ID
* and weight is :macro:`NGHTTP2_DEFAULT_WEIGHT`). To specify the
* priority, use either `nghttp2_priority_spec_group_init()` or
* `nghttp2_priority_spec_dep_init()`. If |pri_spec| is not ``NULL``,
* means the default priority (see
* `nghttp2_priority_spec_default_init()`). To specify the priority,
* use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,
* this function will copy its data members.
*
* The `pri_spec->weight` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
* :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If `pri_spec->weight` is
* strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
* :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
* :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
*
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
* |nvlen| elements. The value is opaque sequence of bytes and
* therefore can contain NULL byte (0x0). If the application requires
...
...
@@ -2234,8 +2167,6 @@ void nghttp2_priority_spec_dep_init(nghttp2_priority_spec *pri_spec,
*
* :enum:`NGHTTP2_ERR_NOMEM`
* Out of memory.
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
* The |pri_spec->pri_type| is invalid.
*/
int
nghttp2_submit_request
(
nghttp2_session
*
session
,
const
nghttp2_priority_spec
*
pri_spec
,
...
...
@@ -2306,12 +2237,17 @@ int nghttp2_submit_response(nghttp2_session *session,
* response, specify stream ID in |stream_id|.
*
* The |pri_spec| is priority specification of this request. ``NULL``
* means the default priority (priority group ID becomes its stream ID
* and weight is :macro:`NGHTTP2_DEFAULT_WEIGHT`). To specify the
* priority, use either `nghttp2_priority_spec_group_init()` or
* `nghttp2_priority_spec_dep_init()`. If |pri_spec| is not ``NULL``,
* means the default priority (see
* `nghttp2_priority_spec_default_init()`). To specify the priority,
* use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``,
* this function will copy its data members.
*
* The `pri_spec->weight` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
* :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If `pri_spec->weight` is
* strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
* :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
* :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
*
* The |nva| is an array of name/value pair :type:`nghttp2_nv` with
* |nvlen| elements. The value is opaque sequence of bytes and
* therefore can contain NULL byte (0x0). If the application requires
...
...
@@ -2336,8 +2272,6 @@ int nghttp2_submit_response(nghttp2_session *session,
*
* :enum:`NGHTTP2_ERR_NOMEM`
* Out of memory.
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
* The |pri_spec->pri_type| is invalid.
*/
int
nghttp2_submit_headers
(
nghttp2_session
*
session
,
uint8_t
flags
,
int32_t
stream_id
,
...
...
@@ -2379,10 +2313,15 @@ int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
* :enum:`NGHTTP2_FLAG_NONE`.
*
* The |pri_spec| is priority specification of this request. ``NULL``
* is not allowed for this function. To specify the priority, use
* either `nghttp2_priority_spec_group_init()` or
* `nghttp2_priority_spec_dep_init()`. This function will copy its
* data members.
* is not allowed for this function. To specify the priority, use
* `nghttp2_priority_spec_init()`. This function will copy its data
* members.
*
* The `pri_spec->weight` must be in [:enum:`NGHTTP2_MIN_WEIGHT`,
* :enum:`NGHTTP2_MAX_WEIGHT`], inclusive. If `pri_spec->weight` is
* strictly less than :enum:`NGHTTP2_MIN_WEIGHT`, it becomes
* :enum:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than
* :enum:`NGHTTP2_MAX_WEIGHT`, it becomes :enum:`NGHTTP2_MAX_WEIGHT`.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
...
...
@@ -2390,8 +2329,7 @@ int nghttp2_submit_data(nghttp2_session *session, uint8_t flags,
* :enum:`NGHTTP2_ERR_NOMEM`
* Out of memory.
* :enum:`NGHTTP2_ERR_INVALID_ARGUMENT`
* The |pri_spec| is NULL; or the |pri_spec->pri_type| is invalid;
* or trying to depend on itself.
* The |pri_spec| is NULL; or trying to depend on itself.
*/
int
nghttp2_submit_priority
(
nghttp2_session
*
session
,
uint8_t
flags
,
int32_t
stream_id
,
...
...
lib/nghttp2_frame.c
View file @
2d4b92fc
...
...
@@ -74,7 +74,12 @@ void nghttp2_frame_headers_init(nghttp2_headers *frame,
frame
->
nva
=
nva
;
frame
->
nvlen
=
nvlen
;
frame
->
cat
=
NGHTTP2_HCAT_REQUEST
;
frame
->
pri_spec
=
*
pri_spec
;
if
(
pri_spec
)
{
frame
->
pri_spec
=
*
pri_spec
;
}
else
{
nghttp2_priority_spec_default_init
(
&
frame
->
pri_spec
);
}
}
void
nghttp2_frame_headers_free
(
nghttp2_headers
*
frame
)
...
...
@@ -85,22 +90,8 @@ void nghttp2_frame_headers_free(nghttp2_headers *frame)
void
nghttp2_frame_priority_init
(
nghttp2_priority
*
frame
,
int32_t
stream_id
,
const
nghttp2_priority_spec
*
pri_spec
)
{
uint8_t
flags
;
switch
(
pri_spec
->
pri_type
)
{
case
NGHTTP2_PRIORITY_TYPE_GROUP
:
flags
=
NGHTTP2_FLAG_PRIORITY_GROUP
;
break
;
case
NGHTTP2_PRIORITY_TYPE_DEP
:
flags
=
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
;
break
;
default:
assert
(
0
);
}
nghttp2_frame_set_hd
(
&
frame
->
hd
,
4
,
NGHTTP2_PRIORITY
,
flags
,
stream_id
);
nghttp2_frame_set_hd
(
&
frame
->
hd
,
5
,
NGHTTP2_PRIORITY
,
NGHTTP2_FLAG_NONE
,
stream_id
);
frame
->
pri_spec
=
*
pri_spec
;
}
...
...
@@ -261,14 +252,10 @@ void nghttp2_frame_private_data_free(nghttp2_private_data *frame)
size_t
nghttp2_frame_priority_len
(
uint8_t
flags
)
{
if
(
flags
&
NGHTTP2_FLAG_PRIORITY
_GROUP
)
{
if
(
flags
&
NGHTTP2_FLAG_PRIORITY
)
{
return
5
;
}
if
(
flags
&
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
)
{
return
4
;
}
return
0
;
}
...
...
@@ -375,7 +362,9 @@ int nghttp2_frame_pack_headers(nghttp2_bufs *bufs,
return
rv
;
}
nghttp2_frame_pack_priority_spec
(
buf
->
pos
,
&
frame
->
pri_spec
);
if
(
frame
->
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY
)
{
nghttp2_frame_pack_priority_spec
(
buf
->
pos
,
&
frame
->
pri_spec
);
}
frame
->
padlen
=
0
;
frame
->
hd
.
length
=
nghttp2_bufs_len
(
bufs
);
...
...
@@ -386,24 +375,11 @@ int nghttp2_frame_pack_headers(nghttp2_bufs *bufs,
void
nghttp2_frame_pack_priority_spec
(
uint8_t
*
buf
,
const
nghttp2_priority_spec
*
pri_spec
)
{
switch
(
pri_spec
->
pri_type
)
{
case
NGHTTP2_PRIORITY_TYPE_GROUP
:
nghttp2_put_uint32be
(
buf
,
pri_spec
->
spec
.
group
.
pri_group_id
);
buf
[
4
]
=
pri_spec
->
spec
.
group
.
weight
-
1
;
return
;
case
NGHTTP2_PRIORITY_TYPE_DEP
:
nghttp2_put_uint32be
(
buf
,
pri_spec
->
spec
.
dep
.
stream_id
);
if
(
pri_spec
->
spec
.
dep
.
exclusive
)
{
buf
[
0
]
|=
0x80
;
}
return
;
default:
return
;
nghttp2_put_uint32be
(
buf
,
pri_spec
->
stream_id
);
if
(
pri_spec
->
exclusive
)
{
buf
[
0
]
|=
0x80
;
}
buf
[
4
]
=
pri_spec
->
weight
-
1
;
}
void
nghttp2_frame_unpack_priority_spec
(
nghttp2_priority_spec
*
pri_spec
,
...
...
@@ -411,33 +387,28 @@ void nghttp2_frame_unpack_priority_spec(nghttp2_priority_spec *pri_spec,
const
uint8_t
*
payload
,
size_t
payloadlen
)
{
if
(
flags
&
NGHTTP2_FLAG_PRIORITY_GROUP
)
{
int32_t
pri_group_id
;
int32_t
weight
;
pri_group_id
=
nghttp2_get_uint32
(
payload
)
&
NGHTTP2_PRI_GROUP_ID_MASK
;
weight
=
payload
[
4
]
+
1
;
nghttp2_priority_spec_group_init
(
pri_spec
,
pri_group_id
,
weight
);
}
else
if
(
flags
&
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
)
{
int32_t
dep_stream_id
;
uint8_t
exclusive
;
int32_t
dep_stream_id
;
uint8_t
exclusive
;
int32_t
weight
;
dep_stream_id
=
nghttp2_get_uint32
(
payload
)
&
NGHTTP2_STREAM_ID_MASK
;
exclusive
=
(
payload
[
0
]
&
0x80
)
>
0
;
dep_stream_id
=
nghttp2_get_uint32
(
payload
)
&
NGHTTP2_STREAM_ID_MASK
;
exclusive
=
(
payload
[
0
]
&
0x80
)
>
0
;
weight
=
payload
[
4
]
+
1
;
nghttp2_priority_spec_dep_init
(
pri_spec
,
dep_stream_id
,
exclusive
);
}
else
{
pri_spec
->
pri_type
=
NGHTTP2_PRIORITY_TYPE_NONE
;
}
nghttp2_priority_spec_init
(
pri_spec
,
dep_stream_id
,
weight
,
exclusive
);
}
int
nghttp2_frame_unpack_headers_payload
(
nghttp2_headers
*
frame
,
const
uint8_t
*
payload
,
size_t
payloadlen
)
{
nghttp2_frame_unpack_priority_spec
(
&
frame
->
pri_spec
,
frame
->
hd
.
flags
,
payload
,
payloadlen
);
if
(
frame
->
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY
)
{
nghttp2_frame_unpack_priority_spec
(
&
frame
->
pri_spec
,
frame
->
hd
.
flags
,
payload
,
payloadlen
);
}
else
{
nghttp2_priority_spec_default_init
(
&
frame
->
pri_spec
);
}
frame
->
nva
=
NULL
;
frame
->
nvlen
=
0
;
...
...
@@ -457,7 +428,7 @@ int nghttp2_frame_pack_priority(nghttp2_bufs *bufs, nghttp2_priority *frame)
nghttp2_frame_pack_priority_spec
(
buf
->
last
,
&
frame
->
pri_spec
);
buf
->
last
+=
nghttp2_frame_priority_len
(
frame
->
hd
.
flags
)
;
buf
->
last
+=
5
;
return
0
;
}
...
...
lib/nghttp2_frame.h
View file @
2d4b92fc
...
...
@@ -155,7 +155,8 @@ int nghttp2_frame_pack_headers(nghttp2_bufs *bufs,
/*
* Unpacks HEADERS frame byte sequence into |frame|. This function
* only unapcks bytes that come before name/value header block.
* only unapcks bytes that come before name/value header block and
* after PAD_HIGH and PAD_LOW.
*
* This function returns 0 if it succeeds or one of the following
* negative error codes:
...
...
lib/nghttp2_priority_spec.c
View file @
2d4b92fc
...
...
@@ -24,18 +24,25 @@
*/
#include "nghttp2_priority_spec.h"
void
nghttp2_priority_spec_group_init
(
nghttp2_priority_spec
*
pri_spec
,
int32_t
pri_group_id
,
int32_t
weight
)
void
nghttp2_priority_spec_init
(
nghttp2_priority_spec
*
pri_spec
,
int32_t
stream_id
,
int32_t
weight
,
int
exclusive
)
{
pri_spec
->
pri_type
=
NGHTTP2_PRIORITY_TYPE_GROUP
;
pri_spec
->
spec
.
group
.
pri_group_id
=
pri_group_id
;
pri_spec
->
spec
.
group
.
weight
=
weight
;
pri_spec
->
stream_id
=
stream_id
;
pri_spec
->
weight
=
weight
;
pri_spec
->
exclusive
=
exclusive
!=
0
;
}
void
nghttp2_priority_spec_dep_init
(
nghttp2_priority_spec
*
pri_spec
,
int32_t
stream_id
,
int
exclusive
)
void
nghttp2_priority_spec_default_init
(
nghttp2_priority_spec
*
pri_spec
)
{
pri_spec
->
pri_type
=
NGHTTP2_PRIORITY_TYPE_DEP
;
pri_spec
->
spec
.
dep
.
stream_id
=
stream_id
;
pri_spec
->
spec
.
dep
.
exclusive
=
exclusive
!=
0
;
pri_spec
->
stream_id
=
0
;
pri_spec
->
weight
=
NGHTTP2_DEFAULT_WEIGHT
;
pri_spec
->
exclusive
=
0
;
}
int
nghttp2_priority_spec_check_default
(
const
nghttp2_priority_spec
*
pri_spec
)
{
return
pri_spec
->
stream_id
==
0
&&
pri_spec
->
weight
==
NGHTTP2_DEFAULT_WEIGHT
&&
pri_spec
->
exclusive
==
0
;
}
lib/nghttp2_session.c
View file @
2d4b92fc
This diff is collapsed.
Click to expand it.
lib/nghttp2_session.h
View file @
2d4b92fc
...
...
@@ -117,7 +117,7 @@ typedef enum {
struct
nghttp2_session
{
nghttp2_map
/* <nghttp2_stream*> */
streams
;
nghttp2_
map
/* <nghttp2_stream_group*> */
stream_group
s
;
nghttp2_
stream_roots
root
s
;
/* Queue for outbound frames other than stream-creating HEADERS */
nghttp2_pq
/* <nghttp2_outbound_item*> */
ob_pq
;
/* Queue for outbound stream-creating HEADERS frame */
...
...
@@ -603,14 +603,6 @@ nghttp2_stream* nghttp2_session_get_stream(nghttp2_session *session,
nghttp2_stream
*
nghttp2_session_get_stream_raw
(
nghttp2_session
*
session
,
int32_t
stream_id
);
/*
* Returns nghttp2_stream_group* object whose priority group ID is
* |pri_group_id|. It could be NULL if such priority group does not
* exist.
*/
nghttp2_stream_group
*
nghttp2_session_get_stream_group
(
nghttp2_session
*
session
,
int32_t
pri_group_id
);
/*
* Packs DATA frame |frame| in wire frame format and stores it in
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
...
...
@@ -698,19 +690,4 @@ int nghttp2_session_reprioritize_stream
(
nghttp2_session
*
session
,
nghttp2_stream
*
stream
,
const
nghttp2_priority_spec
*
pri_spec
);
/*
* Creates new priority group using given values.
*
* This function returns created priority group if it succeeds, or
* NULL.
*/
nghttp2_stream_group
*
nghttp2_session_open_stream_group
(
nghttp2_session
*
session
,
int32_t
pri_group_id
,
int32_t
weight
);
/*
* Closes priority group if it does not include any streams.
*/
void
nghttp2_session_close_stream_group_if_empty
(
nghttp2_session
*
session
,
nghttp2_stream_group
*
stream_group
);
#endif
/* NGHTTP2_SESSION_H */
lib/nghttp2_stream.c
View file @
2d4b92fc
This diff is collapsed.
Click to expand it.
lib/nghttp2_stream.h
View file @
2d4b92fc
...
...
@@ -102,9 +102,9 @@ typedef enum {
NGHTTP2_STREAM_DPRI_REST
=
0x04
}
nghttp2_stream_dpri
;
struct
nghttp2_stream_
group
;
struct
nghttp2_stream_
roots
;
typedef
struct
nghttp2_stream_
group
nghttp2_stream_group
;
typedef
struct
nghttp2_stream_
roots
nghttp2_stream_roots
;
struct
nghttp2_stream
;
...
...
@@ -122,27 +122,28 @@ struct nghttp2_stream {
dep_prev and sib_prev are NULL. */
nghttp2_stream
*
dep_prev
,
*
dep_next
;
nghttp2_stream
*
sib_prev
,
*
sib_next
;
/* pointers to track dependency tree root streams. This is
doubly-linked list and first element is pointed by
roots->head. */
nghttp2_stream
*
root_prev
,
*
root_next
;
/* When stream is kept after closure, it may be kept in single
linked list pointed by nghttp2_session closed_stream_head.
closed_next points to the next stream object if it is the element
of the list. */
nghttp2_stream
*
closed_next
;
/* pointer to roots, which tracks dependency tree roots */
nghttp2_stream_roots
*
roots
;
/* The arbitrary data provided by user for this stream. */
void
*
stream_user_data
;
/* DATA frame item */
nghttp2_outbound_item
*
data_item
;
/* stream ID */
int32_t
stream_id
;
/* priority group this stream belongs to */
nghttp2_stream_group
*
stream_group
;
/* categorized priority of this stream. Only stream bearing
NGHTTP2_STREAM_DPRI_TOP can send DATA frame. */
nghttp2_stream_dpri
dpri
;
/* the number of streams in subtree */
size_t
num_substreams
;
/* the number of streams marked as NGHTTP2_STREAM_DPRI_TOP in
subtree */
ssize_t
num_subtop
;
/* Current remote window size. This value is computed against the
current initial window size of remote endpoint. */
int32_t
remote_window_size
;
...
...
@@ -157,6 +158,16 @@ struct nghttp2_stream {
NGHTTP2_INITIAL_WINDOW_SIZE and could be increased/decreased by
submitting WINDOW_UPDATE. See nghttp2_submit_window_update(). */
int32_t
local_window_size
;
/* weight of this stream */
int32_t
weight
;
/* effective weight of this stream in belonging dependency tree */
int32_t
effective_weight
;
/* sum of weight (not effective_weight) of direct descendants */
int32_t
sum_dep_weight
;
/* sum of weight of direct descendants which have at least one
descendant with dpri == NGHTTP2_STREAM_DPRI_TOP. We use this
value to calculate effective weight. */
int32_t
sum_norest_weight
;
nghttp2_stream_state
state
;
/* This is bitwise-OR of 0 or more of nghttp2_stream_flag. */
uint8_t
flags
;
...
...
@@ -167,6 +178,8 @@ struct nghttp2_stream {
void
nghttp2_stream_init
(
nghttp2_stream
*
stream
,
int32_t
stream_id
,
uint8_t
flags
,
nghttp2_stream_state
initial_state
,
int32_t
weight
,
nghttp2_stream_roots
*
roots
,
int32_t
remote_initial_window_size
,
int32_t
local_initial_window_size
,
void
*
stream_user_data
);
...
...
@@ -259,12 +272,30 @@ nghttp2_stream* nghttp2_stream_get_dep_root(nghttp2_stream *stream);
int
nghttp2_stream_dep_subtree_find
(
nghttp2_stream
*
stream
,
nghttp2_stream
*
target
);
/*
* Computes distributed weight of a stream of the |weight| under the
* |stream| if |stream| is removed from a dependency tree. The result
* is computed using stream->weight rather than
* stream->effective_weight.
*/
int32_t
nghttp2_stream_dep_distributed_weight
(
nghttp2_stream
*
stream
,
int32_t
weight
);
/*
* Computes effective weight of a stream of the |weight| under the
* |stream|. The result is computed using stream->effective_weight
* rather than stream->weight. This function is used to determine
* weight in dependency tree.
*/
int32_t
nghttp2_stream_dep_distributed_effective_weight
(
nghttp2_stream
*
stream
,
int32_t
weight
);
/*
* Makes the |stream| depend on the |dep_stream|. This dependency is
* exclusive. All existing direct descendants of |dep_stream| become
* the descendants of the |stream|. This function assumes
* |stream->data| is NULL and no dpri members are changed in this
* dependency tree.
It also does not change stream->stream_group.
* dependency tree.
*/
void
nghttp2_stream_dep_insert
(
nghttp2_stream
*
dep_stream
,
nghttp2_stream
*
stream
);
...
...
@@ -272,8 +303,7 @@ void nghttp2_stream_dep_insert(nghttp2_stream *dep_stream,
/*
* Makes the |stream| depend on the |dep_stream|. This dependency is
* not exclusive. This function assumes |stream->data| is NULL and no
* dpri members are changed in this dependency tree. It also does not
* change stream->stream_group.
* dpri members are changed in this dependency tree.
*/
void
nghttp2_stream_dep_add
(
nghttp2_stream
*
dep_stream
,
nghttp2_stream
*
stream
);
...
...
@@ -342,8 +372,8 @@ int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream,
/*
* Removes subtree whose root stream is |stream|. Removing subtree
* does not change dpri values
and removed subtree is still in the
*
same stream_group
.
* does not change dpri values
. The effective_weight of streams in
*
removed subtree is not updated
.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
...
...
@@ -354,8 +384,8 @@ int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream,
void
nghttp2_stream_dep_remove_subtree
(
nghttp2_stream
*
stream
);
/*
* Makes the |stream| as root
for |stream_group|. Updates dpri
*
members in this
dependency tree.
* Makes the |stream| as root
. Updates dpri members in this
* dependency tree.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
...
...
@@ -363,53 +393,42 @@ void nghttp2_stream_dep_remove_subtree(nghttp2_stream *stream);
* NGHTTP2_ERR_NOMEM
* Out of memory
*/
int
nghttp2_stream_dep_make_root
(
nghttp2_stream_group
*
stream_group
,
nghttp2_stream
*
stream
,
nghttp2_pq
*
pq
);
int
nghttp2_stream_dep_make_root
(
nghttp2_stream
*
stream
,
nghttp2_pq
*
pq
);
/*
* Priority group of streams.
* Makes the |stream| as root and all existing root streams become
* direct children of |stream|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP2_ERR_NOMEM
* Out of memory
*/
struct
nghttp2_stream_group
{
/* Intrusive Map */
nghttp2_map_entry
map_entry
;
/* The number of streams this priority group contains */
size_t
num_streams
;
/* The number of streams marked as NGHTTP2_STREAM_DPRI_TOP */
ssize_t
num_top
;
/* The priority group ID */
int32_t
pri_group_id
;
/* The weight of this group */
int32_t
weight
;
};
void
nghttp2_stream_group_init
(
nghttp2_stream_group
*
stream_group
,
int32_t
pri_group_id
,
int32_t
weight
);
void
nghttp2_stream_group_free
(
nghttp2_stream_group
*
stream_group
);
int
nghttp2_stream_dep_all_your_stream_are_belong_to_us
(
nghttp2_stream
*
stream
,
nghttp2_pq
*
pq
);
/*
*
Adds |stream| to |stream_group|
.
*
Returns nonzero if |stream| is in any dependency tree
.
*/
void
nghttp2_stream_group_add_stream
(
nghttp2_stream_group
*
stream_group
,
nghttp2_stream
*
stream
);
int
nghttp2_stream_in_dep_tree
(
nghttp2_stream
*
stream
);
/*
* Removes |stream| from |stream_group|.
*/
void
nghttp2_stream_group_remove_stream
(
nghttp2_stream_group
*
stream_group
,
nghttp2_stream
*
stream
);
struct
nghttp2_stream_roots
{
nghttp2_stream
*
head
;
/*
* Updates |stream_group->num_top| += |delta|
*/
void
nghttp2_stream_group_update_num_top
(
nghttp2_stream_group
*
stream_group
,
ssize_t
delta
);
int32_t
num_streams
;
};
/*
* Returns shared weight among the streams belongs to |stream_group|.
*/
size_t
nghttp2_stream_group_shared_wait
(
nghttp2_stream_group
*
stream_group
);
void
nghttp2_stream_roots_init
(
nghttp2_stream_roots
*
roots
);
void
nghttp2_stream_roots_free
(
nghttp2_stream_roots
*
roots
);
void
nghttp2_stream_roots_add
(
nghttp2_stream_roots
*
roots
,
nghttp2_stream
*
stream
);
void
nghttp2_stream_roots_remove
(
nghttp2_stream_roots
*
roots
,
nghttp2_stream
*
stream
);
void
nghttp2_stream_roots_remove_all
(
nghttp2_stream_roots
*
roots
);
#endif
/* NGHTTP2_STREAM */
lib/nghttp2_submit.c
View file @
2d4b92fc
...
...
@@ -77,8 +77,7 @@ static int nghttp2_submit_headers_shared
flags_copy
=
(
flags
&
(
NGHTTP2_FLAG_END_STREAM
|
NGHTTP2_FLAG_END_SEGMENT
|
NGHTTP2_FLAG_PRIORITY_GROUP
|
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
))
|
NGHTTP2_FLAG_PRIORITY
))
|
NGHTTP2_FLAG_END_HEADERS
;
nghttp2_frame_headers_init
(
&
frame
->
headers
,
flags_copy
,
stream_id
,
pri_spec
,
...
...
@@ -102,14 +101,12 @@ static int nghttp2_submit_headers_shared
return
rv
;
}
static
void
adjust_priority_spec_
group_
weight
(
nghttp2_priority_spec
*
pri_spec
)
static
void
adjust_priority_spec_weight
(
nghttp2_priority_spec
*
pri_spec
)
{
assert
(
pri_spec
->
pri_type
==
NGHTTP2_PRIORITY_TYPE_GROUP
);
if
(
pri_spec
->
spec
.
group
.
weight
<
NGHTTP2_MIN_WEIGHT
)
{
pri_spec
->
spec
.
group
.
weight
=
NGHTTP2_MIN_WEIGHT
;
}
else
if
(
pri_spec
->
spec
.
group
.
weight
>
NGHTTP2_MAX_WEIGHT
)
{
pri_spec
->
spec
.
group
.
weight
=
NGHTTP2_MAX_WEIGHT
;
if
(
pri_spec
->
weight
<
NGHTTP2_MIN_WEIGHT
)
{
pri_spec
->
weight
=
NGHTTP2_MIN_WEIGHT
;
}
else
if
(
pri_spec
->
weight
>
NGHTTP2_MAX_WEIGHT
)
{
pri_spec
->
weight
=
NGHTTP2_MAX_WEIGHT
;
}
}
...
...
@@ -125,25 +122,13 @@ static int nghttp2_submit_headers_shared_nva
{
ssize_t
rv
;
nghttp2_nv
*
nva_copy
;
nghttp2_priority_spec
copy_pri_spec
=
{
NGHTTP2_PRIORITY_TYPE_NONE
};
nghttp2_priority_spec
copy_pri_spec
;
if
(
pri_spec
)
{
switch
(
pri_spec
->
pri_type
)
{
case
NGHTTP2_PRIORITY_TYPE_NONE
:
case
NGHTTP2_PRIORITY_TYPE_GROUP
:
case
NGHTTP2_PRIORITY_TYPE_DEP
:
break
;
default:
return
NGHTTP2_ERR_INVALID_ARGUMENT
;
}
copy_pri_spec
=
*
pri_spec
;
if
(
copy_pri_spec
.
pri_type
==
NGHTTP2_PRIORITY_TYPE_GROUP
)
{
adjust_priority_spec_group_weight
(
&
copy_pri_spec
);
}
adjust_priority_spec_weight
(
&
copy_pri_spec
);
}
else
{
nghttp2_priority_spec_default_init
(
&
copy_pri_spec
);
}
rv
=
nghttp2_nv_array_copy
(
&
nva_copy
,
nva
,
nvlen
);
...
...
@@ -164,20 +149,10 @@ int nghttp2_submit_headers(nghttp2_session *session, uint8_t flags,
{
flags
&=
NGHTTP2_FLAG_END_STREAM
;
if
(
pri_spec
)
{
switch
(
pri_spec
->
pri_type
)
{
case
NGHTTP2_PRIORITY_TYPE_GROUP
:
flags
|=
NGHTTP2_FLAG_PRIORITY_GROUP
;
break
;
case
NGHTTP2_PRIORITY_TYPE_DEP
:
flags
|=
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
;
break
;
default:
/* Default weight */
pri_spec
=
NULL
;
break
;
}
if
(
pri_spec
&&
!
nghttp2_priority_spec_check_default
(
pri_spec
))
{
flags
|=
NGHTTP2_FLAG_PRIORITY
;
}
else
{
pri_spec
=
NULL
;
}
return
nghttp2_submit_headers_shared_nva
(
session
,
flags
,
stream_id
,
pri_spec
,
...
...
@@ -203,23 +178,14 @@ int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
return
NGHTTP2_ERR_INVALID_ARGUMENT
;
}
copy_pri_spec
=
*
pri_spec
;
switch
(
copy_pri_spec
.
pri_type
)
{
case
NGHTTP2_PRIORITY_TYPE_GROUP
:
adjust_priority_spec_group_weight
(
&
copy_pri_spec
);
break
;
case
NGHTTP2_PRIORITY_TYPE_DEP
:
if
(
stream_id
==
copy_pri_spec
.
spec
.
dep
.
stream_id
)
{
return
NGHTTP2_ERR_INVALID_ARGUMENT
;
}
break
;
default:
if
(
stream_id
==
pri_spec
->
stream_id
)
{
return
NGHTTP2_ERR_INVALID_ARGUMENT
;
}
copy_pri_spec
=
*
pri_spec
;
adjust_priority_spec_weight
(
&
copy_pri_spec
);
frame
=
malloc
(
sizeof
(
nghttp2_frame
));
if
(
frame
==
NULL
)
{
...
...
@@ -433,17 +399,7 @@ static uint8_t set_request_flags(const nghttp2_priority_spec *pri_spec,
}
if
(
pri_spec
)
{
switch
(
pri_spec
->
pri_type
)
{
case
NGHTTP2_PRIORITY_TYPE_GROUP
:
flags
|=
NGHTTP2_FLAG_PRIORITY_GROUP
;
break
;
case
NGHTTP2_PRIORITY_TYPE_DEP
:
flags
|=
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
;
break
;
default:
/* Default weight */
break
;
}
flags
|=
NGHTTP2_FLAG_PRIORITY
;
}
return
flags
;
...
...
@@ -457,6 +413,10 @@ int nghttp2_submit_request(nghttp2_session *session,
{
uint8_t
flags
;
if
(
pri_spec
&&
nghttp2_priority_spec_check_default
(
pri_spec
))
{
pri_spec
=
NULL
;
}
flags
=
set_request_flags
(
pri_spec
,
data_prd
);
return
nghttp2_submit_headers_shared_nva
(
session
,
flags
,
-
1
,
pri_spec
,
...
...
src/app_helper.cc
View file @
2d4b92fc
...
...
@@ -261,27 +261,15 @@ void print_flags(const nghttp2_frame_hd& hd)
}
s
+=
"PAD_HIGH"
;
}
if
(
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY
_GROUP
)
{
if
(
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY
)
{
if
(
!
s
.
empty
())
{
s
+=
" | "
;
}
s
+=
"PRIORITY_GROUP"
;
}
if
(
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
)
{
if
(
!
s
.
empty
())
{
s
+=
" | "
;
}
s
+=
"PRIORITY_DEPENDENCY"
;
s
+=
"PRIORITY"
;
}
break
;
case
NGHTTP2_PRIORITY
:
if
(
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY_GROUP
)
{
s
+=
"PRIORITY_GROUP"
;
}
else
if
(
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
)
{
s
+=
"PRIORITY_DEPENDENCY"
;
}
break
;
case
NGHTTP2_SETTINGS
:
if
(
hd
.
flags
&
NGHTTP2_FLAG_ACK
)
{
...
...
@@ -368,14 +356,11 @@ void print_frame(print_type ptype, const nghttp2_frame *frame)
case
NGHTTP2_HEADERS
:
print_frame_attr_indent
();
fprintf
(
outfile
,
"(padlen=%zu"
,
frame
->
headers
.
padlen
);
if
(
frame
->
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY_GROUP
)
{
fprintf
(
outfile
,
", pri_group_id=%d, weight=%u"
,
frame
->
headers
.
pri_spec
.
spec
.
group
.
pri_group_id
,
frame
->
headers
.
pri_spec
.
spec
.
group
.
weight
);
}
else
if
(
frame
->
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
)
{
fprintf
(
outfile
,
", stream_id=%d, exclusive=%d"
,
frame
->
headers
.
pri_spec
.
spec
.
dep
.
stream_id
,
frame
->
headers
.
pri_spec
.
spec
.
dep
.
exclusive
);
if
(
frame
->
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY
)
{
fprintf
(
outfile
,
", stream_id=%d, weight=%u, exclusive=%d"
,
frame
->
headers
.
pri_spec
.
stream_id
,
frame
->
headers
.
pri_spec
.
weight
,
frame
->
headers
.
pri_spec
.
exclusive
);
}
fprintf
(
outfile
,
")
\n
"
);
switch
(
frame
->
headers
.
cat
)
{
...
...
@@ -399,19 +384,10 @@ void print_frame(print_type ptype, const nghttp2_frame *frame)
case
NGHTTP2_PRIORITY
:
print_frame_attr_indent
();
fprintf
(
outfile
,
"("
);
if
(
frame
->
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY_GROUP
)
{
fprintf
(
outfile
,
"pri_group_id=%d, weight=%u"
,
frame
->
priority
.
pri_spec
.
spec
.
group
.
pri_group_id
,
frame
->
priority
.
pri_spec
.
spec
.
group
.
weight
);
}
else
if
(
frame
->
hd
.
flags
&
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
)
{
fprintf
(
outfile
,
"stream_id=%d, exclusive=%d"
,
frame
->
priority
.
pri_spec
.
spec
.
dep
.
stream_id
,
frame
->
priority
.
pri_spec
.
spec
.
dep
.
exclusive
);
}
fprintf
(
outfile
,
")
\n
"
);
fprintf
(
outfile
,
"(stream_id=%d, weight=%u, exclusive=%d)
\n
"
,
frame
->
priority
.
pri_spec
.
stream_id
,
frame
->
priority
.
pri_spec
.
weight
,
frame
->
priority
.
pri_spec
.
exclusive
);
break
;
case
NGHTTP2_RST_STREAM
:
...
...
src/nghttp.cc
View file @
2d4b92fc
...
...
@@ -263,7 +263,7 @@ struct Request {
nghttp2_priority_spec
resolve_dep
(
int32_t
pri
)
{
nghttp2_priority_spec
pri_spec
=
{
NGHTTP2_PRIORITY_TYPE_NONE
}
;
nghttp2_priority_spec
pri_spec
;
int
exclusive
=
0
;
int32_t
stream_id
=
-
1
;
...
...
@@ -271,6 +271,8 @@ struct Request {
return
pri_spec
;
}
nghttp2_priority_spec_default_init
(
&
pri_spec
);
auto
start
=
std
::
min
(
pri
,
(
int
)
dep
->
deps
.
size
()
-
1
);
for
(
auto
i
=
start
;
i
>=
0
;
--
i
)
{
...
...
@@ -293,7 +295,8 @@ struct Request {
return
pri_spec
;
}
nghttp2_priority_spec_dep_init
(
&
pri_spec
,
stream_id
,
exclusive
);
nghttp2_priority_spec_init
(
&
pri_spec
,
stream_id
,
NGHTTP2_DEFAULT_WEIGHT
,
exclusive
);
return
pri_spec
;
}
...
...
@@ -1014,12 +1017,9 @@ void update_html_parser(HttpClient *client, Request *req,
nghttp2_priority_spec
pri_spec
;
// We always specify priority group of parent stream, so that
// even if the parent stream is closed, the dependent stream is
// in the same priority group. We adjust the priority using
// separate PRIORITY frame after stream ID becomes known.
nghttp2_priority_spec_group_init
(
&
pri_spec
,
req
->
stream_id
,
config
.
weight
);
// We adjust the priority using separate PRIORITY frame after
// stream ID becomes known.
nghttp2_priority_spec_default_init
(
&
pri_spec
);
if
(
client
->
add_request
(
uri
,
nullptr
,
0
,
pri_spec
,
req
->
dep
,
req
->
level
+
1
)
)
{
...
...
@@ -1108,9 +1108,8 @@ void check_stream_id(nghttp2_session *session, int32_t stream_id,
auto
pri_spec
=
req
->
resolve_dep
(
req
->
pri
);
if
(
pri_spec
.
pri_type
==
NGHTTP2_PRIORITY_TYPE_DEP
)
{
nghttp2_submit_priority
(
session
,
NGHTTP2_FLAG_NONE
,
stream_id
,
&
pri_spec
);
if
(
!
nghttp2_priority_spec_check_default
(
&
pri_spec
))
{
nghttp2_submit_priority
(
session
,
NGHTTP2_FLAG_NONE
,
stream_id
,
&
pri_spec
);
}
auto
itr
=
std
::
begin
(
req
->
dep
->
deps
);
...
...
@@ -1208,7 +1207,9 @@ int on_begin_headers_callback(nghttp2_session *session,
http_parser_url
u
;
memset
(
&
u
,
0
,
sizeof
(
u
));
// TODO Set pri and level
nghttp2_priority_spec
pri_spec
=
{
NGHTTP2_PRIORITY_TYPE_NONE
};
nghttp2_priority_spec
pri_spec
;
nghttp2_priority_spec_default_init
(
&
pri_spec
);
auto
req
=
util
::
make_unique
<
Request
>
(
""
,
u
,
nullptr
,
0
,
pri_spec
,
nullptr
);
...
...
@@ -1624,10 +1625,12 @@ int communicate(const std::string& scheme, const std::string& host,
{
HttpClient
client
{
callbacks
,
evbase
,
ssl_ctx
};
nghttp2_priority_spec
pri_spec
=
{
NGHTTP2_PRIORITY_TYPE_NONE
}
;
nghttp2_priority_spec
pri_spec
;
if
(
config
.
weight
!=
NGHTTP2_DEFAULT_WEIGHT
)
{
nghttp2_priority_spec_group_init
(
&
pri_spec
,
-
1
,
config
.
weight
);
nghttp2_priority_spec_init
(
&
pri_spec
,
0
,
config
.
weight
,
0
);
}
else
{
nghttp2_priority_spec_default_init
(
&
pri_spec
);
}
for
(
auto
req
:
requests
)
{
...
...
tests/main.c
View file @
2d4b92fc
...
...
@@ -222,6 +222,8 @@ int main(int argc, char* argv[])
test_nghttp2_session_stream_dep_add_subtree
)
||
!
CU_add_test
(
pSuite
,
"session_stream_dep_remove_subtree"
,
test_nghttp2_session_stream_dep_remove_subtree
)
||
!
CU_add_test
(
pSuite
,
"session_stream_dep_all_your_stream_are_belong_to_us"
,
test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us
)
||
!
CU_add_test
(
pSuite
,
"session_stream_attach_data"
,
test_nghttp2_session_stream_attach_data
)
||
!
CU_add_test
(
pSuite
,
"session_stream_attach_data_subtree"
,
...
...
tests/nghttp2_frame_test.c
View file @
2d4b92fc
...
...
@@ -92,7 +92,7 @@ void test_nghttp2_frame_pack_headers()
nva
=
headers
();
nvlen
=
HEADERS_LENGTH
;
pri_spec
.
pri_type
=
NGHTTP2_PRIORITY_TYPE_NONE
;
nghttp2_priority_spec_default_init
(
&
pri_spec
)
;
nghttp2_frame_headers_init
(
&
frame
,
NGHTTP2_FLAG_END_STREAM
|
...
...
@@ -110,8 +110,8 @@ void test_nghttp2_frame_pack_headers()
NGHTTP2_HEADERS
,
NGHTTP2_FLAG_END_STREAM
|
NGHTTP2_FLAG_END_HEADERS
,
1000000007
,
&
oframe
.
hd
);
/* We
include NGHTTP2_PRIORITY_TYPE_NONE
*/
CU_ASSERT
(
NGHTTP2_
PRIORITY_TYPE_NONE
==
oframe
.
pri_spec
.
pri_type
);
/* We
did not include PRIORITY flag
*/
CU_ASSERT
(
NGHTTP2_
DEFAULT_WEIGHT
==
oframe
.
pri_spec
.
weight
);
hdblocklen
=
nghttp2_bufs_len
(
&
bufs
)
-
NGHTTP2_FRAME_HDLEN
;
CU_ASSERT
(
hdblocklen
==
...
...
@@ -126,9 +126,9 @@ void test_nghttp2_frame_pack_headers()
nghttp2_bufs_reset
(
&
bufs
);
memset
(
&
oframe
,
0
,
sizeof
(
oframe
));
/* Next, include NGHTTP2_
PRIORITY_TYPE_GROUP
*/
nghttp2_priority_spec_
group_init
(
&
frame
.
pri_spec
,
1000000009
,
12
);
frame
.
hd
.
flags
|=
NGHTTP2_FLAG_PRIORITY
_GROUP
;
/* Next, include NGHTTP2_
FLAG_PRIORITY
*/
nghttp2_priority_spec_
init
(
&
frame
.
pri_spec
,
1000000009
,
12
,
1
);
frame
.
hd
.
flags
|=
NGHTTP2_FLAG_PRIORITY
;
rv
=
nghttp2_frame_pack_headers
(
&
bufs
,
&
frame
,
&
deflater
);
...
...
@@ -139,12 +139,12 @@ void test_nghttp2_frame_pack_headers()
check_frame_header
(
nghttp2_bufs_len
(
&
bufs
)
-
NGHTTP2_FRAME_HDLEN
,
NGHTTP2_HEADERS
,
NGHTTP2_FLAG_END_STREAM
|
NGHTTP2_FLAG_END_HEADERS
|
NGHTTP2_FLAG_PRIORITY
_GROUP
,
NGHTTP2_FLAG_PRIORITY
,
1000000007
,
&
oframe
.
hd
);
CU_ASSERT
(
NGHTTP2_PRIORITY_TYPE_GROUP
==
oframe
.
pri_spec
.
pri_type
);
CU_ASSERT
(
1
000000009
==
oframe
.
pri_spec
.
spec
.
group
.
pri_group_id
);
CU_ASSERT
(
1
2
==
oframe
.
pri_spec
.
spec
.
group
.
weight
);
CU_ASSERT
(
1000000009
==
oframe
.
pri_spec
.
stream_id
);
CU_ASSERT
(
1
2
==
oframe
.
pri_spec
.
weight
);
CU_ASSERT
(
1
==
oframe
.
pri_spec
.
exclusive
);
hdblocklen
=
nghttp2_bufs_len
(
&
bufs
)
-
NGHTTP2_FRAME_HDLEN
-
nghttp2_frame_priority_len
(
oframe
.
hd
.
flags
);
...
...
@@ -159,44 +159,7 @@ void test_nghttp2_frame_pack_headers()
nva_out_reset
(
&
out
);
nghttp2_bufs_reset
(
&
bufs
);
memset
(
&
oframe
,
0
,
sizeof
(
oframe
));
/* Next, include NGHTTP2_PRIORITY_TYPE_DEP */
nghttp2_priority_spec_dep_init
(
&
frame
.
pri_spec
,
123
,
1
);
frame
.
hd
.
flags
=
NGHTTP2_FLAG_END_STREAM
|
NGHTTP2_FLAG_END_HEADERS
|
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
;
rv
=
nghttp2_frame_pack_headers
(
&
bufs
,
&
frame
,
&
deflater
);
CU_ASSERT
(
0
==
rv
);
CU_ASSERT
(
nghttp2_bufs_len
(
&
bufs
)
>
0
);
CU_ASSERT
(
0
==
unpack_framebuf
((
nghttp2_frame
*
)
&
oframe
,
&
bufs
));
check_frame_header
(
nghttp2_bufs_len
(
&
bufs
)
-
NGHTTP2_FRAME_HDLEN
,
NGHTTP2_HEADERS
,
NGHTTP2_FLAG_END_STREAM
|
NGHTTP2_FLAG_END_HEADERS
|
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
,
1000000007
,
&
oframe
.
hd
);
CU_ASSERT
(
NGHTTP2_PRIORITY_TYPE_DEP
==
oframe
.
pri_spec
.
pri_type
);
CU_ASSERT
(
123
==
oframe
.
pri_spec
.
spec
.
dep
.
stream_id
);
CU_ASSERT
(
1
==
oframe
.
pri_spec
.
spec
.
dep
.
exclusive
);
hdblocklen
=
nghttp2_bufs_len
(
&
bufs
)
-
NGHTTP2_FRAME_HDLEN
-
nghttp2_frame_priority_len
(
oframe
.
hd
.
flags
);
CU_ASSERT
(
hdblocklen
==
inflate_hd
(
&
inflater
,
&
out
,
&
bufs
,
NGHTTP2_FRAME_HDLEN
+
nghttp2_frame_priority_len
(
oframe
.
hd
.
flags
)));
nghttp2_nv_array_sort
(
out
.
nva
,
out
.
nvlen
);
CU_ASSERT
(
nvnameeq
(
"method"
,
&
out
.
nva
[
0
]));
nghttp2_frame_headers_free
(
&
oframe
);
nva_out_reset
(
&
out
);
nghttp2_bufs_free
(
&
bufs
);
nghttp2_frame_headers_free
(
&
frame
);
nghttp2_hd_inflate_free
(
&
inflater
);
nghttp2_hd_deflate_free
(
&
deflater
);
...
...
@@ -208,7 +171,6 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void)
nghttp2_headers
frame
;
nghttp2_bufs
bufs
;
nghttp2_nv
*
nva
;
nghttp2_priority_spec
pri_spec
;
ssize_t
nvlen
;
size_t
big_vallen
=
NGHTTP2_HD_MAX_VALUE
;
nghttp2_nv
big_hds
[
16
];
...
...
@@ -228,13 +190,11 @@ void test_nghttp2_frame_pack_headers_frame_too_large(void)
big_hds
[
i
].
flags
=
NGHTTP2_NV_FLAG_NONE
;
}
pri_spec
.
pri_type
=
NGHTTP2_PRIORITY_TYPE_NONE
;
nvlen
=
nghttp2_nv_array_copy
(
&
nva
,
big_hds
,
big_hdslen
);
nghttp2_hd_deflate_init
(
&
deflater
);
nghttp2_frame_headers_init
(
&
frame
,
NGHTTP2_FLAG_END_STREAM
|
NGHTTP2_FLAG_END_HEADERS
,
1000000007
,
&
pri_spec
,
nva
,
nvlen
);
1000000007
,
NULL
,
nva
,
nvlen
);
rv
=
nghttp2_frame_pack_headers
(
&
bufs
,
&
frame
,
&
deflater
);
CU_ASSERT
(
NGHTTP2_ERR_HEADER_COMP
==
rv
);
...
...
@@ -256,7 +216,7 @@ void test_nghttp2_frame_pack_priority(void)
frame_pack_bufs_init
(
&
bufs
);
/* First, pack priority with priority group and weight */
nghttp2_priority_spec_
group_init
(
&
pri_spec
,
1000000009
,
12
);
nghttp2_priority_spec_
init
(
&
pri_spec
,
1000000009
,
12
,
1
);
nghttp2_frame_priority_init
(
&
frame
,
1000000007
,
&
pri_spec
);
rv
=
nghttp2_frame_pack_priority
(
&
bufs
,
&
frame
);
...
...
@@ -264,34 +224,12 @@ void test_nghttp2_frame_pack_priority(void)
CU_ASSERT
(
0
==
rv
);
CU_ASSERT
(
13
==
nghttp2_bufs_len
(
&
bufs
));
CU_ASSERT
(
0
==
unpack_framebuf
((
nghttp2_frame
*
)
&
oframe
,
&
bufs
));
check_frame_header
(
4
,
NGHTTP2_PRIORITY
,
NGHTTP2_FLAG_PRIORITY_GROUP
,
1000000007
,
&
oframe
.
hd
);
CU_ASSERT
(
NGHTTP2_PRIORITY_TYPE_GROUP
==
oframe
.
pri_spec
.
pri_type
);
CU_ASSERT
(
1000000009
==
oframe
.
pri_spec
.
spec
.
group
.
pri_group_id
);
CU_ASSERT
(
12
==
oframe
.
pri_spec
.
spec
.
group
.
weight
);
nghttp2_frame_priority_free
(
&
oframe
);
nghttp2_bufs_reset
(
&
bufs
);
memset
(
&
oframe
,
0
,
sizeof
(
oframe
));
/* Next, pack priority with stream dependency */
nghttp2_priority_spec_dep_init
(
&
pri_spec
,
79
,
1
);
nghttp2_frame_priority_init
(
&
frame
,
1000000007
,
&
pri_spec
);
rv
=
nghttp2_frame_pack_priority
(
&
bufs
,
&
frame
);
CU_ASSERT
(
0
==
rv
);
CU_ASSERT
(
12
==
nghttp2_bufs_len
(
&
bufs
));
CU_ASSERT
(
0
==
unpack_framebuf
((
nghttp2_frame
*
)
&
oframe
,
&
bufs
));
check_frame_header
(
4
,
NGHTTP2_PRIORITY
,
NGHTTP2_FLAG_PRIORITY_DEPENDENCY
,
check_frame_header
(
5
,
NGHTTP2_PRIORITY
,
NGHTTP2_FLAG_NONE
,
1000000007
,
&
oframe
.
hd
);
CU_ASSERT
(
NGHTTP2_PRIORITY_TYPE_DEP
==
oframe
.
pri_spec
.
pri_type
);
CU_ASSERT
(
79
==
oframe
.
pri_spec
.
spec
.
dep
.
stream_id
);
CU_ASSERT
(
1
==
oframe
.
pri_spec
.
spec
.
dep
.
exclusive
);
CU_ASSERT
(
1000000009
==
oframe
.
pri_spec
.
stream_id
);
CU_ASSERT
(
12
==
oframe
.
pri_spec
.
weight
);
CU_ASSERT
(
1
==
oframe
.
pri_spec
.
exclusive
);
nghttp2_frame_priority_free
(
&
oframe
);
nghttp2_bufs_reset
(
&
bufs
);
...
...
tests/nghttp2_session_test.c
View file @
2d4b92fc
This diff is collapsed.
Click to expand it.
tests/nghttp2_session_test.h
View file @
2d4b92fc
...
...
@@ -103,6 +103,7 @@ void test_nghttp2_session_stream_dep_add(void);
void
test_nghttp2_session_stream_dep_remove
(
void
);
void
test_nghttp2_session_stream_dep_add_subtree
(
void
);
void
test_nghttp2_session_stream_dep_remove_subtree
(
void
);
void
test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us
(
void
);
void
test_nghttp2_session_stream_attach_data
(
void
);
void
test_nghttp2_session_stream_attach_data_subtree
(
void
);
void
test_nghttp2_session_keep_closed_stream
(
void
);
...
...
tests/nghttp2_test_helper.c
View file @
2d4b92fc
...
...
@@ -232,12 +232,22 @@ void bufs_large_init(nghttp2_bufs *bufs, size_t chunk_size)
nghttp2_bufs_init2
(
bufs
,
chunk_size
,
16
,
NGHTTP2_FRAME_HDLEN
+
2
);
}
nghttp2_stream
*
open_stream
(
nghttp2_session
*
session
,
int32_t
stream_id
)
static
nghttp2_stream
*
open_stream_with_all
(
nghttp2_session
*
session
,
int32_t
stream_id
,
int32_t
weight
,
uint8_t
exclusive
,
nghttp2_stream
*
dep_stream
)
{
nghttp2_priority_spec
pri_spec
;
int32_t
dep_stream_id
;
if
(
dep_stream
)
{
dep_stream_id
=
dep_stream
->
stream_id
;
}
else
{
dep_stream_id
=
0
;
}
nghttp2_priority_spec_group_init
(
&
pri_spec
,
stream_id
,
NGHTTP2_DEFAULT_WEIGHT
);
nghttp2_priority_spec_init
(
&
pri_spec
,
dep_stream_id
,
weight
,
exclusive
);
return
nghttp2_session_open_stream
(
session
,
stream_id
,
NGHTTP2_STREAM_FLAG_NONE
,
...
...
@@ -246,32 +256,45 @@ nghttp2_stream* open_stream(nghttp2_session *session, int32_t stream_id)
NULL
);
}
nghttp2_stream
*
open_stream
(
nghttp2_session
*
session
,
int32_t
stream_id
)
{
return
open_stream_with_all
(
session
,
stream_id
,
NGHTTP2_DEFAULT_WEIGHT
,
0
,
NULL
);
}
nghttp2_stream
*
open_stream_with_dep
(
nghttp2_session
*
session
,
int32_t
stream_id
,
nghttp2_stream
*
dep_stream
)
{
nghttp2_priority_spec
pri_spec
;
nghttp2_priority_spec_dep_init
(
&
pri_spec
,
dep_stream
->
stream_id
,
0
);
return
open_stream_with_all
(
session
,
stream_id
,
NGHTTP2_DEFAULT_WEIGHT
,
0
,
dep_stream
);
}
return
nghttp2_session_open_stream
(
session
,
stream_id
,
NGHTTP2_STREAM_FLAG_NONE
,
&
pri_spec
,
NGHTTP2_STREAM_OPENED
,
NULL
);
nghttp2_stream
*
open_stream_with_dep_weight
(
nghttp2_session
*
session
,
int32_t
stream_id
,
int32_t
weight
,
nghttp2_stream
*
dep_stream
)
{
return
open_stream_with_all
(
session
,
stream_id
,
weight
,
0
,
dep_stream
);
}
nghttp2_stream
*
open_stream_with_dep_excl
(
nghttp2_session
*
session
,
int32_t
stream_id
,
nghttp2_stream
*
dep_stream
)
{
nghttp2_priority_spec
pri_spec
;
return
open_stream_with_all
(
session
,
stream_id
,
NGHTTP2_DEFAULT_WEIGHT
,
1
,
dep_stream
);
}
nghttp2_outbound_item
*
create_data_ob_item
(
void
)
{
nghttp2_outbound_item
*
item
;
nghttp2_priority_spec_dep_init
(
&
pri_spec
,
dep_stream
->
stream_id
,
1
);
item
=
malloc
(
sizeof
(
nghttp2_outbound_item
));
memset
(
item
,
0
,
sizeof
(
nghttp2_outbound_item
));
item
->
frame_cat
=
NGHTTP2_CAT_DATA
;
return
nghttp2_session_open_stream
(
session
,
stream_id
,
NGHTTP2_STREAM_FLAG_NONE
,
&
pri_spec
,
NGHTTP2_STREAM_OPENED
,
NULL
);
return
item
;
}
tests/nghttp2_test_helper.h
View file @
2d4b92fc
...
...
@@ -89,8 +89,15 @@ nghttp2_stream* open_stream_with_dep(nghttp2_session *session,
int32_t
stream_id
,
nghttp2_stream
*
dep_stream
);
nghttp2_stream
*
open_stream_with_dep_weight
(
nghttp2_session
*
session
,
int32_t
stream_id
,
int32_t
weight
,
nghttp2_stream
*
dep_stream
);
nghttp2_stream
*
open_stream_with_dep_excl
(
nghttp2_session
*
session
,
int32_t
stream_id
,
nghttp2_stream
*
dep_stream
);
nghttp2_outbound_item
*
create_data_ob_item
(
void
);
#endif
/* NGHTTP2_TEST_HELPER_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment