nghttp2_priority_spec.c 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (C) 2015-2018 Alibaba Group Holding Limited
  3. */
  4. #include "nghttp2_priority_spec.h"
  5. void nghttp2_priority_spec_init(nghttp2_priority_spec *pri_spec,
  6. int32_t stream_id, int32_t weight,
  7. int exclusive) {
  8. pri_spec->stream_id = stream_id;
  9. pri_spec->weight = weight;
  10. pri_spec->exclusive = exclusive != 0;
  11. }
  12. void nghttp2_priority_spec_default_init(nghttp2_priority_spec *pri_spec) {
  13. pri_spec->stream_id = 0;
  14. pri_spec->weight = NGHTTP2_DEFAULT_WEIGHT;
  15. pri_spec->exclusive = 0;
  16. }
  17. int nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec) {
  18. return pri_spec->stream_id == 0 &&
  19. pri_spec->weight == NGHTTP2_DEFAULT_WEIGHT && pri_spec->exclusive == 0;
  20. }
  21. void nghttp2_priority_spec_normalize_weight(nghttp2_priority_spec *pri_spec) {
  22. if (pri_spec->weight < NGHTTP2_MIN_WEIGHT) {
  23. pri_spec->weight = NGHTTP2_MIN_WEIGHT;
  24. } else if (pri_spec->weight > NGHTTP2_MAX_WEIGHT) {
  25. pri_spec->weight = NGHTTP2_MAX_WEIGHT;
  26. }
  27. }