tizen 2.4 release
[external/nghttp2.git] / lib / nghttp2_outbound_item.h
1 /*
2  * nghttp2 - HTTP/2 C Library
3  *
4  * Copyright (c) 2012 Tatsuhiro Tsujikawa
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #ifndef NGHTTP2_OUTBOUND_ITEM_H
26 #define NGHTTP2_OUTBOUND_ITEM_H
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif /* HAVE_CONFIG_H */
31
32 #include <nghttp2/nghttp2.h>
33 #include "nghttp2_frame.h"
34 #include "nghttp2_mem.h"
35
36 /* A bit higher weight for non-DATA frames */
37 #define NGHTTP2_OB_EX_WEIGHT 300
38 /* Higher weight for SETTINGS */
39 #define NGHTTP2_OB_SETTINGS_WEIGHT 301
40 /* Highest weight for PING */
41 #define NGHTTP2_OB_PING_WEIGHT 302
42
43 /* struct used for HEADERS and PUSH_PROMISE frame */
44 typedef struct {
45   nghttp2_data_provider data_prd;
46   void *stream_user_data;
47   /* nonzero if this item should be attached to stream object to make
48      it under priority control */
49   uint8_t attach_stream;
50 } nghttp2_headers_aux_data;
51
52 /* struct used for DATA frame */
53 typedef struct {
54   /**
55    * The data to be sent for this DATA frame.
56    */
57   nghttp2_data_provider data_prd;
58   /**
59    * The flags of DATA frame.  We use separate flags here and
60    * nghttp2_data frame.  The latter contains flags actually sent to
61    * peer.  This |flags| may contain NGHTTP2_FLAG_END_STREAM and only
62    * when |eof| becomes nonzero, flags in nghttp2_data has
63    * NGHTTP2_FLAG_END_STREAM set.
64    */
65   uint8_t flags;
66   /**
67    * The flag to indicate whether EOF was reached or not. Initially
68    * |eof| is 0. It becomes 1 after all data were read.
69    */
70   uint8_t eof;
71 } nghttp2_data_aux_data;
72
73 typedef enum {
74   NGHTTP2_GOAWAY_AUX_NONE = 0x0,
75   /* indicates that session should be terminated after the
76      transmission of this frame. */
77   NGHTTP2_GOAWAY_AUX_TERM_ON_SEND = 0x1,
78   /* indicates that this GOAWAY is just a notification for graceful
79      shutdown.  No nghttp2_session.goaway_flags should be updated on
80      the reaction to this frame. */
81   NGHTTP2_GOAWAY_AUX_SHUTDOWN_NOTICE = 0x2,
82 } nghttp2_goaway_aux_flag;
83
84 /* struct used for GOAWAY frame */
85 typedef struct {
86   /* bitwise-OR of one or more of nghttp2_goaway_aux_flag. */
87   uint8_t flags;
88 } nghttp2_goaway_aux_data;
89
90 /* Additional data which cannot be stored in nghttp2_frame struct */
91 typedef union {
92   nghttp2_data_aux_data data;
93   nghttp2_headers_aux_data headers;
94   nghttp2_goaway_aux_data goaway;
95 } nghttp2_aux_data;
96
97 typedef struct {
98   nghttp2_frame frame;
99   nghttp2_aux_data aux_data;
100   int64_t seq;
101   /* Reset count of weight. See comment for last_cycle in
102      nghttp2_session.h */
103   uint64_t cycle;
104   /* The priority used in priority comparion.  Larger is served
105      ealier. */
106   int32_t weight;
107   /* nonzero if this object is queued. */
108   uint8_t queued;
109 } nghttp2_outbound_item;
110
111 /*
112  * Deallocates resource for |item|. If |item| is NULL, this function
113  * does nothing.
114  */
115 void nghttp2_outbound_item_free(nghttp2_outbound_item *item, nghttp2_mem *mem);
116
117 #endif /* NGHTTP2_OUTBOUND_ITEM_H */