GRPC Core  0.11.0.0
 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>
39 #include <grpc/support/slice.h>
40 #include <grpc/support/time.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 */
53  /* Begin a message/metadata element/status - as defined by
54  grpc_message_type. */
56  /* Add a slice of data to the current message/metadata element/status.
57  Must not overflow the forward declared length. */
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 */
71  /* Write flags for the message: see grpc.h GRPC_WRITE_* for the public bits,
72  * GRPC_WRITE_INTERNAL_* for the internal ones. */
75 
76 typedef struct grpc_linked_mdelem {
80  void *reserved;
82 
83 typedef struct grpc_mdelem_list {
87 
88 typedef struct grpc_metadata_batch {
100 
104  grpc_metadata_batch *add);
105 
109  grpc_metadata_batch *src);
110 
117  grpc_linked_mdelem *storage);
124  grpc_linked_mdelem *storage);
125 
133  grpc_linked_mdelem *storage,
134  grpc_mdelem *elem_to_add);
142  grpc_linked_mdelem *storage,
143  grpc_mdelem *elem_to_add);
144 
150  grpc_mdelem *(*filter)(void *user_data,
151  grpc_mdelem *elem),
152  void *user_data);
153 
154 #ifndef NDEBUG
156 #else
157 #define grpc_metadata_batch_assert_ok(comd) \
158  do { \
159  } while (0)
160 #endif
161 
162 /* Represents a single operation performed on a stream/transport */
163 typedef struct grpc_stream_op {
164  /* the operation to be applied */
166  /* the arguments to this operation. union fields are named according to the
167  associated op-code */
168  union {
172  } data;
174 
177 typedef struct grpc_stream_op_buffer {
179  size_t nops;
180  size_t capacity;
183 
184 /* Initialize a stream op buffer */
186 /* Destroy a stream op buffer */
188 /* Reset a sopb to no elements */
190 /* Swap two sopbs */
192 
194 
195 /* Append a GRPC_NO_OP to a buffer */
197 /* Append a GRPC_OP_BEGIN to a buffer */
199  gpr_uint32 flags);
201  grpc_metadata_batch metadata);
202 /* Append a GRPC_SLICE to a buffer - does not ref/unref the slice */
204 /* Append a buffer to a buffer - does not ref/unref any internal objects */
206  size_t nops);
207 
209 
211 
212 #endif /* GRPC_INTERNAL_CORE_TRANSPORT_STREAM_OP_H */
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:296
grpc_metadata_batch metadata
Definition: stream_op.h:170
grpc_stream_op_code
Definition: stream_op.h:48
void grpc_sopb_add_metadata(grpc_stream_op_buffer *sopb, grpc_metadata_batch metadata)
Definition: stream_op.c:140
struct grpc_metadata_batch grpc_metadata_batch
#define GRPC_SOPB_INLINE_ELEMENTS
Definition: stream_op.h:44
Definition: stream_op.h:88
char * grpc_sopb_string(grpc_stream_op_buffer *sopb)
Definition: transport_op_string.c:72
size_t capacity
Definition: stream_op.h:180
gpr_uint32 length
Definition: stream_op.h:70
struct grpc_stream_op grpc_stream_op
void grpc_sopb_swap(grpc_stream_op_buffer *a, grpc_stream_op_buffer *b)
Definition: stream_op.c:61
Definition: stream_op.h:51
void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd)
Definition: stream_op.c:199
void grpc_sopb_reset(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:56
grpc_mdelem * md
Definition: stream_op.h:77
grpc_stream_op * ops
Definition: stream_op.h:178
gpr_uint32 flags
Definition: stream_op.h:73
uint32_t gpr_uint32
Definition: port_platform.h:312
void grpc_sopb_append(grpc_stream_op_buffer *sopb, grpc_stream_op *ops, size_t nops)
Definition: stream_op.c:153
struct grpc_mdelem_list grpc_mdelem_list
grpc_linked_mdelem * tail
Definition: stream_op.h:85
struct grpc_linked_mdelem * prev
Definition: stream_op.h:79
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
void grpc_metadata_batch_init(grpc_metadata_batch *batch)
Definition: stream_op.c:205
Definition: stream_op.h:55
void grpc_metadata_batch_merge(grpc_metadata_batch *target, grpc_metadata_batch *add)
Definition: stream_op.c:276
grpc_linked_mdelem * head
Definition: stream_op.h:84
Definition: metadata.h:78
gpr_slice slice
Definition: stream_op.h:171
struct grpc_begin_message grpc_begin_message
struct grpc_stream_op_buffer grpc_stream_op_buffer
A stream op buffer is a wrapper around stream operations that is dynamically extendable.
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
void * reserved
Definition: stream_op.h:80
void grpc_sopb_destroy(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:51
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:290
size_t nops
Definition: stream_op.h:179
void grpc_sopb_init(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:45
Definition: stream_op.h:76
enum grpc_stream_op_code type
Definition: stream_op.h:165
void grpc_sopb_add_slice(grpc_stream_op_buffer *sopb, gpr_slice slice)
Definition: stream_op.c:147
void grpc_sopb_add_begin_message(grpc_stream_op_buffer *sopb, gpr_uint32 length, gpr_uint32 flags)
Definition: stream_op.c:132
Definition: stream_op.h:52
union grpc_stream_op::@24 data
Definition: stream_op.h:68
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
void grpc_stream_ops_unref_owned_objects(grpc_stream_op *ops, size_t nops)
Definition: stream_op.c:89
void grpc_sopb_move_to(grpc_stream_op_buffer *src, grpc_stream_op_buffer *dst)
Definition: stream_op.c:166
grpc_mdelem_list list
Metadata elements in this batch.
Definition: stream_op.h:90
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:271
Definition: time.h:63
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:98
grpc_begin_message begin_message
Definition: stream_op.h:169
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:94
Definition: stream_op.h:163
A stream op buffer is a wrapper around stream operations that is dynamically extendable.
Definition: stream_op.h:177
struct grpc_linked_mdelem * next
Definition: stream_op.h:78
Definition: stream_op.h:58
grpc_stream_op inlined_ops[4]
Definition: stream_op.h:181
Definition: slice.h:79
void grpc_metadata_batch_destroy(grpc_metadata_batch *batch)
Definition: stream_op.c:211
Definition: stream_op.h:83
void grpc_sopb_add_no_op(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:128
struct grpc_linked_mdelem grpc_linked_mdelem