Path: blob/master/Utilities/cmnghttp2/lib/nghttp2_outbound_item.c
3153 views
/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2012 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#include "nghttp2_outbound_item.h"2526#include <assert.h>27#include <string.h>2829void nghttp2_outbound_item_init(nghttp2_outbound_item *item) {30item->cycle = 0;31item->qnext = NULL;32item->queued = 0;3334memset(&item->aux_data, 0, sizeof(nghttp2_aux_data));35}3637void nghttp2_outbound_item_free(nghttp2_outbound_item *item, nghttp2_mem *mem) {38nghttp2_frame *frame;3940if (item == NULL) {41return;42}4344frame = &item->frame;4546switch (frame->hd.type) {47case NGHTTP2_DATA:48nghttp2_frame_data_free(&frame->data);49break;50case NGHTTP2_HEADERS:51nghttp2_frame_headers_free(&frame->headers, mem);52break;53case NGHTTP2_PRIORITY:54nghttp2_frame_priority_free(&frame->priority);55break;56case NGHTTP2_RST_STREAM:57nghttp2_frame_rst_stream_free(&frame->rst_stream);58break;59case NGHTTP2_SETTINGS:60nghttp2_frame_settings_free(&frame->settings, mem);61break;62case NGHTTP2_PUSH_PROMISE:63nghttp2_frame_push_promise_free(&frame->push_promise, mem);64break;65case NGHTTP2_PING:66nghttp2_frame_ping_free(&frame->ping);67break;68case NGHTTP2_GOAWAY:69nghttp2_frame_goaway_free(&frame->goaway, mem);70break;71case NGHTTP2_WINDOW_UPDATE:72nghttp2_frame_window_update_free(&frame->window_update);73break;74default: {75nghttp2_ext_aux_data *aux_data;7677aux_data = &item->aux_data.ext;7879if (aux_data->builtin == 0) {80nghttp2_frame_extension_free(&frame->ext);81break;82}8384switch (frame->hd.type) {85case NGHTTP2_ALTSVC:86nghttp2_frame_altsvc_free(&frame->ext, mem);87break;88case NGHTTP2_ORIGIN:89nghttp2_frame_origin_free(&frame->ext, mem);90break;91case NGHTTP2_PRIORITY_UPDATE:92nghttp2_frame_priority_update_free(&frame->ext, mem);93break;94default:95assert(0);96break;97}98}99}100}101102void nghttp2_outbound_queue_init(nghttp2_outbound_queue *q) {103q->head = q->tail = NULL;104q->n = 0;105}106107void nghttp2_outbound_queue_push(nghttp2_outbound_queue *q,108nghttp2_outbound_item *item) {109if (q->tail) {110q->tail = q->tail->qnext = item;111} else {112q->head = q->tail = item;113}114++q->n;115}116117void nghttp2_outbound_queue_pop(nghttp2_outbound_queue *q) {118nghttp2_outbound_item *item;119if (!q->head) {120return;121}122item = q->head;123q->head = q->head->qnext;124item->qnext = NULL;125if (!q->head) {126q->tail = NULL;127}128--q->n;129}130131132