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.

85 lines
2.5 KiB

10 years ago
/*
*
* Copyright 2015 gRPC authors.
10 years ago
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
10 years ago
*
* http://www.apache.org/licenses/LICENSE-2.0
10 years ago
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
10 years ago
*
*/
#include <stdio.h>
9 years ago
#include <string.h>
10 years ago
#include <string>
#include "absl/strings/str_cat.h"
10 years ago
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/host_port.h"
10 years ago
#include "test/core/util/port.h"
#include "test/core/util/subprocess.h"
10 years ago
int main(int /*argc*/, const char** argv) {
gpr_log_verbosity_init();
7 years ago
const char* me = argv[0];
const char* lslash = strrchr(me, '/');
10 years ago
char root[1024];
int port = grpc_pick_unused_port_or_die();
char* args[10];
10 years ago
int status;
gpr_subprocess *svr, *cli;
10 years ago
/* figure out where we are */
if (lslash) {
memcpy(root, me, static_cast<size_t>(lslash - me));
10 years ago
root[lslash - me] = 0;
} else {
strcpy(root, ".");
}
/* start the server */
std::string command =
absl::StrCat(root, "/fling_server", gpr_subprocess_binary_extension());
args[0] = const_cast<char*>(command.c_str());
7 years ago
args[1] = const_cast<char*>("--bind");
std::string joined = grpc_core::JoinHostPort("::", port);
args[2] = const_cast<char*>(joined.c_str());
7 years ago
args[3] = const_cast<char*>("--no-secure");
svr = gpr_subprocess_create(4, const_cast<const char**>(args));
10 years ago
/* start the client */
command =
absl::StrCat(root, "/fling_client", gpr_subprocess_binary_extension());
args[0] = const_cast<char*>(command.c_str());
7 years ago
args[1] = const_cast<char*>("--target");
joined = grpc_core::JoinHostPort("127.0.0.1", port);
args[2] = const_cast<char*>(joined.c_str());
7 years ago
args[3] = const_cast<char*>("--scenario=ping-pong-request");
args[4] = const_cast<char*>("--no-secure");
args[5] = nullptr;
cli = gpr_subprocess_create(6, const_cast<const char**>(args));
10 years ago
/* wait for completion */
printf("waiting for client\n");
if ((status = gpr_subprocess_join(cli))) {
gpr_subprocess_destroy(cli);
gpr_subprocess_destroy(svr);
return status;
}
gpr_subprocess_destroy(cli);
gpr_subprocess_interrupt(svr);
status = gpr_subprocess_join(svr);
gpr_subprocess_destroy(svr);
return status;
}