From 4e826be32ee6d67f3e71971e3475fdd8d2f6176c Mon Sep 17 00:00:00 2001 From: Dan Born Date: Mon, 3 Oct 2016 20:33:25 -0700 Subject: Correctly count port indices and siblings --- src/core/lib/iomgr/tcp_server_posix.c | 41 ++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'src/core/lib') diff --git a/src/core/lib/iomgr/tcp_server_posix.c b/src/core/lib/iomgr/tcp_server_posix.c index 2d3f6cf9a7..596f8280d4 100644 --- a/src/core/lib/iomgr/tcp_server_posix.c +++ b/src/core/lib/iomgr/tcp_server_posix.c @@ -648,35 +648,40 @@ done: } } -unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server *s, - unsigned port_index) { - unsigned num_fds = 0; +/* Return listener at port_index or NULL. */ +static grpc_tcp_listener *get_port_index(grpc_tcp_server *s, + unsigned port_index) { + unsigned num_ports = 0; grpc_tcp_listener *sp; - for (sp = s->head; sp && port_index != 0; sp = sp->next) { + for (sp = s->head; sp; sp = sp->next) { if (!sp->is_sibling) { - --port_index; + if (++num_ports > port_index) { + return sp; + } } } - for (; sp; sp = sp->sibling, ++num_fds) - ; + return NULL; +} + +unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server *s, + unsigned port_index) { + unsigned num_fds = 0; + grpc_tcp_listener *sp = get_port_index(s, port_index); + for (; sp; sp = sp->sibling) { + ++num_fds; + } return num_fds; } int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index, unsigned fd_index) { - grpc_tcp_listener *sp; - for (sp = s->head; sp && port_index != 0; sp = sp->next) { - if (!sp->is_sibling) { - --port_index; + grpc_tcp_listener *sp = get_port_index(s, port_index); + for (; sp; sp = sp->sibling, --fd_index) { + if (fd_index == 0) { + return sp->fd; } } - for (; sp && fd_index != 0; sp = sp->sibling, --fd_index) - ; - if (sp) { - return sp->fd; - } else { - return -1; - } + return -1; } void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s, -- cgit v1.2.3 From f88c92b4f2e62c506b69188485012288ed70c43d Mon Sep 17 00:00:00 2001 From: Dan Born Date: Mon, 17 Oct 2016 15:07:05 -0700 Subject: Merge fixup --- src/core/lib/iomgr/tcp_server_posix.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/core/lib') diff --git a/src/core/lib/iomgr/tcp_server_posix.c b/src/core/lib/iomgr/tcp_server_posix.c index 4f49dad815..242388bd17 100644 --- a/src/core/lib/iomgr/tcp_server_posix.c +++ b/src/core/lib/iomgr/tcp_server_posix.c @@ -191,9 +191,6 @@ grpc_error *grpc_tcp_server_create(grpc_closure *shutdown_complete, } static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) { - gpr_mu_lock(&s->mu); - GPR_ASSERT(s->shutdown); - gpr_mu_unlock(&s->mu); if (s->shutdown_complete != NULL) { grpc_exec_ctx_sched(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE, NULL); } -- cgit v1.2.3 From a983dc7fc2689e4f7e0fbd25ef7a6e84f7374cb9 Mon Sep 17 00:00:00 2001 From: Dan Born Date: Mon, 17 Oct 2016 15:11:17 -0700 Subject: Merge fixups --- src/core/lib/iomgr/tcp_server_posix.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/core/lib') diff --git a/src/core/lib/iomgr/tcp_server_posix.c b/src/core/lib/iomgr/tcp_server_posix.c index 242388bd17..4f49dad815 100644 --- a/src/core/lib/iomgr/tcp_server_posix.c +++ b/src/core/lib/iomgr/tcp_server_posix.c @@ -191,6 +191,9 @@ grpc_error *grpc_tcp_server_create(grpc_closure *shutdown_complete, } static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) { + gpr_mu_lock(&s->mu); + GPR_ASSERT(s->shutdown); + gpr_mu_unlock(&s->mu); if (s->shutdown_complete != NULL) { grpc_exec_ctx_sched(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE, NULL); } -- cgit v1.2.3 From 19e01fdc326b73c15d977657c23e4bf6e7e25988 Mon Sep 17 00:00:00 2001 From: Dan Born Date: Tue, 18 Oct 2016 11:49:45 -0700 Subject: clang-format --- src/core/lib/iomgr/tcp_server_posix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/lib') diff --git a/src/core/lib/iomgr/tcp_server_posix.c b/src/core/lib/iomgr/tcp_server_posix.c index 4f49dad815..d8eb24b861 100644 --- a/src/core/lib/iomgr/tcp_server_posix.c +++ b/src/core/lib/iomgr/tcp_server_posix.c @@ -651,7 +651,8 @@ done: } } -/* Return listener at port_index or NULL. Should only be called with s->mu locked. */ +/* Return listener at port_index or NULL. Should only be called with s->mu + locked. */ static grpc_tcp_listener *get_port_index(grpc_tcp_server *s, unsigned port_index) { unsigned num_ports = 0; -- cgit v1.2.3