mirror of https://github.com/grpc/grpc.git
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.3 KiB
93 lines
3.3 KiB
9 years ago
|
/*
|
||
|
*
|
||
|
* Copyright 2015, Google Inc.
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* Redistribution and use in source and binary forms, with or without
|
||
|
* modification, are permitted provided that the following conditions are
|
||
|
* met:
|
||
|
*
|
||
|
* * Redistributions of source code must retain the above copyright
|
||
|
* notice, this list of conditions and the following disclaimer.
|
||
|
* * Redistributions in binary form must reproduce the above
|
||
|
* copyright notice, this list of conditions and the following disclaimer
|
||
|
* in the documentation and/or other materials provided with the
|
||
|
* distribution.
|
||
|
* * Neither the name of Google Inc. nor the names of its
|
||
|
* contributors may be used to endorse or promote products derived from
|
||
|
* this software without specific prior written permission.
|
||
|
*
|
||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <grpc/support/cmdline.h>
|
||
|
#include <grpc/support/log.h>
|
||
|
#include <signal.h>
|
||
|
|
||
|
#include "test/core/bad_ssl/server.h"
|
||
|
#include "test/core/util/test_config.h"
|
||
|
|
||
|
static int got_sigint = 0;
|
||
|
|
||
|
static void sigint_handler(int x) { got_sigint = 1; }
|
||
|
|
||
|
const char *bad_ssl_addr(int argc, char **argv) {
|
||
|
gpr_cmdline *cl;
|
||
|
char *addr = NULL;
|
||
|
cl = gpr_cmdline_create("test server");
|
||
|
gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr);
|
||
|
gpr_cmdline_parse(cl, argc, argv);
|
||
|
gpr_cmdline_destroy(cl);
|
||
|
GPR_ASSERT(addr);
|
||
|
return addr;
|
||
|
}
|
||
|
|
||
|
void bad_ssl_run(grpc_server *server) {
|
||
|
int shutdown_started = 0;
|
||
|
int shutdown_finished = 0;
|
||
|
grpc_event ev;
|
||
|
|
||
|
grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
|
||
|
grpc_server_register_completion_queue(server, cq, NULL);
|
||
|
grpc_server_start(server);
|
||
|
|
||
|
signal(SIGINT, sigint_handler);
|
||
|
while (!shutdown_finished) {
|
||
|
if (got_sigint && !shutdown_started) {
|
||
|
gpr_log(GPR_INFO, "Shutting down due to SIGINT");
|
||
|
grpc_server_shutdown_and_notify(server, cq, NULL);
|
||
|
GPR_ASSERT(grpc_completion_queue_pluck(
|
||
|
cq, NULL, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL)
|
||
|
.type == GRPC_OP_COMPLETE);
|
||
|
grpc_completion_queue_shutdown(cq);
|
||
|
shutdown_started = 1;
|
||
|
}
|
||
|
ev = grpc_completion_queue_next(
|
||
|
cq, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
|
||
|
gpr_time_from_micros(1000000, GPR_TIMESPAN)),
|
||
|
NULL);
|
||
|
switch (ev.type) {
|
||
|
case GRPC_OP_COMPLETE:
|
||
|
GPR_UNREACHABLE_CODE(gpr_log(GPR_DEBUG, "GRPC_OP_COMPLETE"));
|
||
|
break;
|
||
|
case GRPC_QUEUE_SHUTDOWN:
|
||
|
GPR_ASSERT(shutdown_started);
|
||
|
shutdown_finished = 1;
|
||
|
break;
|
||
|
case GRPC_QUEUE_TIMEOUT:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|