|
|
|
@ -657,41 +657,46 @@ done: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server *s, |
|
|
|
|
/* 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_fds = 0; |
|
|
|
|
unsigned num_ports = 0; |
|
|
|
|
grpc_tcp_listener *sp; |
|
|
|
|
gpr_mu_lock(&s->mu); |
|
|
|
|
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; |
|
|
|
|
gpr_mu_lock(&s->mu); |
|
|
|
|
grpc_tcp_listener *sp = get_port_index(s, port_index); |
|
|
|
|
for (; sp; sp = sp->sibling) { |
|
|
|
|
++num_fds; |
|
|
|
|
} |
|
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
|
return num_fds; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int grpc_tcp_server_port_fd(grpc_tcp_server *s, unsigned port_index, |
|
|
|
|
unsigned fd_index) { |
|
|
|
|
grpc_tcp_listener *sp; |
|
|
|
|
int fd; |
|
|
|
|
gpr_mu_lock(&s->mu); |
|
|
|
|
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) { |
|
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
|
return sp->fd; |
|
|
|
|
} |
|
|
|
|
for (; sp && fd_index != 0; sp = sp->sibling, --fd_index) |
|
|
|
|
; |
|
|
|
|
if (sp) { |
|
|
|
|
fd = sp->fd; |
|
|
|
|
} else { |
|
|
|
|
fd = -1; |
|
|
|
|
} |
|
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
|
return fd; |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s, |
|
|
|
|