diff options
author | Craig Tiller <ctiller@google.com> | 2016-05-04 16:29:57 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-05-04 16:29:57 -0700 |
commit | 2b782d877c5f6e774addd40b7584c39d9da9d198 (patch) | |
tree | 31775f9a4e31b642e63030117a43b9df9c117e47 | |
parent | 76e4e16e7838e3381c218f16977934cd3cad4098 (diff) |
Progress converting to new error system
-rw-r--r-- | src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c | 8 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/chttp2_transport.c | 116 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/frame.h | 8 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/internal.h | 18 | ||||
-rw-r--r-- | src/core/ext/transport/chttp2/transport/parsing.c | 234 | ||||
-rw-r--r-- | src/core/lib/iomgr/error.h | 2 | ||||
-rw-r--r-- | src/core/lib/iomgr/unix_sockets_posix.c | 15 | ||||
-rw-r--r-- | src/core/lib/security/credentials.h | 3 |
8 files changed, 217 insertions, 187 deletions
diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c index 1ed7b5b8ae..71e3b682d1 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c @@ -195,15 +195,15 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr, sc->channel_args = grpc_server_get_channel_args(server); /* resolve address */ - resolved = grpc_blocking_resolve_address(addr, "https"); - if (!resolved) { + err = grpc_blocking_resolve_address(addr, "https", &resolved); + if (err != GRPC_ERROR_NONE) { goto error; } state = gpr_malloc(sizeof(*state)); memset(state, 0, sizeof(*state)); grpc_closure_init(&state->destroy_closure, destroy_done, state); - tcp = grpc_tcp_server_create(&state->destroy_closure); - if (!tcp) { + err = grpc_tcp_server_create(&state->destroy_closure, &tcp); + if (err != GRPC_ERROR_NONE) { goto error; } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 8c8593748d..d49c56ab63 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -82,12 +82,9 @@ int grpc_flowctl_trace = 0; static const grpc_transport_vtable vtable; /* forward declarations of various callbacks that we'll build closures around */ -static void writing_action(grpc_exec_ctx *exec_ctx, void *t, - bool iomgr_success_ignored); -static void reading_action(grpc_exec_ctx *exec_ctx, void *t, - bool iomgr_success_ignored); -static void parsing_action(grpc_exec_ctx *exec_ctx, void *t, - bool iomgr_success_ignored); +static void writing_action(grpc_exec_ctx *exec_ctx, void *t, grpc_error *error); +static void reading_action(grpc_exec_ctx *exec_ctx, void *t, grpc_error *error); +static void parsing_action(grpc_exec_ctx *exec_ctx, void *t, grpc_error *error); /** Set a transport level setting, and push it to our peer */ static void push_setting(grpc_chttp2_transport *t, grpc_chttp2_setting_id id, @@ -188,7 +185,8 @@ static void destruct_transport(grpc_exec_ctx *exec_ctx, and maybe they hold resources that need to be freed */ while (t->global.pings.next != &t->global.pings) { grpc_chttp2_outstanding_ping *ping = t->global.pings.next; - grpc_exec_ctx_enqueue(exec_ctx, ping->on_recv, false, NULL); + grpc_exec_ctx_push(exec_ctx, ping->on_recv, + GRPC_ERROR_CREATE("Transport closed"), NULL); ping->next->prev = ping->prev; ping->prev->next = ping->next; gpr_free(ping); @@ -624,7 +622,7 @@ static void finish_global_actions(grpc_exec_ctx *exec_ctx, t->executor.writing_active = 1; REF_TRANSPORT(t, "writing"); prevent_endpoint_shutdown(t); - grpc_exec_ctx_enqueue(exec_ctx, &t->writing_action, true, NULL); + grpc_exec_ctx_push(exec_ctx, &t->writing_action, GRPC_ERROR_NONE, NULL); } check_read_ops(exec_ctx, &t->global); @@ -735,11 +733,11 @@ static void terminate_writing_with_lock(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s_ignored, void *a) { - bool success = (bool)(uintptr_t)a; + grpc_error *error = a; allow_endpoint_shutdown_locked(exec_ctx, t); - if (!success) { + if (error != GRPC_ERROR_NONE) { drop_connection(exec_ctx, t); } @@ -764,15 +762,14 @@ static void terminate_writing_with_lock(grpc_exec_ctx *exec_ctx, } void grpc_chttp2_terminate_writing(grpc_exec_ctx *exec_ctx, - void *transport_writing, bool success) { + void *transport_writing, grpc_error *error) { grpc_chttp2_transport *t = TRANSPORT_FROM_WRITING(transport_writing); grpc_chttp2_run_with_global_lock(exec_ctx, t, NULL, - terminate_writing_with_lock, - (void *)(uintptr_t)success, 0); + terminate_writing_with_lock, error, 0); } static void writing_action(grpc_exec_ctx *exec_ctx, void *gt, - bool iomgr_success_ignored) { + grpc_error *error) { grpc_chttp2_transport *t = gt; GPR_TIMER_BEGIN("writing_action", 0); grpc_chttp2_perform_writes(exec_ctx, &t->writing, t->ep); @@ -851,7 +848,7 @@ static void maybe_start_some_streams( #define CLOSURE_BARRIER_FIRST_REF_BIT (1 << 16) static grpc_closure *add_closure_barrier(grpc_closure *closure) { - closure->final_data += CLOSURE_BARRIER_FIRST_REF_BIT; + closure->final_data.scratch += CLOSURE_BARRIER_FIRST_REF_BIT; return closure; } @@ -862,19 +859,19 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, if (closure == NULL) { return; } - closure->final_data -= CLOSURE_BARRIER_FIRST_REF_BIT; + closure->final_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT; if (!success) { - closure->final_data |= CLOSURE_BARRIER_FAILURE_BIT; + closure->final_data.scratch |= CLOSURE_BARRIER_FAILURE_BIT; } - if (closure->final_data < CLOSURE_BARRIER_FIRST_REF_BIT) { - if (closure->final_data & CLOSURE_BARRIER_STATS_BIT) { + if (closure->final_data.scratch < CLOSURE_BARRIER_FIRST_REF_BIT) { + if (closure->final_data.scratch & CLOSURE_BARRIER_STATS_BIT) { grpc_transport_move_stats(&stream_global->stats, stream_global->collecting_stats); stream_global->collecting_stats = NULL; } - grpc_exec_ctx_enqueue( + grpc_exec_ctx_push( exec_ctx, closure, - (closure->final_data & CLOSURE_BARRIER_FAILURE_BIT) == 0, NULL); + (closure->final_data.scratch & CLOSURE_BARRIER_FAILURE_BIT) == 0, NULL); } *pclosure = NULL; } @@ -892,7 +889,7 @@ static int contains_non_ok_status( return 0; } -static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, bool success) {} +static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {} static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, @@ -909,12 +906,12 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, } /* use final_data as a barrier until enqueue time; the inital counter is dropped at the end of this function */ - on_complete->final_data = CLOSURE_BARRIER_FIRST_REF_BIT; + on_complete->final_data.scratch = CLOSURE_BARRIER_FIRST_REF_BIT; if (op->collect_stats != NULL) { GPR_ASSERT(stream_global->collecting_stats == NULL); stream_global->collecting_stats = op->collect_stats; - on_complete->final_data |= CLOSURE_BARRIER_STATS_BIT; + on_complete->final_data.scratch |= CLOSURE_BARRIER_STATS_BIT; } if (op->cancel_with_status != GRPC_STATUS_OK) { @@ -1056,7 +1053,7 @@ static void ack_ping_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, for (ping = transport_global->pings.next; ping != &transport_global->pings; ping = ping->next) { if (0 == memcmp(opaque_8bytes, ping->id, 8)) { - grpc_exec_ctx_enqueue(exec_ctx, ping->on_recv, true, NULL); + grpc_exec_ctx_push(exec_ctx, ping->on_recv, GRPC_ERROR_NONE, NULL); ping->next->prev = ping->prev; ping->prev->next = ping->next; gpr_free(ping); @@ -1089,7 +1086,7 @@ static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx, return; } - grpc_exec_ctx_enqueue(exec_ctx, op->on_consumed, true, NULL); + grpc_exec_ctx_push(exec_ctx, op->on_consumed, GRPC_ERROR_NONE, NULL); if (op->on_connectivity_state_change != NULL) { grpc_connectivity_state_notify_on_state_change( @@ -1151,8 +1148,8 @@ static void check_read_ops(grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer_publish( &stream_global->received_initial_metadata, stream_global->recv_initial_metadata); - grpc_exec_ctx_enqueue( - exec_ctx, stream_global->recv_initial_metadata_ready, true, NULL); + grpc_exec_ctx_push(exec_ctx, stream_global->recv_initial_metadata_ready, + GRPC_ERROR_NONE, NULL); stream_global->recv_initial_metadata_ready = NULL; } if (stream_global->recv_message_ready != NULL) { @@ -1165,13 +1162,13 @@ static void check_read_ops(grpc_exec_ctx *exec_ctx, *stream_global->recv_message = grpc_chttp2_incoming_frame_queue_pop( &stream_global->incoming_frames); GPR_ASSERT(*stream_global->recv_message != NULL); - grpc_exec_ctx_enqueue(exec_ctx, stream_global->recv_message_ready, true, - NULL); + grpc_exec_ctx_push(exec_ctx, stream_global->recv_message_ready, + GRPC_ERROR_NONE, NULL); stream_global->recv_message_ready = NULL; } else if (stream_global->published_trailing_metadata) { *stream_global->recv_message = NULL; - grpc_exec_ctx_enqueue(exec_ctx, stream_global->recv_message_ready, true, - NULL); + grpc_exec_ctx_push(exec_ctx, stream_global->recv_message_ready, + GRPC_ERROR_NONE, NULL); stream_global->recv_message_ready = NULL; } } @@ -1502,20 +1499,22 @@ static void update_global_window(void *args, uint32_t id, void *stream) { static void reading_action_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s_unused, void *arg); -static void parsing_action(grpc_exec_ctx *exec_ctx, void *arg, bool success); +static void parsing_action(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error); static void post_reading_action_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s_unused, void *arg); static void post_parse_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s_unused, void *arg); -static void reading_action(grpc_exec_ctx *exec_ctx, void *tp, bool success) { +static void reading_action(grpc_exec_ctx *exec_ctx, void *tp, + grpc_error *error) { /* Control flow: reading_action_locked -> (parse_unlocked -> post_parse_locked)? -> post_reading_action_locked */ grpc_chttp2_run_with_global_lock(exec_ctx, tp, NULL, reading_action_locked, - (void *)(uintptr_t)success, 0); + error, 0); } static void reading_action_locked(grpc_exec_ctx *exec_ctx, @@ -1523,7 +1522,7 @@ static void reading_action_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s_unused, void *arg) { grpc_chttp2_transport_global *transport_global = &t->global; grpc_chttp2_transport_parsing *transport_parsing = &t->parsing; - bool success = (bool)(uintptr_t)arg; + grpc_error *error = arg; GPR_ASSERT(!t->executor.parsing_active); if (!t->closed) { @@ -1532,27 +1531,30 @@ static void reading_action_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream_map_move_into(&t->new_stream_map, &t->parsing_stream_map); grpc_chttp2_prepare_to_read(transport_global, transport_parsing); - grpc_exec_ctx_enqueue(exec_ctx, &t->parsing_action, success, NULL); + grpc_exec_ctx_push(exec_ctx, &t->parsing_action, error, NULL); } else { post_reading_action_locked(exec_ctx, t, s_unused, arg); } } -static void parsing_action(grpc_exec_ctx *exec_ctx, void *arg, bool success) { +static void parsing_action(grpc_exec_ctx *exec_ctx, void *arg, + grpc_error *error) { grpc_chttp2_transport *t = arg; GPR_TIMER_BEGIN("reading_action.parse", 0); size_t i = 0; - for (; i < t->read_buffer.count && - grpc_chttp2_perform_read(exec_ctx, &t->parsing, - t->read_buffer.slices[i]); - i++) - ; - if (i != t->read_buffer.count) { - success = false; - } + grpc_error *errors[2] = {error, GRPC_ERROR_NONE}; + for (; i < t->read_buffer.count && errors[1] == GRPC_ERROR_NONE; i++) { + errors[1] = grpc_chttp2_perform_read(exec_ctx, &t->parsing, + t->read_buffer.slices[i]); + }; + grpc_error *err = + errors[0] == GRPC_ERROR_NONE && errors[1] == GRPC_ERROR_NONE + ? GRPC_ERROR_NONE + : GRPC_ERROR_CREATE_REFERENCING("Failed parsing HTTP/2", errors, + GPR_ARRAY_SIZE(errors)); GPR_TIMER_END("reading_action.parse", 0); - grpc_chttp2_run_with_global_lock(exec_ctx, t, NULL, post_parse_locked, - (void *)(uintptr_t)success, 0); + grpc_chttp2_run_with_global_lock(exec_ctx, t, NULL, post_parse_locked, err, + 0); } static void post_parse_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, @@ -1746,9 +1748,10 @@ static void incoming_byte_stream_next_locked(grpc_exec_ctx *exec_ctx, } if (bs->slices.count > 0) { *arg->slice = gpr_slice_buffer_take_first(&bs->slices); - grpc_exec_ctx_enqueue(exec_ctx, arg->on_complete, true, NULL); - } else if (bs->failed) { - grpc_exec_ctx_enqueue(exec_ctx, arg->on_complete, false, NULL); + grpc_exec_ctx_push(exec_ctx, arg->on_complete, GRPC_ERROR_NONE, NULL); + } else if (bs->error != GRPC_ERROR_NONE) { + grpc_exec_ctx_push(exec_ctx, arg->on_complete, grpc_error_ref(bs->error), + NULL); } else { bs->on_next = arg->on_complete; bs->next = arg->slice; @@ -1805,7 +1808,7 @@ static void incoming_byte_stream_push_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs = arg->byte_stream; if (bs->on_next != NULL) { *bs->next = arg->slice; - grpc_exec_ctx_enqueue(exec_ctx, bs->on_next, true, NULL); + grpc_exec_ctx_push(exec_ctx, bs->on_next, GRPC_ERROR_NONE, NULL); bs->on_next = NULL; } else { gpr_slice_buffer_add(&bs->slices, arg->slice); @@ -1827,9 +1830,10 @@ static void incoming_byte_stream_finished_failed_locked( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, void *argp) { grpc_chttp2_incoming_byte_stream *bs = argp; - grpc_exec_ctx_enqueue(exec_ctx, bs->on_next, false, NULL); + grpc_error *error = argp; + grpc_exec_ctx_push(exec_ctx, bs->on_next, grpc_error_ref(error), NULL); bs->on_next = NULL; - bs->failed = 1; + bs->error = error; incoming_byte_stream_unref(exec_ctx, bs); } @@ -1883,7 +1887,7 @@ grpc_chttp2_incoming_byte_stream *grpc_chttp2_incoming_byte_stream_create( gpr_slice_buffer_init(&incoming_byte_stream->slices); incoming_byte_stream->on_next = NULL; incoming_byte_stream->is_tail = 1; - incoming_byte_stream->failed = 0; + incoming_byte_stream->error = GRPC_ERROR_NONE; if (add_to_queue->head == NULL) { add_to_queue->head = incoming_byte_stream; } else { @@ -2012,5 +2016,5 @@ void grpc_chttp2_transport_start_reading(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t = (grpc_chttp2_transport *)transport; REF_TRANSPORT(t, "reading_action"); /* matches unref inside reading_action */ gpr_slice_buffer_addn(&t->read_buffer, slices, nslices); - reading_action(exec_ctx, t, 1); + reading_action(exec_ctx, t, GRPC_ERROR_NONE); } diff --git a/src/core/ext/transport/chttp2/transport/frame.h b/src/core/ext/transport/chttp2/transport/frame.h index 5c72d91c2a..7776609367 100644 --- a/src/core/ext/transport/chttp2/transport/frame.h +++ b/src/core/ext/transport/chttp2/transport/frame.h @@ -37,13 +37,7 @@ #include <grpc/support/port_platform.h> #include <grpc/support/slice.h> -/* Common definitions for frame handling in the chttp2 transport */ - -typedef enum { - GRPC_CHTTP2_PARSE_OK, - GRPC_CHTTP2_STREAM_ERROR, - GRPC_CHTTP2_CONNECTION_ERROR -} grpc_chttp2_parse_error; +#include "src/core/lib/iomgr/error.h" /* defined in internal.h */ typedef struct grpc_chttp2_stream_parsing grpc_chttp2_stream_parsing; diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 8c4fa2d34a..cb5ed9fc25 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -156,7 +156,7 @@ struct grpc_chttp2_incoming_byte_stream { grpc_byte_stream base; gpr_refcount refs; struct grpc_chttp2_incoming_byte_stream *next_message; - int failed; + grpc_error *error; grpc_chttp2_transport *transport; grpc_chttp2_stream *stream; @@ -275,10 +275,10 @@ struct grpc_chttp2_transport_parsing { /* active parser */ void *parser_data; grpc_chttp2_stream_parsing *incoming_stream; - grpc_chttp2_parse_error (*parser)( - grpc_exec_ctx *exec_ctx, void *parser_user_data, - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last); + grpc_error *(*parser)(grpc_exec_ctx *exec_ctx, void *parser_user_data, + grpc_chttp2_transport_parsing *transport_parsing, + grpc_chttp2_stream_parsing *stream_parsing, + gpr_slice slice, int is_last); /* received settings */ uint32_t settings[GRPC_CHTTP2_NUM_SETTINGS]; @@ -530,7 +530,7 @@ void grpc_chttp2_perform_writes( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint); void grpc_chttp2_terminate_writing(grpc_exec_ctx *exec_ctx, - void *transport_writing, bool success); + void *transport_writing, grpc_error *error); void grpc_chttp2_cleanup_writing(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *global, grpc_chttp2_transport_writing *writing); @@ -539,9 +539,9 @@ void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global, grpc_chttp2_transport_parsing *parsing); /** Process one slice of incoming data; return 1 if the connection is still viable after reading, or 0 if the connection should be torn down */ -int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport_parsing *transport_parsing, - gpr_slice slice); +grpc_error *grpc_chttp2_perform_read( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, + gpr_slice slice); void grpc_chttp2_publish_reads(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *global, grpc_chttp2_transport_parsing *parsing); diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index 2995066e51..aaa66a6c91 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -45,30 +45,30 @@ #include "src/core/lib/profiling/timers.h" #include "src/core/lib/transport/static_metadata.h" -static int init_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport_parsing *transport_parsing); -static int init_header_frame_parser( +static grpc_error *init_frame_parser( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); +static grpc_error *init_header_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, int is_continuation); -static int init_data_frame_parser( +static grpc_error *init_data_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); -static int init_rst_stream_parser( +static grpc_error *init_rst_stream_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); -static int init_settings_frame_parser( +static grpc_error *init_settings_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); -static int init_window_update_frame_parser( +static grpc_error *init_window_update_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); -static int init_ping_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport_parsing *transport_parsing); -static int init_goaway_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport_parsing *transport_parsing); -static int init_skip_frame_parser( +static grpc_error *init_ping_parser( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); +static grpc_error *init_goaway_parser( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); +static grpc_error *init_skip_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, int is_header); -static int parse_frame_slice(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport_parsing *transport_parsing, - gpr_slice slice, int is_last); +static grpc_error *parse_frame_slice( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, + gpr_slice slice, int is_last); void grpc_chttp2_prepare_to_read( grpc_chttp2_transport_global *transport_global, @@ -83,8 +83,8 @@ void grpc_chttp2_prepare_to_read( transport_global->settings[GRPC_SENT_SETTINGS], sizeof(transport_parsing->last_sent_settings)); transport_parsing->max_frame_size = - transport_global->settings[GRPC_ACKED_SETTINGS] - [GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE]; + transport_global + ->settings[GRPC_ACKED_SETTINGS][GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE]; /* update the parsing view of incoming window */ while (grpc_chttp2_list_pop_unannounced_incoming_window_available( @@ -248,14 +248,15 @@ void grpc_chttp2_publish_reads( } } -int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport_parsing *transport_parsing, - gpr_slice slice) { +grpc_error *grpc_chttp2_perform_read( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, + gpr_slice slice) { uint8_t *beg = GPR_SLICE_START_PTR(slice); uint8_t *end = GPR_SLICE_END_PTR(slice); uint8_t *cur = beg; + grpc_error *err; - if (cur == end) return 1; + if (cur == end) return GRPC_ERROR_NONE; switch (transport_parsing->deframe_state) { case GRPC_DTS_CLIENT_PREFIX_0: @@ -285,21 +286,25 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, while (cur != end && transport_parsing->deframe_state != GRPC_DTS_FH_0) { if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing ->deframe_state]) { - gpr_log(GPR_INFO, - "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " - "at byte %d", - GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing - ->deframe_state], - (int)(uint8_t)GRPC_CHTTP2_CLIENT_CONNECT_STRING - [transport_parsing->deframe_state], - *cur, (int)*cur, transport_parsing->deframe_state); - return 0; + char *msg; + gpr_asprintf( + &msg, + "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " + "at byte %d", + GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing + ->deframe_state], + (int)(uint8_t)GRPC_CHTTP2_CLIENT_CONNECT_STRING + [transport_parsing->deframe_state], + *cur, (int)*cur, transport_parsing->deframe_state); + err = GRPC_ERROR_CREATE(msg); + gpr_free(msg); + return err; } ++cur; ++transport_parsing->deframe_state; } if (cur == end) { - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ dts_fh_0: @@ -308,7 +313,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_frame_size = ((uint32_t)*cur) << 16; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_1; - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FH_1: @@ -316,7 +321,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_frame_size |= ((uint32_t)*cur) << 8; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_2; - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FH_2: @@ -324,7 +329,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_frame_size |= *cur; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_3; - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FH_3: @@ -332,7 +337,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_frame_type = *cur; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_4; - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FH_4: @@ -340,7 +345,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_frame_flags = *cur; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_5; - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FH_5: @@ -348,7 +353,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_stream_id = (((uint32_t)*cur) & 0x7f) << 24; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_6; - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FH_6: @@ -356,7 +361,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_stream_id |= ((uint32_t)*cur) << 16; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_7; - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FH_7: @@ -364,15 +369,16 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_stream_id |= ((uint32_t)*cur) << 8; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_8; - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FH_8: GPR_ASSERT(cur < end); transport_parsing->incoming_stream_id |= ((uint32_t)*cur); transport_parsing->deframe_state = GRPC_DTS_FRAME; - if (!init_frame_parser(exec_ctx, transport_parsing)) { - return 0; + err = init_frame_parser(exec_ctx, transport_parsing); + if (err != GRPC_ERROR_NONE) { + return err; } if (transport_parsing->incoming_stream_id != 0 && transport_parsing->incoming_stream_id > @@ -381,62 +387,69 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, transport_parsing->incoming_stream_id; } if (transport_parsing->incoming_frame_size == 0) { - if (!parse_frame_slice(exec_ctx, transport_parsing, gpr_empty_slice(), - 1)) { - return 0; + err = parse_frame_slice(exec_ctx, transport_parsing, gpr_empty_slice(), + 1); + if (err != GRPC_ERROR_NONE) { + return err; } transport_parsing->incoming_stream = NULL; if (++cur == end) { transport_parsing->deframe_state = GRPC_DTS_FH_0; - return 1; + return GRPC_ERROR_NONE; } goto dts_fh_0; /* loop */ } else if (transport_parsing->incoming_frame_size > transport_parsing->max_frame_size) { - gpr_log(GPR_DEBUG, "Frame size %d is larger than max frame size %d", - transport_parsing->incoming_frame_size, - transport_parsing->max_frame_size); - return 0; + char *msg; + gpr_asprintf(&msg, "Frame size %d is larger than max frame size %d", + transport_parsing->incoming_frame_size, + transport_parsing->max_frame_size); + err = GRPC_ERROR_CREATE(msg); + gpr_free(msg); + return err; } if (++cur == end) { - return 1; + return GRPC_ERROR_NONE; } /* fallthrough */ case GRPC_DTS_FRAME: GPR_ASSERT(cur < end); if ((uint32_t)(end - cur) == transport_parsing->incoming_frame_size) { - if (!parse_frame_slice(exec_ctx, transport_parsing, - gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - 1)) { - return 0; + err = parse_frame_slice(exec_ctx, transport_parsing, + gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), + (size_t)(end - beg)), + 1); + if (err != GRPC_ERROR_NONE) { + return err; } transport_parsing->deframe_state = GRPC_DTS_FH_0; transport_parsing->incoming_stream = NULL; - return 1; + return GRPC_ERROR_NONE; } else if ((uint32_t)(end - cur) > transport_parsing->incoming_frame_size) { size_t cur_offset = (size_t)(cur - beg); - if (!parse_frame_slice( - exec_ctx, transport_parsing, - gpr_slice_sub_no_ref( - slice, cur_offset, - cur_offset + transport_parsing->incoming_frame_size), - 1)) { - return 0; + err = parse_frame_slice( + exec_ctx, transport_parsing, + gpr_slice_sub_no_ref( + slice, cur_offset, + cur_offset + transport_parsing->incoming_frame_size), + 1); + if (err != GRPC_ERROR_NONE) { + return err; } cur += transport_parsing->incoming_frame_size; transport_parsing->incoming_stream = NULL; goto dts_fh_0; /* loop */ } else { - if (!parse_frame_slice(exec_ctx, transport_parsing, - gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - 0)) { - return 0; + err = parse_frame_slice(exec_ctx, transport_parsing, + gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), + (size_t)(end - beg)), + 0); + if (err != GRPC_ERROR_NONE) { + return err; } transport_parsing->incoming_frame_size -= (uint32_t)(end - cur); - return 1; + return GRPC_ERROR_NONE; } GPR_UNREACHABLE_CODE(return 0); } @@ -444,23 +457,30 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, GPR_UNREACHABLE_CODE(return 0); } -static int init_frame_parser(grpc_exec_ctx *exec_ctx, - grpc_chttp2_transport_parsing *transport_parsing) { +static grpc_error *init_frame_parser( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) { if (transport_parsing->expect_continuation_stream_id != 0) { if (transport_parsing->incoming_frame_type != GRPC_CHTTP2_FRAME_CONTINUATION) { - gpr_log(GPR_ERROR, "Expected CONTINUATION frame, got frame type %02x", - transport_parsing->incoming_frame_type); - return 0; + char *msg; + gpr_asprintf(&msg, "Expected CONTINUATION frame, got frame type %02x", + transport_parsing->incoming_frame_type); + grpc_error *err = GRPC_ERROR_CREATE(msg); + gpr_free(msg); + return err; } if (transport_parsing->expect_continuation_stream_id != transport_parsing->incoming_stream_id) { - gpr_log(GPR_ERROR, - "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got " - "grpc_chttp2_stream %08x", - transport_parsing->expect_continuation_stream_id, - transport_parsing->incoming_stream_id); - return 0; + char *msg; + gpr_asprintf( + &msg, + "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got " + "grpc_chttp2_stream %08x", + transport_parsing->expect_continuation_stream_id, + transport_parsing->incoming_stream_id); + grpc_error *err = GRPC_ERROR_CREATE(msg); + gpr_free(msg); + return err; } return init_header_frame_parser(exec_ctx, transport_parsing, 1); } @@ -483,22 +503,24 @@ static int init_frame_parser(grpc_exec_ctx *exec_ctx, case GRPC_CHTTP2_FRAME_GOAWAY: return init_goaway_parser(exec_ctx, transport_parsing); default: - gpr_log(GPR_ERROR, "Unknown frame type %02x", - transport_parsing->incoming_frame_type); + if (grpc_http_trace) { + gpr_log(GPR_ERROR, "Unknown frame type %02x", + transport_parsing->incoming_frame_type); + } return init_skip_frame_parser(exec_ctx, transport_parsing, 0); } } -static grpc_chttp2_parse_error skip_parser( - grpc_exec_ctx *exec_ctx, void *parser, - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last) { - return GRPC_CHTTP2_PARSE_OK; +static grpc_error *skip_parser(grpc_exec_ctx *exec_ctx, void *parser, + grpc_chttp2_transport_parsing *transport_parsing, + grpc_chttp2_stream_parsing *stream_parsing, + gpr_slice slice, int is_last) { + return GRPC_ERROR_NONE; } static void skip_header(void *tp, grpc_mdelem *md) { GRPC_MDELEM_UNREF(md); } -static int init_skip_frame_parser( +static grpc_error *init_skip_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, int is_header) { if (is_header) { @@ -513,7 +535,7 @@ static int init_skip_frame_parser( } else { transport_parsing->parser = skip_parser; } - return 1; + return GRPC_ERROR_NONE; } void grpc_chttp2_parsing_become_skip_parser( @@ -523,22 +545,28 @@ void grpc_chttp2_parsing_become_skip_parser( transport_parsing->parser == grpc_chttp2_header_parser_parse); } -static grpc_chttp2_parse_error update_incoming_window( +static grpc_error *update_incoming_window( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, grpc_chttp2_stream_parsing *stream_parsing) { uint32_t incoming_frame_size = transport_parsing->incoming_frame_size; if (incoming_frame_size > transport_parsing->incoming_window) { - gpr_log(GPR_ERROR, "frame of size %d overflows incoming window of %d", - transport_parsing->incoming_frame_size, - transport_parsing->incoming_window); - return GRPC_CHTTP2_CONNECTION_ERROR; + char *msg; + gpr_asprintf(&msg, "frame of size %d overflows incoming window of %d", + transport_parsing->incoming_frame_size, + transport_parsing->incoming_window); + grpc_error *err = GRPC_ERROR_CREATE(msg); + gpr_free(msg); + return err; } if (incoming_frame_size > stream_parsing->incoming_window) { - gpr_log(GPR_ERROR, "frame of size %d overflows incoming window of %d", - transport_parsing->incoming_frame_size, - stream_parsing->incoming_window); - return GRPC_CHTTP2_CONNECTION_ERROR; + char *msg; + gpr_asprintf(&msg, "frame of size %d overflows incoming window of %d", + transport_parsing->incoming_frame_size, + stream_parsing->incoming_window); + grpc_error *err = GRPC_ERROR_CREATE(msg); + gpr_free(msg); + return err; } GRPC_CHTTP2_FLOW_DEBIT_TRANSPORT("parse", transport_parsing, incoming_window, @@ -552,7 +580,7 @@ static grpc_chttp2_parse_error update_incoming_window( return GRPC_CHTTP2_PARSE_OK; } -static int init_data_frame_parser( +static grpc_error *init_data_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) { grpc_chttp2_stream_parsing *stream_parsing = grpc_chttp2_parsing_lookup_stream(transport_parsing, @@ -577,7 +605,7 @@ static int init_data_frame_parser( transport_parsing->incoming_stream = stream_parsing; transport_parsing->parser = grpc_chttp2_data_parser_parse; transport_parsing->parser_data = &stream_parsing->data_parser; - return 1; + return GRPC_ERROR_NONE; case GRPC_CHTTP2_STREAM_ERROR: stream_parsing->received_close = 1; stream_parsing->saw_rst_stream = 1; @@ -669,7 +697,7 @@ static void on_trailing_header(void *tp, grpc_mdelem *md) { GPR_TIMER_END("on_trailing_header", 0); } -static int init_header_frame_parser( +static grpc_error *init_header_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing, int is_continuation) { uint8_t is_eoh = (transport_parsing->incoming_frame_flags & @@ -764,10 +792,10 @@ static int init_header_frame_parser( GRPC_CHTTP2_FLAG_HAS_PRIORITY)) { grpc_chttp2_hpack_parser_set_has_priority(&transport_parsing->hpack_parser); } - return 1; + return GRPC_ERROR_NONE; } -static int init_window_update_frame_parser( +static grpc_error *init_window_update_frame_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) { int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_window_update_parser_begin_frame( &transport_parsing->simple.window_update, diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 0ce684fdbc..1429631b67 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -44,6 +44,7 @@ typedef enum { GRPC_ERROR_INT_ERRNO, GRPC_ERROR_INT_FILE_LINE, GRPC_ERROR_INT_STATUS_CODE, + GRPC_ERROR_INT_WARNING, } grpc_error_ints; typedef enum { @@ -75,6 +76,7 @@ grpc_error *grpc_error_ref(grpc_error *err); void grpc_error_unref(grpc_error *err); grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which, intptr_t value); +const intptr_t *grpc_error_get_int(grpc_error *error, grpc_error_ints which); grpc_error *grpc_error_set_time(grpc_error *src, grpc_error_times which, gpr_timespec value); grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which, diff --git a/src/core/lib/iomgr/unix_sockets_posix.c b/src/core/lib/iomgr/unix_sockets_posix.c index 5767c852df..0e7670e5a5 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.c +++ b/src/core/lib/iomgr/unix_sockets_posix.c @@ -47,17 +47,18 @@ void grpc_create_socketpair_if_unix(int sv[2]) { GPR_ASSERT(socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0); } -grpc_resolved_addresses *grpc_resolve_unix_domain_address(const char *name) { +grpc_error *grpc_resolve_unix_domain_address(const char *name, + grpc_resolved_addresses **addrs) { struct sockaddr_un *un; - grpc_resolved_addresses *addrs = gpr_malloc(sizeof(grpc_resolved_addresses)); - addrs->naddrs = 1; - addrs->addrs = gpr_malloc(sizeof(grpc_resolved_address)); - un = (struct sockaddr_un *)addrs->addrs->addr; + *addrs = gpr_malloc(sizeof(grpc_resolved_addresses)); + (*addrs)->naddrs = 1; + (*addrs)->addrs = gpr_malloc(sizeof(grpc_resolved_address)); + un = (struct sockaddr_un *)(*addrs)->addrs->addr; un->sun_family = AF_UNIX; strcpy(un->sun_path, name); - addrs->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1; - return addrs; + (*addrs)->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1; + return GRPC_ERROR_NONE; } int grpc_is_unix_socket(const struct sockaddr *addr) { diff --git a/src/core/lib/security/credentials.h b/src/core/lib/security/credentials.h index 0373ceaa3f..48fcd7ba06 100644 --- a/src/core/lib/security/credentials.h +++ b/src/core/lib/security/credentials.h @@ -318,7 +318,8 @@ typedef void (*grpc_fetch_oauth2_func)(grpc_exec_ctx *exec_ctx, grpc_credentials_metadata_request *req, grpc_httpcli_context *http_context, grpc_pollset *pollset, - grpc_httpcli_response_cb response_cb, + grpc_closure *on_http_response, + grpc_http_response *response, gpr_timespec deadline); typedef struct { |