Name unnamed union in nghttp2_priority_spec so that we can be C90 compatible

This commit is contained in:
Tatsuhiro Tsujikawa 2014-04-05 18:40:44 +09:00
parent c1060f0d48
commit 8f23c0c38b
8 changed files with 44 additions and 43 deletions

View File

@ -814,7 +814,7 @@ typedef struct {
* :enum:`NGHTTP2_PRIORITY_TYPE_DEP`. * :enum:`NGHTTP2_PRIORITY_TYPE_DEP`.
*/ */
nghttp2_priority_dep dep; nghttp2_priority_dep dep;
}; } spec;
} nghttp2_priority_spec; } nghttp2_priority_spec;
/** /**

View File

@ -389,14 +389,14 @@ void nghttp2_frame_pack_priority_spec(uint8_t *buf,
switch(pri_spec->pri_type) { switch(pri_spec->pri_type) {
case NGHTTP2_PRIORITY_TYPE_GROUP: case NGHTTP2_PRIORITY_TYPE_GROUP:
nghttp2_put_uint32be(buf, pri_spec->group.pri_group_id); nghttp2_put_uint32be(buf, pri_spec->spec.group.pri_group_id);
buf[4] = pri_spec->group.weight - 1; buf[4] = pri_spec->spec.group.weight - 1;
return; return;
case NGHTTP2_PRIORITY_TYPE_DEP: case NGHTTP2_PRIORITY_TYPE_DEP:
nghttp2_put_uint32be(buf, pri_spec->dep.stream_id); nghttp2_put_uint32be(buf, pri_spec->spec.dep.stream_id);
if(pri_spec->dep.exclusive) { if(pri_spec->spec.dep.exclusive) {
buf[0] |= 0x80; buf[0] |= 0x80;
} }

View File

@ -28,14 +28,14 @@ void nghttp2_priority_spec_group_init(nghttp2_priority_spec *pri_spec,
int32_t pri_group_id, int32_t weight) int32_t pri_group_id, int32_t weight)
{ {
pri_spec->pri_type = NGHTTP2_PRIORITY_TYPE_GROUP; pri_spec->pri_type = NGHTTP2_PRIORITY_TYPE_GROUP;
pri_spec->group.pri_group_id = pri_group_id; pri_spec->spec.group.pri_group_id = pri_group_id;
pri_spec->group.weight = weight; pri_spec->spec.group.weight = weight;
} }
void nghttp2_priority_spec_dep_init(nghttp2_priority_spec *pri_spec, void nghttp2_priority_spec_dep_init(nghttp2_priority_spec *pri_spec,
int32_t stream_id, int exclusive) int32_t stream_id, int exclusive)
{ {
pri_spec->pri_type = NGHTTP2_PRIORITY_TYPE_DEP; pri_spec->pri_type = NGHTTP2_PRIORITY_TYPE_DEP;
pri_spec->dep.stream_id = stream_id; pri_spec->spec.dep.stream_id = stream_id;
pri_spec->dep.exclusive = exclusive != 0; pri_spec->spec.dep.exclusive = exclusive != 0;
} }

View File

@ -491,7 +491,7 @@ int nghttp2_session_reprioritize_stream
switch(pri_spec->pri_type) { switch(pri_spec->pri_type) {
case NGHTTP2_PRIORITY_TYPE_GROUP: case NGHTTP2_PRIORITY_TYPE_GROUP:
group = &pri_spec->group; group = &pri_spec->spec.group;
old_stream_group = stream->stream_group; old_stream_group = stream->stream_group;
@ -523,7 +523,7 @@ int nghttp2_session_reprioritize_stream
return 0; return 0;
case NGHTTP2_PRIORITY_TYPE_DEP: case NGHTTP2_PRIORITY_TYPE_DEP:
dep = &pri_spec->dep; dep = &pri_spec->spec.dep;
if(dep->stream_id == stream->stream_id || dep->stream_id == 0) { if(dep->stream_id == stream->stream_id || dep->stream_id == 0) {
return nghttp2_session_terminate_session(session, return nghttp2_session_terminate_session(session,
@ -616,10 +616,10 @@ int nghttp2_session_add_frame(nghttp2_session *session,
/* Initial HEADERS, which will open stream */ /* Initial HEADERS, which will open stream */
if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_GROUP) { if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_GROUP) {
item->weight = frame->headers.pri_spec.group.weight; item->weight = frame->headers.pri_spec.spec.group.weight;
} else if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_DEPENDENCY) { } else if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_DEPENDENCY) {
dep_stream = nghttp2_session_get_stream dep_stream = nghttp2_session_get_stream
(session, frame->headers.pri_spec.dep.stream_id); (session, frame->headers.pri_spec.spec.dep.stream_id);
if(dep_stream) { if(dep_stream) {
item->weight = dep_stream->stream_group->weight; item->weight = dep_stream->stream_group->weight;
} else { } else {
@ -768,13 +768,13 @@ nghttp2_stream* nghttp2_session_open_stream(nghttp2_session *session,
switch(pri_spec->pri_type) { switch(pri_spec->pri_type) {
case NGHTTP2_PRIORITY_TYPE_GROUP: case NGHTTP2_PRIORITY_TYPE_GROUP:
pri_group_id = pri_spec->group.pri_group_id; pri_group_id = pri_spec->spec.group.pri_group_id;
weight = pri_spec->group.weight; weight = pri_spec->spec.group.weight;
break; break;
case NGHTTP2_PRIORITY_TYPE_DEP: case NGHTTP2_PRIORITY_TYPE_DEP:
dep_stream = nghttp2_session_get_stream_raw(session, dep_stream = nghttp2_session_get_stream_raw(session,
pri_spec->dep.stream_id); pri_spec->spec.dep.stream_id);
if(dep_stream) { if(dep_stream) {
pri_group_id = dep_stream->stream_group->pri_group_id; pri_group_id = dep_stream->stream_group->pri_group_id;
@ -854,7 +854,7 @@ nghttp2_stream* nghttp2_session_open_stream(nghttp2_session *session,
root_stream = nghttp2_stream_get_dep_root(dep_stream); root_stream = nghttp2_stream_get_dep_root(dep_stream);
if(root_stream->num_substreams < NGHTTP2_MAX_DEP_TREE_LENGTH) { if(root_stream->num_substreams < NGHTTP2_MAX_DEP_TREE_LENGTH) {
if(pri_spec->dep.exclusive) { if(pri_spec->spec.dep.exclusive) {
nghttp2_stream_dep_insert(dep_stream, stream); nghttp2_stream_dep_insert(dep_stream, stream);
} else { } else {
nghttp2_stream_dep_add(dep_stream, stream); nghttp2_stream_dep_add(dep_stream, stream);
@ -1499,10 +1499,11 @@ static int nghttp2_session_prep_frame(nghttp2_session *session,
session->next_stream_id += 2; session->next_stream_id += 2;
if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_GROUP) { if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_GROUP) {
if(frame->headers.pri_spec.group.pri_group_id == -1) { if(frame->headers.pri_spec.spec.group.pri_group_id == -1) {
/* We now know stream_id. Assign stream_id to /* We now know stream_id. Assign stream_id to
pri_group_id if it is -1. */ pri_group_id if it is -1. */
frame->headers.pri_spec.group.pri_group_id = frame->hd.stream_id; frame->headers.pri_spec.spec.group.pri_group_id =
frame->hd.stream_id;
} }
} }
@ -2811,8 +2812,8 @@ int nghttp2_session_on_request_headers_received(nghttp2_session *session,
} }
if(frame->headers.pri_spec.pri_type == NGHTTP2_PRIORITY_TYPE_DEP && if(frame->headers.pri_spec.pri_type == NGHTTP2_PRIORITY_TYPE_DEP &&
(frame->headers.pri_spec.dep.stream_id == frame->hd.stream_id || (frame->headers.pri_spec.spec.dep.stream_id == frame->hd.stream_id ||
frame->headers.pri_spec.dep.stream_id == 0)) { frame->headers.pri_spec.spec.dep.stream_id == 0)) {
return nghttp2_session_inflate_handle_invalid_connection return nghttp2_session_inflate_handle_invalid_connection
(session, frame, NGHTTP2_PROTOCOL_ERROR); (session, frame, NGHTTP2_PROTOCOL_ERROR);
} }

View File

@ -106,10 +106,10 @@ static void adjust_priority_spec_group_weight(nghttp2_priority_spec *pri_spec)
{ {
assert(pri_spec->pri_type == NGHTTP2_PRIORITY_TYPE_GROUP); assert(pri_spec->pri_type == NGHTTP2_PRIORITY_TYPE_GROUP);
if(pri_spec->group.weight < NGHTTP2_MIN_WEIGHT) { if(pri_spec->spec.group.weight < NGHTTP2_MIN_WEIGHT) {
pri_spec->group.weight = NGHTTP2_MIN_WEIGHT; pri_spec->spec.group.weight = NGHTTP2_MIN_WEIGHT;
} else if(pri_spec->group.weight > NGHTTP2_MAX_WEIGHT) { } else if(pri_spec->spec.group.weight > NGHTTP2_MAX_WEIGHT) {
pri_spec->group.weight = NGHTTP2_MAX_WEIGHT; pri_spec->spec.group.weight = NGHTTP2_MAX_WEIGHT;
} }
} }
@ -202,7 +202,7 @@ int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags,
break; break;
case NGHTTP2_PRIORITY_TYPE_DEP: case NGHTTP2_PRIORITY_TYPE_DEP:
if(stream_id == copy_pri_spec.dep.stream_id) { if(stream_id == copy_pri_spec.spec.dep.stream_id) {
return NGHTTP2_ERR_INVALID_ARGUMENT; return NGHTTP2_ERR_INVALID_ARGUMENT;
} }

View File

@ -370,12 +370,12 @@ void print_frame(print_type ptype, const nghttp2_frame *frame)
fprintf(outfile, "(padlen=%zu", frame->headers.padlen); fprintf(outfile, "(padlen=%zu", frame->headers.padlen);
if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_GROUP) { if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_GROUP) {
fprintf(outfile, ", pri_group_id=%d, weight=%u", fprintf(outfile, ", pri_group_id=%d, weight=%u",
frame->headers.pri_spec.group.pri_group_id, frame->headers.pri_spec.spec.group.pri_group_id,
frame->headers.pri_spec.group.weight); frame->headers.pri_spec.spec.group.weight);
} else if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_DEPENDENCY) { } else if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_DEPENDENCY) {
fprintf(outfile, ", stream_id=%d, exclusive=%d", fprintf(outfile, ", stream_id=%d, exclusive=%d",
frame->headers.pri_spec.dep.stream_id, frame->headers.pri_spec.spec.dep.stream_id,
frame->headers.pri_spec.dep.exclusive); frame->headers.pri_spec.spec.dep.exclusive);
} }
fprintf(outfile, ")\n"); fprintf(outfile, ")\n");
switch(frame->headers.cat) { switch(frame->headers.cat) {
@ -403,12 +403,12 @@ void print_frame(print_type ptype, const nghttp2_frame *frame)
if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_GROUP) { if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_GROUP) {
fprintf(outfile, "pri_group_id=%d, weight=%u", fprintf(outfile, "pri_group_id=%d, weight=%u",
frame->priority.pri_spec.group.pri_group_id, frame->priority.pri_spec.spec.group.pri_group_id,
frame->priority.pri_spec.group.weight); frame->priority.pri_spec.spec.group.weight);
} else if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_DEPENDENCY) { } else if(frame->hd.flags & NGHTTP2_FLAG_PRIORITY_DEPENDENCY) {
fprintf(outfile, "stream_id=%d, exclusive=%d", fprintf(outfile, "stream_id=%d, exclusive=%d",
frame->priority.pri_spec.dep.stream_id, frame->priority.pri_spec.spec.dep.stream_id,
frame->priority.pri_spec.dep.exclusive); frame->priority.pri_spec.spec.dep.exclusive);
} }
fprintf(outfile, ")\n"); fprintf(outfile, ")\n");

View File

@ -143,8 +143,8 @@ void test_nghttp2_frame_pack_headers()
1000000007, &oframe.hd); 1000000007, &oframe.hd);
CU_ASSERT(NGHTTP2_PRIORITY_TYPE_GROUP == oframe.pri_spec.pri_type); CU_ASSERT(NGHTTP2_PRIORITY_TYPE_GROUP == oframe.pri_spec.pri_type);
CU_ASSERT(1000000009 == oframe.pri_spec.group.pri_group_id); CU_ASSERT(1000000009 == oframe.pri_spec.spec.group.pri_group_id);
CU_ASSERT(12 == oframe.pri_spec.group.weight); CU_ASSERT(12 == oframe.pri_spec.spec.group.weight);
hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN
- nghttp2_frame_priority_len(oframe.hd.flags); - nghttp2_frame_priority_len(oframe.hd.flags);
@ -181,8 +181,8 @@ void test_nghttp2_frame_pack_headers()
1000000007, &oframe.hd); 1000000007, &oframe.hd);
CU_ASSERT(NGHTTP2_PRIORITY_TYPE_DEP == oframe.pri_spec.pri_type); CU_ASSERT(NGHTTP2_PRIORITY_TYPE_DEP == oframe.pri_spec.pri_type);
CU_ASSERT(123 == oframe.pri_spec.dep.stream_id); CU_ASSERT(123 == oframe.pri_spec.spec.dep.stream_id);
CU_ASSERT(1 == oframe.pri_spec.dep.exclusive); CU_ASSERT(1 == oframe.pri_spec.spec.dep.exclusive);
hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN
- nghttp2_frame_priority_len(oframe.hd.flags); - nghttp2_frame_priority_len(oframe.hd.flags);
@ -268,8 +268,8 @@ void test_nghttp2_frame_pack_priority(void)
1000000007, &oframe.hd); 1000000007, &oframe.hd);
CU_ASSERT(NGHTTP2_PRIORITY_TYPE_GROUP == oframe.pri_spec.pri_type); CU_ASSERT(NGHTTP2_PRIORITY_TYPE_GROUP == oframe.pri_spec.pri_type);
CU_ASSERT(1000000009 == oframe.pri_spec.group.pri_group_id); CU_ASSERT(1000000009 == oframe.pri_spec.spec.group.pri_group_id);
CU_ASSERT(12 == oframe.pri_spec.group.weight); CU_ASSERT(12 == oframe.pri_spec.spec.group.weight);
nghttp2_frame_priority_free(&oframe); nghttp2_frame_priority_free(&oframe);
nghttp2_bufs_reset(&bufs); nghttp2_bufs_reset(&bufs);
@ -290,8 +290,8 @@ void test_nghttp2_frame_pack_priority(void)
1000000007, &oframe.hd); 1000000007, &oframe.hd);
CU_ASSERT(NGHTTP2_PRIORITY_TYPE_DEP == oframe.pri_spec.pri_type); CU_ASSERT(NGHTTP2_PRIORITY_TYPE_DEP == oframe.pri_spec.pri_type);
CU_ASSERT(79 == oframe.pri_spec.dep.stream_id); CU_ASSERT(79 == oframe.pri_spec.spec.dep.stream_id);
CU_ASSERT(1 == oframe.pri_spec.dep.exclusive); CU_ASSERT(1 == oframe.pri_spec.spec.dep.exclusive);
nghttp2_frame_priority_free(&oframe); nghttp2_frame_priority_free(&oframe);
nghttp2_bufs_reset(&bufs); nghttp2_bufs_reset(&bufs);

View File

@ -1718,7 +1718,7 @@ void test_nghttp2_session_on_priority_received(void)
/* push and initiated by remote peer: no update */ /* push and initiated by remote peer: no update */
stream->flags = NGHTTP2_STREAM_FLAG_PUSH; stream->flags = NGHTTP2_STREAM_FLAG_PUSH;
frame.priority.pri_spec.group.weight = 3; frame.priority.pri_spec.spec.group.weight = 3;
CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame)); CU_ASSERT(0 == nghttp2_session_on_priority_received(session, &frame));