Path: blob/master/Utilities/cmnghttp2/lib/nghttp2_outbound_item.h
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#ifndef NGHTTP2_OUTBOUND_ITEM_H25#define NGHTTP2_OUTBOUND_ITEM_H2627#ifdef HAVE_CONFIG_H28# include <config.h>29#endif /* HAVE_CONFIG_H */3031#include <nghttp2/nghttp2.h>32#include "nghttp2_frame.h"33#include "nghttp2_mem.h"3435/* struct used for HEADERS and PUSH_PROMISE frame */36typedef struct {37nghttp2_data_provider data_prd;38void *stream_user_data;39/* error code when request HEADERS is canceled by RST_STREAM while40it is in queue. */41uint32_t error_code;42/* nonzero if request HEADERS is canceled. The error code is stored43in |error_code|. */44uint8_t canceled;45} nghttp2_headers_aux_data;4647/* struct used for DATA frame */48typedef struct {49/**50* The data to be sent for this DATA frame.51*/52nghttp2_data_provider data_prd;53/**54* The flags of DATA frame. We use separate flags here and55* nghttp2_data frame. The latter contains flags actually sent to56* peer. This |flags| may contain NGHTTP2_FLAG_END_STREAM and only57* when |eof| becomes nonzero, flags in nghttp2_data has58* NGHTTP2_FLAG_END_STREAM set.59*/60uint8_t flags;61/**62* The flag to indicate whether EOF was reached or not. Initially63* |eof| is 0. It becomes 1 after all data were read.64*/65uint8_t eof;66/**67* The flag to indicate that NGHTTP2_DATA_FLAG_NO_COPY is used.68*/69uint8_t no_copy;70} nghttp2_data_aux_data;7172typedef enum {73NGHTTP2_GOAWAY_AUX_NONE = 0x0,74/* indicates that session should be terminated after the75transmission of this frame. */76NGHTTP2_GOAWAY_AUX_TERM_ON_SEND = 0x1,77/* indicates that this GOAWAY is just a notification for graceful78shutdown. No nghttp2_session.goaway_flags should be updated on79the reaction to this frame. */80NGHTTP2_GOAWAY_AUX_SHUTDOWN_NOTICE = 0x281} nghttp2_goaway_aux_flag;8283/* struct used for GOAWAY frame */84typedef struct {85/* bitwise-OR of one or more of nghttp2_goaway_aux_flag. */86uint8_t flags;87} nghttp2_goaway_aux_data;8889/* struct used for extension frame */90typedef struct {91/* nonzero if this extension frame is serialized by library92function, instead of user-defined callbacks. */93uint8_t builtin;94} nghttp2_ext_aux_data;9596/* Additional data which cannot be stored in nghttp2_frame struct */97typedef union {98nghttp2_data_aux_data data;99nghttp2_headers_aux_data headers;100nghttp2_goaway_aux_data goaway;101nghttp2_ext_aux_data ext;102} nghttp2_aux_data;103104struct nghttp2_outbound_item;105typedef struct nghttp2_outbound_item nghttp2_outbound_item;106107struct nghttp2_outbound_item {108nghttp2_frame frame;109/* Storage for extension frame payload. frame->ext.payload points110to this structure to avoid frequent memory allocation. */111nghttp2_ext_frame_payload ext_frame_payload;112nghttp2_aux_data aux_data;113/* The priority used in priority comparison. Smaller is served114earlier. For PING, SETTINGS and non-DATA frames (excluding115response HEADERS frame) have dedicated cycle value defined above.116For DATA frame, cycle is computed by taking into account of117effective weight and frame payload length previously sent, so118that the amount of transmission is distributed across streams119proportional to effective weight (inside a tree). */120uint64_t cycle;121nghttp2_outbound_item *qnext;122/* nonzero if this object is queued, except for DATA or HEADERS123which are attached to stream as item. */124uint8_t queued;125};126127/*128* Initializes |item|. No memory allocation is done in this function.129* Don't call nghttp2_outbound_item_free() until frame member is130* initialized.131*/132void nghttp2_outbound_item_init(nghttp2_outbound_item *item);133134/*135* Deallocates resource for |item|. If |item| is NULL, this function136* does nothing.137*/138void nghttp2_outbound_item_free(nghttp2_outbound_item *item, nghttp2_mem *mem);139140/*141* queue for nghttp2_outbound_item.142*/143typedef struct {144nghttp2_outbound_item *head, *tail;145/* number of items in this queue. */146size_t n;147} nghttp2_outbound_queue;148149void nghttp2_outbound_queue_init(nghttp2_outbound_queue *q);150151/* Pushes |item| into |q| */152void nghttp2_outbound_queue_push(nghttp2_outbound_queue *q,153nghttp2_outbound_item *item);154155/* Pops |item| at the top from |q|. If |q| is empty, nothing156happens. */157void nghttp2_outbound_queue_pop(nghttp2_outbound_queue *q);158159/* Returns the top item. */160#define nghttp2_outbound_queue_top(Q) ((Q)->head)161162/* Returns the size of the queue */163#define nghttp2_outbound_queue_size(Q) ((Q)->n)164165#endif /* NGHTTP2_OUTBOUND_ITEM_H */166167168