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
transport.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_TRANSPORT_H
35 #define GRPC_INTERNAL_CORE_TRANSPORT_TRANSPORT_H
36
37 #include <stddef.h>
38
39 #include "src/core/iomgr/pollset.h"
40 #include "src/core/iomgr/pollset_set.h"
41 #include "src/core/transport/stream_op.h"
42 #include "src/core/channel/context.h"
43
44 /* forward declarations */
45 typedef struct grpc_transport grpc_transport;
46
47 /* grpc_stream doesn't actually exist. It's used as a typesafe
48 opaque pointer for whatever data the transport wants to track
49 for a stream. */
50 typedef struct grpc_stream grpc_stream;
51
52 /* Represents the send/recv closed state of a stream. */
53 typedef enum grpc_stream_state {
54 /* the stream is open for sends and receives */
55 GRPC_STREAM_OPEN,
56 /* the stream is closed for sends, but may still receive data */
57 GRPC_STREAM_SEND_CLOSED,
58 /* the stream is closed for receives, but may still send data */
59 GRPC_STREAM_RECV_CLOSED,
60 /* the stream is closed for both sends and receives */
61 GRPC_STREAM_CLOSED
62 } grpc_stream_state;
63
64 /* Transport stream op: a set of operations to perform on a transport
65 against a single stream */
66 typedef struct grpc_transport_stream_op {
67 grpc_iomgr_closure *on_consumed;
68
69 grpc_stream_op_buffer *send_ops;
70 int is_last_send;
71 grpc_iomgr_closure *on_done_send;
72
73 grpc_stream_op_buffer *recv_ops;
74 grpc_stream_state *recv_state;
78 gpr_uint32 max_recv_bytes;
79 grpc_iomgr_closure *on_done_recv;
80
81 grpc_pollset *bind_pollset;
82
83 grpc_status_code cancel_with_status;
84
85 /* Indexes correspond to grpc_context_index enum values */
86 grpc_call_context_element *context;
87 } grpc_transport_stream_op;
88
90 typedef struct grpc_transport_op {
92 grpc_iomgr_closure *on_consumed;
94 grpc_iomgr_closure *on_connectivity_state_change;
95 grpc_connectivity_state *connectivity_state;
97 int disconnect;
101 int send_goaway;
103 grpc_status_code goaway_status;
104 gpr_slice *goaway_message;
107 void (*set_accept_stream)(void *user_data, grpc_transport *transport,
108 const void *server_data);
109 void *set_accept_stream_user_data;
111 grpc_pollset *bind_pollset;
113 grpc_pollset_set *bind_pollset_set;
115 grpc_iomgr_closure *send_ping;
116 } grpc_transport_op;
117
118 /* Returns the amount of memory required to store a grpc_stream for this
119 transport */
120 size_t grpc_transport_stream_size(grpc_transport *transport);
121
122 /* Initialize transport data for a stream.
123
124 Returns 0 on success, any other (transport-defined) value for failure.
125
126 Arguments:
127 transport - the transport on which to create this stream
128 stream - a pointer to uninitialized memory to initialize
129 server_data - either NULL for a client initiated stream, or a pointer
130 supplied from the accept_stream callback function */
131 int grpc_transport_init_stream(grpc_transport *transport, grpc_stream *stream,
132 const void *server_data,
133 grpc_transport_stream_op *initial_op);
134
135 /* Destroy transport data for a stream.
136
137 Requires: a recv_batch with final_state == GRPC_STREAM_CLOSED has been
138 received by the up-layer. Must not be called in the same call stack as
139 recv_frame.
140
141 Arguments:
142 transport - the transport on which to create this stream
143 stream - the grpc_stream to destroy (memory is still owned by the
144 caller, but any child memory must be cleaned up) */
145 void grpc_transport_destroy_stream(grpc_transport *transport,
146 grpc_stream *stream);
147
148 void grpc_transport_stream_op_finish_with_failure(grpc_transport_stream_op *op);
149
150 void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op,
151 grpc_status_code status,
152 grpc_mdstr *message);
153
154 char *grpc_transport_stream_op_string(grpc_transport_stream_op *op);
155
156 /* Send a batch of operations on a transport
157
158 Takes ownership of any objects contained in ops.
159
160 Arguments:
161 transport - the transport on which to initiate the stream
162 stream - the stream on which to send the operations. This must be
163 non-NULL and previously initialized by the same transport.
164 op - a grpc_transport_stream_op specifying the op to perform */
165 void grpc_transport_perform_stream_op(grpc_transport *transport,
166 grpc_stream *stream,
167 grpc_transport_stream_op *op);
168
169 void grpc_transport_perform_op(grpc_transport *transport,
170 grpc_transport_op *op);
171
172 /* Send a ping on a transport
173
174 Calls cb with user data when a response is received. */
175 void grpc_transport_ping(grpc_transport *transport, grpc_iomgr_closure *cb);
176
177 /* Advise peer of pending connection termination. */
178 void grpc_transport_goaway(grpc_transport *transport, grpc_status_code status,
179 gpr_slice debug_data);
180
181 /* Close a transport. Aborts all open streams. */
182 void grpc_transport_close(grpc_transport *transport);
183
184 /* Destroy the transport */
185 void grpc_transport_destroy(grpc_transport *transport);
186
187 /* Get the transports peer */
188 char *grpc_transport_get_peer(grpc_transport *transport);
189
190 #endif /* GRPC_INTERNAL_CORE_TRANSPORT_TRANSPORT_H */
GRPC_STREAM_RECV_CLOSED
Definition: transport.h:59
grpc_connectivity_state
grpc_connectivity_state
Connectivity state of a channel.
Definition: grpc.h:139
grpc_transport_init_stream
int grpc_transport_init_stream(grpc_transport *transport, grpc_stream *stream, const void *server_data, grpc_transport_stream_op *initial_op)
Definition: transport.c:45
grpc_transport_perform_op
void grpc_transport_perform_op(grpc_transport *transport, grpc_transport_op *op)
Definition: transport.c:58
grpc_transport_stream_op::is_last_send
int is_last_send
Definition: transport.h:70
grpc_transport_stream_op::recv_ops
grpc_stream_op_buffer * recv_ops
Definition: transport.h:73
grpc_transport_destroy_stream
void grpc_transport_destroy_stream(grpc_transport *transport, grpc_stream *stream)
Definition: transport.c:63
GRPC_STREAM_OPEN
Definition: transport.h:55
grpc_transport_ping
void grpc_transport_ping(grpc_transport *transport, grpc_iomgr_closure *cb)
grpc_transport_op::goaway_message
gpr_slice * goaway_message
Definition: transport.h:104
grpc_stream
struct grpc_stream grpc_stream
Definition: transport.h:50
grpc_transport_stream_size
size_t grpc_transport_stream_size(grpc_transport *transport)
Definition: transport.c:37
grpc_transport_stream_op
Definition: transport.h:66
grpc_mdstr
Definition: metadata.h:70
grpc_transport_op
struct grpc_transport_op grpc_transport_op
Transport op: a set of operations to perform on a transport as a whole.
pollset.h
gpr_uint32
uint32_t gpr_uint32
Definition: port_platform.h:309
grpc_transport_destroy
void grpc_transport_destroy(grpc_transport *transport)
Definition: transport.c:41
grpc_transport_stream_op::recv_state
grpc_stream_state * recv_state
Definition: transport.h:74
GRPC_STREAM_CLOSED
Definition: transport.h:61
grpc_pollset
Definition: pollset_posix.h:48
grpc_transport_get_peer
char * grpc_transport_get_peer(grpc_transport *transport)
Definition: transport.c:68
grpc_transport_op::bind_pollset_set
grpc_pollset_set * bind_pollset_set
add this transport to a pollset_set
Definition: transport.h:113
grpc_transport_stream_op::max_recv_bytes
gpr_uint32 max_recv_bytes
The number of bytes this peer is currently prepared to receive.
Definition: transport.h:78
grpc_transport_op::on_consumed
grpc_iomgr_closure * on_consumed
called when processing of this op is done
Definition: transport.h:92
grpc_transport_stream_op_string
char * grpc_transport_stream_op_string(grpc_transport_stream_op *op)
Definition: transport_op_string.c:108
grpc_transport_op::on_connectivity_state_change
grpc_iomgr_closure * on_connectivity_state_change
connectivity monitoring
Definition: transport.h:94
grpc_stream_state
grpc_stream_state
Definition: transport.h:53
grpc_transport_close
void grpc_transport_close(grpc_transport *transport)
grpc_transport_op::set_accept_stream_user_data
void * set_accept_stream_user_data
Definition: transport.h:109
grpc_transport_stream_op_add_cancellation
void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op, grpc_status_code status, grpc_mdstr *message)
Definition: transport.c:85
grpc_transport_op::connectivity_state
grpc_connectivity_state * connectivity_state
Definition: transport.h:95
grpc_transport_stream_op::on_consumed
grpc_iomgr_closure * on_consumed
Definition: transport.h:67
grpc_transport_op::goaway_status
grpc_status_code goaway_status
what should the goaway contain?
Definition: transport.h:103
grpc_transport_stream_op::send_ops
grpc_stream_op_buffer * send_ops
Definition: transport.h:69
grpc_transport_stream_op::cancel_with_status
grpc_status_code cancel_with_status
Definition: transport.h:83
GRPC_STREAM_SEND_CLOSED
Definition: transport.h:57
grpc_iomgr_closure
A closure over a grpc_iomgr_cb_func.
Definition: iomgr.h:45
grpc_transport_op::set_accept_stream
void(* set_accept_stream)(void *user_data, grpc_transport *transport, const void *server_data)
set the callback for accepting new streams; this is a permanent callback, unlike the other one-shot c...
Definition: transport.h:107
grpc_transport_goaway
void grpc_transport_goaway(grpc_transport *transport, grpc_status_code status, gpr_slice debug_data)
grpc_transport_op::bind_pollset
grpc_pollset * bind_pollset
add this transport to a pollset
Definition: transport.h:111
grpc_call_context_element
Definition: context.h:44
grpc_transport_stream_op::bind_pollset
grpc_pollset * bind_pollset
Definition: transport.h:81
grpc_transport_stream_op::on_done_recv
grpc_iomgr_closure * on_done_recv
Definition: transport.h:79
context.h
grpc_transport_op::send_goaway
int send_goaway
should we send a goaway? after a goaway is sent, once there are no more active calls on the transport...
Definition: transport.h:101
pollset_set.h
grpc_transport_stream_op::on_done_send
grpc_iomgr_closure * on_done_send
Definition: transport.h:71
stream_op.h
grpc_status_code
grpc_status_code
Definition: status.h:41
grpc_transport_perform_stream_op
void grpc_transport_perform_stream_op(grpc_transport *transport, grpc_stream *stream, grpc_transport_stream_op *op)
Definition: transport.c:52
grpc_pollset_set
Definition: pollset_set_posix.h:40
grpc_transport
Definition: transport_impl.h:67
grpc_transport_op::disconnect
int disconnect
should the transport be disconnected
Definition: transport.h:97
grpc_stream_op_buffer
A stream op buffer is a wrapper around stream operations that is dynamically extendable.
Definition: stream_op.h:176
grpc_transport_stream_op::context
grpc_call_context_element * context
Definition: transport.h:86
gpr_slice
Definition: slice.h:79
grpc_transport_op
Transport op: a set of operations to perform on a transport as a whole.
Definition: transport.h:90
grpc_transport_stream_op_finish_with_failure
void grpc_transport_stream_op_finish_with_failure(grpc_transport_stream_op *op)
Definition: transport.c:72
grpc_transport_stream_op
struct grpc_transport_stream_op grpc_transport_stream_op
grpc_transport_op::send_ping
grpc_iomgr_closure * send_ping
send a ping, call this back if not NULL
Definition: transport.h:115