blob: 434e75dd15ed22b9c3a80708ec91746d1f022cad [file] [log] [blame]
Craig Tiller17effab2015-08-04 08:19:36 -07001/*
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#include "test/core/end2end/fixtures/proxy.h"
35
36#include <string.h>
37
38#include <grpc/support/alloc.h>
39#include <grpc/support/host_port.h>
40#include <grpc/support/log.h>
41#include <grpc/support/sync.h>
42#include <grpc/support/thd.h>
43#include <grpc/support/useful.h>
44
45#include "test/core/util/port.h"
46
Craig Tillera82950e2015-09-22 12:33:20 -070047struct grpc_end2end_proxy {
Craig Tiller17effab2015-08-04 08:19:36 -070048 gpr_thd_id thd;
49 char *proxy_port;
50 char *server_port;
51 grpc_completion_queue *cq;
52 grpc_server *server;
53 grpc_channel *client;
54
Craig Tiller402acf62015-08-05 10:43:10 -070055 int shutdown;
56
Craig Tiller17effab2015-08-04 08:19:36 -070057 /* requested call */
58 grpc_call *new_call;
59 grpc_call_details new_call_details;
60 grpc_metadata_array new_call_metadata;
61};
62
Craig Tillera82950e2015-09-22 12:33:20 -070063typedef struct {
64 void (*func)(void *arg, int success);
Craig Tiller17effab2015-08-04 08:19:36 -070065 void *arg;
66} closure;
67
Craig Tillera82950e2015-09-22 12:33:20 -070068typedef struct {
Craig Tiller17effab2015-08-04 08:19:36 -070069 gpr_refcount refs;
Craig Tiller402acf62015-08-05 10:43:10 -070070 grpc_end2end_proxy *proxy;
Craig Tiller17effab2015-08-04 08:19:36 -070071
72 grpc_call *c2p;
73 grpc_call *p2s;
74
75 grpc_metadata_array c2p_initial_metadata;
76 grpc_metadata_array p2s_initial_metadata;
77
78 grpc_byte_buffer *c2p_msg;
79 grpc_byte_buffer *p2s_msg;
80
81 grpc_metadata_array p2s_trailing_metadata;
82 grpc_status_code p2s_status;
83 char *p2s_status_details;
84 size_t p2s_status_details_capacity;
85
86 int c2p_server_cancelled;
87} proxy_call;
88
Craig Tillera82950e2015-09-22 12:33:20 -070089static void thread_main(void *arg);
90static void request_call(grpc_end2end_proxy *proxy);
Craig Tiller17effab2015-08-04 08:19:36 -070091
Craig Tillera82950e2015-09-22 12:33:20 -070092grpc_end2end_proxy *grpc_end2end_proxy_create(
93 const grpc_end2end_proxy_def *def) {
94 gpr_thd_options opt = gpr_thd_options_default();
95 int proxy_port = grpc_pick_unused_port_or_die();
96 int server_port = grpc_pick_unused_port_or_die();
Craig Tiller17effab2015-08-04 08:19:36 -070097
Craig Tillera82950e2015-09-22 12:33:20 -070098 grpc_end2end_proxy *proxy = gpr_malloc(sizeof(*proxy));
99 memset(proxy, 0, sizeof(*proxy));
Craig Tiller17effab2015-08-04 08:19:36 -0700100
Craig Tillera82950e2015-09-22 12:33:20 -0700101 gpr_join_host_port(&proxy->proxy_port, "localhost", proxy_port);
102 gpr_join_host_port(&proxy->server_port, "localhost", server_port);
Craig Tiller40cd8202015-09-22 07:24:21 -0700103
Craig Tillera82950e2015-09-22 12:33:20 -0700104 gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port,
105 proxy->server_port);
Craig Tiller40cd8202015-09-22 07:24:21 -0700106
Craig Tillera82950e2015-09-22 12:33:20 -0700107 proxy->cq = grpc_completion_queue_create(NULL);
108 proxy->server = def->create_server(proxy->proxy_port);
109 proxy->client = def->create_client(proxy->server_port);
Craig Tiller17effab2015-08-04 08:19:36 -0700110
Craig Tillera82950e2015-09-22 12:33:20 -0700111 grpc_server_register_completion_queue(proxy->server, proxy->cq, NULL);
112 grpc_server_start(proxy->server);
Craig Tiller17effab2015-08-04 08:19:36 -0700113
Craig Tillera82950e2015-09-22 12:33:20 -0700114 gpr_thd_options_set_joinable(&opt);
115 GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt));
Craig Tiller17effab2015-08-04 08:19:36 -0700116
Craig Tillera82950e2015-09-22 12:33:20 -0700117 request_call(proxy);
Craig Tiller17effab2015-08-04 08:19:36 -0700118
119 return proxy;
120}
121
Craig Tillera82950e2015-09-22 12:33:20 -0700122static closure *new_closure(void (*func)(void *arg, int success), void *arg) {
123 closure *cl = gpr_malloc(sizeof(*cl));
Craig Tiller17effab2015-08-04 08:19:36 -0700124 cl->func = func;
125 cl->arg = arg;
126 return cl;
127}
128
Craig Tillera82950e2015-09-22 12:33:20 -0700129static void shutdown_complete(void *arg, int success) {
Craig Tiller402acf62015-08-05 10:43:10 -0700130 grpc_end2end_proxy *proxy = arg;
131 proxy->shutdown = 1;
Craig Tillera82950e2015-09-22 12:33:20 -0700132 grpc_completion_queue_shutdown(proxy->cq);
Craig Tiller402acf62015-08-05 10:43:10 -0700133}
Craig Tiller17effab2015-08-04 08:19:36 -0700134
Craig Tillera82950e2015-09-22 12:33:20 -0700135void grpc_end2end_proxy_destroy(grpc_end2end_proxy *proxy) {
136 grpc_server_shutdown_and_notify(proxy->server, proxy->cq,
137 new_closure(shutdown_complete, proxy));
138 gpr_thd_join(proxy->thd);
139 gpr_free(proxy->proxy_port);
140 gpr_free(proxy->server_port);
141 grpc_server_destroy(proxy->server);
142 grpc_channel_destroy(proxy->client);
143 grpc_completion_queue_destroy(proxy->cq);
144 grpc_call_details_destroy(&proxy->new_call_details);
145 gpr_free(proxy);
Craig Tiller17effab2015-08-04 08:19:36 -0700146}
147
Craig Tillera82950e2015-09-22 12:33:20 -0700148static void unrefpc(proxy_call *pc, const char *reason) {
149 if (gpr_unref(&pc->refs)) {
150 grpc_call_destroy(pc->c2p);
151 grpc_call_destroy(pc->p2s);
152 grpc_metadata_array_destroy(&pc->c2p_initial_metadata);
153 grpc_metadata_array_destroy(&pc->p2s_initial_metadata);
154 grpc_metadata_array_destroy(&pc->p2s_trailing_metadata);
155 gpr_free(pc->p2s_status_details);
156 gpr_free(pc);
157 }
Craig Tiller17effab2015-08-04 08:19:36 -0700158}
159
Craig Tiller82e249b2015-11-11 01:14:39 +0000160static void refpc(proxy_call *pc, const char *reason) { gpr_ref(&pc->refs); }
Craig Tiller17effab2015-08-04 08:19:36 -0700161
Craig Tillera82950e2015-09-22 12:33:20 -0700162static void on_c2p_sent_initial_metadata(void *arg, int success) {
Craig Tiller17effab2015-08-04 08:19:36 -0700163 proxy_call *pc = arg;
Craig Tillera82950e2015-09-22 12:33:20 -0700164 unrefpc(pc, "on_c2p_sent_initial_metadata");
Craig Tiller17effab2015-08-04 08:19:36 -0700165}
166
Craig Tillera82950e2015-09-22 12:33:20 -0700167static void on_p2s_recv_initial_metadata(void *arg, int success) {
Craig Tiller17effab2015-08-04 08:19:36 -0700168 proxy_call *pc = arg;
169 grpc_op op;
170 grpc_call_error err;
171
Craig Tillera82950e2015-09-22 12:33:20 -0700172 if (!pc->proxy->shutdown) {
173 op.op = GRPC_OP_SEND_INITIAL_METADATA;
174 op.flags = 0;
175 op.reserved = NULL;
176 op.data.send_initial_metadata.count = pc->p2s_initial_metadata.count;
177 op.data.send_initial_metadata.metadata = pc->p2s_initial_metadata.metadata;
178 refpc(pc, "on_c2p_sent_initial_metadata");
179 err = grpc_call_start_batch(
180 pc->c2p, &op, 1, new_closure(on_c2p_sent_initial_metadata, pc), NULL);
181 GPR_ASSERT(err == GRPC_CALL_OK);
182 }
Craig Tiller17effab2015-08-04 08:19:36 -0700183
Craig Tillera82950e2015-09-22 12:33:20 -0700184 unrefpc(pc, "on_p2s_recv_initial_metadata");
Craig Tiller17effab2015-08-04 08:19:36 -0700185}
186
Craig Tillera82950e2015-09-22 12:33:20 -0700187static void on_p2s_sent_initial_metadata(void *arg, int success) {
Craig Tiller17effab2015-08-04 08:19:36 -0700188 proxy_call *pc = arg;
Craig Tillera82950e2015-09-22 12:33:20 -0700189 unrefpc(pc, "on_p2s_sent_initial_metadata");
Craig Tiller17effab2015-08-04 08:19:36 -0700190}
191
Craig Tillera82950e2015-09-22 12:33:20 -0700192static void on_c2p_recv_msg(void *arg, int success);
Craig Tiller17effab2015-08-04 08:19:36 -0700193
Craig Tillera82950e2015-09-22 12:33:20 -0700194static void on_p2s_sent_message(void *arg, int success) {
Craig Tiller17effab2015-08-04 08:19:36 -0700195 proxy_call *pc = arg;
196 grpc_op op;
197 grpc_call_error err;
198
Craig Tillera82950e2015-09-22 12:33:20 -0700199 grpc_byte_buffer_destroy(pc->c2p_msg);
200 if (!pc->proxy->shutdown && success) {
201 op.op = GRPC_OP_RECV_MESSAGE;
202 op.flags = 0;
203 op.reserved = NULL;
204 op.data.recv_message = &pc->c2p_msg;
205 refpc(pc, "on_c2p_recv_msg");
206 err = grpc_call_start_batch(pc->c2p, &op, 1,
207 new_closure(on_c2p_recv_msg, pc), NULL);
208 GPR_ASSERT(err == GRPC_CALL_OK);
209 }
Craig Tiller17effab2015-08-04 08:19:36 -0700210
Craig Tillera82950e2015-09-22 12:33:20 -0700211 unrefpc(pc, "on_p2s_sent_message");
Craig Tiller17effab2015-08-04 08:19:36 -0700212}
213
Craig Tillera82950e2015-09-22 12:33:20 -0700214static void on_p2s_sent_close(void *arg, int success) {
Craig Tiller17effab2015-08-04 08:19:36 -0700215 proxy_call *pc = arg;
Craig Tillera82950e2015-09-22 12:33:20 -0700216 unrefpc(pc, "on_p2s_sent_close");
Craig Tiller17effab2015-08-04 08:19:36 -0700217}
218
Craig Tillera82950e2015-09-22 12:33:20 -0700219static void on_c2p_recv_msg(void *arg, int success) {
Craig Tiller17effab2015-08-04 08:19:36 -0700220 proxy_call *pc = arg;
221 grpc_op op;
222 grpc_call_error err;
223
Craig Tillera82950e2015-09-22 12:33:20 -0700224 if (!pc->proxy->shutdown && success) {
225 if (pc->c2p_msg != NULL) {
Craig Tiller17effab2015-08-04 08:19:36 -0700226 op.op = GRPC_OP_SEND_MESSAGE;
227 op.flags = 0;
Craig Tiller42758992015-08-18 10:34:32 -0700228 op.reserved = NULL;
Craig Tillera82950e2015-09-22 12:33:20 -0700229 op.data.send_message = pc->c2p_msg;
230 refpc(pc, "on_p2s_sent_message");
231 err = grpc_call_start_batch(pc->p2s, &op, 1,
232 new_closure(on_p2s_sent_message, pc), NULL);
233 GPR_ASSERT(err == GRPC_CALL_OK);
234 } else {
235 op.op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
236 op.flags = 0;
237 op.reserved = NULL;
238 refpc(pc, "on_p2s_sent_close");
239 err = grpc_call_start_batch(pc->p2s, &op, 1,
240 new_closure(on_p2s_sent_close, pc), NULL);
241 GPR_ASSERT(err == GRPC_CALL_OK);
Craig Tiller45724b32015-09-22 10:42:19 -0700242 }
Craig Tillera82950e2015-09-22 12:33:20 -0700243 }
244
245 unrefpc(pc, "on_c2p_recv_msg");
Craig Tiller45724b32015-09-22 10:42:19 -0700246}
247
Craig Tillera82950e2015-09-22 12:33:20 -0700248static void on_p2s_recv_msg(void *arg, int success);
Craig Tiller45724b32015-09-22 10:42:19 -0700249
Craig Tillera82950e2015-09-22 12:33:20 -0700250static void on_c2p_sent_message(void *arg, int success) {
Craig Tiller45724b32015-09-22 10:42:19 -0700251 proxy_call *pc = arg;
252 grpc_op op;
253 grpc_call_error err;
254
Craig Tillera82950e2015-09-22 12:33:20 -0700255 grpc_byte_buffer_destroy(pc->p2s_msg);
256 if (!pc->proxy->shutdown && success) {
257 op.op = GRPC_OP_RECV_MESSAGE;
258 op.flags = 0;
259 op.reserved = NULL;
260 op.data.recv_message = &pc->p2s_msg;
261 refpc(pc, "on_p2s_recv_msg");
262 err = grpc_call_start_batch(pc->p2s, &op, 1,
263 new_closure(on_p2s_recv_msg, pc), NULL);
264 GPR_ASSERT(err == GRPC_CALL_OK);
265 }
Craig Tiller17effab2015-08-04 08:19:36 -0700266
Craig Tillera82950e2015-09-22 12:33:20 -0700267 unrefpc(pc, "on_c2p_sent_message");
Craig Tiller17effab2015-08-04 08:19:36 -0700268}
269
Craig Tillera82950e2015-09-22 12:33:20 -0700270static void on_p2s_recv_msg(void *arg, int success) {
Craig Tiller17effab2015-08-04 08:19:36 -0700271 proxy_call *pc = arg;
Craig Tillera82950e2015-09-22 12:33:20 -0700272 grpc_op op;
273 grpc_call_error err;
274
275 if (!pc->proxy->shutdown && success && pc->p2s_msg) {
276 op.op = GRPC_OP_SEND_MESSAGE;
277 op.flags = 0;
278 op.reserved = NULL;
279 op.data.send_message = pc->p2s_msg;
280 refpc(pc, "on_c2p_sent_message");
281 err = grpc_call_start_batch(pc->c2p, &op, 1,
282 new_closure(on_c2p_sent_message, pc), NULL);
283 GPR_ASSERT(err == GRPC_CALL_OK);
284 }
285 unrefpc(pc, "on_p2s_recv_msg");
Craig Tiller17effab2015-08-04 08:19:36 -0700286}
287
Craig Tillera82950e2015-09-22 12:33:20 -0700288static void on_c2p_sent_status(void *arg, int success) {
289 proxy_call *pc = arg;
290 unrefpc(pc, "on_c2p_sent_status");
291}
292
293static void on_p2s_status(void *arg, int success) {
294 proxy_call *pc = arg;
295 grpc_op op;
296 grpc_call_error err;
297
298 if (!pc->proxy->shutdown) {
299 GPR_ASSERT(success);
300 op.op = GRPC_OP_SEND_STATUS_FROM_SERVER;
301 op.flags = 0;
302 op.reserved = NULL;
303 op.data.send_status_from_server.trailing_metadata_count =
304 pc->p2s_trailing_metadata.count;
305 op.data.send_status_from_server.trailing_metadata =
306 pc->p2s_trailing_metadata.metadata;
307 op.data.send_status_from_server.status = pc->p2s_status;
308 op.data.send_status_from_server.status_details = pc->p2s_status_details;
309 refpc(pc, "on_c2p_sent_status");
310 err = grpc_call_start_batch(pc->c2p, &op, 1,
311 new_closure(on_c2p_sent_status, pc), NULL);
312 GPR_ASSERT(err == GRPC_CALL_OK);
313 }
314
315 unrefpc(pc, "on_p2s_status");
316}
317
318static void on_c2p_closed(void *arg, int success) {
319 proxy_call *pc = arg;
320 unrefpc(pc, "on_c2p_closed");
321}
322
323static void on_new_call(void *arg, int success) {
Craig Tiller17effab2015-08-04 08:19:36 -0700324 grpc_end2end_proxy *proxy = arg;
325 grpc_call_error err;
326
Craig Tillera82950e2015-09-22 12:33:20 -0700327 if (success) {
328 grpc_op op;
329 proxy_call *pc = gpr_malloc(sizeof(*pc));
330 memset(pc, 0, sizeof(*pc));
331 pc->proxy = proxy;
332 GPR_SWAP(grpc_metadata_array, pc->c2p_initial_metadata,
333 proxy->new_call_metadata);
334 pc->c2p = proxy->new_call;
335 pc->p2s = grpc_channel_create_call(
336 proxy->client, pc->c2p, GRPC_PROPAGATE_DEFAULTS, proxy->cq,
337 proxy->new_call_details.method, proxy->new_call_details.host,
338 proxy->new_call_details.deadline, NULL);
339 gpr_ref_init(&pc->refs, 1);
Craig Tiller17effab2015-08-04 08:19:36 -0700340
Craig Tillera82950e2015-09-22 12:33:20 -0700341 op.flags = 0;
342 op.reserved = NULL;
Craig Tiller17effab2015-08-04 08:19:36 -0700343
Craig Tillera82950e2015-09-22 12:33:20 -0700344 op.op = GRPC_OP_RECV_INITIAL_METADATA;
345 op.data.recv_initial_metadata = &pc->p2s_initial_metadata;
346 refpc(pc, "on_p2s_recv_initial_metadata");
347 err = grpc_call_start_batch(
348 pc->p2s, &op, 1, new_closure(on_p2s_recv_initial_metadata, pc), NULL);
349 GPR_ASSERT(err == GRPC_CALL_OK);
Craig Tiller17effab2015-08-04 08:19:36 -0700350
Craig Tillera82950e2015-09-22 12:33:20 -0700351 op.op = GRPC_OP_SEND_INITIAL_METADATA;
352 op.data.send_initial_metadata.count = pc->c2p_initial_metadata.count;
353 op.data.send_initial_metadata.metadata = pc->c2p_initial_metadata.metadata;
354 refpc(pc, "on_p2s_sent_initial_metadata");
355 err = grpc_call_start_batch(
356 pc->p2s, &op, 1, new_closure(on_p2s_sent_initial_metadata, pc), NULL);
357 GPR_ASSERT(err == GRPC_CALL_OK);
Craig Tiller17effab2015-08-04 08:19:36 -0700358
Craig Tillera82950e2015-09-22 12:33:20 -0700359 op.op = GRPC_OP_RECV_MESSAGE;
360 op.data.recv_message = &pc->c2p_msg;
361 refpc(pc, "on_c2p_recv_msg");
362 err = grpc_call_start_batch(pc->c2p, &op, 1,
363 new_closure(on_c2p_recv_msg, pc), NULL);
364 GPR_ASSERT(err == GRPC_CALL_OK);
Craig Tiller17effab2015-08-04 08:19:36 -0700365
Craig Tillera82950e2015-09-22 12:33:20 -0700366 op.op = GRPC_OP_RECV_MESSAGE;
367 op.data.recv_message = &pc->p2s_msg;
368 refpc(pc, "on_p2s_recv_msg");
369 err = grpc_call_start_batch(pc->p2s, &op, 1,
370 new_closure(on_p2s_recv_msg, pc), NULL);
371 GPR_ASSERT(err == GRPC_CALL_OK);
Craig Tiller17effab2015-08-04 08:19:36 -0700372
Craig Tillera82950e2015-09-22 12:33:20 -0700373 op.op = GRPC_OP_RECV_STATUS_ON_CLIENT;
374 op.data.recv_status_on_client.trailing_metadata =
375 &pc->p2s_trailing_metadata;
376 op.data.recv_status_on_client.status = &pc->p2s_status;
377 op.data.recv_status_on_client.status_details = &pc->p2s_status_details;
378 op.data.recv_status_on_client.status_details_capacity =
379 &pc->p2s_status_details_capacity;
380 refpc(pc, "on_p2s_status");
381 err = grpc_call_start_batch(pc->p2s, &op, 1, new_closure(on_p2s_status, pc),
382 NULL);
383 GPR_ASSERT(err == GRPC_CALL_OK);
Craig Tiller17effab2015-08-04 08:19:36 -0700384
Craig Tillera82950e2015-09-22 12:33:20 -0700385 op.op = GRPC_OP_RECV_CLOSE_ON_SERVER;
386 op.data.recv_close_on_server.cancelled = &pc->c2p_server_cancelled;
387 refpc(pc, "on_c2p_closed");
388 err = grpc_call_start_batch(pc->c2p, &op, 1, new_closure(on_c2p_closed, pc),
389 NULL);
390 GPR_ASSERT(err == GRPC_CALL_OK);
Craig Tiller17effab2015-08-04 08:19:36 -0700391
Craig Tillera82950e2015-09-22 12:33:20 -0700392 request_call(proxy);
Craig Tiller17effab2015-08-04 08:19:36 -0700393
Craig Tillera82950e2015-09-22 12:33:20 -0700394 unrefpc(pc, "init");
395 } else {
396 GPR_ASSERT(proxy->new_call == NULL);
397 }
Craig Tiller17effab2015-08-04 08:19:36 -0700398}
399
Craig Tillera82950e2015-09-22 12:33:20 -0700400static void request_call(grpc_end2end_proxy *proxy) {
Craig Tiller17effab2015-08-04 08:19:36 -0700401 proxy->new_call = NULL;
Craig Tillera82950e2015-09-22 12:33:20 -0700402 GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
403 proxy->server, &proxy->new_call,
404 &proxy->new_call_details,
405 &proxy->new_call_metadata, proxy->cq,
406 proxy->cq, new_closure(on_new_call, proxy)));
Craig Tiller17effab2015-08-04 08:19:36 -0700407}
408
Craig Tillera82950e2015-09-22 12:33:20 -0700409static void thread_main(void *arg) {
Craig Tiller17effab2015-08-04 08:19:36 -0700410 grpc_end2end_proxy *proxy = arg;
411 closure *cl;
Craig Tillera82950e2015-09-22 12:33:20 -0700412 for (;;) {
413 grpc_event ev = grpc_completion_queue_next(
414 proxy->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL);
415 switch (ev.type) {
416 case GRPC_QUEUE_TIMEOUT:
417 gpr_log(GPR_ERROR, "Should never reach here");
418 abort();
419 case GRPC_QUEUE_SHUTDOWN:
420 return;
421 case GRPC_OP_COMPLETE:
422 cl = ev.tag;
423 cl->func(cl->arg, ev.success);
424 gpr_free(cl);
425 break;
Craig Tiller17effab2015-08-04 08:19:36 -0700426 }
Craig Tillera82950e2015-09-22 12:33:20 -0700427 }
Craig Tiller17effab2015-08-04 08:19:36 -0700428}
429
Craig Tillera82950e2015-09-22 12:33:20 -0700430const char *grpc_end2end_proxy_get_client_target(grpc_end2end_proxy *proxy) {
Craig Tiller17effab2015-08-04 08:19:36 -0700431 return proxy->proxy_port;
432}
433
Craig Tillera82950e2015-09-22 12:33:20 -0700434const char *grpc_end2end_proxy_get_server_port(grpc_end2end_proxy *proxy) {
Craig Tiller17effab2015-08-04 08:19:36 -0700435 return proxy->server_port;
436}