static int add_slice_to_message(grpc_call *call, gpr_slice slice) { if (GPR_SLICE_LENGTH(slice) == 0) { gpr_slice_unref(slice); return 1; } /* we have to be reading a message to know what to do here */ if (!call->reading_message) { cancel_with_status( call, GRPC_STATUS_INVALID_ARGUMENT, "Received payload data while not reading a message", 1); return 0; } /* append the slice to the incoming buffer */ gpr_slice_buffer_add(&call->incoming_message, slice); if (call->incoming_message.length > call->incoming_message_length) { /* if we got too many bytes, complain */ char *message = NULL; gpr_asprintf( &message, "Receiving message overflow; read %d bytes, expected %d", (int)call->incoming_message.length, (int)call->incoming_message_length); cancel_with_status(call, GRPC_STATUS_INVALID_ARGUMENT, message, 1); gpr_free(message); return 0; } else if (call->incoming_message.length == call->incoming_message_length) { finish_message(call); return 1; } else { return 1; } }
static int begin_message(grpc_call *call, grpc_begin_message msg) { /* can't begin a message when we're still reading a message */ if (call->reading_message) { char *message = NULL; gpr_asprintf( &message, "Message terminated early; read %d bytes, expected %d", (int)call->incoming_message.length, (int)call->incoming_message_length); cancel_with_status(call, GRPC_STATUS_INVALID_ARGUMENT, message, 1); gpr_free(message); return 0; } /* stash away parameters, and prepare for incoming slices */ if (msg.length > grpc_channel_get_max_message_length(call->channel)) { char *message = NULL; gpr_asprintf( &message, "Maximum message length of %d exceeded by a message of length %d", grpc_channel_get_max_message_length(call->channel), msg.length); cancel_with_status(call, GRPC_STATUS_INVALID_ARGUMENT, message, 1); gpr_free(message); return 0; } else if (msg.length > 0) { call->reading_message = 1; call->incoming_message_length = msg.length; return 1; } else { finish_message(call); return 1; } }
static void call_alarm(grpc_exec_ctx *exec_ctx, void *arg, int success) { grpc_call *call = arg; gpr_mu_lock(&call->mu); call->have_alarm = 0; if (success) { cancel_with_status(exec_ctx, call, GRPC_STATUS_DEADLINE_EXCEEDED, "Deadline Exceeded"); } gpr_mu_unlock(&call->mu); GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "alarm"); }
static void call_alarm(void *arg, int success) { grpc_call *call = arg; if (success) { if (call->is_client) { cancel_with_status(call, GRPC_STATUS_DEADLINE_EXCEEDED, "Deadline Exceeded", 0); } else { grpc_call_cancel(call); } } GRPC_CALL_INTERNAL_UNREF(call, "alarm", 1); }
grpc_call_error grpc_call_cancel_with_status(grpc_call *c, grpc_status_code status, const char *description, void *reserved) { grpc_call_error r; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GRPC_API_TRACE( "grpc_call_cancel_with_status(" "c=%p, status=%d, description=%s, reserved=%p)", 4, (c, (int)status, description, reserved)); GPR_ASSERT(reserved == NULL); gpr_mu_lock(&c->mu); r = cancel_with_status(&exec_ctx, c, status, description); gpr_mu_unlock(&c->mu); grpc_exec_ctx_finish(&exec_ctx); return r; }
static void receiving_stream_ready(grpc_exec_ctx *exec_ctx, void *bctlp, int success) { batch_control *bctl = bctlp; grpc_call *call = bctl->call; if (call->receiving_stream == NULL) { *call->receiving_buffer = NULL; if (gpr_unref(&bctl->steps_to_complete)) { post_batch_completion(exec_ctx, bctl); } } else if (call->receiving_stream->length > grpc_channel_get_max_message_length(call->channel)) { cancel_with_status(exec_ctx, call, GRPC_STATUS_INTERNAL, "Max message size exceeded"); grpc_byte_stream_destroy(call->receiving_stream); call->receiving_stream = NULL; *call->receiving_buffer = NULL; if (gpr_unref(&bctl->steps_to_complete)) { post_batch_completion(exec_ctx, bctl); } } else { call->test_only_last_message_flags = call->receiving_stream->flags; if ((call->receiving_stream->flags & GRPC_WRITE_INTERNAL_COMPRESS) && (call->compression_algorithm > GRPC_COMPRESS_NONE)) { *call->receiving_buffer = grpc_raw_compressed_byte_buffer_create( NULL, 0, call->compression_algorithm); } else { *call->receiving_buffer = grpc_raw_byte_buffer_create(NULL, 0); } grpc_closure_init(&call->receiving_slice_ready, receiving_slice_ready, bctl); continue_receiving_slices(exec_ctx, bctl); /* early out */ return; } }
void grpc_end2end_tests(int argc, char **argv, grpc_end2end_test_config config) { int i; GPR_ASSERT(g_pre_init_called); if (argc <= 1) { authority_not_supported(config); bad_hostname(config); binary_metadata(config); call_creds(config); cancel_after_accept(config); cancel_after_client_done(config); cancel_after_invoke(config); cancel_before_invoke(config); cancel_in_a_vacuum(config); cancel_with_status(config); compressed_payload(config); connectivity(config); default_host(config); disappearing_server(config); empty_batch(config); filter_call_init_fails(config); filter_causes_close(config); filter_latency(config); graceful_server_shutdown(config); high_initial_seqno(config); hpack_size(config); idempotent_request(config); invoke_large_request(config); large_metadata(config); load_reporting_hook(config); max_concurrent_streams(config); max_message_length(config); negative_deadline(config); network_status_change(config); no_logging(config); no_op(config); payload(config); ping(config); ping_pong_streaming(config); registered_call(config); request_with_flags(config); request_with_payload(config); resource_quota_server(config); server_finishes_request(config); shutdown_finishes_calls(config); shutdown_finishes_tags(config); simple_cacheable_request(config); simple_delayed_request(config); simple_metadata(config); simple_request(config); streaming_error_response(config); trailing_metadata(config); return; } for (i = 1; i < argc; i++) { if (0 == strcmp("authority_not_supported", argv[i])) { authority_not_supported(config); continue; } if (0 == strcmp("bad_hostname", argv[i])) { bad_hostname(config); continue; } if (0 == strcmp("binary_metadata", argv[i])) { binary_metadata(config); continue; } if (0 == strcmp("call_creds", argv[i])) { call_creds(config); continue; } if (0 == strcmp("cancel_after_accept", argv[i])) { cancel_after_accept(config); continue; } if (0 == strcmp("cancel_after_client_done", argv[i])) { cancel_after_client_done(config); continue; } if (0 == strcmp("cancel_after_invoke", argv[i])) { cancel_after_invoke(config); continue; } if (0 == strcmp("cancel_before_invoke", argv[i])) { cancel_before_invoke(config); continue; } if (0 == strcmp("cancel_in_a_vacuum", argv[i])) { cancel_in_a_vacuum(config); continue; } if (0 == strcmp("cancel_with_status", argv[i])) { cancel_with_status(config); continue; } if (0 == strcmp("compressed_payload", argv[i])) { compressed_payload(config); continue; } if (0 == strcmp("connectivity", argv[i])) { connectivity(config); continue; } if (0 == strcmp("default_host", argv[i])) { default_host(config); continue; } if (0 == strcmp("disappearing_server", argv[i])) { disappearing_server(config); continue; } if (0 == strcmp("empty_batch", argv[i])) { empty_batch(config); continue; } if (0 == strcmp("filter_call_init_fails", argv[i])) { filter_call_init_fails(config); continue; } if (0 == strcmp("filter_causes_close", argv[i])) { filter_causes_close(config); continue; } if (0 == strcmp("filter_latency", argv[i])) { filter_latency(config); continue; } if (0 == strcmp("graceful_server_shutdown", argv[i])) { graceful_server_shutdown(config); continue; } if (0 == strcmp("high_initial_seqno", argv[i])) { high_initial_seqno(config); continue; } if (0 == strcmp("hpack_size", argv[i])) { hpack_size(config); continue; } if (0 == strcmp("idempotent_request", argv[i])) { idempotent_request(config); continue; } if (0 == strcmp("invoke_large_request", argv[i])) { invoke_large_request(config); continue; } if (0 == strcmp("large_metadata", argv[i])) { large_metadata(config); continue; } if (0 == strcmp("load_reporting_hook", argv[i])) { load_reporting_hook(config); continue; } if (0 == strcmp("max_concurrent_streams", argv[i])) { max_concurrent_streams(config); continue; } if (0 == strcmp("max_message_length", argv[i])) { max_message_length(config); continue; } if (0 == strcmp("negative_deadline", argv[i])) { negative_deadline(config); continue; } if (0 == strcmp("network_status_change", argv[i])) { network_status_change(config); continue; } if (0 == strcmp("no_logging", argv[i])) { no_logging(config); continue; } if (0 == strcmp("no_op", argv[i])) { no_op(config); continue; } if (0 == strcmp("payload", argv[i])) { payload(config); continue; } if (0 == strcmp("ping", argv[i])) { ping(config); continue; } if (0 == strcmp("ping_pong_streaming", argv[i])) { ping_pong_streaming(config); continue; } if (0 == strcmp("registered_call", argv[i])) { registered_call(config); continue; } if (0 == strcmp("request_with_flags", argv[i])) { request_with_flags(config); continue; } if (0 == strcmp("request_with_payload", argv[i])) { request_with_payload(config); continue; } if (0 == strcmp("resource_quota_server", argv[i])) { resource_quota_server(config); continue; } if (0 == strcmp("server_finishes_request", argv[i])) { server_finishes_request(config); continue; } if (0 == strcmp("shutdown_finishes_calls", argv[i])) { shutdown_finishes_calls(config); continue; } if (0 == strcmp("shutdown_finishes_tags", argv[i])) { shutdown_finishes_tags(config); continue; } if (0 == strcmp("simple_cacheable_request", argv[i])) { simple_cacheable_request(config); continue; } if (0 == strcmp("simple_delayed_request", argv[i])) { simple_delayed_request(config); continue; } if (0 == strcmp("simple_metadata", argv[i])) { simple_metadata(config); continue; } if (0 == strcmp("simple_request", argv[i])) { simple_request(config); continue; } if (0 == strcmp("streaming_error_response", argv[i])) { streaming_error_response(config); continue; } if (0 == strcmp("trailing_metadata", argv[i])) { trailing_metadata(config); continue; } gpr_log(GPR_DEBUG, "not a test: '%s'", argv[i]); abort(); } }
void grpc_end2end_tests(int argc, char **argv, grpc_end2end_test_config config) { int i; if (argc <= 1) { bad_hostname(config); binary_metadata(config); cancel_after_accept(config); cancel_after_client_done(config); cancel_after_invoke(config); cancel_before_invoke(config); cancel_in_a_vacuum(config); cancel_with_status(config); channel_connectivity(config); channel_ping(config); compressed_payload(config); default_host(config); disappearing_server(config); empty_batch(config); graceful_server_shutdown(config); high_initial_seqno(config); hpack_size(config); invoke_large_request(config); large_metadata(config); max_concurrent_streams(config); max_message_length(config); metadata(config); negative_deadline(config); no_op(config); payload(config); ping_pong_streaming(config); registered_call(config); request_with_flags(config); request_with_payload(config); server_finishes_request(config); shutdown_finishes_calls(config); shutdown_finishes_tags(config); simple_delayed_request(config); simple_request(config); trailing_metadata(config); return; } for (i = 1; i < argc; i++) { if (0 == strcmp("bad_hostname", argv[i])) { bad_hostname(config); continue; } if (0 == strcmp("binary_metadata", argv[i])) { binary_metadata(config); continue; } if (0 == strcmp("cancel_after_accept", argv[i])) { cancel_after_accept(config); continue; } if (0 == strcmp("cancel_after_client_done", argv[i])) { cancel_after_client_done(config); continue; } if (0 == strcmp("cancel_after_invoke", argv[i])) { cancel_after_invoke(config); continue; } if (0 == strcmp("cancel_before_invoke", argv[i])) { cancel_before_invoke(config); continue; } if (0 == strcmp("cancel_in_a_vacuum", argv[i])) { cancel_in_a_vacuum(config); continue; } if (0 == strcmp("cancel_with_status", argv[i])) { cancel_with_status(config); continue; } if (0 == strcmp("channel_connectivity", argv[i])) { channel_connectivity(config); continue; } if (0 == strcmp("channel_ping", argv[i])) { channel_ping(config); continue; } if (0 == strcmp("compressed_payload", argv[i])) { compressed_payload(config); continue; } if (0 == strcmp("default_host", argv[i])) { default_host(config); continue; } if (0 == strcmp("disappearing_server", argv[i])) { disappearing_server(config); continue; } if (0 == strcmp("empty_batch", argv[i])) { empty_batch(config); continue; } if (0 == strcmp("graceful_server_shutdown", argv[i])) { graceful_server_shutdown(config); continue; } if (0 == strcmp("high_initial_seqno", argv[i])) { high_initial_seqno(config); continue; } if (0 == strcmp("hpack_size", argv[i])) { hpack_size(config); continue; } if (0 == strcmp("invoke_large_request", argv[i])) { invoke_large_request(config); continue; } if (0 == strcmp("large_metadata", argv[i])) { large_metadata(config); continue; } if (0 == strcmp("max_concurrent_streams", argv[i])) { max_concurrent_streams(config); continue; } if (0 == strcmp("max_message_length", argv[i])) { max_message_length(config); continue; } if (0 == strcmp("metadata", argv[i])) { metadata(config); continue; } if (0 == strcmp("negative_deadline", argv[i])) { negative_deadline(config); continue; } if (0 == strcmp("no_op", argv[i])) { no_op(config); continue; } if (0 == strcmp("payload", argv[i])) { payload(config); continue; } if (0 == strcmp("ping_pong_streaming", argv[i])) { ping_pong_streaming(config); continue; } if (0 == strcmp("registered_call", argv[i])) { registered_call(config); continue; } if (0 == strcmp("request_with_flags", argv[i])) { request_with_flags(config); continue; } if (0 == strcmp("request_with_payload", argv[i])) { request_with_payload(config); continue; } if (0 == strcmp("server_finishes_request", argv[i])) { server_finishes_request(config); continue; } if (0 == strcmp("shutdown_finishes_calls", argv[i])) { shutdown_finishes_calls(config); continue; } if (0 == strcmp("shutdown_finishes_tags", argv[i])) { shutdown_finishes_tags(config); continue; } if (0 == strcmp("simple_delayed_request", argv[i])) { simple_delayed_request(config); continue; } if (0 == strcmp("simple_request", argv[i])) { simple_request(config); continue; } if (0 == strcmp("trailing_metadata", argv[i])) { trailing_metadata(config); continue; } gpr_log(GPR_DEBUG, "not a test: '%%s'", argv[i]); abort(); } }
grpc_call_error grpc_call_cancel_with_status(grpc_call *c, grpc_status_code status, const char *description) { return cancel_with_status(c, status, description, 0); }