GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
stream_op.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright 2015, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
34 #ifndef GRPC_INTERNAL_CORE_TRANSPORT_STREAM_OP_H
35 #define GRPC_INTERNAL_CORE_TRANSPORT_STREAM_OP_H
36
37 #include <grpc/grpc.h>
38 #include <grpc/support/port_platform.h>
39 #include <grpc/support/slice.h>
40 #include <grpc/support/time.h>
41 #include "src/core/transport/metadata.h"
42
43 /* this many stream ops are inlined into a sopb before allocating */
44 #define GRPC_SOPB_INLINE_ELEMENTS 4
45
46 /* Operations that can be performed on a stream.
47 Used by grpc_stream_op. */
48 typedef enum grpc_stream_op_code {
49 /* Do nothing code. Useful if rewriting a batch to exclude some operations.
50 Must be ignored by receivers */
51 GRPC_NO_OP,
52 GRPC_OP_METADATA,
53 /* Begin a message/metadata element/status - as defined by
54 grpc_message_type. */
55 GRPC_OP_BEGIN_MESSAGE,
56 /* Add a slice of data to the current message/metadata element/status.
57 Must not overflow the forward declared length. */
58 GRPC_OP_SLICE
59 } grpc_stream_op_code;
60
63 #define GRPC_WRITE_INTERNAL_COMPRESS (0x80000000u)
64
65 #define GRPC_WRITE_INTERNAL_USED_MASK (GRPC_WRITE_INTERNAL_COMPRESS)
66
67 /* Arguments for GRPC_OP_BEGIN_MESSAGE */
68 typedef struct grpc_begin_message {
69 /* How many bytes of data will this message contain */
70 gpr_uint32 length;
71 /* Write flags for the message: see grpc.h GRPC_WRITE_* for the public bits,
72 * GRPC_WRITE_INTERNAL_* for the internal ones. */
73 gpr_uint32 flags;
74 } grpc_begin_message;
75
76 typedef struct grpc_linked_mdelem {
77 grpc_mdelem *md;
78 struct grpc_linked_mdelem *next;
79 struct grpc_linked_mdelem *prev;
80 } grpc_linked_mdelem;
81
82 typedef struct grpc_mdelem_list {
83 grpc_linked_mdelem *head;
84 grpc_linked_mdelem *tail;
85 } grpc_mdelem_list;
86
87 typedef struct grpc_metadata_batch {
89 grpc_mdelem_list list;
93 grpc_mdelem_list garbage;
97 gpr_timespec deadline;
98 } grpc_metadata_batch;
99
100 void grpc_metadata_batch_init(grpc_metadata_batch *batch);
101 void grpc_metadata_batch_destroy(grpc_metadata_batch *batch);
102 void grpc_metadata_batch_merge(grpc_metadata_batch *target,
103 grpc_metadata_batch *add);
104
107 void grpc_metadata_batch_move(grpc_metadata_batch *dst,
108 grpc_metadata_batch *src);
109
115 void grpc_metadata_batch_link_head(grpc_metadata_batch *batch,
116 grpc_linked_mdelem *storage);
122 void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch,
123 grpc_linked_mdelem *storage);
124
131 void grpc_metadata_batch_add_head(grpc_metadata_batch *batch,
132 grpc_linked_mdelem *storage,
133 grpc_mdelem *elem_to_add);
140 void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch,
141 grpc_linked_mdelem *storage,
142 grpc_mdelem *elem_to_add);
143
148 void grpc_metadata_batch_filter(grpc_metadata_batch *batch,
149 grpc_mdelem *(*filter)(void *user_data,
150 grpc_mdelem *elem),
151 void *user_data);
152
153 #ifndef NDEBUG
154 void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd);
155 #else
156 #define grpc_metadata_batch_assert_ok(comd) \
157 do { \
158 } while (0)
159 #endif
160
161 /* Represents a single operation performed on a stream/transport */
162 typedef struct grpc_stream_op {
163 /* the operation to be applied */
164 enum grpc_stream_op_code type;
165 /* the arguments to this operation. union fields are named according to the
166 associated op-code */
167 union {
168 grpc_begin_message begin_message;
169 grpc_metadata_batch metadata;
170 gpr_slice slice;
171 } data;
172 } grpc_stream_op;
173
176 typedef struct grpc_stream_op_buffer {
177 grpc_stream_op *ops;
178 size_t nops;
179 size_t capacity;
180 grpc_stream_op inlined_ops[GRPC_SOPB_INLINE_ELEMENTS];
181 } grpc_stream_op_buffer;
182
183 /* Initialize a stream op buffer */
184 void grpc_sopb_init(grpc_stream_op_buffer *sopb);
185 /* Destroy a stream op buffer */
186 void grpc_sopb_destroy(grpc_stream_op_buffer *sopb);
187 /* Reset a sopb to no elements */
188 void grpc_sopb_reset(grpc_stream_op_buffer *sopb);
189 /* Swap two sopbs */
190 void grpc_sopb_swap(grpc_stream_op_buffer *a, grpc_stream_op_buffer *b);
191
192 void grpc_stream_ops_unref_owned_objects(grpc_stream_op *ops, size_t nops);
193
194 /* Append a GRPC_NO_OP to a buffer */
195 void grpc_sopb_add_no_op(grpc_stream_op_buffer *sopb);
196 /* Append a GRPC_OP_BEGIN to a buffer */
197 void grpc_sopb_add_begin_message(grpc_stream_op_buffer *sopb, gpr_uint32 length,
198 gpr_uint32 flags);
199 void grpc_sopb_add_metadata(grpc_stream_op_buffer *sopb,
200 grpc_metadata_batch metadata);
201 /* Append a GRPC_SLICE to a buffer - does not ref/unref the slice */
202 void grpc_sopb_add_slice(grpc_stream_op_buffer *sopb, gpr_slice slice);
203 /* Append a buffer to a buffer - does not ref/unref any internal objects */
204 void grpc_sopb_append(grpc_stream_op_buffer *sopb, grpc_stream_op *ops,
205 size_t nops);
206
207 void grpc_sopb_move_to(grpc_stream_op_buffer *src, grpc_stream_op_buffer *dst);
208
209 char *grpc_sopb_string(grpc_stream_op_buffer *sopb);
210
211 #endif /* GRPC_INTERNAL_CORE_TRANSPORT_STREAM_OP_H */
grpc_metadata_batch_filter
void grpc_metadata_batch_filter(grpc_metadata_batch *batch, grpc_mdelem *(*filter)(void *user_data, grpc_mdelem *elem), void *user_data)
For each element in batch, execute filter.
Definition: stream_op.c:295
grpc_stream_op::metadata
grpc_metadata_batch metadata
Definition: stream_op.h:169
grpc_stream_op_code
grpc_stream_op_code
Definition: stream_op.h:48
grpc_sopb_add_metadata
void grpc_sopb_add_metadata(grpc_stream_op_buffer *sopb, grpc_metadata_batch metadata)
Definition: stream_op.c:140
port_platform.h
grpc_metadata_batch
struct grpc_metadata_batch grpc_metadata_batch
grpc_stream_op::data
union grpc_stream_op::@22 data
GRPC_SOPB_INLINE_ELEMENTS
#define GRPC_SOPB_INLINE_ELEMENTS
Definition: stream_op.h:44
grpc_metadata_batch
Definition: stream_op.h:87
time.h
grpc_sopb_string
char * grpc_sopb_string(grpc_stream_op_buffer *sopb)
Definition: transport_op_string.c:72
grpc_stream_op_buffer::capacity
size_t capacity
Definition: stream_op.h:179
grpc_begin_message::length
gpr_uint32 length
Definition: stream_op.h:70
grpc_stream_op
struct grpc_stream_op grpc_stream_op
grpc_sopb_swap
void grpc_sopb_swap(grpc_stream_op_buffer *a, grpc_stream_op_buffer *b)
Definition: stream_op.c:61
GRPC_NO_OP
Definition: stream_op.h:51
metadata.h
grpc_metadata_batch_assert_ok
void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd)
Definition: stream_op.c:199
grpc_sopb_reset
void grpc_sopb_reset(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:56
grpc_linked_mdelem::md
grpc_mdelem * md
Definition: stream_op.h:77
grpc_stream_op_buffer::ops
grpc_stream_op * ops
Definition: stream_op.h:177
grpc_begin_message::flags
gpr_uint32 flags
Definition: stream_op.h:73
gpr_uint32
uint32_t gpr_uint32
Definition: port_platform.h:309
grpc_sopb_append
void grpc_sopb_append(grpc_stream_op_buffer *sopb, grpc_stream_op *ops, size_t nops)
Definition: stream_op.c:153
grpc_mdelem_list
struct grpc_mdelem_list grpc_mdelem_list
grpc_mdelem_list::tail
grpc_linked_mdelem * tail
Definition: stream_op.h:84
grpc_linked_mdelem::prev
struct grpc_linked_mdelem * prev
Definition: stream_op.h:79
grpc_metadata_batch_add_head
void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem *elem_to_add)
Add elem_to_add as the first element in batch, using storage as backing storage for the linked list e...
Definition: stream_op.c:221
grpc_metadata_batch_init
void grpc_metadata_batch_init(grpc_metadata_batch *batch)
Definition: stream_op.c:205
GRPC_OP_BEGIN_MESSAGE
Definition: stream_op.h:55
grpc_metadata_batch_merge
void grpc_metadata_batch_merge(grpc_metadata_batch *target, grpc_metadata_batch *add)
Definition: stream_op.c:275
grpc_mdelem_list::head
grpc_linked_mdelem * head
Definition: stream_op.h:83
grpc_mdelem
Definition: metadata.h:78
grpc_stream_op::slice
gpr_slice slice
Definition: stream_op.h:170
grpc_begin_message
struct grpc_begin_message grpc_begin_message
grpc_stream_op_buffer
struct grpc_stream_op_buffer grpc_stream_op_buffer
A stream op buffer is a wrapper around stream operations that is dynamically extendable.
grpc_metadata_batch_link_head
void grpc_metadata_batch_link_head(grpc_metadata_batch *batch, grpc_linked_mdelem *storage)
Add storage to the beginning of batch.
Definition: stream_op.c:243
grpc_sopb_destroy
void grpc_sopb_destroy(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:51
grpc_metadata_batch_move
void grpc_metadata_batch_move(grpc_metadata_batch *dst, grpc_metadata_batch *src)
Moves the metadata information from src to dst.
Definition: stream_op.c:289
grpc_stream_op_buffer::nops
size_t nops
Definition: stream_op.h:178
grpc_sopb_init
void grpc_sopb_init(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:45
grpc_linked_mdelem
Definition: stream_op.h:76
grpc_stream_op::type
enum grpc_stream_op_code type
Definition: stream_op.h:164
grpc_sopb_add_slice
void grpc_sopb_add_slice(grpc_stream_op_buffer *sopb, gpr_slice slice)
Definition: stream_op.c:147
grpc_sopb_add_begin_message
void grpc_sopb_add_begin_message(grpc_stream_op_buffer *sopb, gpr_uint32 length, gpr_uint32 flags)
Definition: stream_op.c:132
GRPC_OP_METADATA
Definition: stream_op.h:52
grpc_begin_message
Definition: stream_op.h:68
slice.h
grpc_metadata_batch_add_tail
void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem *elem_to_add)
Add elem_to_add as the last element in batch, using storage as backing storage for the linked list el...
Definition: stream_op.c:248
grpc_stream_ops_unref_owned_objects
void grpc_stream_ops_unref_owned_objects(grpc_stream_op *ops, size_t nops)
Definition: stream_op.c:89
grpc_sopb_move_to
void grpc_sopb_move_to(grpc_stream_op_buffer *src, grpc_stream_op_buffer *dst)
Definition: stream_op.c:166
grpc_metadata_batch::list
grpc_mdelem_list list
Metadata elements in this batch.
Definition: stream_op.h:89
grpc_metadata_batch_link_tail
void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, grpc_linked_mdelem *storage)
Add storage to the end of batch.
Definition: stream_op.c:270
gpr_timespec
Definition: time.h:60
grpc_metadata_batch::deadline
gpr_timespec deadline
Used to calculate grpc-timeout at the point of sending, or gpr_inf_future if this batch does not need...
Definition: stream_op.h:97
grpc_stream_op::begin_message
grpc_begin_message begin_message
Definition: stream_op.h:168
grpc_metadata_batch::garbage
grpc_mdelem_list garbage
Elements that have been removed from the batch, but have not yet been unreffed - used to allow collec...
Definition: stream_op.h:93
grpc_stream_op
Definition: stream_op.h:162
grpc_stream_op_buffer
A stream op buffer is a wrapper around stream operations that is dynamically extendable.
Definition: stream_op.h:176
grpc.h
grpc_linked_mdelem::next
struct grpc_linked_mdelem * next
Definition: stream_op.h:78
GRPC_OP_SLICE
Definition: stream_op.h:58
grpc_stream_op_buffer::inlined_ops
grpc_stream_op inlined_ops[4]
Definition: stream_op.h:180
gpr_slice
Definition: slice.h:79
grpc_metadata_batch_destroy
void grpc_metadata_batch_destroy(grpc_metadata_batch *batch)
Definition: stream_op.c:211
grpc_mdelem_list
Definition: stream_op.h:82
grpc_sopb_add_no_op
void grpc_sopb_add_no_op(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:128
grpc_linked_mdelem
struct grpc_linked_mdelem grpc_linked_mdelem