diff options
Diffstat (limited to 'test/core/iomgr/fd_posix_test.c')
-rw-r--r-- | test/core/iomgr/fd_posix_test.c | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 1c62f34d3e..d19ce18081 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -46,8 +46,8 @@ #include "src/core/lib/iomgr/socket_utils_posix.h" #include "test/core/util/test_config.h" -static gpr_mu *g_mu; -static grpc_pollset *g_pollset; +static gpr_mu* g_mu; +static grpc_pollset* g_pollset; /* buffer size used to send and receive data. 1024 is the minimal value to set TCP send and receive buffer. */ @@ -56,8 +56,8 @@ static grpc_pollset *g_pollset; /* Create a test socket with the right properties for testing. port is the TCP port to listen or connect to. Return a socket FD and sockaddr_in. */ -static void create_test_socket(int port, int *socket_fd, - struct sockaddr_in *sin) { +static void create_test_socket(int port, int* socket_fd, + struct sockaddr_in* sin) { int fd; int one = 1; int buffer_size_bytes = BUF_SIZE; @@ -82,20 +82,20 @@ static void create_test_socket(int port, int *socket_fd, } /* Dummy gRPC callback */ -void no_op_cb(void *arg, int success) {} +void no_op_cb(void* arg, int success) {} /* =======An upload server to test notify_on_read=========== The server simply reads and counts a stream of bytes. */ /* An upload server. */ typedef struct { - grpc_fd *em_fd; /* listening fd */ + grpc_fd* em_fd; /* listening fd */ ssize_t read_bytes_total; /* total number of received bytes */ int done; /* set to 1 when a server finishes serving */ grpc_closure listen_closure; } server; -static void server_init(server *sv) { +static void server_init(server* sv) { sv->read_bytes_total = 0; sv->done = 0; } @@ -103,18 +103,18 @@ static void server_init(server *sv) { /* An upload session. Created when a new upload request arrives in the server. */ typedef struct { - server *sv; /* not owned by a single session */ - grpc_fd *em_fd; /* fd to read upload bytes */ + server* sv; /* not owned by a single session */ + grpc_fd* em_fd; /* fd to read upload bytes */ char read_buf[BUF_SIZE]; /* buffer to store upload bytes */ grpc_closure session_read_closure; } session; /* Called when an upload session can be safely shutdown. Close session FD and start to shutdown listen FD. */ -static void session_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ +static void session_shutdown_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ bool success) { - session *se = arg; - server *sv = se->sv; + session* se = arg; + server* sv = se->sv; grpc_fd_orphan(exec_ctx, se->em_fd, NULL, NULL, false /* already_closed */, "a"); gpr_free(se); @@ -124,9 +124,9 @@ static void session_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ } /* Called when data become readable in a session. */ -static void session_read_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ - grpc_error *error) { - session *se = arg; +static void session_read_cb(grpc_exec_ctx* exec_ctx, void* arg, /*session */ + grpc_error* error) { + session* se = arg; int fd = grpc_fd_wrapped_fd(se->em_fd); ssize_t read_once = 0; @@ -169,9 +169,9 @@ static void session_read_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */ /* Called when the listen FD can be safely shutdown. Close listen FD and signal that server can be shutdown. */ -static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */, +static void listen_shutdown_cb(grpc_exec_ctx* exec_ctx, void* arg /*server */, int success) { - server *sv = arg; + server* sv = arg; grpc_fd_orphan(exec_ctx, sv->em_fd, NULL, NULL, false /* already_closed */, "b"); @@ -184,22 +184,22 @@ static void listen_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg /*server */, } /* Called when a new TCP connection request arrives in the listening port. */ -static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/ - grpc_error *error) { - server *sv = arg; +static void listen_cb(grpc_exec_ctx* exec_ctx, void* arg, /*=sv_arg*/ + grpc_error* error) { + server* sv = arg; int fd; int flags; - session *se; + session* se; struct sockaddr_storage ss; socklen_t slen = sizeof(ss); - grpc_fd *listen_em_fd = sv->em_fd; + grpc_fd* listen_em_fd = sv->em_fd; if (error != GRPC_ERROR_NONE) { listen_shutdown_cb(exec_ctx, arg, 1); return; } - fd = accept(grpc_fd_wrapped_fd(listen_em_fd), (struct sockaddr *)&ss, &slen); + fd = accept(grpc_fd_wrapped_fd(listen_em_fd), (struct sockaddr*)&ss, &slen); GPR_ASSERT(fd >= 0); GPR_ASSERT(fd < FD_SETSIZE); flags = fcntl(fd, F_GETFL, 0); @@ -222,7 +222,7 @@ static void listen_cb(grpc_exec_ctx *exec_ctx, void *arg, /*=sv_arg*/ listen_cb() is registered to be interested in reading from listen_fd. When connection request arrives, listen_cb() is called to accept the connection request. */ -static int server_start(grpc_exec_ctx *exec_ctx, server *sv) { +static int server_start(grpc_exec_ctx* exec_ctx, server* sv) { int port = 0; int fd; struct sockaddr_in sin; @@ -230,8 +230,8 @@ static int server_start(grpc_exec_ctx *exec_ctx, server *sv) { create_test_socket(port, &fd, &sin); addr_len = sizeof(sin); - GPR_ASSERT(bind(fd, (struct sockaddr *)&sin, addr_len) == 0); - GPR_ASSERT(getsockname(fd, (struct sockaddr *)&sin, &addr_len) == 0); + GPR_ASSERT(bind(fd, (struct sockaddr*)&sin, addr_len) == 0); + GPR_ASSERT(getsockname(fd, (struct sockaddr*)&sin, &addr_len) == 0); port = ntohs(sin.sin_port); GPR_ASSERT(listen(fd, MAX_NUM_FD) == 0); @@ -246,11 +246,11 @@ static int server_start(grpc_exec_ctx *exec_ctx, server *sv) { } /* Wait and shutdown a sever. */ -static void server_wait_and_shutdown(server *sv) { +static void server_wait_and_shutdown(server* sv) { gpr_mu_lock(g_mu); while (!sv->done) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_pollset_worker *worker = NULL; + grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); @@ -270,7 +270,7 @@ static void server_wait_and_shutdown(server *sv) { /* An upload client. */ typedef struct { - grpc_fd *em_fd; + grpc_fd* em_fd; char write_buf[CLIENT_WRITE_BUF_SIZE]; ssize_t write_bytes_total; /* Number of times that the client fills up the write buffer and calls @@ -281,7 +281,7 @@ typedef struct { grpc_closure write_closure; } client; -static void client_init(client *cl) { +static void client_init(client* cl) { memset(cl->write_buf, 0, sizeof(cl->write_buf)); cl->write_bytes_total = 0; cl->client_write_cnt = 0; @@ -289,9 +289,9 @@ static void client_init(client *cl) { } /* Called when a client upload session is ready to shutdown. */ -static void client_session_shutdown_cb(grpc_exec_ctx *exec_ctx, - void *arg /*client */, int success) { - client *cl = arg; +static void client_session_shutdown_cb(grpc_exec_ctx* exec_ctx, + void* arg /*client */, int success) { + client* cl = arg; grpc_fd_orphan(exec_ctx, cl->em_fd, NULL, NULL, false /* already_closed */, "c"); cl->done = 1; @@ -300,9 +300,9 @@ static void client_session_shutdown_cb(grpc_exec_ctx *exec_ctx, } /* Write as much as possible, then register notify_on_write. */ -static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ - grpc_error *error) { - client *cl = arg; +static void client_session_write(grpc_exec_ctx* exec_ctx, void* arg, /*client */ + grpc_error* error) { + client* cl = arg; int fd = grpc_fd_wrapped_fd(cl->em_fd); ssize_t write_once = 0; @@ -336,11 +336,11 @@ static void client_session_write(grpc_exec_ctx *exec_ctx, void *arg, /*client */ } /* Start a client to send a stream of bytes. */ -static void client_start(grpc_exec_ctx *exec_ctx, client *cl, int port) { +static void client_start(grpc_exec_ctx* exec_ctx, client* cl, int port) { int fd; struct sockaddr_in sin; create_test_socket(port, &fd, &sin); - if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) { + if (connect(fd, (struct sockaddr*)&sin, sizeof(sin)) == -1) { if (errno == EINPROGRESS) { struct pollfd pfd; pfd.fd = fd; @@ -363,10 +363,10 @@ static void client_start(grpc_exec_ctx *exec_ctx, client *cl, int port) { } /* Wait for the signal to shutdown a client. */ -static void client_wait_and_shutdown(client *cl) { +static void client_wait_and_shutdown(client* cl) { gpr_mu_lock(g_mu); while (!cl->done) { - grpc_pollset_worker *worker = NULL; + grpc_pollset_worker* worker = NULL; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, @@ -402,14 +402,14 @@ typedef struct fd_change_data { grpc_iomgr_cb_func cb_that_ran; } fd_change_data; -void init_change_data(fd_change_data *fdc) { fdc->cb_that_ran = NULL; } +void init_change_data(fd_change_data* fdc) { fdc->cb_that_ran = NULL; } -void destroy_change_data(fd_change_data *fdc) {} +void destroy_change_data(fd_change_data* fdc) {} -static void first_read_callback(grpc_exec_ctx *exec_ctx, - void *arg /* fd_change_data */, - grpc_error *error) { - fd_change_data *fdc = arg; +static void first_read_callback(grpc_exec_ctx* exec_ctx, + void* arg /* fd_change_data */, + grpc_error* error) { + fd_change_data* fdc = arg; gpr_mu_lock(g_mu); fdc->cb_that_ran = first_read_callback; @@ -418,10 +418,10 @@ static void first_read_callback(grpc_exec_ctx *exec_ctx, gpr_mu_unlock(g_mu); } -static void second_read_callback(grpc_exec_ctx *exec_ctx, - void *arg /* fd_change_data */, - grpc_error *error) { - fd_change_data *fdc = arg; +static void second_read_callback(grpc_exec_ctx* exec_ctx, + void* arg /* fd_change_data */, + grpc_error* error) { + fd_change_data* fdc = arg; gpr_mu_lock(g_mu); fdc->cb_that_ran = second_read_callback; @@ -435,7 +435,7 @@ static void second_read_callback(grpc_exec_ctx *exec_ctx, point is to have two different function pointers and two different data pointers and make sure that changing both really works. */ static void test_grpc_fd_change(void) { - grpc_fd *em_fd; + grpc_fd* em_fd; fd_change_data a, b; int flags; int sv[2]; @@ -471,7 +471,7 @@ static void test_grpc_fd_change(void) { /* And now wait for it to run. */ gpr_mu_lock(g_mu); while (a.cb_that_ran == NULL) { - grpc_pollset_worker *worker = NULL; + grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); @@ -495,7 +495,7 @@ static void test_grpc_fd_change(void) { gpr_mu_lock(g_mu); while (b.cb_that_ran == NULL) { - grpc_pollset_worker *worker = NULL; + grpc_pollset_worker* worker = NULL; GPR_ASSERT(GRPC_LOG_IF_ERROR( "pollset_work", grpc_pollset_work(&exec_ctx, g_pollset, &worker, GRPC_MILLIS_INF_FUTURE))); @@ -514,12 +514,12 @@ static void test_grpc_fd_change(void) { close(sv[1]); } -static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, - grpc_error *error) { +static void destroy_pollset(grpc_exec_ctx* exec_ctx, void* p, + grpc_error* error) { grpc_pollset_destroy(exec_ctx, p); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { grpc_closure destroyed; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_test_init(argc, argv); @@ -540,6 +540,6 @@ int main(int argc, char **argv) { #else /* GRPC_POSIX_SOCKET */ -int main(int argc, char **argv) { return 1; } +int main(int argc, char** argv) { return 1; } #endif /* GRPC_POSIX_SOCKET */ |