| 1 |
/* |
| 2 |
* |
| 3 |
* Copyright 2015 gRPC authors. |
| 4 |
* |
| 5 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 |
* you may not use this file except in compliance with the License. |
| 7 |
* You may obtain a copy of the License at |
| 8 |
* |
| 9 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
* |
| 11 |
* Unless required by applicable law or agreed to in writing, software |
| 12 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
* See the License for the specific language governing permissions and |
| 15 |
* limitations under the License. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "test/core/end2end/fixtures/proxy.h" |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
#include <string.h> |
| 23 |
|
| 24 |
#include <string> |
| 25 |
#include <utility> |
| 26 |
|
| 27 |
#include <grpc/byte_buffer.h> |
| 28 |
#include <grpc/impl/codegen/propagation_bits.h> |
| 29 |
#include <grpc/slice.h> |
| 30 |
#include <grpc/status.h> |
| 31 |
#include <grpc/support/alloc.h> |
| 32 |
#include <grpc/support/log.h> |
| 33 |
#include <grpc/support/sync.h> |
| 34 |
#include <grpc/support/time.h> |
| 35 |
|
| 36 |
#include "src/core/lib/channel/channel_args.h" |
| 37 |
#include "src/core/lib/gprpp/host_port.h" |
| 38 |
#include "src/core/lib/gprpp/thd.h" |
| 39 |
#include "src/core/lib/surface/call.h" |
| 40 |
#include "test/core/util/port.h" |
| 41 |
|
| 42 |
struct grpc_end2end_proxy { |
| 43 |
grpc_end2end_proxy() |
| 44 |
: cq(nullptr), |
| 45 |
server(nullptr), |
| 46 |
client(nullptr), |
| 47 |
shutdown(false), |
| 48 |
new_call(nullptr) { |
| 49 |
memset(&new_call_details, 0, sizeof(new_call_details)); |
| 50 |
memset(&new_call_metadata, 0, sizeof(new_call_metadata)); |
| 51 |
} |
| 52 |
grpc_core::Thread thd; |
| 53 |
std::string proxy_port; |
| 54 |
std::string server_port; |
| 55 |
grpc_completion_queue* cq; |
| 56 |
grpc_server* server; |
| 57 |
grpc_channel* client; |
| 58 |
|
| 59 |
int shutdown; |
| 60 |
|
| 61 |
/* requested call */ |
| 62 |
grpc_call* new_call; |
| 63 |
grpc_call_details new_call_details; |
| 64 |
grpc_metadata_array new_call_metadata; |
| 65 |
}; |
| 66 |
|
| 67 |
typedef struct { |
| 68 |
void (*func)(void* arg, int success); |
| 69 |
void* arg; |
| 70 |
} closure; |
| 71 |
|
| 72 |
typedef struct { |
| 73 |
gpr_refcount refs; |
| 74 |
grpc_end2end_proxy* proxy; |
| 75 |
|
| 76 |
grpc_call* c2p; |
| 77 |
grpc_call* p2s; |
| 78 |
|
| 79 |
grpc_metadata_array c2p_initial_metadata; |
| 80 |
grpc_metadata_array p2s_initial_metadata; |
| 81 |
|
| 82 |
grpc_byte_buffer* c2p_msg; |
| 83 |
grpc_byte_buffer* p2s_msg; |
| 84 |
|
| 85 |
grpc_metadata_array p2s_trailing_metadata; |
| 86 |
grpc_status_code p2s_status; |
| 87 |
grpc_slice p2s_status_details; |
| 88 |
|
| 89 |
int c2p_server_cancelled; |
| 90 |
} proxy_call; |
| 91 |
|
| 92 |
static void thread_main(void* arg); |
| 93 |
static void request_call(grpc_end2end_proxy* proxy); |
| 94 |
|
| 95 |
grpc_end2end_proxy* grpc_end2end_proxy_create( |
| 96 |
const grpc_end2end_proxy_def* def, const grpc_channel_args* client_args, |
| 97 |
const grpc_channel_args* server_args) { |
| 98 |
int proxy_port = grpc_pick_unused_port_or_die(); |
| 99 |
int server_port = grpc_pick_unused_port_or_die(); |
| 100 |
|
| 101 |
grpc_end2end_proxy* proxy = new grpc_end2end_proxy(); |
| 102 |
|
| 103 |
proxy->proxy_port = grpc_core::JoinHostPort("localhost", proxy_port); |
| 104 |
proxy->server_port = grpc_core::JoinHostPort("localhost", server_port); |
| 105 |
|
| 106 |
gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port.c_str(), |
| 107 |
proxy->server_port.c_str()); |
| 108 |
|
| 109 |
proxy->cq = grpc_completion_queue_create_for_next(nullptr); |
| 110 |
proxy->server = def->create_server(proxy->proxy_port.c_str(), server_args); |
| 111 |
|
| 112 |
const char* arg_to_remove = GRPC_ARG_ENABLE_RETRIES; |
| 113 |
grpc_arg arg_to_add = grpc_channel_arg_integer_create( |
| 114 |
const_cast<char*>(GRPC_ARG_ENABLE_RETRIES), 0); |
| 115 |
const grpc_channel_args* proxy_client_args = |
| 116 |
grpc_channel_args_copy_and_add_and_remove(client_args, &arg_to_remove, 1, |
| 117 |
&arg_to_add, 1); |
| 118 |
proxy->client = |
| 119 |
def->create_client(proxy->server_port.c_str(), proxy_client_args); |
| 120 |
grpc_channel_args_destroy(proxy_client_args); |
| 121 |
|
| 122 |
grpc_server_register_completion_queue(proxy->server, proxy->cq, nullptr); |
| 123 |
grpc_server_start(proxy->server); |
| 124 |
|
| 125 |
grpc_call_details_init(&proxy->new_call_details); |
| 126 |
proxy->thd = grpc_core::Thread("grpc_end2end_proxy", thread_main, proxy); |
| 127 |
proxy->thd.Start(); |
| 128 |
|
| 129 |
request_call(proxy); |
| 130 |
|
| 131 |
return proxy; |
| 132 |
} |
| 133 |
|
| 134 |
static closure* new_closure(void (*func)(void* arg, int success), void* arg) { |
| 135 |
closure* cl = static_cast<closure*>(gpr_malloc(sizeof(*cl))); |
| 136 |
cl->func = func; |
| 137 |
cl->arg = arg; |
| 138 |
return cl; |
| 139 |
} |
| 140 |
|
| 141 |
static void shutdown_complete(void* arg, int /*success*/) { |
| 142 |
grpc_end2end_proxy* proxy = static_cast<grpc_end2end_proxy*>(arg); |
| 143 |
proxy->shutdown = 1; |
| 144 |
grpc_completion_queue_shutdown(proxy->cq); |
| 145 |
} |
| 146 |
|
| 147 |
void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy) { |
| 148 |
grpc_server_shutdown_and_notify(proxy->server, proxy->cq, |
| 149 |
new_closure(shutdown_complete, proxy)); |
| 150 |
proxy->thd.Join(); |
| 151 |
grpc_server_destroy(proxy->server); |
| 152 |
grpc_channel_destroy(proxy->client); |
| 153 |
grpc_completion_queue_destroy(proxy->cq); |
| 154 |
grpc_call_details_destroy(&proxy->new_call_details); |
| 155 |
delete proxy; |
| 156 |
} |
| 157 |
|
| 158 |
static void unrefpc(proxy_call* pc, const char* /*reason*/) { |
| 159 |
if (gpr_unref(&pc->refs)) { |
| 160 |
grpc_call_unref(pc->c2p); |
| 161 |
grpc_call_unref(pc->p2s); |
| 162 |
grpc_metadata_array_destroy(&pc->c2p_initial_metadata); |
| 163 |
grpc_metadata_array_destroy(&pc->p2s_initial_metadata); |
| 164 |
grpc_metadata_array_destroy(&pc->p2s_trailing_metadata); |
| 165 |
grpc_slice_unref(pc->p2s_status_details); |
| 166 |
gpr_free(pc); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
static void refpc(proxy_call* pc, const char* /*reason*/) { |
| 171 |
gpr_ref(&pc->refs); |
| 172 |
} |
| 173 |
|
| 174 |
static void on_c2p_sent_initial_metadata(void* arg, int /*success*/) { |
| 175 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 176 |
unrefpc(pc, "on_c2p_sent_initial_metadata"); |
| 177 |
} |
| 178 |
|
| 179 |
static void on_p2s_recv_initial_metadata(void* arg, int /*success*/) { |
| 180 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 181 |
grpc_op op; |
| 182 |
grpc_call_error err; |
| 183 |
|
| 184 |
memset(&op, 0, sizeof(op)); |
| 185 |
if (!pc->proxy->shutdown && !grpc_call_is_trailers_only(pc->p2s)) { |
| 186 |
op.op = GRPC_OP_SEND_INITIAL_METADATA; |
| 187 |
op.flags = 0; |
| 188 |
op.reserved = nullptr; |
| 189 |
op.data.send_initial_metadata.count = pc->p2s_initial_metadata.count; |
| 190 |
op.data.send_initial_metadata.metadata = pc->p2s_initial_metadata.metadata; |
| 191 |
refpc(pc, "on_c2p_sent_initial_metadata"); |
| 192 |
err = grpc_call_start_batch(pc->c2p, &op, 1, |
| 193 |
new_closure(on_c2p_sent_initial_metadata, pc), |
| 194 |
nullptr); |
| 195 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 196 |
} |
| 197 |
|
| 198 |
unrefpc(pc, "on_p2s_recv_initial_metadata"); |
| 199 |
} |
| 200 |
|
| 201 |
static void on_p2s_sent_initial_metadata(void* arg, int /*success*/) { |
| 202 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 203 |
unrefpc(pc, "on_p2s_sent_initial_metadata"); |
| 204 |
} |
| 205 |
|
| 206 |
static void on_c2p_recv_msg(void* arg, int success); |
| 207 |
|
| 208 |
static void on_p2s_sent_message(void* arg, int success) { |
| 209 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 210 |
grpc_op op; |
| 211 |
grpc_call_error err; |
| 212 |
|
| 213 |
grpc_byte_buffer_destroy(pc->c2p_msg); |
| 214 |
if (!pc->proxy->shutdown && success) { |
| 215 |
op.op = GRPC_OP_RECV_MESSAGE; |
| 216 |
op.flags = 0; |
| 217 |
op.reserved = nullptr; |
| 218 |
op.data.recv_message.recv_message = &pc->c2p_msg; |
| 219 |
refpc(pc, "on_c2p_recv_msg"); |
| 220 |
err = grpc_call_start_batch(pc->c2p, &op, 1, |
| 221 |
new_closure(on_c2p_recv_msg, pc), nullptr); |
| 222 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 223 |
} |
| 224 |
|
| 225 |
unrefpc(pc, "on_p2s_sent_message"); |
| 226 |
} |
| 227 |
|
| 228 |
static void on_p2s_sent_close(void* arg, int /*success*/) { |
| 229 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 230 |
unrefpc(pc, "on_p2s_sent_close"); |
| 231 |
} |
| 232 |
|
| 233 |
static void on_c2p_recv_msg(void* arg, int success) { |
| 234 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 235 |
grpc_op op; |
| 236 |
grpc_call_error err; |
| 237 |
|
| 238 |
if (!pc->proxy->shutdown && success) { |
| 239 |
if (pc->c2p_msg != nullptr) { |
| 240 |
op.op = GRPC_OP_SEND_MESSAGE; |
| 241 |
op.flags = 0; |
| 242 |
op.reserved = nullptr; |
| 243 |
op.data.send_message.send_message = pc->c2p_msg; |
| 244 |
refpc(pc, "on_p2s_sent_message"); |
| 245 |
err = grpc_call_start_batch( |
| 246 |
pc->p2s, &op, 1, new_closure(on_p2s_sent_message, pc), nullptr); |
| 247 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 248 |
} else { |
| 249 |
op.op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
| 250 |
op.flags = 0; |
| 251 |
op.reserved = nullptr; |
| 252 |
refpc(pc, "on_p2s_sent_close"); |
| 253 |
err = grpc_call_start_batch(pc->p2s, &op, 1, |
| 254 |
new_closure(on_p2s_sent_close, pc), nullptr); |
| 255 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 256 |
} |
| 257 |
} else { |
| 258 |
if (pc->c2p_msg != nullptr) { |
| 259 |
grpc_byte_buffer_destroy(pc->c2p_msg); |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
unrefpc(pc, "on_c2p_recv_msg"); |
| 264 |
} |
| 265 |
|
| 266 |
static void on_p2s_recv_msg(void* arg, int success); |
| 267 |
|
| 268 |
static void on_c2p_sent_message(void* arg, int success) { |
| 269 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 270 |
grpc_op op; |
| 271 |
grpc_call_error err; |
| 272 |
|
| 273 |
grpc_byte_buffer_destroy(pc->p2s_msg); |
| 274 |
if (!pc->proxy->shutdown && success) { |
| 275 |
op.op = GRPC_OP_RECV_MESSAGE; |
| 276 |
op.flags = 0; |
| 277 |
op.reserved = nullptr; |
| 278 |
op.data.recv_message.recv_message = &pc->p2s_msg; |
| 279 |
refpc(pc, "on_p2s_recv_msg"); |
| 280 |
err = grpc_call_start_batch(pc->p2s, &op, 1, |
| 281 |
new_closure(on_p2s_recv_msg, pc), nullptr); |
| 282 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 283 |
} |
| 284 |
|
| 285 |
unrefpc(pc, "on_c2p_sent_message"); |
| 286 |
} |
| 287 |
|
| 288 |
static void on_p2s_recv_msg(void* arg, int success) { |
| 289 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 290 |
grpc_op op; |
| 291 |
grpc_call_error err; |
| 292 |
|
| 293 |
if (!pc->proxy->shutdown && success && pc->p2s_msg) { |
| 294 |
op.op = GRPC_OP_SEND_MESSAGE; |
| 295 |
op.flags = 0; |
| 296 |
op.reserved = nullptr; |
| 297 |
op.data.send_message.send_message = pc->p2s_msg; |
| 298 |
refpc(pc, "on_c2p_sent_message"); |
| 299 |
err = grpc_call_start_batch(pc->c2p, &op, 1, |
| 300 |
new_closure(on_c2p_sent_message, pc), nullptr); |
| 301 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 302 |
} else { |
| 303 |
grpc_byte_buffer_destroy(pc->p2s_msg); |
| 304 |
} |
| 305 |
unrefpc(pc, "on_p2s_recv_msg"); |
| 306 |
} |
| 307 |
|
| 308 |
static void on_c2p_sent_status(void* arg, int /*success*/) { |
| 309 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 310 |
unrefpc(pc, "on_c2p_sent_status"); |
| 311 |
} |
| 312 |
|
| 313 |
static void on_p2s_status(void* arg, int success) { |
| 314 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 315 |
grpc_op op[2]; // Possibly send empty initial metadata also if trailers-only |
| 316 |
grpc_call_error err; |
| 317 |
|
| 318 |
memset(op, 0, sizeof(op)); |
| 319 |
|
| 320 |
if (!pc->proxy->shutdown) { |
| 321 |
GPR_ASSERT(success); |
| 322 |
|
| 323 |
int op_count = 0; |
| 324 |
if (grpc_call_is_trailers_only(pc->p2s)) { |
| 325 |
op[op_count].op = GRPC_OP_SEND_INITIAL_METADATA; |
| 326 |
op_count++; |
| 327 |
} |
| 328 |
|
| 329 |
op[op_count].op = GRPC_OP_SEND_STATUS_FROM_SERVER; |
| 330 |
op[op_count].flags = 0; |
| 331 |
op[op_count].reserved = nullptr; |
| 332 |
op[op_count].data.send_status_from_server.trailing_metadata_count = |
| 333 |
pc->p2s_trailing_metadata.count; |
| 334 |
op[op_count].data.send_status_from_server.trailing_metadata = |
| 335 |
pc->p2s_trailing_metadata.metadata; |
| 336 |
op[op_count].data.send_status_from_server.status = pc->p2s_status; |
| 337 |
op[op_count].data.send_status_from_server.status_details = |
| 338 |
&pc->p2s_status_details; |
| 339 |
op_count++; |
| 340 |
refpc(pc, "on_c2p_sent_status"); |
| 341 |
err = grpc_call_start_batch(pc->c2p, op, op_count, |
| 342 |
new_closure(on_c2p_sent_status, pc), nullptr); |
| 343 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 344 |
} |
| 345 |
|
| 346 |
unrefpc(pc, "on_p2s_status"); |
| 347 |
} |
| 348 |
|
| 349 |
static void on_c2p_closed(void* arg, int /*success*/) { |
| 350 |
proxy_call* pc = static_cast<proxy_call*>(arg); |
| 351 |
unrefpc(pc, "on_c2p_closed"); |
| 352 |
} |
| 353 |
|
| 354 |
static void on_new_call(void* arg, int success) { |
| 355 |
grpc_end2end_proxy* proxy = static_cast<grpc_end2end_proxy*>(arg); |
| 356 |
grpc_call_error err; |
| 357 |
|
| 358 |
if (success) { |
| 359 |
grpc_op op; |
| 360 |
memset(&op, 0, sizeof(op)); |
| 361 |
proxy_call* pc = static_cast<proxy_call*>(gpr_malloc(sizeof(*pc))); |
| 362 |
memset(pc, 0, sizeof(*pc)); |
| 363 |
pc->proxy = proxy; |
| 364 |
std::swap(pc->c2p_initial_metadata, proxy->new_call_metadata); |
| 365 |
pc->c2p = proxy->new_call; |
| 366 |
pc->p2s = grpc_channel_create_call( |
| 367 |
proxy->client, pc->c2p, GRPC_PROPAGATE_DEFAULTS, proxy->cq, |
| 368 |
proxy->new_call_details.method, &proxy->new_call_details.host, |
| 369 |
proxy->new_call_details.deadline, nullptr); |
| 370 |
gpr_ref_init(&pc->refs, 1); |
| 371 |
|
| 372 |
op.reserved = nullptr; |
| 373 |
|
| 374 |
op.op = GRPC_OP_RECV_INITIAL_METADATA; |
| 375 |
op.flags = 0; |
| 376 |
op.data.recv_initial_metadata.recv_initial_metadata = |
| 377 |
&pc->p2s_initial_metadata; |
| 378 |
refpc(pc, "on_p2s_recv_initial_metadata"); |
| 379 |
err = grpc_call_start_batch(pc->p2s, &op, 1, |
| 380 |
new_closure(on_p2s_recv_initial_metadata, pc), |
| 381 |
nullptr); |
| 382 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 383 |
|
| 384 |
op.op = GRPC_OP_SEND_INITIAL_METADATA; |
| 385 |
op.flags = 0; |
| 386 |
op.data.send_initial_metadata.count = pc->c2p_initial_metadata.count; |
| 387 |
op.data.send_initial_metadata.metadata = pc->c2p_initial_metadata.metadata; |
| 388 |
refpc(pc, "on_p2s_sent_initial_metadata"); |
| 389 |
err = grpc_call_start_batch(pc->p2s, &op, 1, |
| 390 |
new_closure(on_p2s_sent_initial_metadata, pc), |
| 391 |
nullptr); |
| 392 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 393 |
|
| 394 |
op.op = GRPC_OP_RECV_MESSAGE; |
| 395 |
op.flags = 0; |
| 396 |
op.data.recv_message.recv_message = &pc->c2p_msg; |
| 397 |
refpc(pc, "on_c2p_recv_msg"); |
| 398 |
err = grpc_call_start_batch(pc->c2p, &op, 1, |
| 399 |
new_closure(on_c2p_recv_msg, pc), nullptr); |
| 400 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 401 |
|
| 402 |
op.op = GRPC_OP_RECV_MESSAGE; |
| 403 |
op.flags = 0; |
| 404 |
op.data.recv_message.recv_message = &pc->p2s_msg; |
| 405 |
refpc(pc, "on_p2s_recv_msg"); |
| 406 |
err = grpc_call_start_batch(pc->p2s, &op, 1, |
| 407 |
new_closure(on_p2s_recv_msg, pc), nullptr); |
| 408 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 409 |
|
| 410 |
op.op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
| 411 |
op.flags = 0; |
| 412 |
op.data.recv_status_on_client.trailing_metadata = |
| 413 |
&pc->p2s_trailing_metadata; |
| 414 |
op.data.recv_status_on_client.status = &pc->p2s_status; |
| 415 |
op.data.recv_status_on_client.status_details = &pc->p2s_status_details; |
| 416 |
refpc(pc, "on_p2s_status"); |
| 417 |
err = grpc_call_start_batch(pc->p2s, &op, 1, new_closure(on_p2s_status, pc), |
| 418 |
nullptr); |
| 419 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 420 |
|
| 421 |
op.op = GRPC_OP_RECV_CLOSE_ON_SERVER; |
| 422 |
op.flags = 0; |
| 423 |
op.data.recv_close_on_server.cancelled = &pc->c2p_server_cancelled; |
| 424 |
refpc(pc, "on_c2p_closed"); |
| 425 |
err = grpc_call_start_batch(pc->c2p, &op, 1, new_closure(on_c2p_closed, pc), |
| 426 |
nullptr); |
| 427 |
GPR_ASSERT(err == GRPC_CALL_OK); |
| 428 |
|
| 429 |
request_call(proxy); |
| 430 |
|
| 431 |
grpc_call_details_destroy(&proxy->new_call_details); |
| 432 |
grpc_call_details_init(&proxy->new_call_details); |
| 433 |
|
| 434 |
unrefpc(pc, "init"); |
| 435 |
} else { |
| 436 |
GPR_ASSERT(proxy->new_call == nullptr); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
static void request_call(grpc_end2end_proxy* proxy) { |
| 441 |
proxy->new_call = nullptr; |
| 442 |
GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( |
| 443 |
proxy->server, &proxy->new_call, |
| 444 |
&proxy->new_call_details, |
| 445 |
&proxy->new_call_metadata, proxy->cq, |
| 446 |
proxy->cq, new_closure(on_new_call, proxy))); |
| 447 |
} |
| 448 |
|
| 449 |
static void thread_main(void* arg) { |
| 450 |
grpc_end2end_proxy* proxy = static_cast<grpc_end2end_proxy*>(arg); |
| 451 |
closure* cl; |
| 452 |
for (;;) { |
| 453 |
grpc_event ev = grpc_completion_queue_next( |
| 454 |
proxy->cq, gpr_inf_future(GPR_CLOCK_MONOTONIC), nullptr); |
| 455 |
switch (ev.type) { |
| 456 |
case GRPC_QUEUE_TIMEOUT: |
| 457 |
gpr_log(GPR_ERROR, "Should never reach here"); |
| 458 |
abort(); |
| 459 |
case GRPC_QUEUE_SHUTDOWN: |
| 460 |
return; |
| 461 |
case GRPC_OP_COMPLETE: |
| 462 |
cl = static_cast<closure*>(ev.tag); |
| 463 |
cl->func(cl->arg, ev.success); |
| 464 |
gpr_free(cl); |
| 465 |
break; |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
const char* grpc_end2end_proxy_get_client_target(grpc_end2end_proxy* proxy) { |
| 471 |
return proxy->proxy_port.c_str(); |
| 472 |
} |
| 473 |
|
| 474 |
const char* grpc_end2end_proxy_get_server_port(grpc_end2end_proxy* proxy) { |
| 475 |
return proxy->server_port.c_str(); |
| 476 |
} |