void test_nghttp2_frame_pack_priority(void) { nghttp2_priority frame, oframe; nghttp2_bufs bufs; nghttp2_priority_spec pri_spec; int rv; frame_pack_bufs_init(&bufs); /* First, pack priority with priority group and weight */ nghttp2_priority_spec_init(&pri_spec, 1000000009, 12, 1); nghttp2_frame_priority_init(&frame, 1000000007, &pri_spec); rv = nghttp2_frame_pack_priority(&bufs, &frame); CU_ASSERT(0 == rv); CU_ASSERT(NGHTTP2_FRAME_HDLEN + 5 == nghttp2_bufs_len(&bufs)); CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs)); check_frame_header(5, NGHTTP2_PRIORITY, NGHTTP2_FLAG_NONE, 1000000007, &oframe.hd); 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); nghttp2_bufs_free(&bufs); nghttp2_frame_priority_free(&frame); }
int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags _U_, int32_t stream_id, const nghttp2_priority_spec *pri_spec) { int rv; nghttp2_outbound_item *item; nghttp2_frame *frame; nghttp2_priority_spec copy_pri_spec; nghttp2_mem *mem; mem = &session->mem; if (stream_id == 0 || pri_spec == NULL) { return NGHTTP2_ERR_INVALID_ARGUMENT; } if (stream_id == pri_spec->stream_id) { return NGHTTP2_ERR_INVALID_ARGUMENT; } copy_pri_spec = *pri_spec; nghttp2_priority_spec_normalize_weight(©_pri_spec); item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item)); if (item == NULL) { return NGHTTP2_ERR_NOMEM; } nghttp2_outbound_item_init(item); frame = &item->frame; nghttp2_frame_priority_init(&frame->priority, stream_id, ©_pri_spec); rv = nghttp2_session_add_item(session, item); if (rv != 0) { nghttp2_frame_priority_free(&frame->priority); nghttp2_mem_free(mem, item); return rv; } return 0; }