From 91472967c7134003229ecc881f361a2c2a4b7ea2 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 9 May 2016 11:01:15 -0700 Subject: [PATCH] Progress converting to new error system --- .../chttp2/transport/chttp2_transport.c | 46 +++++++++++-------- .../ext/transport/chttp2/transport/internal.h | 8 ++-- .../ext/transport/chttp2/transport/writing.c | 10 ++-- src/core/lib/iomgr/tcp_server_posix.c | 3 +- 4 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 1b1dcabe71a..f2a3d3592b6 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -143,6 +143,7 @@ static void incoming_byte_stream_destroy_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s, void *byte_stream); static void fail_pending_writes(grpc_exec_ctx *exec_ctx, + grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global, grpc_error *error); @@ -750,7 +751,8 @@ static void terminate_writing_with_lock(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream_global *stream_global; while (grpc_chttp2_list_pop_closed_waiting_for_writing(&t->global, &stream_global)) { - fail_pending_writes(exec_ctx, stream_global, GRPC_ERROR_REF(error)); + fail_pending_writes(exec_ctx, &t->global, stream_global, + GRPC_ERROR_REF(error)); GRPC_CHTTP2_STREAM_UNREF(exec_ctx, stream_global, "finish_writes"); } @@ -860,10 +862,10 @@ static grpc_closure *add_closure_barrier(grpc_closure *closure) { return closure; } -void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, - grpc_chttp2_stream_global *stream_global, - grpc_closure **pclosure, - grpc_error *error) { +void grpc_chttp2_complete_closure_step( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global, + grpc_chttp2_stream_global *stream_global, grpc_closure **pclosure, + grpc_error *error) { grpc_closure *closure = *pclosure; if (closure == NULL) { GRPC_ERROR_UNREF(error); @@ -874,6 +876,9 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, if (closure->error == GRPC_ERROR_NONE) { closure->error = GRPC_ERROR_CREATE("Error in HTTP transport completing operation"); + closure->error = grpc_error_set_str( + closure->error, GRPC_ERROR_STR_TARGET_ADDRESS, + TRANSPORT_FROM_GLOBAL(transport_global)->peer_string); } closure->error = grpc_error_add_child(closure->error, error); } @@ -919,6 +924,7 @@ 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->next_data.scratch = CLOSURE_BARRIER_FIRST_REF_BIT; + on_complete->error = GRPC_ERROR_NONE; if (op->collect_stats != NULL) { GPR_ASSERT(stream_global->collecting_stats == NULL); @@ -957,7 +963,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, } } else { grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, + exec_ctx, transport_global, stream_global, &stream_global->send_initial_metadata_finished, GRPC_ERROR_CREATE( "Attempt to send initial metadata after stream was closed")); @@ -970,7 +976,8 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, stream_global->send_message_finished = add_closure_barrier(on_complete); if (stream_global->write_closed) { grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, &stream_global->send_message_finished, + exec_ctx, transport_global, stream_global, + &stream_global->send_message_finished, GRPC_ERROR_CREATE("Attempt to send message after stream was closed")); } else { stream_global->send_message = op->send_message; @@ -991,7 +998,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, } if (stream_global->write_closed) { grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, + exec_ctx, transport_global, stream_global, &stream_global->send_trailing_metadata_finished, grpc_metadata_batch_is_empty(op->send_trailing_metadata) ? GRPC_ERROR_NONE @@ -1034,8 +1041,8 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_list_add_check_read_ops(transport_global, stream_global); } - grpc_chttp2_complete_closure_step(exec_ctx, stream_global, &on_complete, - GRPC_ERROR_NONE); + grpc_chttp2_complete_closure_step(exec_ctx, transport_global, stream_global, + &on_complete, GRPC_ERROR_NONE); GPR_TIMER_END("perform_stream_op_locked", 0); } @@ -1205,7 +1212,7 @@ static void check_read_ops(grpc_exec_ctx *exec_ctx, &stream_global->received_trailing_metadata, stream_global->recv_trailing_metadata); grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, + exec_ctx, transport_global, stream_global, &stream_global->recv_trailing_metadata_finished, GRPC_ERROR_NONE); } } @@ -1323,16 +1330,18 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, } static void fail_pending_writes(grpc_exec_ctx *exec_ctx, + grpc_chttp2_transport_global *transport_global, grpc_chttp2_stream_global *stream_global, grpc_error *error) { grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, &stream_global->send_initial_metadata_finished, - GRPC_ERROR_REF(error)); - grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, &stream_global->send_trailing_metadata_finished, - GRPC_ERROR_REF(error)); + exec_ctx, transport_global, stream_global, + &stream_global->send_initial_metadata_finished, GRPC_ERROR_REF(error)); grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, &stream_global->send_message_finished, error); + exec_ctx, transport_global, stream_global, + &stream_global->send_trailing_metadata_finished, GRPC_ERROR_REF(error)); + grpc_chttp2_complete_closure_step(exec_ctx, transport_global, stream_global, + &stream_global->send_message_finished, + error); } void grpc_chttp2_mark_stream_closed( @@ -1358,7 +1367,8 @@ void grpc_chttp2_mark_stream_closed( grpc_chttp2_list_add_closed_waiting_for_writing(transport_global, stream_global); } else { - fail_pending_writes(exec_ctx, stream_global, GRPC_ERROR_REF(error)); + fail_pending_writes(exec_ctx, transport_global, stream_global, + GRPC_ERROR_REF(error)); } } if (stream_global->read_closed && stream_global->write_closed) { diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 1a8b44d86e3..ff01f70319c 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -671,10 +671,10 @@ void grpc_chttp2_for_all_streams( void grpc_chttp2_parsing_become_skip_parser( grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing); -void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, - grpc_chttp2_stream_global *stream_global, - grpc_closure **pclosure, - grpc_error *error); +void grpc_chttp2_complete_closure_step( + grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global, + grpc_chttp2_stream_global *stream_global, grpc_closure **pclosure, + grpc_error *error); void grpc_chttp2_run_with_global_lock(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *transport, diff --git a/src/core/ext/transport/chttp2/transport/writing.c b/src/core/ext/transport/chttp2/transport/writing.c index ff42fd249a4..ca56debc841 100644 --- a/src/core/ext/transport/chttp2/transport/writing.c +++ b/src/core/ext/transport/chttp2/transport/writing.c @@ -335,21 +335,21 @@ void grpc_chttp2_cleanup_writing( transport_global, transport_writing, &stream_global, &stream_writing)) { if (stream_writing->sent_initial_metadata) { grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, + exec_ctx, transport_global, stream_global, &stream_global->send_initial_metadata_finished, GRPC_ERROR_NONE); } grpc_transport_move_one_way_stats(&stream_writing->stats, &stream_global->stats.outgoing); if (stream_writing->sent_message) { GPR_ASSERT(stream_writing->send_message == NULL); - grpc_chttp2_complete_closure_step(exec_ctx, stream_global, - &stream_global->send_message_finished, - GRPC_ERROR_NONE); + grpc_chttp2_complete_closure_step( + exec_ctx, transport_global, stream_global, + &stream_global->send_message_finished, GRPC_ERROR_NONE); stream_writing->sent_message = 0; } if (stream_writing->sent_trailing_metadata) { grpc_chttp2_complete_closure_step( - exec_ctx, stream_global, + exec_ctx, transport_global, stream_global, &stream_global->send_trailing_metadata_finished, GRPC_ERROR_NONE); } if (stream_writing->sent_trailing_metadata) { diff --git a/src/core/lib/iomgr/tcp_server_posix.c b/src/core/lib/iomgr/tcp_server_posix.c index bb51ba2c763..dca068fd25d 100644 --- a/src/core/lib/iomgr/tcp_server_posix.c +++ b/src/core/lib/iomgr/tcp_server_posix.c @@ -394,12 +394,13 @@ static grpc_error *add_socket_to_server(grpc_tcp_server *s, int fd, unsigned fd_index, grpc_tcp_listener **listener) { grpc_tcp_listener *sp = NULL; - int port; + int port = -1; char *addr_str; char *name; grpc_error *err = prepare_socket(fd, addr, addr_len, &port); if (err == GRPC_ERROR_NONE) { + GPR_ASSERT(port > 0); grpc_sockaddr_to_string(&addr_str, (struct sockaddr *)&addr, 1); gpr_asprintf(&name, "tcp-server-listener:%s", addr_str); gpr_mu_lock(&s->mu);