GRPC Core  0.10.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 {
81 
82 typedef struct grpc_mdelem_list {
86 
87 typedef struct grpc_metadata_batch {
99 
103  grpc_metadata_batch *add);
104 
108  grpc_metadata_batch *src);
109 
116  grpc_linked_mdelem *storage);
123  grpc_linked_mdelem *storage);
124 
132  grpc_linked_mdelem *storage,
133  grpc_mdelem *elem_to_add);
141  grpc_linked_mdelem *storage,
142  grpc_mdelem *elem_to_add);
143 
149  grpc_mdelem *(*filter)(void *user_data,
150  grpc_mdelem *elem),
151  void *user_data);
152 
153 #ifndef NDEBUG
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 */
165  /* the arguments to this operation. union fields are named according to the
166  associated op-code */
167  union {
171  } data;
173 
176 typedef struct grpc_stream_op_buffer {
178  size_t nops;
179  size_t capacity;
182 
183 /* Initialize a stream op buffer */
185 /* Destroy a stream op buffer */
187 /* Reset a sopb to no elements */
189 /* Swap two sopbs */
191 
193 
194 /* Append a GRPC_NO_OP to a buffer */
196 /* Append a GRPC_OP_BEGIN to a buffer */
198  gpr_uint32 flags);
200  grpc_metadata_batch metadata);
201 /* Append a GRPC_SLICE to a buffer - does not ref/unref the slice */
203 /* Append a buffer to a buffer - does not ref/unref any internal objects */
205  size_t nops);
206 
208 
210 
211 #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:295
grpc_metadata_batch metadata
Definition: stream_op.h:169
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
union grpc_stream_op::@22 data
#define GRPC_SOPB_INLINE_ELEMENTS
Definition: stream_op.h:44
Definition: stream_op.h:87
char * grpc_sopb_string(grpc_stream_op_buffer *sopb)
Definition: transport_op_string.c:72
size_t capacity
Definition: stream_op.h:179
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:177
gpr_uint32 flags
Definition: stream_op.h:73
uint32_t gpr_uint32
Definition: port_platform.h:309
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:84
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:275
grpc_linked_mdelem * head
Definition: stream_op.h:83
Definition: metadata.h:78
gpr_slice slice
Definition: stream_op.h:170
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 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:289
size_t nops
Definition: stream_op.h:178
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:164
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
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:89
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
Definition: time.h:60
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_begin_message begin_message
Definition: stream_op.h:168
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
Definition: stream_op.h:162
A stream op buffer is a wrapper around stream operations that is dynamically extendable.
Definition: stream_op.h:176
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:180
Definition: slice.h:79
void grpc_metadata_batch_destroy(grpc_metadata_batch *batch)
Definition: stream_op.c:211
Definition: stream_op.h:82
void grpc_sopb_add_no_op(grpc_stream_op_buffer *sopb)
Definition: stream_op.c:128
struct grpc_linked_mdelem grpc_linked_mdelem