GRPC Core  0.11.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 
85 
90 
91  /* Indexes correspond to grpc_context_index enum values */
94 
96 typedef struct grpc_transport_op {
113  void (*set_accept_stream)(void *user_data, grpc_transport *transport,
114  const void *server_data);
123 
124 /* Returns the amount of memory required to store a grpc_stream for this
125  transport */
126 size_t grpc_transport_stream_size(grpc_transport *transport);
127 
128 /* Initialize transport data for a stream.
129 
130  Returns 0 on success, any other (transport-defined) value for failure.
131 
132  Arguments:
133  transport - the transport on which to create this stream
134  stream - a pointer to uninitialized memory to initialize
135  server_data - either NULL for a client initiated stream, or a pointer
136  supplied from the accept_stream callback function */
138  const void *server_data,
139  grpc_transport_stream_op *initial_op);
140 
141 /* Destroy transport data for a stream.
142 
143  Requires: a recv_batch with final_state == GRPC_STREAM_CLOSED has been
144  received by the up-layer. Must not be called in the same call stack as
145  recv_frame.
146 
147  Arguments:
148  transport - the transport on which to create this stream
149  stream - the grpc_stream to destroy (memory is still owned by the
150  caller, but any child memory must be cleaned up) */
152  grpc_stream *stream);
153 
155 
157  grpc_status_code status);
158 
160  grpc_status_code status,
161  gpr_slice *optional_message);
162 
164 
165 /* Send a batch of operations on a transport
166 
167  Takes ownership of any objects contained in ops.
168 
169  Arguments:
170  transport - the transport on which to initiate the stream
171  stream - the stream on which to send the operations. This must be
172  non-NULL and previously initialized by the same transport.
173  op - a grpc_transport_stream_op specifying the op to perform */
175  grpc_stream *stream,
177 
179  grpc_transport_op *op);
180 
181 /* Send a ping on a transport
182 
183  Calls cb with user data when a response is received. */
185 
186 /* Advise peer of pending connection termination. */
188  gpr_slice debug_data);
189 
190 /* Close a transport. Aborts all open streams. */
191 void grpc_transport_close(grpc_transport *transport);
192 
193 /* Destroy the transport */
194 void grpc_transport_destroy(grpc_transport *transport);
195 
196 /* Get the transports peer */
197 char *grpc_transport_get_peer(grpc_transport *transport);
198 
199 #endif /* GRPC_INTERNAL_CORE_TRANSPORT_TRANSPORT_H */
Definition: transport.h:59
grpc_connectivity_state
Connectivity state of a channel.
Definition: grpc.h:145
int grpc_transport_init_stream(grpc_transport *transport, grpc_stream *stream, const void *server_data, grpc_transport_stream_op *initial_op)
Definition: transport.c:47
void grpc_transport_perform_op(grpc_transport *transport, grpc_transport_op *op)
Definition: transport.c:60
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:65
Definition: transport.h:55
void grpc_transport_ping(grpc_transport *transport, grpc_iomgr_closure *cb)
gpr_slice * goaway_message
Definition: transport.h:110
void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op, grpc_status_code status)
Definition: transport.c:87
struct grpc_stream grpc_stream
Definition: transport.h:50
size_t grpc_transport_stream_size(grpc_transport *transport)
Definition: transport.c:39
Definition: transport.h:66
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:312
void grpc_transport_destroy(grpc_transport *transport)
Definition: transport.c:43
grpc_stream_state * recv_state
Definition: transport.h:74
Definition: transport.h:61
Definition: pollset_posix.h:55
char * grpc_transport_get_peer(grpc_transport *transport)
Definition: transport.c:70
grpc_pollset_set * bind_pollset_set
add this transport to a pollset_set
Definition: transport.h:119
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:98
void grpc_transport_stream_op_add_close(grpc_transport_stream_op *op, grpc_status_code status, gpr_slice *optional_message)
Definition: transport.c:117
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:100
grpc_stream_state
Definition: transport.h:53
void grpc_transport_close(grpc_transport *transport)
void * set_accept_stream_user_data
Definition: transport.h:115
grpc_connectivity_state * connectivity_state
Definition: transport.h:101
grpc_iomgr_closure * on_consumed
Definition: transport.h:67
grpc_status_code goaway_status
what should the goaway contain?
Definition: transport.h:109
grpc_stream_op_buffer * send_ops
Definition: transport.h:69
grpc_status_code cancel_with_status
If != GRPC_STATUS_OK, cancel this stream.
Definition: transport.h:84
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:113
grpc_status_code close_with_status
If != GRPC_STATUS_OK, send grpc-status, grpc-message, and close this stream for both reading and writ...
Definition: transport.h:88
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:117
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:107
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:54
Definition: pollset_set_posix.h:40
Definition: transport_impl.h:67
int disconnect
should the transport be disconnected
Definition: transport.h:103
A stream op buffer is a wrapper around stream operations that is dynamically extendable.
Definition: stream_op.h:177
grpc_call_context_element * context
Definition: transport.h:92
Definition: slice.h:79
Transport op: a set of operations to perform on a transport as a whole.
Definition: transport.h:96
gpr_slice * optional_close_message
Definition: transport.h:89
void grpc_transport_stream_op_finish_with_failure(grpc_transport_stream_op *op)
Definition: transport.c:74
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:121