Add make udp_server shutdown_fd() protected by mutex lock.

pull/10796/head
Dan Zhang 8 years ago
parent 98c6c9bc16
commit fefd2f2d8b
  1. 19
      src/core/lib/iomgr/udp_server.c

@ -92,6 +92,11 @@ struct grpc_udp_listener {
struct grpc_udp_listener *next; struct grpc_udp_listener *next;
}; };
struct shutdown_fd_args {
grpc_fd *fd;
gpr_mu *server_mu;
};
/* the overall server */ /* the overall server */
struct grpc_udp_server { struct grpc_udp_server {
gpr_mu mu; gpr_mu mu;
@ -151,8 +156,13 @@ grpc_udp_server *grpc_udp_server_create(const grpc_channel_args *args) {
return s; return s;
} }
static void shutdown_fd(grpc_exec_ctx *exec_ctx, void *fd, grpc_error *error) { static void shutdown_fd(grpc_exec_ctx *exec_ctx, void *args,
grpc_fd_shutdown(exec_ctx, (grpc_fd *)fd, GRPC_ERROR_REF(error)); grpc_error *error) {
struct shutdown_fd_args *shutdown_args = (struct shutdown_fd_args *)args;
gpr_mu_lock(shutdown_args->server_mu);
grpc_fd_shutdown(exec_ctx, shutdown_args->fd, GRPC_ERROR_REF(error));
gpr_mu_unlock(shutdown_args->server_mu);
gpr_free(shutdown_args);
} }
static void dummy_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { static void dummy_cb(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
@ -242,7 +252,10 @@ void grpc_udp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_udp_server *s,
if (s->active_ports) { if (s->active_ports) {
for (sp = s->head; sp; sp = sp->next) { for (sp = s->head; sp; sp = sp->next) {
GPR_ASSERT(sp->orphan_cb); GPR_ASSERT(sp->orphan_cb);
grpc_closure_init(&sp->orphan_fd_closure, shutdown_fd, sp->emfd, struct shutdown_fd_args *args = gpr_malloc(sizeof(*args));
args->fd = sp->emfd;
args->server_mu = &s->mu;
grpc_closure_init(&sp->orphan_fd_closure, shutdown_fd, args,
grpc_schedule_on_exec_ctx); grpc_schedule_on_exec_ctx);
sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure, sp->orphan_cb(exec_ctx, sp->emfd, &sp->orphan_fd_closure,
sp->server->user_data); sp->server->user_data);

Loading…
Cancel
Save