From 8ed24e205c1596a179029d0d488ce57754c44827 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 8 May 2015 09:59:51 -0700 Subject: Plumb pollset_set through to tcp setup --- src/core/surface/secure_channel_create.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/core/surface/secure_channel_create.c') diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index 3e331293b5..73f4d51855 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -140,9 +140,10 @@ static int maybe_try_next_resolved(request *r) { if (!r->resolved) return 0; if (r->resolved_index == r->resolved->naddrs) return 0; addr = &r->resolved->addrs[r->resolved_index++]; - grpc_tcp_client_connect(on_connect, r, (struct sockaddr *)&addr->addr, - addr->len, - grpc_client_setup_request_deadline(r->cs_request)); + grpc_tcp_client_connect( + on_connect, r, grpc_client_setup_get_interested_parties(r->cs_request), + (struct sockaddr *)&addr->addr, addr->len, + grpc_client_setup_request_deadline(r->cs_request)); return 1; } -- cgit v1.2.3 From cb36e9f95874fc12516a87521abeca716d4f55a8 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 29 May 2015 11:20:21 -0700 Subject: Fix memory leak, add debug --- src/core/channel/client_setup.c | 39 +++++++++++++++++++++----------- src/core/channel/client_setup.h | 6 ++--- src/core/surface/channel_create.c | 8 +++---- src/core/surface/secure_channel_create.c | 8 +++---- 4 files changed, 37 insertions(+), 24 deletions(-) (limited to 'src/core/surface/secure_channel_create.c') diff --git a/src/core/channel/client_setup.c b/src/core/channel/client_setup.c index df6d0b6ece..edad1f0dac 100644 --- a/src/core/channel/client_setup.c +++ b/src/core/channel/client_setup.c @@ -93,6 +93,8 @@ static void setup_initiate(grpc_transport_setup *sp) { grpc_client_setup_request *r = gpr_malloc(sizeof(grpc_client_setup_request)); int in_alarm = 0; + gpr_log(GPR_DEBUG, "setup_initiate: %p", r); + r->setup = s; grpc_pollset_set_init(&r->interested_parties); /* TODO(klempner): Actually set a deadline */ @@ -168,6 +170,7 @@ static void setup_cancel(grpc_transport_setup *sp) { if (s->in_alarm) { cancel_alarm = 1; } + gpr_log(GPR_DEBUG, "%p setup_cancel: refs=%d", s, s->refs); if (--s->refs == 0) { gpr_mu_unlock(&s->mu); destroy_setup(s); @@ -179,7 +182,8 @@ static void setup_cancel(grpc_transport_setup *sp) { } } -int grpc_client_setup_cb_begin(grpc_client_setup_request *r) { +int grpc_client_setup_cb_begin(grpc_client_setup_request *r, const char *reason) { + gpr_log(GPR_DEBUG, "setup_cb_begin: %p %s", r, reason); gpr_mu_lock(&r->setup->mu); if (r->setup->cancelled) { gpr_mu_unlock(&r->setup->mu); @@ -190,7 +194,8 @@ int grpc_client_setup_cb_begin(grpc_client_setup_request *r) { return 1; } -void grpc_client_setup_cb_end(grpc_client_setup_request *r) { +void grpc_client_setup_cb_end(grpc_client_setup_request *r, const char *reason) { + gpr_log(GPR_DEBUG, "setup_cb_end: %p %s", r, reason); gpr_mu_lock(&r->setup->mu); r->setup->in_cb--; if (r->setup->cancelled) gpr_cv_signal(&r->setup->cv); @@ -209,6 +214,8 @@ void grpc_client_setup_create_and_attach( void (*done)(void *user_data), void *user_data) { grpc_client_setup *s = gpr_malloc(sizeof(grpc_client_setup)); + gpr_log(GPR_DEBUG, "%p setup_create", s); + s->base.vtable = &setup_vtable; gpr_mu_init(&s->mu); gpr_cv_init(&s->cv); @@ -227,14 +234,16 @@ void grpc_client_setup_create_and_attach( grpc_client_channel_set_transport_setup(newly_minted_channel, &s->base); } -int grpc_client_setup_request_should_continue(grpc_client_setup_request *r) { +int grpc_client_setup_request_should_continue(grpc_client_setup_request *r, const char *reason) { int result; if (gpr_time_cmp(gpr_now(), r->deadline) > 0) { - return 0; + result = 0; + } else { + gpr_mu_lock(&r->setup->mu); + result = r->setup->active_request == r; + gpr_mu_unlock(&r->setup->mu); } - gpr_mu_lock(&r->setup->mu); - result = r->setup->active_request == r; - gpr_mu_unlock(&r->setup->mu); + gpr_log(GPR_DEBUG, "should_continue: %p result=%d %s", r, result, reason); return result; } @@ -266,20 +275,22 @@ void grpc_client_setup_request_finish(grpc_client_setup_request *r, int retry = !was_successful; grpc_client_setup *s = r->setup; + gpr_log(GPR_DEBUG, "setup_request_finish: %p success=%d retry0=%d", r, was_successful, retry); + gpr_mu_lock(&s->mu); if (s->active_request == r) { s->active_request = NULL; } else { retry = 0; } + + gpr_log(GPR_DEBUG, "retry=%d", retry); + if (!retry && 0 == --s->refs) { gpr_mu_unlock(&s->mu); destroy_setup(s); destroy_request(r); - return; - } - - if (retry) { + } else if (retry) { /* TODO(klempner): Replace these values with further consideration. 2x is probably too aggressive of a backoff. */ gpr_timespec max_backoff = gpr_time_from_minutes(2); @@ -293,9 +304,11 @@ void grpc_client_setup_request_finish(grpc_client_setup_request *r, if (gpr_time_cmp(s->current_backoff_interval, max_backoff) > 0) { s->current_backoff_interval = max_backoff; } + gpr_mu_unlock(&s->mu); + } else { + gpr_mu_unlock(&s->mu); + destroy_request(r); } - - gpr_mu_unlock(&s->mu); } const grpc_channel_args *grpc_client_setup_get_channel_args( diff --git a/src/core/channel/client_setup.h b/src/core/channel/client_setup.h index 24e7517c83..cbabb510b1 100644 --- a/src/core/channel/client_setup.h +++ b/src/core/channel/client_setup.h @@ -52,7 +52,7 @@ void grpc_client_setup_create_and_attach( /* Check that r is the active request: needs to be performed at each callback. If this races, we'll have two connection attempts running at once and the old one will get cleaned up in due course, which is fine. */ -int grpc_client_setup_request_should_continue(grpc_client_setup_request *r); +int grpc_client_setup_request_should_continue(grpc_client_setup_request *r, const char *reason); void grpc_client_setup_request_finish(grpc_client_setup_request *r, int was_successful); const grpc_channel_args *grpc_client_setup_get_channel_args( @@ -61,8 +61,8 @@ const grpc_channel_args *grpc_client_setup_get_channel_args( /* Call before calling back into the setup listener, and call only if this function returns 1. If it returns 1, also promise to call grpc_client_setup_cb_end */ -int grpc_client_setup_cb_begin(grpc_client_setup_request *r); -void grpc_client_setup_cb_end(grpc_client_setup_request *r); +int grpc_client_setup_cb_begin(grpc_client_setup_request *r, const char *reason); +void grpc_client_setup_cb_end(grpc_client_setup_request *r, const char *reason); /* Get the deadline for a request passed in to initiate. Implementations should make a best effort to honor this deadline. */ diff --git a/src/core/surface/channel_create.c b/src/core/surface/channel_create.c index b2d3a1923b..061669ec6e 100644 --- a/src/core/surface/channel_create.c +++ b/src/core/surface/channel_create.c @@ -90,7 +90,7 @@ static void done(request *r, int was_successful) { static void on_connect(void *rp, grpc_endpoint *tcp) { request *r = rp; - if (!grpc_client_setup_request_should_continue(r->cs_request)) { + if (!grpc_client_setup_request_should_continue(r->cs_request, "on_connect")) { if (tcp) { grpc_endpoint_shutdown(tcp); grpc_endpoint_destroy(tcp); @@ -106,12 +106,12 @@ static void on_connect(void *rp, grpc_endpoint *tcp) { } else { return; } - } else if (grpc_client_setup_cb_begin(r->cs_request)) { + } else if (grpc_client_setup_cb_begin(r->cs_request, "on_connect")) { grpc_create_chttp2_transport( r->setup->setup_callback, r->setup->setup_user_data, grpc_client_setup_get_channel_args(r->cs_request), tcp, NULL, 0, grpc_client_setup_get_mdctx(r->cs_request), 1); - grpc_client_setup_cb_end(r->cs_request); + grpc_client_setup_cb_end(r->cs_request, "on_connect"); done(r, 1); return; } else { @@ -137,7 +137,7 @@ static void on_resolved(void *rp, grpc_resolved_addresses *resolved) { request *r = rp; /* if we're not still the active request, abort */ - if (!grpc_client_setup_request_should_continue(r->cs_request)) { + if (!grpc_client_setup_request_should_continue(r->cs_request, "on_resolved")) { if (resolved) { grpc_resolved_addresses_destroy(resolved); } diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index 73f4d51855..dfc4a1920a 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -96,12 +96,12 @@ static void on_secure_transport_setup_done(void *rp, if (status != GRPC_SECURITY_OK) { gpr_log(GPR_ERROR, "Secure transport setup failed with error %d.", status); done(r, 0); - } else if (grpc_client_setup_cb_begin(r->cs_request)) { + } else if (grpc_client_setup_cb_begin(r->cs_request, "on_secure_transport_setup_done")) { grpc_create_chttp2_transport( r->setup->setup_callback, r->setup->setup_user_data, grpc_client_setup_get_channel_args(r->cs_request), secure_endpoint, NULL, 0, grpc_client_setup_get_mdctx(r->cs_request), 1); - grpc_client_setup_cb_end(r->cs_request); + grpc_client_setup_cb_end(r->cs_request, "on_secure_transport_setup_done"); done(r, 1); } else { done(r, 0); @@ -112,7 +112,7 @@ static void on_secure_transport_setup_done(void *rp, static void on_connect(void *rp, grpc_endpoint *tcp) { request *r = rp; - if (!grpc_client_setup_request_should_continue(r->cs_request)) { + if (!grpc_client_setup_request_should_continue(r->cs_request, "on_connect.secure")) { if (tcp) { grpc_endpoint_shutdown(tcp); grpc_endpoint_destroy(tcp); @@ -152,7 +152,7 @@ static void on_resolved(void *rp, grpc_resolved_addresses *resolved) { request *r = rp; /* if we're not still the active request, abort */ - if (!grpc_client_setup_request_should_continue(r->cs_request)) { + if (!grpc_client_setup_request_should_continue(r->cs_request, "on_resolved.secure")) { if (resolved) { grpc_resolved_addresses_destroy(resolved); } -- cgit v1.2.3 From 8674cb10eb1c8f02de5ad36aaa6bd4d7638de384 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 5 Jun 2015 07:09:25 -0700 Subject: clang-format --- include/grpc/grpc.h | 20 +++---- src/core/channel/child_channel.c | 11 ++-- src/core/channel/client_setup.c | 9 ++-- src/core/channel/client_setup.h | 6 ++- src/core/iomgr/fd_posix.c | 12 +++-- src/core/iomgr/fd_posix.h | 8 +-- src/core/iomgr/iomgr.c | 7 +-- src/core/iomgr/pollset.h | 3 +- src/core/iomgr/pollset_kick_posix.c | 14 ++--- src/core/iomgr/pollset_kick_posix.h | 14 +++-- src/core/iomgr/pollset_multipoller_with_epoll.c | 12 +++-- .../iomgr/pollset_multipoller_with_poll_posix.c | 9 ++-- src/core/iomgr/pollset_posix.c | 2 +- src/core/iomgr/pollset_set_windows.h | 4 +- src/core/iomgr/pollset_windows.c | 8 ++- src/core/iomgr/pollset_windows.h | 6 +-- src/core/iomgr/tcp_client.h | 2 +- src/core/iomgr/tcp_client_posix.c | 3 +- src/core/iomgr/tcp_client_windows.c | 18 +++---- src/core/iomgr/tcp_posix.c | 5 +- src/core/iomgr/tcp_server_posix.c | 5 +- src/core/security/client_auth_filter.c | 15 +++--- src/core/security/credentials.c | 19 +++---- src/core/security/credentials.h | 5 +- src/core/security/google_default_credentials.c | 4 +- src/core/surface/channel.c | 2 +- src/core/surface/channel_create.c | 3 +- src/core/surface/completion_queue.c | 18 ++----- src/core/surface/lame_client.c | 6 +-- src/core/surface/secure_channel_create.c | 9 ++-- src/core/surface/server.c | 4 +- src/core/transport/chttp2_transport.c | 63 ++++++++++++---------- 32 files changed, 159 insertions(+), 167 deletions(-) (limited to 'src/core/surface/secure_channel_create.c') diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 2821c9ebcf..43ee1211bc 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -93,7 +93,7 @@ typedef struct { } grpc_arg; /** An array of arguments that can be passed around. - + Used to set optional channel-level configuration. These configuration options are modelled as key-value pairs as defined by grpc_arg; keys are strings to allow easy backwards-compatible extension @@ -196,11 +196,11 @@ typedef struct grpc_metadata { /** The type of completion (for grpc_event) */ typedef enum grpc_completion_type { /** Shutting down */ - GRPC_QUEUE_SHUTDOWN, + GRPC_QUEUE_SHUTDOWN, /** No event before timeout */ - GRPC_QUEUE_TIMEOUT, + GRPC_QUEUE_TIMEOUT, /** Operation completion */ - GRPC_OP_COMPLETE + GRPC_OP_COMPLETE } grpc_completion_type; /** The result of an operation. @@ -209,7 +209,7 @@ typedef enum grpc_completion_type { typedef struct grpc_event { /** The type of the completion. */ grpc_completion_type type; - /** non-zero if the operation was successful, 0 upon failure. + /** non-zero if the operation was successful, 0 upon failure. Only GRPC_OP_COMPLETE can succeed or fail. */ int success; /** The tag passed to grpc_call_start_batch etc to start this operation. @@ -336,7 +336,7 @@ typedef struct grpc_op { } grpc_op; /** Initialize the grpc library. - + It is not safe to call any other grpc functions before calling this. (To avoid overhead, little checking is done, and some things may work. We do not warrant that they will continue to do so in future revisions of this @@ -344,7 +344,7 @@ typedef struct grpc_op { void grpc_init(void); /** Shut down the grpc library. - + No memory is used by grpc after this call returns, nor are any instructions executing within the grpc library. Prior to calling, all application owned grpc objects must have been @@ -355,7 +355,7 @@ void grpc_shutdown(void); grpc_completion_queue *grpc_completion_queue_create(void); /** Blocks until an event is available, the completion queue is being shut down, - or deadline is reached. + or deadline is reached. Returns NULL on timeout, otherwise the event that occurred. @@ -365,7 +365,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cq, gpr_timespec deadline); /** Blocks until an event with tag 'tag' is available, the completion queue is - being shutdown or deadline is reached. + being shutdown or deadline is reached. Returns NULL on timeout, or a pointer to the event that occurred. @@ -512,7 +512,7 @@ void grpc_server_start(grpc_server *server); void grpc_server_shutdown_and_notify(grpc_server *server, grpc_completion_queue *cq, void *tag); -/* Cancel all in-progress calls. +/* Cancel all in-progress calls. Only usable after shutdown. */ void grpc_server_cancel_all_calls(grpc_server *server); diff --git a/src/core/channel/child_channel.c b/src/core/channel/child_channel.c index cdc1c11681..d3e6af7287 100644 --- a/src/core/channel/child_channel.c +++ b/src/core/channel/child_channel.c @@ -157,16 +157,11 @@ static void lb_destroy_channel_elem(grpc_channel_element *elem) { } const grpc_channel_filter grpc_child_channel_top_filter = { - lb_start_transport_op, - lb_channel_op, + lb_start_transport_op, lb_channel_op, - sizeof(lb_call_data), - lb_init_call_elem, - lb_destroy_call_elem, + sizeof(lb_call_data), lb_init_call_elem, lb_destroy_call_elem, - sizeof(lb_channel_data), - lb_init_channel_elem, - lb_destroy_channel_elem, + sizeof(lb_channel_data), lb_init_channel_elem, lb_destroy_channel_elem, "child-channel", }; diff --git a/src/core/channel/client_setup.c b/src/core/channel/client_setup.c index f305d8ba9e..8a318eaa86 100644 --- a/src/core/channel/client_setup.c +++ b/src/core/channel/client_setup.c @@ -179,7 +179,8 @@ static void setup_cancel(grpc_transport_setup *sp) { } } -int grpc_client_setup_cb_begin(grpc_client_setup_request *r, const char *reason) { +int grpc_client_setup_cb_begin(grpc_client_setup_request *r, + const char *reason) { gpr_mu_lock(&r->setup->mu); if (r->setup->cancelled) { gpr_mu_unlock(&r->setup->mu); @@ -190,7 +191,8 @@ int grpc_client_setup_cb_begin(grpc_client_setup_request *r, const char *reason) return 1; } -void grpc_client_setup_cb_end(grpc_client_setup_request *r, const char *reason) { +void grpc_client_setup_cb_end(grpc_client_setup_request *r, + const char *reason) { gpr_mu_lock(&r->setup->mu); r->setup->in_cb--; if (r->setup->cancelled) gpr_cv_signal(&r->setup->cv); @@ -227,7 +229,8 @@ void grpc_client_setup_create_and_attach( grpc_client_channel_set_transport_setup(newly_minted_channel, &s->base); } -int grpc_client_setup_request_should_continue(grpc_client_setup_request *r, const char *reason) { +int grpc_client_setup_request_should_continue(grpc_client_setup_request *r, + const char *reason) { int result; if (gpr_time_cmp(gpr_now(), r->deadline) > 0) { result = 0; diff --git a/src/core/channel/client_setup.h b/src/core/channel/client_setup.h index cbabb510b1..7d40338840 100644 --- a/src/core/channel/client_setup.h +++ b/src/core/channel/client_setup.h @@ -52,7 +52,8 @@ void grpc_client_setup_create_and_attach( /* Check that r is the active request: needs to be performed at each callback. If this races, we'll have two connection attempts running at once and the old one will get cleaned up in due course, which is fine. */ -int grpc_client_setup_request_should_continue(grpc_client_setup_request *r, const char *reason); +int grpc_client_setup_request_should_continue(grpc_client_setup_request *r, + const char *reason); void grpc_client_setup_request_finish(grpc_client_setup_request *r, int was_successful); const grpc_channel_args *grpc_client_setup_get_channel_args( @@ -61,7 +62,8 @@ const grpc_channel_args *grpc_client_setup_get_channel_args( /* Call before calling back into the setup listener, and call only if this function returns 1. If it returns 1, also promise to call grpc_client_setup_cb_end */ -int grpc_client_setup_cb_begin(grpc_client_setup_request *r, const char *reason); +int grpc_client_setup_cb_begin(grpc_client_setup_request *r, + const char *reason); void grpc_client_setup_cb_end(grpc_client_setup_request *r, const char *reason); /* Get the deadline for a request passed in to initiate. Implementations should diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c index 2ac1866a66..347d8793c8 100644 --- a/src/core/iomgr/fd_posix.c +++ b/src/core/iomgr/fd_posix.c @@ -112,7 +112,8 @@ static void destroy(grpc_fd *fd) { #ifdef GRPC_FD_REF_COUNT_DEBUG #define REF_BY(fd, n, reason) ref_by(fd, n, reason, __FILE__, __LINE__) #define UNREF_BY(fd, n, reason) unref_by(fd, n, reason, __FILE__, __LINE__) -static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file, int line) { +static void ref_by(grpc_fd *fd, int n, const char *reason, const char *file, + int line) { gpr_log(GPR_DEBUG, "FD %d %p ref %d %d -> %d [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), gpr_atm_no_barrier_load(&fd->refst) + n, reason, file, line); @@ -125,7 +126,8 @@ static void ref_by(grpc_fd *fd, int n) { } #ifdef GRPC_FD_REF_COUNT_DEBUG -static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file, int line) { +static void unref_by(grpc_fd *fd, int n, const char *reason, const char *file, + int line) { gpr_atm old; gpr_log(GPR_DEBUG, "FD %d %p unref %d %d -> %d [%s; %s:%d]", fd->fd, fd, n, gpr_atm_no_barrier_load(&fd->refst), @@ -225,7 +227,7 @@ void grpc_fd_unref(grpc_fd *fd) { unref_by(fd, 2); } #endif static void process_callback(grpc_iomgr_closure *closure, int success, - int allow_synchronous_callback) { + int allow_synchronous_callback) { if (allow_synchronous_callback) { closure->cb(closure->cb_arg, success); } else { @@ -265,7 +267,7 @@ static void notify_on(grpc_fd *fd, gpr_atm *st, grpc_iomgr_closure *closure, GPR_ASSERT(gpr_atm_no_barrier_load(st) == READY); gpr_atm_rel_store(st, NOT_READY); process_callback(closure, !gpr_atm_acq_load(&fd->shutdown), - allow_synchronous_callback); + allow_synchronous_callback); return; default: /* WAITING */ /* upcallptr was set to a different closure. This is an error! */ @@ -309,7 +311,7 @@ static void set_ready(grpc_fd *fd, gpr_atm *st, /* only one set_ready can be active at once (but there may be a racing notify_on) */ int success; - grpc_iomgr_closure* closure; + grpc_iomgr_closure *closure; size_t ncb = 0; gpr_mu_lock(&fd->set_state_mu); diff --git a/src/core/iomgr/fd_posix.h b/src/core/iomgr/fd_posix.h index 523d040d17..94d0019fa4 100644 --- a/src/core/iomgr/fd_posix.h +++ b/src/core/iomgr/fd_posix.h @@ -62,12 +62,12 @@ struct grpc_fd { gpr_atm shutdown; /* The watcher list. - + The following watcher related fields are protected by watcher_mu. - + An fd_watcher is an ephemeral object created when an fd wants to begin polling, and destroyed after the poll. - + It denotes the fd's interest in whether to read poll or write poll or both or neither on this fd. @@ -175,4 +175,4 @@ void grpc_fd_unref(grpc_fd *fd); void grpc_fd_global_init(void); void grpc_fd_global_shutdown(void); -#endif /* GRPC_INTERNAL_CORE_IOMGR_FD_POSIX_H */ +#endif /* GRPC_INTERNAL_CORE_IOMGR_FD_POSIX_H */ diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index c6c44658df..d2c092b450 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -143,8 +143,8 @@ void grpc_iomgr_shutdown(void) { } if (g_root_object.next != &g_root_object) { int timeout = 0; - gpr_timespec short_deadline = gpr_time_add(gpr_now(), - gpr_time_from_millis(100)); + gpr_timespec short_deadline = + gpr_time_add(gpr_now(), gpr_time_from_millis(100)); while (gpr_cv_wait(&g_rcv, &g_mu, short_deadline) && g_cbs_head == NULL) { if (gpr_time_cmp(gpr_now(), shutdown_deadline) > 0) { timeout = 1; @@ -193,7 +193,6 @@ void grpc_iomgr_unregister_object(grpc_iomgr_object *obj) { gpr_mu_unlock(&g_mu); } - void grpc_iomgr_closure_init(grpc_iomgr_closure *closure, grpc_iomgr_cb_func cb, void *cb_arg) { closure->cb = cb; @@ -217,12 +216,10 @@ void grpc_iomgr_add_delayed_callback(grpc_iomgr_closure *closure, int success) { gpr_mu_unlock(&g_mu); } - void grpc_iomgr_add_callback(grpc_iomgr_closure *closure) { grpc_iomgr_add_delayed_callback(closure, 1 /* GPR_TRUE */); } - int grpc_maybe_call_delayed_callbacks(gpr_mu *drop_mu, int success) { int n = 0; gpr_mu *retake_mu = NULL; diff --git a/src/core/iomgr/pollset.h b/src/core/iomgr/pollset.h index 334e0ebde1..da3c94ec11 100644 --- a/src/core/iomgr/pollset.h +++ b/src/core/iomgr/pollset.h @@ -58,7 +58,6 @@ void grpc_pollset_shutdown(grpc_pollset *pollset, void *shutdown_done_arg); void grpc_pollset_destroy(grpc_pollset *pollset); - /* Do some work on a pollset. May involve invoking asynchronous callbacks, or actually polling file descriptors. @@ -70,4 +69,4 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline); Requires GRPC_POLLSET_MU(pollset) locked. */ void grpc_pollset_kick(grpc_pollset *pollset); -#endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_H */ +#endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_H */ diff --git a/src/core/iomgr/pollset_kick_posix.c b/src/core/iomgr/pollset_kick_posix.c index 21c9bb6542..51021784f2 100644 --- a/src/core/iomgr/pollset_kick_posix.c +++ b/src/core/iomgr/pollset_kick_posix.c @@ -73,7 +73,7 @@ static grpc_kick_fd_info *allocate_wfd(void) { return info; } -static void destroy_wfd(grpc_kick_fd_info* wfd) { +static void destroy_wfd(grpc_kick_fd_info *wfd) { grpc_wakeup_fd_destroy(&wfd->wakeup_fd); gpr_free(wfd); } @@ -104,7 +104,8 @@ void grpc_pollset_kick_destroy(grpc_pollset_kick_state *kick_state) { GPR_ASSERT(kick_state->fd_list.next == &kick_state->fd_list); } -grpc_kick_fd_info *grpc_pollset_kick_pre_poll(grpc_pollset_kick_state *kick_state) { +grpc_kick_fd_info *grpc_pollset_kick_pre_poll( + grpc_pollset_kick_state *kick_state) { grpc_kick_fd_info *fd_info; gpr_mu_lock(&kick_state->mu); if (kick_state->kicked) { @@ -120,11 +121,13 @@ grpc_kick_fd_info *grpc_pollset_kick_pre_poll(grpc_pollset_kick_state *kick_stat return fd_info; } -void grpc_pollset_kick_consume(grpc_pollset_kick_state *kick_state, grpc_kick_fd_info *fd_info) { +void grpc_pollset_kick_consume(grpc_pollset_kick_state *kick_state, + grpc_kick_fd_info *fd_info) { grpc_wakeup_fd_consume_wakeup(&fd_info->wakeup_fd); } -void grpc_pollset_kick_post_poll(grpc_pollset_kick_state *kick_state, grpc_kick_fd_info *fd_info) { +void grpc_pollset_kick_post_poll(grpc_pollset_kick_state *kick_state, + grpc_kick_fd_info *fd_info) { gpr_mu_lock(&kick_state->mu); fd_info->next->prev = fd_info->prev; fd_info->prev->next = fd_info->next; @@ -162,5 +165,4 @@ void grpc_pollset_kick_global_destroy(void) { gpr_mu_destroy(&fd_freelist_mu); } - -#endif /* GPR_POSIX_SOCKET */ +#endif /* GPR_POSIX_SOCKET */ diff --git a/src/core/iomgr/pollset_kick_posix.h b/src/core/iomgr/pollset_kick_posix.h index b35c2cfbe0..0a404b601b 100644 --- a/src/core/iomgr/pollset_kick_posix.h +++ b/src/core/iomgr/pollset_kick_posix.h @@ -51,7 +51,8 @@ typedef struct grpc_pollset_kick_state { struct grpc_kick_fd_info fd_list; } grpc_pollset_kick_state; -#define GRPC_POLLSET_KICK_GET_FD(kick_fd_info) GRPC_WAKEUP_FD_GET_READ_FD(&(kick_fd_info)->wakeup_fd) +#define GRPC_POLLSET_KICK_GET_FD(kick_fd_info) \ + GRPC_WAKEUP_FD_GET_READ_FD(&(kick_fd_info)->wakeup_fd) /* This is an abstraction around the typical pipe mechanism for waking up a thread sitting in a poll() style call. */ @@ -69,15 +70,18 @@ void grpc_pollset_kick_global_init_fallback_fd(void); /* Must be called before entering poll(). If return value is -1, this consumed an existing kick. Otherwise the return value is an FD to add to the poll set. */ -grpc_kick_fd_info *grpc_pollset_kick_pre_poll(grpc_pollset_kick_state *kick_state); +grpc_kick_fd_info *grpc_pollset_kick_pre_poll( + grpc_pollset_kick_state *kick_state); /* Consume an existing kick. Must be called after poll returns that the fd was readable, and before calling kick_post_poll. */ -void grpc_pollset_kick_consume(grpc_pollset_kick_state *kick_state, grpc_kick_fd_info *fd_info); +void grpc_pollset_kick_consume(grpc_pollset_kick_state *kick_state, + grpc_kick_fd_info *fd_info); /* Must be called after pre_poll, and after consume if applicable */ -void grpc_pollset_kick_post_poll(grpc_pollset_kick_state *kick_state, grpc_kick_fd_info *fd_info); +void grpc_pollset_kick_post_poll(grpc_pollset_kick_state *kick_state, + grpc_kick_fd_info *fd_info); void grpc_pollset_kick_kick(grpc_pollset_kick_state *kick_state); -#endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_KICK_POSIX_H */ +#endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_KICK_POSIX_H */ diff --git a/src/core/iomgr/pollset_multipoller_with_epoll.c b/src/core/iomgr/pollset_multipoller_with_epoll.c index 05b522bbf2..8e585a007d 100644 --- a/src/core/iomgr/pollset_multipoller_with_epoll.c +++ b/src/core/iomgr/pollset_multipoller_with_epoll.c @@ -143,7 +143,8 @@ static int multipoll_with_epoll_pollset_maybe_work( return 1; } -static void multipoll_with_epoll_pollset_finish_shutdown(grpc_pollset *pollset) {} +static void multipoll_with_epoll_pollset_finish_shutdown( + grpc_pollset *pollset) {} static void multipoll_with_epoll_pollset_destroy(grpc_pollset *pollset) { pollset_hdr *h = pollset->data.ptr; @@ -158,9 +159,12 @@ static void epoll_kick(grpc_pollset *pollset) { } static const grpc_pollset_vtable multipoll_with_epoll_pollset = { - multipoll_with_epoll_pollset_add_fd, multipoll_with_epoll_pollset_del_fd, - multipoll_with_epoll_pollset_maybe_work, epoll_kick, - multipoll_with_epoll_pollset_finish_shutdown, multipoll_with_epoll_pollset_destroy}; + multipoll_with_epoll_pollset_add_fd, + multipoll_with_epoll_pollset_del_fd, + multipoll_with_epoll_pollset_maybe_work, + epoll_kick, + multipoll_with_epoll_pollset_finish_shutdown, + multipoll_with_epoll_pollset_destroy}; static void epoll_become_multipoller(grpc_pollset *pollset, grpc_fd **fds, size_t nfds) { diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c index afce5f65db..5ee6980732 100644 --- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c +++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c @@ -231,9 +231,12 @@ static void multipoll_with_poll_pollset_destroy(grpc_pollset *pollset) { } static const grpc_pollset_vtable multipoll_with_poll_pollset = { - multipoll_with_poll_pollset_add_fd, multipoll_with_poll_pollset_del_fd, - multipoll_with_poll_pollset_maybe_work, multipoll_with_poll_pollset_kick, - multipoll_with_poll_pollset_finish_shutdown, multipoll_with_poll_pollset_destroy}; + multipoll_with_poll_pollset_add_fd, + multipoll_with_poll_pollset_del_fd, + multipoll_with_poll_pollset_maybe_work, + multipoll_with_poll_pollset_kick, + multipoll_with_poll_pollset_finish_shutdown, + multipoll_with_poll_pollset_destroy}; void grpc_poll_become_multipoller(grpc_pollset *pollset, grpc_fd **fds, size_t nfds) { diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index 796b1b9ebf..c701abb91d 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -417,7 +417,7 @@ static void basic_pollset_destroy(grpc_pollset *pollset) { } static const grpc_pollset_vtable basic_pollset = { - basic_pollset_add_fd, basic_pollset_del_fd, basic_pollset_maybe_work, + basic_pollset_add_fd, basic_pollset_del_fd, basic_pollset_maybe_work, kick_using_pollset_kick, basic_pollset_destroy, basic_pollset_destroy}; static void become_basic_pollset(grpc_pollset *pollset, grpc_fd *fd_or_null) { diff --git a/src/core/iomgr/pollset_set_windows.h b/src/core/iomgr/pollset_set_windows.h index 0f91f1ede7..cada0d2b61 100644 --- a/src/core/iomgr/pollset_set_windows.h +++ b/src/core/iomgr/pollset_set_windows.h @@ -34,8 +34,6 @@ #ifndef GRPC_INTERNAL_CORE_IOMGR_POLLSET_SET_WINDOWS_H #define GRPC_INTERNAL_CORE_IOMGR_POLLSET_SET_WINDOWS_H -typedef struct grpc_pollset_set { - void *unused; -} grpc_pollset_set; +typedef struct grpc_pollset_set { void *unused; } grpc_pollset_set; #endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_WINDOWS_H */ diff --git a/src/core/iomgr/pollset_windows.c b/src/core/iomgr/pollset_windows.c index 88db774cc4..9deb0fa8fa 100644 --- a/src/core/iomgr/pollset_windows.c +++ b/src/core/iomgr/pollset_windows.c @@ -46,9 +46,7 @@ set of features for the sake of the rest of grpc. But grpc_pollset_work won't actually do any polling, and return as quickly as possible. */ -void grpc_pollset_init(grpc_pollset *pollset) { - gpr_mu_init(&pollset->mu); -} +void grpc_pollset_init(grpc_pollset *pollset) { gpr_mu_init(&pollset->mu); } void grpc_pollset_shutdown(grpc_pollset *pollset, void (*shutdown_done)(void *arg), @@ -75,6 +73,6 @@ int grpc_pollset_work(grpc_pollset *pollset, gpr_timespec deadline) { return 0 /* GPR_FALSE */; } -void grpc_pollset_kick(grpc_pollset *p) { } +void grpc_pollset_kick(grpc_pollset *p) {} -#endif /* GPR_WINSOCK_SOCKET */ +#endif /* GPR_WINSOCK_SOCKET */ diff --git a/src/core/iomgr/pollset_windows.h b/src/core/iomgr/pollset_windows.h index acd82d0a0a..7ec960450d 100644 --- a/src/core/iomgr/pollset_windows.h +++ b/src/core/iomgr/pollset_windows.h @@ -45,10 +45,8 @@ and a condition variable, as this is the minimal set of features we need implemented for the rest of grpc. But we won't use them directly. */ -typedef struct grpc_pollset { - gpr_mu mu; -} grpc_pollset; +typedef struct grpc_pollset { gpr_mu mu; } grpc_pollset; #define GRPC_POLLSET_MU(pollset) (&(pollset)->mu) -#endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_WINDOWS_H */ +#endif /* GRPC_INTERNAL_CORE_IOMGR_POLLSET_WINDOWS_H */ diff --git a/src/core/iomgr/tcp_client.h b/src/core/iomgr/tcp_client.h index e1fdf235ec..f40a5043c8 100644 --- a/src/core/iomgr/tcp_client.h +++ b/src/core/iomgr/tcp_client.h @@ -47,4 +47,4 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *tcp), const struct sockaddr *addr, int addr_len, gpr_timespec deadline); -#endif /* GRPC_INTERNAL_CORE_IOMGR_TCP_CLIENT_H */ +#endif /* GRPC_INTERNAL_CORE_IOMGR_TCP_CLIENT_H */ diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c index 2cd4aa2f45..df6203b70c 100644 --- a/src/core/iomgr/tcp_client_posix.c +++ b/src/core/iomgr/tcp_client_posix.c @@ -222,8 +222,7 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), fdobj = grpc_fd_create(fd, name); if (err >= 0) { - cb(arg, - grpc_tcp_create(fdobj, GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); + cb(arg, grpc_tcp_create(fdobj, GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); goto done; } diff --git a/src/core/iomgr/tcp_client_windows.c b/src/core/iomgr/tcp_client_windows.c index 88141a3dc2..b1a169b519 100644 --- a/src/core/iomgr/tcp_client_windows.c +++ b/src/core/iomgr/tcp_client_windows.c @@ -52,7 +52,7 @@ #include "src/core/iomgr/socket_windows.h" typedef struct { - void(*cb)(void *arg, grpc_endpoint *tcp); + void (*cb)(void *arg, grpc_endpoint *tcp); void *cb_arg; gpr_mu mu; grpc_winsocket *socket; @@ -86,7 +86,7 @@ static void on_connect(void *acp, int from_iocp) { SOCKET sock = ac->socket->socket; grpc_endpoint *ep = NULL; grpc_winsocket_callback_info *info = &ac->socket->write_info; - void(*cb)(void *arg, grpc_endpoint *tcp) = ac->cb; + void (*cb)(void *arg, grpc_endpoint *tcp) = ac->cb; void *cb_arg = ac->cb_arg; int aborted; @@ -99,8 +99,7 @@ static void on_connect(void *acp, int from_iocp) { DWORD transfered_bytes = 0; DWORD flags; BOOL wsa_success = WSAGetOverlappedResult(sock, &info->overlapped, - &transfered_bytes, FALSE, - &flags); + &transfered_bytes, FALSE, &flags); info->outstanding = 0; GPR_ASSERT(transfered_bytes == 0); if (!wsa_success) { @@ -176,9 +175,9 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *tcp), /* Grab the function pointer for ConnectEx for that specific socket. It may change depending on the interface. */ - status = WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER, - &guid, sizeof(guid), &ConnectEx, sizeof(ConnectEx), - &ioctl_num_bytes, NULL, NULL); + status = + WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid), + &ConnectEx, sizeof(ConnectEx), &ioctl_num_bytes, NULL, NULL); if (status != 0) { message = "Unable to retrieve ConnectEx pointer: %s"; @@ -187,8 +186,7 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *tcp), grpc_sockaddr_make_wildcard6(0, &local_address); - status = bind(sock, (struct sockaddr *) &local_address, - sizeof(local_address)); + status = bind(sock, (struct sockaddr *)&local_address, sizeof(local_address)); if (status != 0) { message = "Unable to bind socket: %s"; goto failure; @@ -234,4 +232,4 @@ failure: cb(arg, NULL); } -#endif /* GPR_WINSOCK_SOCKET */ +#endif /* GPR_WINSOCK_SOCKET */ diff --git a/src/core/iomgr/tcp_posix.c b/src/core/iomgr/tcp_posix.c index e3289f6806..9ad089af66 100644 --- a/src/core/iomgr/tcp_posix.c +++ b/src/core/iomgr/tcp_posix.c @@ -266,7 +266,7 @@ typedef struct { grpc_endpoint base; grpc_fd *em_fd; int fd; - int iov_size; /* Number of slices to allocate per read attempt */ + int iov_size; /* Number of slices to allocate per read attempt */ int finished_edge; size_t slice_size; gpr_refcount refcount; @@ -412,8 +412,7 @@ static void grpc_tcp_continue_read(grpc_tcp *tcp) { ++tcp->iov_size; } GPR_ASSERT(slice_state_has_available(&read_state)); - slice_state_transfer_ownership(&read_state, &final_slices, - &final_nslices); + slice_state_transfer_ownership(&read_state, &final_slices, &final_nslices); call_read_cb(tcp, final_slices, final_nslices, GRPC_ENDPOINT_CB_OK); slice_state_destroy(&read_state); grpc_tcp_unref(tcp); diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c index 759a493795..713abc6db3 100644 --- a/src/core/iomgr/tcp_server_posix.c +++ b/src/core/iomgr/tcp_server_posix.c @@ -335,9 +335,8 @@ static void on_read(void *arg, int success) { for (i = 0; i < sp->server->pollset_count; i++) { grpc_pollset_add_fd(sp->server->pollsets[i], fdobj); } - sp->server->cb( - sp->server->cb_arg, - grpc_tcp_create(fdobj, GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); + sp->server->cb(sp->server->cb_arg, + grpc_tcp_create(fdobj, GRPC_TCP_DEFAULT_READ_SLICE_SIZE)); gpr_free(name); gpr_free(addr_str); diff --git a/src/core/security/client_auth_filter.c b/src/core/security/client_auth_filter.c index 9d55362da6..5ef635a262 100644 --- a/src/core/security/client_auth_filter.c +++ b/src/core/security/client_auth_filter.c @@ -302,13 +302,10 @@ static void init_channel_elem(grpc_channel_element *elem, chand->security_connector = (grpc_channel_security_connector *)grpc_security_connector_ref(sc); chand->md_ctx = metadata_context; - chand->authority_string = - grpc_mdstr_from_string(chand->md_ctx, ":authority"); + chand->authority_string = grpc_mdstr_from_string(chand->md_ctx, ":authority"); chand->path_string = grpc_mdstr_from_string(chand->md_ctx, ":path"); - chand->error_msg_key = - grpc_mdstr_from_string(chand->md_ctx, "grpc-message"); - chand->status_key = - grpc_mdstr_from_string(chand->md_ctx, "grpc-status"); + chand->error_msg_key = grpc_mdstr_from_string(chand->md_ctx, "grpc-message"); + chand->status_key = grpc_mdstr_from_string(chand->md_ctx, "grpc-status"); } /* Destructor for channel data */ @@ -332,6 +329,6 @@ static void destroy_channel_elem(grpc_channel_element *elem) { } const grpc_channel_filter grpc_client_auth_filter = { - auth_start_transport_op, channel_op, sizeof(call_data), init_call_elem, - destroy_call_elem, sizeof(channel_data), init_channel_elem, - destroy_channel_elem, "client-auth"}; + auth_start_transport_op, channel_op, sizeof(call_data), + init_call_elem, destroy_call_elem, sizeof(channel_data), + init_channel_elem, destroy_channel_elem, "client-auth"}; diff --git a/src/core/security/credentials.c b/src/core/security/credentials.c index f3d0cf5452..7fc3f003fd 100644 --- a/src/core/security/credentials.c +++ b/src/core/security/credentials.c @@ -485,8 +485,8 @@ static int oauth2_token_fetcher_has_request_metadata_only( grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( - const grpc_httpcli_response *response, - grpc_credentials_md_store **token_md, gpr_timespec *token_lifetime) { + const grpc_httpcli_response *response, grpc_credentials_md_store **token_md, + gpr_timespec *token_lifetime) { char *null_terminated_body = NULL; char *new_access_token = NULL; grpc_credentials_status status = GRPC_CREDENTIALS_OK; @@ -609,7 +609,8 @@ static void oauth2_token_fetcher_get_request_metadata( if (c->access_token_md != NULL && (gpr_time_cmp(gpr_time_sub(c->token_expiration, gpr_now()), refresh_threshold) > 0)) { - cached_access_token_md = grpc_credentials_md_store_ref(c->access_token_md); + cached_access_token_md = + grpc_credentials_md_store_ref(c->access_token_md); } gpr_mu_unlock(&c->mu); } @@ -639,8 +640,7 @@ static void init_oauth2_token_fetcher(grpc_oauth2_token_fetcher_credentials *c, /* -- ComputeEngine credentials. -- */ static grpc_credentials_vtable compute_engine_vtable = { - oauth2_token_fetcher_destroy, - oauth2_token_fetcher_has_request_metadata, + oauth2_token_fetcher_destroy, oauth2_token_fetcher_has_request_metadata, oauth2_token_fetcher_has_request_metadata_only, oauth2_token_fetcher_get_request_metadata, NULL}; @@ -685,8 +685,7 @@ static void service_account_destroy(grpc_credentials *creds) { } static grpc_credentials_vtable service_account_vtable = { - service_account_destroy, - oauth2_token_fetcher_has_request_metadata, + service_account_destroy, oauth2_token_fetcher_has_request_metadata, oauth2_token_fetcher_has_request_metadata_only, oauth2_token_fetcher_get_request_metadata, NULL}; @@ -759,8 +758,7 @@ static void refresh_token_destroy(grpc_credentials *creds) { } static grpc_credentials_vtable refresh_token_vtable = { - refresh_token_destroy, - oauth2_token_fetcher_has_request_metadata, + refresh_token_destroy, oauth2_token_fetcher_has_request_metadata, oauth2_token_fetcher_has_request_metadata_only, oauth2_token_fetcher_get_request_metadata, NULL}; @@ -899,8 +897,7 @@ static int fake_transport_security_has_request_metadata_only( return 0; } -static grpc_security_status -fake_transport_security_create_security_connector( +static grpc_security_status fake_transport_security_create_security_connector( grpc_credentials *c, const char *target, const grpc_channel_args *args, grpc_credentials *request_metadata_creds, grpc_channel_security_connector **sc, grpc_channel_args **new_args) { diff --git a/src/core/security/credentials.h b/src/core/security/credentials.h index 9c876d4226..75af73a0c6 100644 --- a/src/core/security/credentials.h +++ b/src/core/security/credentials.h @@ -108,7 +108,6 @@ grpc_credentials_md_store *grpc_credentials_md_store_ref( grpc_credentials_md_store *store); void grpc_credentials_md_store_unref(grpc_credentials_md_store *store); - /* --- grpc_credentials. --- */ /* It is the caller's responsibility to gpr_free the result if not NULL. */ @@ -177,8 +176,8 @@ grpc_credentials *grpc_credentials_contains_type( /* Exposed for testing only. */ grpc_credentials_status grpc_oauth2_token_fetcher_credentials_parse_server_response( - const struct grpc_httpcli_response *response, grpc_credentials_md_store **token_md, - gpr_timespec *token_lifetime); + const struct grpc_httpcli_response *response, + grpc_credentials_md_store **token_md, gpr_timespec *token_lifetime); /* Simulates an oauth2 token fetch with the specified value for testing. */ grpc_credentials *grpc_fake_oauth2_credentials_create( diff --git a/src/core/security/google_default_credentials.c b/src/core/security/google_default_credentials.c index 5d40627ba4..5822ce6337 100644 --- a/src/core/security/google_default_credentials.c +++ b/src/core/security/google_default_credentials.c @@ -55,9 +55,7 @@ static int compute_engine_detection_done = 0; static gpr_mu g_mu; static gpr_once g_once = GPR_ONCE_INIT; -static void init_default_credentials(void) { - gpr_mu_init(&g_mu); -} +static void init_default_credentials(void) { gpr_mu_init(&g_mu); } typedef struct { grpc_pollset pollset; diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c index 70485d71da..b97f05ad8a 100644 --- a/src/core/surface/channel.c +++ b/src/core/surface/channel.c @@ -200,7 +200,7 @@ static void destroy_channel(void *p, int ok) { #ifdef GRPC_CHANNEL_REF_COUNT_DEBUG void grpc_channel_internal_unref(grpc_channel *channel, const char *reason) { - gpr_log(GPR_DEBUG, "CHANNEL: unref %p %d -> %d [%s]", channel, + gpr_log(GPR_DEBUG, "CHANNEL: unref %p %d -> %d [%s]", channel, channel->refs.count, channel->refs.count - 1, reason); #else void grpc_channel_internal_unref(grpc_channel *channel) { diff --git a/src/core/surface/channel_create.c b/src/core/surface/channel_create.c index a49b754d9a..d137ce12ac 100644 --- a/src/core/surface/channel_create.c +++ b/src/core/surface/channel_create.c @@ -137,7 +137,8 @@ static void on_resolved(void *rp, grpc_resolved_addresses *resolved) { request *r = rp; /* if we're not still the active request, abort */ - if (!grpc_client_setup_request_should_continue(r->cs_request, "on_resolved")) { + if (!grpc_client_setup_request_should_continue(r->cs_request, + "on_resolved")) { if (resolved) { grpc_resolved_addresses_destroy(resolved); } diff --git a/src/core/surface/completion_queue.c b/src/core/surface/completion_queue.c index 6808c976e1..57ecf365cc 100644 --- a/src/core/surface/completion_queue.c +++ b/src/core/surface/completion_queue.c @@ -86,21 +86,10 @@ grpc_completion_queue *grpc_completion_queue_create(void) { return cc; } - - - - - - - - - - - - #ifdef GRPC_CQ_REF_COUNT_DEBUG void grpc_cq_internal_ref(grpc_completion_queue *cc, const char *reason) { - gpr_log(GPR_DEBUG, "CQ:%p ref %d -> %d %s", cc, (int)cc->owning_refs.count, (int)cc->owning_refs.count + 1, reason); + gpr_log(GPR_DEBUG, "CQ:%p ref %d -> %d %s", cc, (int)cc->owning_refs.count, + (int)cc->owning_refs.count + 1, reason); #else void grpc_cq_internal_ref(grpc_completion_queue *cc) { #endif @@ -114,7 +103,8 @@ static void on_pollset_destroy_done(void *arg) { #ifdef GRPC_CQ_REF_COUNT_DEBUG void grpc_cq_internal_unref(grpc_completion_queue *cc, const char *reason) { - gpr_log(GPR_DEBUG, "CQ:%p unref %d -> %d %s", cc, (int)cc->owning_refs.count, (int)cc->owning_refs.count - 1, reason); + gpr_log(GPR_DEBUG, "CQ:%p unref %d -> %d %s", cc, (int)cc->owning_refs.count, + (int)cc->owning_refs.count - 1, reason); #else void grpc_cq_internal_unref(grpc_completion_queue *cc) { #endif diff --git a/src/core/surface/lame_client.c b/src/core/surface/lame_client.c index 6c07b01544..b667128aef 100644 --- a/src/core/surface/lame_client.c +++ b/src/core/surface/lame_client.c @@ -118,9 +118,9 @@ static void init_channel_elem(grpc_channel_element *elem, static void destroy_channel_elem(grpc_channel_element *elem) {} static const grpc_channel_filter lame_filter = { - lame_start_transport_op, channel_op, sizeof(call_data), init_call_elem, - destroy_call_elem, sizeof(channel_data), init_channel_elem, - destroy_channel_elem, "lame-client", + lame_start_transport_op, channel_op, sizeof(call_data), + init_call_elem, destroy_call_elem, sizeof(channel_data), + init_channel_elem, destroy_channel_elem, "lame-client", }; grpc_channel *grpc_lame_client_channel_create(void) { diff --git a/src/core/surface/secure_channel_create.c b/src/core/surface/secure_channel_create.c index 3875eb0614..4854ec9ded 100644 --- a/src/core/surface/secure_channel_create.c +++ b/src/core/surface/secure_channel_create.c @@ -96,7 +96,8 @@ static void on_secure_transport_setup_done(void *rp, if (status != GRPC_SECURITY_OK) { gpr_log(GPR_ERROR, "Secure transport setup failed with error %d.", status); done(r, 0); - } else if (grpc_client_setup_cb_begin(r->cs_request, "on_secure_transport_setup_done")) { + } else if (grpc_client_setup_cb_begin(r->cs_request, + "on_secure_transport_setup_done")) { grpc_create_chttp2_transport( r->setup->setup_callback, r->setup->setup_user_data, grpc_client_setup_get_channel_args(r->cs_request), secure_endpoint, @@ -112,7 +113,8 @@ static void on_secure_transport_setup_done(void *rp, static void on_connect(void *rp, grpc_endpoint *tcp) { request *r = rp; - if (!grpc_client_setup_request_should_continue(r->cs_request, "on_connect.secure")) { + if (!grpc_client_setup_request_should_continue(r->cs_request, + "on_connect.secure")) { if (tcp) { grpc_endpoint_shutdown(tcp); grpc_endpoint_destroy(tcp); @@ -152,7 +154,8 @@ static void on_resolved(void *rp, grpc_resolved_addresses *resolved) { request *r = rp; /* if we're not still the active request, abort */ - if (!grpc_client_setup_request_should_continue(r->cs_request, "on_resolved.secure")) { + if (!grpc_client_setup_request_should_continue(r->cs_request, + "on_resolved.secure")) { if (resolved) { grpc_resolved_addresses_destroy(resolved); } diff --git a/src/core/surface/server.c b/src/core/surface/server.c index 4cf9213e66..68b8d839a0 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -494,7 +494,6 @@ static void server_on_recv(void *ptr, int success) { calld->state = ZOMBIED; grpc_iomgr_closure_init(&calld->kill_zombie_closure, kill_zombie, elem); grpc_iomgr_add_callback(&calld->kill_zombie_closure); - } if (call_list_remove(calld, ALL_CALLS)) { decrement_call_count(chand); @@ -590,7 +589,8 @@ static void finish_shutdown_channel(void *p, int success) { gpr_free(sca); } -static void shutdown_channel(channel_data *chand, int send_goaway, int send_disconnect) { +static void shutdown_channel(channel_data *chand, int send_goaway, + int send_disconnect) { shutdown_channel_args *sca; GRPC_CHANNEL_INTERNAL_REF(chand->channel, "shutdown"); sca = gpr_malloc(sizeof(shutdown_channel_args)); diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index d9c712cc63..a14eebb683 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -998,10 +998,12 @@ static void finalize_outbuf(transport *t) { while ((s = stream_list_remove_head(t, WRITING))) { grpc_chttp2_encode(s->writing_sopb.ops, s->writing_sopb.nops, - s->send_closed != DONT_SEND_CLOSED, s->id, &t->hpack_compressor, &t->outbuf); + s->send_closed != DONT_SEND_CLOSED, s->id, + &t->hpack_compressor, &t->outbuf); s->writing_sopb.nops = 0; if (s->send_closed == SEND_CLOSED_WITH_RST_STREAM) { - gpr_slice_buffer_add(&t->outbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_CHTTP2_NO_ERROR)); + gpr_slice_buffer_add(&t->outbuf, grpc_chttp2_rst_stream_create( + s->id, GRPC_CHTTP2_NO_ERROR)); } if (s->send_closed != DONT_SEND_CLOSED) { stream_list_join(t, s, WRITTEN_CLOSED); @@ -1064,12 +1066,12 @@ static void perform_write(transport *t, grpc_endpoint *ep) { } } -static void add_goaway(transport *t, gpr_uint32 goaway_error, gpr_slice goaway_text) { +static void add_goaway(transport *t, gpr_uint32 goaway_error, + gpr_slice goaway_text) { if (t->num_pending_goaways == t->cap_pending_goaways) { t->cap_pending_goaways = GPR_MAX(1, t->cap_pending_goaways * 2); - t->pending_goaways = - gpr_realloc(t->pending_goaways, - sizeof(pending_goaway) * t->cap_pending_goaways); + t->pending_goaways = gpr_realloc( + t->pending_goaways, sizeof(pending_goaway) * t->cap_pending_goaways); } t->pending_goaways[t->num_pending_goaways].status = grpc_chttp2_http2_error_to_grpc_status(goaway_error); @@ -1077,13 +1079,12 @@ static void add_goaway(transport *t, gpr_uint32 goaway_error, gpr_slice goaway_t t->num_pending_goaways++; } - static void maybe_start_some_streams(transport *t) { /* start streams where we have free stream ids and free concurrency */ - while ( - t->next_stream_id <= MAX_CLIENT_STREAM_ID && - grpc_chttp2_stream_map_size(&t->stream_map) < - t->settings[PEER_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]) { + while (t->next_stream_id <= MAX_CLIENT_STREAM_ID && + grpc_chttp2_stream_map_size(&t->stream_map) < + t->settings[PEER_SETTINGS] + [GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS]) { stream *s = stream_list_remove_head(t, WAITING_FOR_CONCURRENCY); if (!s) return; @@ -1091,7 +1092,9 @@ static void maybe_start_some_streams(transport *t) { t->is_client ? "CLI" : "SVR", s, t->next_stream_id)); if (t->next_stream_id == MAX_CLIENT_STREAM_ID) { - add_goaway(t, GRPC_CHTTP2_NO_ERROR, gpr_slice_from_copied_string("Exceeded sequence number limit")); + add_goaway( + t, GRPC_CHTTP2_NO_ERROR, + gpr_slice_from_copied_string("Exceeded sequence number limit")); } GPR_ASSERT(s->id == 0); @@ -1109,7 +1112,10 @@ static void maybe_start_some_streams(transport *t) { stream *s = stream_list_remove_head(t, WAITING_FOR_CONCURRENCY); if (!s) return; - cancel_stream(t, s, GRPC_STATUS_UNAVAILABLE, grpc_chttp2_grpc_status_to_http2_error(GRPC_STATUS_UNAVAILABLE), NULL, 0); + cancel_stream( + t, s, GRPC_STATUS_UNAVAILABLE, + grpc_chttp2_grpc_status_to_http2_error(GRPC_STATUS_UNAVAILABLE), NULL, + 0); } } @@ -1167,7 +1173,7 @@ static void perform_op_locked(transport *t, stream *s, grpc_transport_op *op) { op_closure c; c.cb = op->on_consumed; c.user_data = op->on_consumed_user_data; - schedule_cb(t, c, 1); + schedule_cb(t, c, 1); } } @@ -1262,8 +1268,8 @@ static void cancel_stream_inner(transport *t, stream *s, gpr_uint32 id, /* synthesize a status if we don't believe we'll get one */ gpr_ltoa(local_status, buffer); add_incoming_metadata( - t, s, - grpc_mdelem_from_strings(t->metadata_context, "grpc-status", buffer)); + t, s, grpc_mdelem_from_strings(t->metadata_context, "grpc-status", + buffer)); if (!optional_message) { switch (local_status) { case GRPC_STATUS_CANCELLED: @@ -1502,7 +1508,8 @@ static int init_header_frame_parser(transport *t, int is_continuation) { t->last_incoming_stream_id, t->incoming_stream_id); return init_skip_frame(t, 1); } else if ((t->incoming_stream_id & 1) == 0) { - gpr_log(GPR_ERROR, "ignoring stream with non-client generated index %d", t->incoming_stream_id); + gpr_log(GPR_ERROR, "ignoring stream with non-client generated index %d", + t->incoming_stream_id); return init_skip_frame(t, 1); } t->incoming_stream = NULL; @@ -1562,10 +1569,10 @@ static int init_ping_parser(transport *t) { } static int init_rst_stream_parser(transport *t) { - int ok = GRPC_CHTTP2_PARSE_OK == - grpc_chttp2_rst_stream_parser_begin_frame(&t->simple_parsers.rst_stream, - t->incoming_frame_size, - t->incoming_frame_flags); + int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_rst_stream_parser_begin_frame( + &t->simple_parsers.rst_stream, + t->incoming_frame_size, + t->incoming_frame_flags); if (!ok) { drop_connection(t); } @@ -1655,7 +1662,7 @@ static void add_metadata_batch(transport *t, stream *s) { we can reconstitute the list. We can't do list building here as later incoming metadata may reallocate the underlying array. */ - b.list.tail = (void*)(gpr_intptr)s->incoming_metadata_count; + b.list.tail = (void *)(gpr_intptr)s->incoming_metadata_count; b.garbage.head = b.garbage.tail = NULL; b.deadline = s->incoming_deadline; s->incoming_deadline = gpr_inf_future; @@ -2013,7 +2020,7 @@ static void patch_metadata_ops(stream *s) { int found_metadata = 0; /* rework the array of metadata into a linked list, making use - of the breadcrumbs we left in metadata batches during + of the breadcrumbs we left in metadata batches during add_metadata_batch */ for (i = 0; i < nops; i++) { grpc_stream_op *op = &ops[i]; @@ -2029,11 +2036,11 @@ static void patch_metadata_ops(stream *s) { op->data.metadata.list.head = &s->incoming_metadata[mdidx]; op->data.metadata.list.tail = &s->incoming_metadata[last_mdidx - 1]; for (j = mdidx + 1; j < last_mdidx; j++) { - s->incoming_metadata[j].prev = &s->incoming_metadata[j-1]; - s->incoming_metadata[j-1].next = &s->incoming_metadata[j]; + s->incoming_metadata[j].prev = &s->incoming_metadata[j - 1]; + s->incoming_metadata[j - 1].next = &s->incoming_metadata[j]; } s->incoming_metadata[mdidx].prev = NULL; - s->incoming_metadata[last_mdidx-1].next = NULL; + s->incoming_metadata[last_mdidx - 1].next = NULL; /* track where we're up to */ mdidx = last_mdidx; } @@ -2045,7 +2052,8 @@ static void patch_metadata_ops(stream *s) { size_t copy_bytes = sizeof(*s->incoming_metadata) * new_count; GPR_ASSERT(mdidx < s->incoming_metadata_count); s->incoming_metadata = gpr_malloc(copy_bytes); - memcpy(s->old_incoming_metadata + mdidx, s->incoming_metadata, copy_bytes); + memcpy(s->old_incoming_metadata + mdidx, s->incoming_metadata, + copy_bytes); s->incoming_metadata_count = s->incoming_metadata_capacity = new_count; } else { s->incoming_metadata = NULL; @@ -2082,7 +2090,6 @@ static void finish_reads(transport *t) { schedule_cb(t, s->recv_done_closure, 1); } } - } static void schedule_cb(transport *t, op_closure closure, int success) { -- cgit v1.2.3