2012-02-19 15:42:25 +01:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-02-19 15:42:25 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
#ifndef NGHTTP2_OUTBOUND_ITEM_H
|
|
|
|
#define NGHTTP2_OUTBOUND_ITEM_H
|
2012-02-19 15:42:25 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2014-11-27 15:39:04 +01:00
|
|
|
#include <config.h>
|
2012-02-19 15:42:25 +01:00
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include <nghttp2/nghttp2.h>
|
|
|
|
#include "nghttp2_frame.h"
|
2014-12-07 15:07:13 +01:00
|
|
|
#include "nghttp2_mem.h"
|
2012-02-19 15:42:25 +01:00
|
|
|
|
2014-09-30 14:45:15 +02:00
|
|
|
/* struct used for HEADERS and PUSH_PROMISE frame */
|
2012-02-19 15:42:25 +01:00
|
|
|
typedef struct {
|
2014-09-30 14:45:15 +02:00
|
|
|
nghttp2_data_provider data_prd;
|
2012-02-19 15:42:25 +01:00
|
|
|
void *stream_user_data;
|
2015-02-13 15:41:48 +01:00
|
|
|
/* error code when request HEADERS is canceled by RST_STREAM while
|
|
|
|
it is in queue. */
|
|
|
|
uint32_t error_code;
|
|
|
|
/* nonzero if request HEADERS is canceled. The error code is stored
|
|
|
|
in |error_code|. */
|
|
|
|
uint8_t canceled;
|
2013-07-15 14:45:59 +02:00
|
|
|
} nghttp2_headers_aux_data;
|
2012-02-19 15:42:25 +01:00
|
|
|
|
2014-10-02 17:59:44 +02:00
|
|
|
/* struct used for DATA frame */
|
|
|
|
typedef struct {
|
|
|
|
/**
|
|
|
|
* The data to be sent for this DATA frame.
|
|
|
|
*/
|
|
|
|
nghttp2_data_provider data_prd;
|
|
|
|
/**
|
|
|
|
* The flags of DATA frame. We use separate flags here and
|
|
|
|
* nghttp2_data frame. The latter contains flags actually sent to
|
|
|
|
* peer. This |flags| may contain NGHTTP2_FLAG_END_STREAM and only
|
|
|
|
* when |eof| becomes nonzero, flags in nghttp2_data has
|
|
|
|
* NGHTTP2_FLAG_END_STREAM set.
|
|
|
|
*/
|
|
|
|
uint8_t flags;
|
|
|
|
/**
|
|
|
|
* The flag to indicate whether EOF was reached or not. Initially
|
|
|
|
* |eof| is 0. It becomes 1 after all data were read.
|
|
|
|
*/
|
|
|
|
uint8_t eof;
|
2015-04-03 16:10:51 +02:00
|
|
|
/**
|
|
|
|
* The flag to indicate that NGHTTP2_DATA_FLAG_NO_COPY is used.
|
|
|
|
*/
|
|
|
|
uint8_t no_copy;
|
2014-10-02 17:59:44 +02:00
|
|
|
} nghttp2_data_aux_data;
|
|
|
|
|
2015-01-21 17:43:56 +01:00
|
|
|
typedef enum {
|
|
|
|
NGHTTP2_GOAWAY_AUX_NONE = 0x0,
|
|
|
|
/* indicates that session should be terminated after the
|
|
|
|
transmission of this frame. */
|
|
|
|
NGHTTP2_GOAWAY_AUX_TERM_ON_SEND = 0x1,
|
|
|
|
/* indicates that this GOAWAY is just a notification for graceful
|
|
|
|
shutdown. No nghttp2_session.goaway_flags should be updated on
|
|
|
|
the reaction to this frame. */
|
2015-04-30 00:28:18 +02:00
|
|
|
NGHTTP2_GOAWAY_AUX_SHUTDOWN_NOTICE = 0x2
|
2015-01-21 17:43:56 +01:00
|
|
|
} nghttp2_goaway_aux_flag;
|
|
|
|
|
2014-11-28 14:59:13 +01:00
|
|
|
/* struct used for GOAWAY frame */
|
|
|
|
typedef struct {
|
2015-01-21 17:43:56 +01:00
|
|
|
/* bitwise-OR of one or more of nghttp2_goaway_aux_flag. */
|
|
|
|
uint8_t flags;
|
2014-11-28 14:59:13 +01:00
|
|
|
} nghttp2_goaway_aux_data;
|
|
|
|
|
2016-03-29 16:29:26 +02:00
|
|
|
/* struct used for extension frame */
|
|
|
|
typedef struct {
|
|
|
|
/* nonzero if this extension frame is serialized by library
|
|
|
|
function, instead of user-defined callbacks. */
|
|
|
|
uint8_t builtin;
|
|
|
|
} nghttp2_ext_aux_data;
|
|
|
|
|
2014-09-30 14:45:15 +02:00
|
|
|
/* Additional data which cannot be stored in nghttp2_frame struct */
|
|
|
|
typedef union {
|
2014-10-02 17:59:44 +02:00
|
|
|
nghttp2_data_aux_data data;
|
2014-09-30 14:45:15 +02:00
|
|
|
nghttp2_headers_aux_data headers;
|
2014-11-28 14:59:13 +01:00
|
|
|
nghttp2_goaway_aux_data goaway;
|
2016-03-29 16:29:26 +02:00
|
|
|
nghttp2_ext_aux_data ext;
|
2014-09-30 14:45:15 +02:00
|
|
|
} nghttp2_aux_data;
|
|
|
|
|
2015-04-24 15:30:32 +02:00
|
|
|
struct nghttp2_outbound_item;
|
|
|
|
typedef struct nghttp2_outbound_item nghttp2_outbound_item;
|
|
|
|
|
|
|
|
struct nghttp2_outbound_item {
|
2014-10-02 17:59:44 +02:00
|
|
|
nghttp2_frame frame;
|
2016-04-03 16:03:34 +02:00
|
|
|
/* Storage for extension frame payload. frame->ext.payload points
|
|
|
|
to this structure to avoid frequent memory allocation. */
|
|
|
|
nghttp2_ext_frame_payload ext_frame_payload;
|
2014-09-30 14:45:15 +02:00
|
|
|
nghttp2_aux_data aux_data;
|
2015-04-16 14:38:13 +02:00
|
|
|
/* The priority used in priority comparion. Smaller is served
|
|
|
|
ealier. For PING, SETTINGS and non-DATA frames (excluding
|
|
|
|
response HEADERS frame) have dedicated cycle value defined above.
|
|
|
|
For DATA frame, cycle is computed by taking into account of
|
|
|
|
effective weight and frame payload length previously sent, so
|
|
|
|
that the amount of transmission is distributed across streams
|
|
|
|
proportional to effective weight (inside a tree). */
|
2014-05-08 16:07:29 +02:00
|
|
|
uint64_t cycle;
|
2015-04-24 15:30:32 +02:00
|
|
|
nghttp2_outbound_item *qnext;
|
2015-08-16 12:01:10 +02:00
|
|
|
/* nonzero if this object is queued, except for DATA or HEADERS
|
|
|
|
which are attached to stream as item. */
|
2014-03-25 18:04:24 +01:00
|
|
|
uint8_t queued;
|
2015-04-24 15:30:32 +02:00
|
|
|
};
|
2012-02-19 15:42:25 +01:00
|
|
|
|
2015-04-24 19:23:01 +02:00
|
|
|
/*
|
|
|
|
* Initializes |item|. No memory allocation is done in this function.
|
|
|
|
* Don't call nghttp2_outbound_item_free() until frame member is
|
|
|
|
* initialized.
|
|
|
|
*/
|
|
|
|
void nghttp2_outbound_item_init(nghttp2_outbound_item *item);
|
|
|
|
|
2012-02-19 15:42:25 +01:00
|
|
|
/*
|
|
|
|
* Deallocates resource for |item|. If |item| is NULL, this function
|
|
|
|
* does nothing.
|
|
|
|
*/
|
2014-12-07 15:07:13 +01:00
|
|
|
void nghttp2_outbound_item_free(nghttp2_outbound_item *item, nghttp2_mem *mem);
|
2012-02-19 15:42:25 +01:00
|
|
|
|
2015-04-24 15:30:32 +02:00
|
|
|
/*
|
|
|
|
* queue for nghttp2_outbound_item.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
nghttp2_outbound_item *head, *tail;
|
|
|
|
/* number of items in this queue. */
|
|
|
|
size_t n;
|
|
|
|
} nghttp2_outbound_queue;
|
|
|
|
|
|
|
|
void nghttp2_outbound_queue_init(nghttp2_outbound_queue *q);
|
|
|
|
|
|
|
|
/* Pushes |item| into |q| */
|
|
|
|
void nghttp2_outbound_queue_push(nghttp2_outbound_queue *q,
|
|
|
|
nghttp2_outbound_item *item);
|
|
|
|
|
|
|
|
/* Pops |item| at the top from |q|. If |q| is empty, nothing
|
|
|
|
happens. */
|
|
|
|
void nghttp2_outbound_queue_pop(nghttp2_outbound_queue *q);
|
|
|
|
|
|
|
|
/* Returns the top item. */
|
|
|
|
#define nghttp2_outbound_queue_top(Q) ((Q)->head)
|
|
|
|
|
|
|
|
/* Returns the size of the queue */
|
|
|
|
#define nghttp2_outbound_queue_size(Q) ((Q)->n)
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#endif /* NGHTTP2_OUTBOUND_ITEM_H */
|