diff options
Diffstat (limited to 'src/core/lib/iomgr/tcp_server_uv.cc')
-rw-r--r-- | src/core/lib/iomgr/tcp_server_uv.cc | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc index fc4b58f81c..2116ec106c 100644 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ b/src/core/lib/iomgr/tcp_server_uv.cc @@ -37,12 +37,12 @@ /* one listening port */ typedef struct grpc_tcp_listener grpc_tcp_listener; struct grpc_tcp_listener { - uv_tcp_t *handle; - grpc_tcp_server *server; + uv_tcp_t* handle; + grpc_tcp_server* server; unsigned port_index; int port; /* linked list */ - struct grpc_tcp_listener *next; + struct grpc_tcp_listener* next; bool closed; @@ -54,36 +54,36 @@ struct grpc_tcp_server { /* Called whenever accept() succeeds on a server port. */ grpc_tcp_server_cb on_accept_cb; - void *on_accept_cb_arg; + void* on_accept_cb_arg; int open_ports; /* linked list of server ports */ - grpc_tcp_listener *head; - grpc_tcp_listener *tail; + grpc_tcp_listener* head; + grpc_tcp_listener* tail; /* List of closures passed to shutdown_starting_add(). */ grpc_closure_list shutdown_starting; /* shutdown callback */ - grpc_closure *shutdown_complete; + grpc_closure* shutdown_complete; bool shutdown; - grpc_resource_quota *resource_quota; + grpc_resource_quota* resource_quota; }; -grpc_error *grpc_tcp_server_create(grpc_closure *shutdown_complete, - const grpc_channel_args *args, - grpc_tcp_server **server) { - grpc_tcp_server *s = (grpc_tcp_server *)gpr_malloc(sizeof(grpc_tcp_server)); +grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { + grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); s->resource_quota = grpc_resource_quota_create(NULL); for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) { if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { if (args->args[i].type == GRPC_ARG_POINTER) { grpc_resource_quota_unref_internal(s->resource_quota); s->resource_quota = grpc_resource_quota_ref_internal( - (grpc_resource_quota *)args->args[i].value.pointer.p); + (grpc_resource_quota*)args->args[i].value.pointer.p); } else { grpc_resource_quota_unref_internal(s->resource_quota); gpr_free(s); @@ -106,26 +106,26 @@ grpc_error *grpc_tcp_server_create(grpc_closure *shutdown_complete, return GRPC_ERROR_NONE; } -grpc_tcp_server *grpc_tcp_server_ref(grpc_tcp_server *s) { +grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { GRPC_UV_ASSERT_SAME_THREAD(); gpr_ref(&s->refs); return s; } -void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s, - grpc_closure *shutdown_starting) { +void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, GRPC_ERROR_NONE); } -static void finish_shutdown(grpc_tcp_server *s) { +static void finish_shutdown(grpc_tcp_server* s) { GPR_ASSERT(s->shutdown); if (s->shutdown_complete != NULL) { GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); } while (s->head) { - grpc_tcp_listener *sp = s->head; + grpc_tcp_listener* sp = s->head; s->head = sp->next; sp->next = NULL; gpr_free(sp->handle); @@ -135,8 +135,8 @@ static void finish_shutdown(grpc_tcp_server *s) { gpr_free(s); } -static void handle_close_callback(uv_handle_t *handle) { - grpc_tcp_listener *sp = (grpc_tcp_listener *)handle->data; +static void handle_close_callback(uv_handle_t* handle) { + grpc_tcp_listener* sp = (grpc_tcp_listener*)handle->data; ExecCtx _local_exec_ctx; sp->server->open_ports--; if (sp->server->open_ports == 0 && sp->server->shutdown) { @@ -145,16 +145,16 @@ static void handle_close_callback(uv_handle_t *handle) { grpc_exec_ctx_finish(); } -static void close_listener(grpc_tcp_listener *sp) { +static void close_listener(grpc_tcp_listener* sp) { if (!sp->closed) { sp->closed = true; - uv_close((uv_handle_t *)sp->handle, handle_close_callback); + uv_close((uv_handle_t*)sp->handle, handle_close_callback); } } -static void tcp_server_destroy(grpc_tcp_server *s) { +static void tcp_server_destroy(grpc_tcp_server* s) { int immediately_done = 0; - grpc_tcp_listener *sp; + grpc_tcp_listener* sp; GPR_ASSERT(!s->shutdown); s->shutdown = true; @@ -171,7 +171,7 @@ static void tcp_server_destroy(grpc_tcp_server *s) { } } -void grpc_tcp_server_unref(grpc_tcp_server *s) { +void grpc_tcp_server_unref(grpc_tcp_server* s) { GRPC_UV_ASSERT_SAME_THREAD(); if (gpr_unref(&s->refs)) { /* Complete shutdown_starting work before destroying. */ @@ -188,25 +188,25 @@ void grpc_tcp_server_unref(grpc_tcp_server *s) { } } -static void finish_accept(grpc_tcp_listener *sp) { - grpc_tcp_server_acceptor *acceptor = - (grpc_tcp_server_acceptor *)gpr_malloc(sizeof(*acceptor)); - uv_tcp_t *client = NULL; - grpc_endpoint *ep = NULL; +static void finish_accept(grpc_tcp_listener* sp) { + grpc_tcp_server_acceptor* acceptor = + (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); + uv_tcp_t* client = NULL; + grpc_endpoint* ep = NULL; grpc_resolved_address peer_name; - char *peer_name_string; + char* peer_name_string; int err; - uv_tcp_t *server = sp->handle; + uv_tcp_t* server = sp->handle; - client = (uv_tcp_t *)gpr_malloc(sizeof(uv_tcp_t)); + client = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); uv_tcp_init(uv_default_loop(), client); // UV documentation says this is guaranteed to succeed - uv_accept((uv_stream_t *)server, (uv_stream_t *)client); + uv_accept((uv_stream_t*)server, (uv_stream_t*)client); peer_name_string = NULL; memset(&peer_name, 0, sizeof(grpc_resolved_address)); peer_name.len = sizeof(struct sockaddr_storage); - err = uv_tcp_getpeername(client, (struct sockaddr *)&peer_name.addr, - (int *)&peer_name.len); + err = uv_tcp_getpeername(client, (struct sockaddr*)&peer_name.addr, + (int*)&peer_name.len); if (err == 0) { peer_name_string = grpc_sockaddr_to_uri(&peer_name); } else { @@ -228,8 +228,8 @@ static void finish_accept(grpc_tcp_listener *sp) { gpr_free(peer_name_string); } -static void on_connect(uv_stream_t *server, int status) { - grpc_tcp_listener *sp = (grpc_tcp_listener *)server->data; +static void on_connect(uv_stream_t* server, int status) { + grpc_tcp_listener* sp = (grpc_tcp_listener*)server->data; ExecCtx _local_exec_ctx; if (status < 0) { @@ -258,18 +258,18 @@ static void on_connect(uv_stream_t *server, int status) { grpc_exec_ctx_finish(); } -static grpc_error *add_socket_to_server(grpc_tcp_server *s, uv_tcp_t *handle, - const grpc_resolved_address *addr, +static grpc_error* add_socket_to_server(grpc_tcp_server* s, uv_tcp_t* handle, + const grpc_resolved_address* addr, unsigned port_index, - grpc_tcp_listener **listener) { - grpc_tcp_listener *sp = NULL; + grpc_tcp_listener** listener) { + grpc_tcp_listener* sp = NULL; int port = -1; int status; - grpc_error *error; + grpc_error* error; grpc_resolved_address sockname_temp; // The last argument to uv_tcp_bind is flags - status = uv_tcp_bind(handle, (struct sockaddr *)addr->addr, 0); + status = uv_tcp_bind(handle, (struct sockaddr*)addr->addr, 0); if (status != 0) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to bind to port"); error = @@ -278,7 +278,7 @@ static grpc_error *add_socket_to_server(grpc_tcp_server *s, uv_tcp_t *handle, return error; } - status = uv_listen((uv_stream_t *)handle, SOMAXCONN, on_connect); + status = uv_listen((uv_stream_t*)handle, SOMAXCONN, on_connect); if (status != 0) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to listen to port"); error = @@ -288,8 +288,8 @@ static grpc_error *add_socket_to_server(grpc_tcp_server *s, uv_tcp_t *handle, } sockname_temp.len = (int)sizeof(struct sockaddr_storage); - status = uv_tcp_getsockname(handle, (struct sockaddr *)&sockname_temp.addr, - (int *)&sockname_temp.len); + status = uv_tcp_getsockname(handle, (struct sockaddr*)&sockname_temp.addr, + (int*)&sockname_temp.len); if (status != 0) { error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getsockname failed"); error = @@ -302,7 +302,7 @@ static grpc_error *add_socket_to_server(grpc_tcp_server *s, uv_tcp_t *handle, GPR_ASSERT(port >= 0); GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server"); - sp = (grpc_tcp_listener *)gpr_zalloc(sizeof(grpc_tcp_listener)); + sp = (grpc_tcp_listener*)gpr_zalloc(sizeof(grpc_tcp_listener)); sp->next = NULL; if (s->head == NULL) { s->head = sp; @@ -323,19 +323,19 @@ static grpc_error *add_socket_to_server(grpc_tcp_server *s, uv_tcp_t *handle, return GRPC_ERROR_NONE; } -grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, - const grpc_resolved_address *addr, - int *port) { +grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* port) { // This function is mostly copied from tcp_server_windows.c - grpc_tcp_listener *sp = NULL; - uv_tcp_t *handle; + grpc_tcp_listener* sp = NULL; + uv_tcp_t* handle; grpc_resolved_address addr6_v4mapped; grpc_resolved_address wildcard; - grpc_resolved_address *allocated_addr = NULL; + grpc_resolved_address* allocated_addr = NULL; grpc_resolved_address sockname_temp; unsigned port_index = 0; int status; - grpc_error *error = GRPC_ERROR_NONE; + grpc_error* error = GRPC_ERROR_NONE; int family; GRPC_UV_ASSERT_SAME_THREAD(); @@ -350,12 +350,12 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, for (sp = s->head; sp; sp = sp->next) { sockname_temp.len = sizeof(struct sockaddr_storage); if (0 == uv_tcp_getsockname(sp->handle, - (struct sockaddr *)&sockname_temp.addr, - (int *)&sockname_temp.len)) { + (struct sockaddr*)&sockname_temp.addr, + (int*)&sockname_temp.len)) { *port = grpc_sockaddr_get_port(&sockname_temp); if (*port > 0) { - allocated_addr = (grpc_resolved_address *)gpr_malloc( - sizeof(grpc_resolved_address)); + allocated_addr = + (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address)); memcpy(allocated_addr, addr, sizeof(grpc_resolved_address)); grpc_sockaddr_set_port(allocated_addr, *port); addr = allocated_addr; @@ -376,14 +376,14 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, addr = &wildcard; } - handle = (uv_tcp_t *)gpr_malloc(sizeof(uv_tcp_t)); + handle = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); family = grpc_sockaddr_get_family(addr); status = uv_tcp_init_ex(uv_default_loop(), handle, (unsigned int)family); #if defined(GPR_LINUX) && defined(SO_REUSEPORT) if (family == AF_INET || family == AF_INET6) { int fd; - uv_fileno((uv_handle_t *)handle, &fd); + uv_fileno((uv_handle_t*)handle, &fd); int enable = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(enable)); } @@ -402,9 +402,9 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, gpr_free(allocated_addr); if (GRPC_TRACER_ON(grpc_tcp_trace)) { - char *port_string; + char* port_string; grpc_sockaddr_to_string(&port_string, addr, 0); - const char *str = grpc_error_string(error); + const char* str = grpc_error_string(error); if (port_string) { gpr_log(GPR_DEBUG, "SERVER %p add_port %s error=%s", s, port_string, str); gpr_free(port_string); @@ -414,7 +414,7 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, } if (error != GRPC_ERROR_NONE) { - grpc_error *error_out = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + grpc_error* error_out = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( "Failed to add port to server", &error, 1); GRPC_ERROR_UNREF(error); error = error_out; @@ -426,10 +426,10 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, return error; } -void grpc_tcp_server_start(grpc_tcp_server *server, grpc_pollset **pollsets, +void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, size_t pollset_count, - grpc_tcp_server_cb on_accept_cb, void *cb_arg) { - grpc_tcp_listener *sp; + grpc_tcp_server_cb on_accept_cb, void* cb_arg) { + grpc_tcp_listener* sp; (void)pollsets; (void)pollset_count; GRPC_UV_ASSERT_SAME_THREAD(); @@ -448,6 +448,6 @@ void grpc_tcp_server_start(grpc_tcp_server *server, grpc_pollset **pollsets, } } -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server *s) {} +void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} #endif /* GRPC_UV */ |