diff options
Diffstat (limited to 'test/core/network_benchmarks')
-rw-r--r-- | test/core/network_benchmarks/BUILD | 4 | ||||
-rw-r--r-- | test/core/network_benchmarks/low_level_ping_pong.cc (renamed from test/core/network_benchmarks/low_level_ping_pong.c) | 35 |
2 files changed, 22 insertions, 17 deletions
diff --git a/test/core/network_benchmarks/BUILD b/test/core/network_benchmarks/BUILD index 0e15393030..e1b4953608 100644 --- a/test/core/network_benchmarks/BUILD +++ b/test/core/network_benchmarks/BUILD @@ -22,8 +22,8 @@ licenses(["notice"]) # Apache v2 grpc_cc_binary( name = "low_level_ping_pong", - srcs = ["low_level_ping_pong.c"], - language = "C", + srcs = ["low_level_ping_pong.cc"], + language = "C++", deps = [ "//:gpr", "//:grpc", diff --git a/test/core/network_benchmarks/low_level_ping_pong.c b/test/core/network_benchmarks/low_level_ping_pong.cc index 868011739c..722652148c 100644 --- a/test/core/network_benchmarks/low_level_ping_pong.c +++ b/test/core/network_benchmarks/low_level_ping_pong.cc @@ -56,7 +56,7 @@ typedef struct thread_args { int (*write_bytes)(struct thread_args* args, char* buf); int (*setup)(struct thread_args* args); int epoll_fd; - char* strategy_name; + const char* strategy_name; } thread_args; /* @@ -252,7 +252,7 @@ static int epoll_setup(thread_args* args) { #endif static void server_thread(thread_args* args) { - char* buf = gpr_malloc(args->msg_size); + char* buf = static_cast<char*>(gpr_malloc(args->msg_size)); if (args->setup(args) < 0) { gpr_log(GPR_ERROR, "Setup failed"); } @@ -271,7 +271,7 @@ static void server_thread(thread_args* args) { } static void server_thread_wrap(void* arg) { - thread_args* args = arg; + thread_args* args = static_cast<thread_args*>(arg); server_thread(args); } @@ -291,7 +291,7 @@ static double now(void) { } static void client_thread(thread_args* args) { - char* buf = gpr_malloc(args->msg_size * sizeof(char)); + char* buf = static_cast<char*>(gpr_malloc(args->msg_size * sizeof(char))); memset(buf, 0, args->msg_size * sizeof(char)); gpr_histogram* histogram = gpr_histogram_create(0.01, 60e9); double start_time; @@ -538,7 +538,7 @@ void print_usage(char* argv0) { } typedef struct test_strategy { - char* name; + const char* name; int (*read_strategy)(struct thread_args* args, char* buf); int (*setup)(struct thread_args* args); } test_strategy; @@ -553,9 +553,10 @@ static test_strategy test_strategies[] = { {"spin_read", spin_read_bytes, set_socket_nonblocking}, {"spin_poll", poll_read_bytes_spin, set_socket_nonblocking}}; -static char* socket_types[] = {"tcp", "socketpair", "pipe"}; +static const char* socket_types[] = {"tcp", "socketpair", "pipe"}; -int create_socket(char* socket_type, fd_pair* client_fds, fd_pair* server_fds) { +int create_socket(const char* socket_type, fd_pair* client_fds, + fd_pair* server_fds) { if (strcmp(socket_type, "tcp") == 0) { create_sockets_tcp(client_fds, server_fds); } else if (strcmp(socket_type, "socketpair") == 0) { @@ -569,7 +570,7 @@ int create_socket(char* socket_type, fd_pair* client_fds, fd_pair* server_fds) { return 0; } -static int run_benchmark(char* socket_type, thread_args* client_args, +static int run_benchmark(const char* socket_type, thread_args* client_args, thread_args* server_args) { gpr_thd_id tid; int rv = 0; @@ -594,9 +595,11 @@ static int run_all_benchmarks(size_t msg_size) { test_strategy* strategy = &test_strategies[i]; size_t j; for (j = 0; j < GPR_ARRAY_SIZE(socket_types); ++j) { - thread_args* client_args = gpr_malloc(sizeof(thread_args)); - thread_args* server_args = gpr_malloc(sizeof(thread_args)); - char* socket_type = socket_types[j]; + thread_args* client_args = + static_cast<thread_args*>(gpr_malloc(sizeof(thread_args))); + thread_args* server_args = + static_cast<thread_args*>(gpr_malloc(sizeof(thread_args))); + const char* socket_type = socket_types[j]; client_args->read_bytes = strategy->read_strategy; client_args->write_bytes = blocking_write_bytes; @@ -618,11 +621,13 @@ static int run_all_benchmarks(size_t msg_size) { } int main(int argc, char** argv) { - thread_args* client_args = gpr_malloc(sizeof(thread_args)); - thread_args* server_args = gpr_malloc(sizeof(thread_args)); + thread_args* client_args = + static_cast<thread_args*>(gpr_malloc(sizeof(thread_args))); + thread_args* server_args = + static_cast<thread_args*>(gpr_malloc(sizeof(thread_args))); int msg_size = -1; - char* read_strategy = NULL; - char* socket_type = NULL; + const char* read_strategy = NULL; + const char* socket_type = NULL; size_t i; const test_strategy* strategy = NULL; int error = 0; |