GRPC Core  0.10.0.0
 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"
43 
44 /* forward declarations */
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 */
56  /* the stream is closed for sends, but may still receive data */
58  /* the stream is closed for receives, but may still send data */
60  /* the stream is closed for both sends and receives */
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 {
68 
72 
80 
82 
84 
85  /* Indexes correspond to grpc_context_index enum values */
88 
90 typedef struct grpc_transport_op {
107  void (*set_accept_stream)(void *user_data, grpc_transport *transport,
108  const void *server_data);
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 */
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) */
146  grpc_stream *stream);
147 
149 
151  grpc_status_code status,
152  grpc_mdstr *message);
153 
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 */
166  grpc_stream *stream,
168 
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. */
176 
177 /* Advise peer of pending connection termination. */
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 */
Definition: transport.h:59
grpc_connectivity_state
Connectivity state of a channel.
Definition: grpc.h:139
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
void grpc_transport_perform_op(grpc_transport *transport, grpc_transport_op *op)
Definition: transport.c:58
int is_last_send
Definition: transport.h:70
grpc_stream_op_buffer * recv_ops
Definition: transport.h:73
void grpc_transport_destroy_stream(grpc_transport *transport, grpc_stream *stream)
Definition: transport.c:63
Definition: transport.h:55
void grpc_transport_ping(grpc_transport *transport, grpc_iomgr_closure *cb)
gpr_slice * goaway_message
Definition: transport.h:104
struct grpc_stream grpc_stream
Definition: transport.h:50
size_t grpc_transport_stream_size(grpc_transport *transport)
Definition: transport.c:37
Definition: transport.h:66
Definition: metadata.h:70
struct grpc_transport_op grpc_transport_op
Transport op: a set of operations to perform on a transport as a whole.
uint32_t gpr_uint32
Definition: port_platform.h:309
void grpc_transport_destroy(grpc_transport *transport)
Definition: transport.c:41
grpc_stream_state * recv_state
Definition: transport.h:74
Definition: transport.h:61
Definition: pollset_posix.h:48
char * grpc_transport_get_peer(grpc_transport *transport)
Definition: transport.c:68
grpc_pollset_set * bind_pollset_set
add this transport to a pollset_set
Definition: transport.h:113
gpr_uint32 max_recv_bytes
The number of bytes this peer is currently prepared to receive.
Definition: transport.h:78
grpc_iomgr_closure * on_consumed
called when processing of this op is done
Definition: transport.h:92
char * grpc_transport_stream_op_string(grpc_transport_stream_op *op)
Definition: transport_op_string.c:108
grpc_iomgr_closure * on_connectivity_state_change
connectivity monitoring
Definition: transport.h:94
grpc_stream_state
Definition: transport.h:53
void grpc_transport_close(grpc_transport *transport)
void * set_accept_stream_user_data
Definition: transport.h:109
void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op, grpc_status_code status, grpc_mdstr *message)
Definition: transport.c:85
grpc_connectivity_state * connectivity_state
Definition: transport.h:95
grpc_iomgr_closure * on_consumed
Definition: transport.h:67
grpc_status_code goaway_status
what should the goaway contain?
Definition: transport.h:103
grpc_stream_op_buffer * send_ops
Definition: transport.h:69
grpc_status_code cancel_with_status
Definition: transport.h:83
Definition: transport.h:57
A closure over a grpc_iomgr_cb_func.
Definition: iomgr.h:45
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
void grpc_transport_goaway(grpc_transport *transport, grpc_status_code status, gpr_slice debug_data)
grpc_pollset * bind_pollset
add this transport to a pollset
Definition: transport.h:111
Definition: context.h:44
grpc_pollset * bind_pollset
Definition: transport.h:81
grpc_iomgr_closure * on_done_recv
Definition: transport.h:79
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
grpc_iomgr_closure * on_done_send
Definition: transport.h:71
grpc_status_code
Definition: status.h:41
void grpc_transport_perform_stream_op(grpc_transport *transport, grpc_stream *stream, grpc_transport_stream_op *op)
Definition: transport.c:52
Definition: pollset_set_posix.h:40
Definition: transport_impl.h:67
int disconnect
should the transport be disconnected
Definition: transport.h:97
A stream op buffer is a wrapper around stream operations that is dynamically extendable.
Definition: stream_op.h:176
grpc_call_context_element * context
Definition: transport.h:86
Definition: slice.h:79
Transport op: a set of operations to perform on a transport as a whole.
Definition: transport.h:90
void grpc_transport_stream_op_finish_with_failure(grpc_transport_stream_op *op)
Definition: transport.c:72
struct grpc_transport_stream_op grpc_transport_stream_op
grpc_iomgr_closure * send_ping
send a ping, call this back if not NULL
Definition: transport.h:115