Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: components/grpc_support/include/bidirectional_stream_c.h

Issue 2492703002: Third try at landing gRPC refactoring. Previous issue failed on the waterfall (Closed)
Patch Set: Change DCHECK Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/grpc_support/include/DEPS ('k') | components/grpc_support/include/headers.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_ 5 #ifndef COMPONENTS_GRPC_SUPPORT_INCLUDE_BIDIRECTIONAL_STREAM_C_H_
6 #define COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_ 6 #define COMPONENTS_GRPC_SUPPORT_INCLUDE_BIDIRECTIONAL_STREAM_C_H_
7 7
8 #define CRONET_EXPORT __attribute__((visibility("default"))) 8 #if defined(WIN32)
9 #define GRPC_SUPPORT_EXPORT
10 #else
11 #define GRPC_SUPPORT_EXPORT __attribute__((visibility("default")))
12 #endif
9 13
10 #ifdef __cplusplus 14 #ifdef __cplusplus
11 extern "C" { 15 extern "C" {
12 #endif 16 #endif
13 17
14 #include <stddef.h> 18 #include <stddef.h>
15 19
16 /* Cronet Engine API. */ 20 /* Engine API. */
17 21
18 /* Opaque object representing Cronet Engine. Created and configured outside 22 /* Opaque object representing a Bidirectional stream creating engine. Created
19 * of this API to facilitate sharing with other components */ 23 * and configured outside of this API to facilitate sharing with other
20 typedef struct cronet_engine { 24 * components */
25 typedef struct stream_engine {
21 void* obj; 26 void* obj;
22 void* annotation; 27 void* annotation;
23 } cronet_engine; 28 } stream_engine;
24 29
25 /* Cronet Bidirectional Stream API */ 30 /* Bidirectional Stream API */
26 31
27 /* Opaque object representing Cronet Bidirectional Stream. */ 32 /* Opaque object representing Bidirectional Stream. */
28 typedef struct cronet_bidirectional_stream { 33 typedef struct bidirectional_stream {
29 void* obj; 34 void* obj;
30 void* annotation; 35 void* annotation;
31 } cronet_bidirectional_stream; 36 } bidirectional_stream;
32 37
33 /* A single request or response header element. */ 38 /* A single request or response header element. */
34 typedef struct cronet_bidirectional_stream_header { 39 typedef struct bidirectional_stream_header {
35 const char* key; 40 const char* key;
36 const char* value; 41 const char* value;
37 } cronet_bidirectional_stream_header; 42 } bidirectional_stream_header;
38 43
39 /* Array of request or response headers or trailers. */ 44 /* Array of request or response headers or trailers. */
40 typedef struct cronet_bidirectional_stream_header_array { 45 typedef struct bidirectional_stream_header_array {
41 size_t count; 46 size_t count;
42 size_t capacity; 47 size_t capacity;
43 cronet_bidirectional_stream_header* headers; 48 bidirectional_stream_header* headers;
44 } cronet_bidirectional_stream_header_array; 49 } bidirectional_stream_header_array;
45 50
46 /* Set of callbacks used to receive callbacks from bidirectional stream. */ 51 /* Set of callbacks used to receive callbacks from bidirectional stream. */
47 typedef struct cronet_bidirectional_stream_callback { 52 typedef struct bidirectional_stream_callback {
48 /* Invoked when the stream is ready for reading and writing. 53 /* Invoked when the stream is ready for reading and writing.
49 * Consumer may call cronet_bidirectional_stream_read() to start reading data. 54 * Consumer may call bidirectional_stream_read() to start reading data.
50 * Consumer may call cronet_bidirectional_stream_write() to start writing 55 * Consumer may call bidirectional_stream_write() to start writing
51 * data. 56 * data.
52 */ 57 */
53 void (*on_stream_ready)(cronet_bidirectional_stream* stream); 58 void (*on_stream_ready)(bidirectional_stream* stream);
54 59
55 /* Invoked when initial response headers are received. 60 /* Invoked when initial response headers are received.
56 * Consumer must call cronet_bidirectional_stream_read() to start reading. 61 * Consumer must call bidirectional_stream_read() to start reading.
57 * Consumer may call cronet_bidirectional_stream_write() to start writing or 62 * Consumer may call bidirectional_stream_write() to start writing or
58 * close the stream. Contents of |headers| is valid for duration of the call. 63 * close the stream. Contents of |headers| is valid for duration of the call.
59 */ 64 */
60 void (*on_response_headers_received)( 65 void (*on_response_headers_received)(
61 cronet_bidirectional_stream* stream, 66 bidirectional_stream* stream,
62 const cronet_bidirectional_stream_header_array* headers, 67 const bidirectional_stream_header_array* headers,
63 const char* negotiated_protocol); 68 const char* negotiated_protocol);
64 69
65 /* Invoked when data is read into the buffer passed to 70 /* Invoked when data is read into the buffer passed to
66 * cronet_bidirectional_stream_read(). Only part of the buffer may be 71 * bidirectional_stream_read(). Only part of the buffer may be
67 * populated. To continue reading, call cronet_bidirectional_stream_read(). 72 * populated. To continue reading, call bidirectional_stream_read().
68 * It may be invoked after on_response_trailers_received()}, if there was 73 * It may be invoked after on_response_trailers_received()}, if there was
69 * pending read data before trailers were received. 74 * pending read data before trailers were received.
70 * 75 *
71 * If |bytes_read| is 0, it means the remote side has signaled that it will 76 * If |bytes_read| is 0, it means the remote side has signaled that it will
72 * send no more data; future calls to cronet_bidirectional_stream_read() 77 * send no more data; future calls to bidirectional_stream_read()
73 * will result in the on_data_read() callback or on_succeded() callback if 78 * will result in the on_data_read() callback or on_succeded() callback if
74 * cronet_bidirectional_stream_write() was invoked with end_of_stream set to 79 * bidirectional_stream_write() was invoked with end_of_stream set to
75 * true. 80 * true.
76 */ 81 */
77 void (*on_read_completed)(cronet_bidirectional_stream* stream, 82 void (*on_read_completed)(bidirectional_stream* stream,
78 char* data, 83 char* data,
79 int bytes_read); 84 int bytes_read);
80 85
81 /** 86 /**
82 * Invoked when all data passed to cronet_bidirectional_stream_write() is 87 * Invoked when all data passed to bidirectional_stream_write() is
83 * sent. To continue writing, call cronet_bidirectional_stream_write(). 88 * sent. To continue writing, call bidirectional_stream_write().
84 */ 89 */
85 void (*on_write_completed)(cronet_bidirectional_stream* stream, 90 void (*on_write_completed)(bidirectional_stream* stream, const char* data);
86 const char* data);
87 91
88 /* Invoked when trailers are received before closing the stream. Only invoked 92 /* Invoked when trailers are received before closing the stream. Only invoked
89 * when server sends trailers, which it may not. May be invoked while there is 93 * when server sends trailers, which it may not. May be invoked while there is
90 * read data remaining in local buffer. Contents of |trailers| is valid for 94 * read data remaining in local buffer. Contents of |trailers| is valid for
91 * duration of the call. 95 * duration of the call.
92 */ 96 */
93 void (*on_response_trailers_received)( 97 void (*on_response_trailers_received)(
94 cronet_bidirectional_stream* stream, 98 bidirectional_stream* stream,
95 const cronet_bidirectional_stream_header_array* trailers); 99 const bidirectional_stream_header_array* trailers);
96 100
97 /** 101 /**
98 * Invoked when there is no data to be read or written and the stream is 102 * Invoked when there is no data to be read or written and the stream is
99 * closed successfully remotely and locally. Once invoked, no further callback 103 * closed successfully remotely and locally. Once invoked, no further callback
100 * methods will be invoked. 104 * methods will be invoked.
101 */ 105 */
102 void (*on_succeded)(cronet_bidirectional_stream* stream); 106 void (*on_succeded)(bidirectional_stream* stream);
103 107
104 /** 108 /**
105 * Invoked if the stream failed for any reason after 109 * Invoked if the stream failed for any reason after
106 * cronet_bidirectional_stream_start(). HTTP/2 error codes are 110 * bidirectional_stream_start(). HTTP/2 error codes are
107 * mapped to chrome net error codes. Once invoked, no further callback methods 111 * mapped to chrome net error codes. Once invoked, no further callback methods
108 * will be invoked. 112 * will be invoked.
109 */ 113 */
110 void (*on_failed)(cronet_bidirectional_stream* stream, int net_error); 114 void (*on_failed)(bidirectional_stream* stream, int net_error);
111 115
112 /** 116 /**
113 * Invoked if the stream was canceled via 117 * Invoked if the stream was canceled via
114 * cronet_bidirectional_stream_cancel(). Once invoked, no further callback 118 * bidirectional_stream_cancel(). Once invoked, no further callback
115 * methods will be invoked. 119 * methods will be invoked.
116 */ 120 */
117 void (*on_canceled)(cronet_bidirectional_stream* stream); 121 void (*on_canceled)(bidirectional_stream* stream);
118 } cronet_bidirectional_stream_callback; 122 } bidirectional_stream_callback;
119 123
120 /* Creates a new stream object that uses |engine| and |callback|. All stream 124 /* Creates a new stream object that uses |engine| and |callback|. All stream
121 * tasks are performed asynchronously on the |engine| network thread. |callback| 125 * tasks are performed asynchronously on the |engine| network thread. |callback|
122 * methods are invoked synchronously on the |engine| network thread, but must 126 * methods are invoked synchronously on the |engine| network thread, but must
123 * not run tasks on the current thread to prevent blocking networking operations 127 * not run tasks on the current thread to prevent blocking networking operations
124 * and causing exceptions during shutdown. The |annotation| is stored in 128 * and causing exceptions during shutdown. The |annotation| is stored in
125 * bidirectional stream for arbitrary use by application. 129 * bidirectional stream for arbitrary use by application.
126 * 130 *
127 * Returned |cronet_bidirectional_stream*| is owned by the caller, and must be 131 * Returned |bidirectional_stream*| is owned by the caller, and must be
128 * destroyed using |cronet_bidirectional_stream_destroy|. 132 * destroyed using |bidirectional_stream_destroy|.
129 * 133 *
130 * Both |calback| and |engine| must remain valid until stream is destroyed. 134 * Both |calback| and |engine| must remain valid until stream is destroyed.
131 */ 135 */
132 CRONET_EXPORT 136 GRPC_SUPPORT_EXPORT
133 cronet_bidirectional_stream* cronet_bidirectional_stream_create( 137 bidirectional_stream* bidirectional_stream_create(
134 cronet_engine* engine, 138 stream_engine* engine,
135 void* annotation, 139 void* annotation,
136 cronet_bidirectional_stream_callback* callback); 140 bidirectional_stream_callback* callback);
137 141
138 /* TBD: The following methods return int. Should it be a custom type? */ 142 /* TBD: The following methods return int. Should it be a custom type? */
139 143
140 /* Destroys stream object. Destroy could be called from any thread, including 144 /* Destroys stream object. Destroy could be called from any thread, including
141 * network thread, but is posted, so |stream| is valid until calling task is 145 * network thread, but is posted, so |stream| is valid until calling task is
142 * complete. 146 * complete.
143 */ 147 */
144 CRONET_EXPORT 148 GRPC_SUPPORT_EXPORT
145 int cronet_bidirectional_stream_destroy(cronet_bidirectional_stream* stream); 149 int bidirectional_stream_destroy(bidirectional_stream* stream);
146 150
147 /** 151 /**
148 * Disables or enables auto flush. By default, data is flushed after 152 * Disables or enables auto flush. By default, data is flushed after
149 * every cronet_bidirectional_stream_write(). If the auto flush is disabled, 153 * every bidirectional_stream_write(). If the auto flush is disabled,
150 * the client should explicitly call cronet_bidirectional_stream_flush to flush 154 * the client should explicitly call bidirectional_stream_flush to flush
151 * the data. 155 * the data.
152 */ 156 */
153 CRONET_EXPORT void cronet_bidirectional_stream_disable_auto_flush( 157 GRPC_SUPPORT_EXPORT void bidirectional_stream_disable_auto_flush(
154 cronet_bidirectional_stream* stream, 158 bidirectional_stream* stream,
155 bool disable_auto_flush); 159 bool disable_auto_flush);
156 160
157 /** 161 /**
158 * Delays sending request headers until cronet_bidirectional_stream_flush() 162 * Delays sending request headers until bidirectional_stream_flush()
159 * is called. This flag is currently only respected when QUIC is negotiated. 163 * is called. This flag is currently only respected when QUIC is negotiated.
160 * When true, QUIC will send request header frame along with data frame(s) 164 * When true, QUIC will send request header frame along with data frame(s)
161 * as a single packet when possible. 165 * as a single packet when possible.
162 */ 166 */
163 CRONET_EXPORT 167 GRPC_SUPPORT_EXPORT
164 void cronet_bidirectional_stream_delay_request_headers_until_flush( 168 void bidirectional_stream_delay_request_headers_until_flush(
165 cronet_bidirectional_stream* stream, 169 bidirectional_stream* stream,
166 bool delay_headers_until_flush); 170 bool delay_headers_until_flush);
167 171
168 /* Starts the stream by sending request to |url| using |method| and |headers|. 172 /* Starts the stream by sending request to |url| using |method| and |headers|.
169 * If |end_of_stream| is true, then no data is expected to be written. The 173 * If |end_of_stream| is true, then no data is expected to be written. The
170 * |method| is HTTP verb, with PUT having a special meaning to mark idempotent 174 * |method| is HTTP verb, with PUT having a special meaning to mark idempotent
171 * request, which could use QUIC 0-RTT. 175 * request, which could use QUIC 0-RTT.
172 */ 176 */
173 CRONET_EXPORT 177 GRPC_SUPPORT_EXPORT
174 int cronet_bidirectional_stream_start( 178 int bidirectional_stream_start(bidirectional_stream* stream,
175 cronet_bidirectional_stream* stream, 179 const char* url,
176 const char* url, 180 int priority,
177 int priority, 181 const char* method,
178 const char* method, 182 const bidirectional_stream_header_array* headers,
179 const cronet_bidirectional_stream_header_array* headers, 183 bool end_of_stream);
180 bool end_of_stream);
181 184
182 /* Reads response data into |buffer| of |capacity| length. Must only be called 185 /* Reads response data into |buffer| of |capacity| length. Must only be called
183 * at most once in response to each invocation of the 186 * at most once in response to each invocation of the
184 * on_stream_ready()/on_response_headers_received() and on_read_completed() 187 * on_stream_ready()/on_response_headers_received() and on_read_completed()
185 * methods of the cronet_bidirectional_stream_callback. 188 * methods of the bidirectional_stream_callback.
186 * Each call will result in an invocation of the callback's 189 * Each call will result in an invocation of the callback's
187 * on_read_completed() method if data is read, or its on_failed() method if 190 * on_read_completed() method if data is read, or its on_failed() method if
188 * there's an error. The callback's on_succeeded() method is also invoked if 191 * there's an error. The callback's on_succeeded() method is also invoked if
189 * there is no more data to read and |end_of_stream| was previously sent. 192 * there is no more data to read and |end_of_stream| was previously sent.
190 */ 193 */
191 CRONET_EXPORT 194 GRPC_SUPPORT_EXPORT
192 int cronet_bidirectional_stream_read(cronet_bidirectional_stream* stream, 195 int bidirectional_stream_read(bidirectional_stream* stream,
193 char* buffer, 196 char* buffer,
194 int capacity); 197 int capacity);
195 198
196 /* Writes request data from |buffer| of |buffer_length| length. If auto flush is 199 /* Writes request data from |buffer| of |buffer_length| length. If auto flush is
197 * disabled, data will be sent only after cronet_bidirectional_stream_flush() is 200 * disabled, data will be sent only after bidirectional_stream_flush() is
198 * called. 201 * called.
199 * Each call will result in an invocation the callback's on_write_completed() 202 * Each call will result in an invocation the callback's on_write_completed()
200 * method if data is sent, or its on_failed() method if there's an error. 203 * method if data is sent, or its on_failed() method if there's an error.
201 * The callback's on_succeeded() method is also invoked if |end_of_stream| is 204 * The callback's on_succeeded() method is also invoked if |end_of_stream| is
202 * set and all response data has been read. 205 * set and all response data has been read.
203 */ 206 */
204 CRONET_EXPORT 207 GRPC_SUPPORT_EXPORT
205 int cronet_bidirectional_stream_write(cronet_bidirectional_stream* stream, 208 int bidirectional_stream_write(bidirectional_stream* stream,
206 const char* buffer, 209 const char* buffer,
207 int buffer_length, 210 int buffer_length,
208 bool end_of_stream); 211 bool end_of_stream);
209 212
210 /** 213 /**
211 * Flushes pending writes. This method should not be called before invocation of 214 * Flushes pending writes. This method should not be called before invocation of
212 * on_stream_ready() method of the cronet_bidirectional_stream_callback. 215 * on_stream_ready() method of the bidirectional_stream_callback.
213 * For each previously called cronet_bidirectional_stream_write() 216 * For each previously called bidirectional_stream_write()
214 * a corresponding on_write_completed() callback will be invoked when the buffer 217 * a corresponding on_write_completed() callback will be invoked when the buffer
215 * is sent. 218 * is sent.
216 */ 219 */
217 CRONET_EXPORT 220 GRPC_SUPPORT_EXPORT
218 void cronet_bidirectional_stream_flush(cronet_bidirectional_stream* stream); 221 void bidirectional_stream_flush(bidirectional_stream* stream);
219 222
220 /* Cancels the stream. Can be called at any time after 223 /* Cancels the stream. Can be called at any time after
221 * cronet_bidirectional_stream_start(). The on_canceled() method of 224 * bidirectional_stream_start(). The on_canceled() method of
222 * cronet_bidirectional_stream_callback will be invoked when cancelation 225 * bidirectional_stream_callback will be invoked when cancelation
223 * is complete and no further callback methods will be invoked. If the 226 * is complete and no further callback methods will be invoked. If the
224 * stream has completed or has not started, calling 227 * stream has completed or has not started, calling
225 * cronet_bidirectional_stream_cancel() has no effect and on_canceled() will not 228 * bidirectional_stream_cancel() has no effect and on_canceled() will not
226 * be invoked. At most one callback method may be invoked after 229 * be invoked. At most one callback method may be invoked after
227 * cronet_bidirectional_stream_cancel() has completed. 230 * bidirectional_stream_cancel() has completed.
228 */ 231 */
229 CRONET_EXPORT 232 GRPC_SUPPORT_EXPORT
230 void cronet_bidirectional_stream_cancel(cronet_bidirectional_stream* stream); 233 void bidirectional_stream_cancel(bidirectional_stream* stream);
231 234
232 /* Returns true if the |stream| was successfully started and is now done 235 /* Returns true if the |stream| was successfully started and is now done
233 * (succeeded, canceled, or failed). 236 * (succeeded, canceled, or failed).
234 * Returns false if the |stream| stream is not yet started or is in progress. 237 * Returns false if the |stream| stream is not yet started or is in progress.
235 */ 238 */
236 CRONET_EXPORT 239 GRPC_SUPPORT_EXPORT
237 bool cronet_bidirectional_stream_is_done(cronet_bidirectional_stream* stream); 240 bool bidirectional_stream_is_done(bidirectional_stream* stream);
238 241
239 #ifdef __cplusplus 242 #ifdef __cplusplus
240 } 243 }
241 #endif 244 #endif
242 245
243 #endif // COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_ 246 #endif // COMPONENTS_GRPC_SUPPORT_INCLUDE_BIDIRECTIONAL_STREAM_H_
OLDNEW
« no previous file with comments | « components/grpc_support/include/DEPS ('k') | components/grpc_support/include/headers.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698