|
|
@ -239,6 +239,14 @@ static const char *op_id_string(enum e_op_id i) { |
|
|
|
return "UNKNOWN"; |
|
|
|
return "UNKNOWN"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void free_read_buffer(stream_obj *s) { |
|
|
|
|
|
|
|
if (s->state.rs.read_buffer && |
|
|
|
|
|
|
|
s->state.rs.read_buffer != s->state.rs.grpc_header_bytes) { |
|
|
|
|
|
|
|
gpr_free(s->state.rs.read_buffer); |
|
|
|
|
|
|
|
s->state.rs.read_buffer = NULL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
Add a new stream op to op storage. |
|
|
|
Add a new stream op to op storage. |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -341,6 +349,7 @@ static void on_failed(cronet_bidirectional_stream *stream, int net_error) { |
|
|
|
gpr_free(s->state.ws.write_buffer); |
|
|
|
gpr_free(s->state.ws.write_buffer); |
|
|
|
s->state.ws.write_buffer = NULL; |
|
|
|
s->state.ws.write_buffer = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
free_read_buffer(s); |
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
execute_from_storage(s); |
|
|
|
execute_from_storage(s); |
|
|
|
} |
|
|
|
} |
|
|
@ -363,6 +372,7 @@ static void on_canceled(cronet_bidirectional_stream *stream) { |
|
|
|
gpr_free(s->state.ws.write_buffer); |
|
|
|
gpr_free(s->state.ws.write_buffer); |
|
|
|
s->state.ws.write_buffer = NULL; |
|
|
|
s->state.ws.write_buffer = NULL; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
free_read_buffer(s); |
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
execute_from_storage(s); |
|
|
|
execute_from_storage(s); |
|
|
|
} |
|
|
|
} |
|
|
@ -377,6 +387,7 @@ static void on_succeeded(cronet_bidirectional_stream *stream) { |
|
|
|
cronet_bidirectional_stream_destroy(s->cbs); |
|
|
|
cronet_bidirectional_stream_destroy(s->cbs); |
|
|
|
s->state.state_callback_received[OP_SUCCEEDED] = true; |
|
|
|
s->state.state_callback_received[OP_SUCCEEDED] = true; |
|
|
|
s->cbs = NULL; |
|
|
|
s->cbs = NULL; |
|
|
|
|
|
|
|
free_read_buffer(s); |
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
gpr_mu_unlock(&s->mu); |
|
|
|
execute_from_storage(s); |
|
|
|
execute_from_storage(s); |
|
|
|
} |
|
|
|
} |
|
|
@ -531,7 +542,8 @@ static void create_grpc_frame(gpr_slice_buffer *write_slice_buffer, |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void convert_metadata_to_cronet_headers( |
|
|
|
static void convert_metadata_to_cronet_headers( |
|
|
|
grpc_linked_mdelem *head, const char *host, char **pp_url, |
|
|
|
grpc_linked_mdelem *head, const char *host, char **pp_url, |
|
|
|
cronet_bidirectional_stream_header **pp_headers, size_t *p_num_headers) { |
|
|
|
cronet_bidirectional_stream_header **pp_headers, size_t *p_num_headers, |
|
|
|
|
|
|
|
const char **method) { |
|
|
|
grpc_linked_mdelem *curr = head; |
|
|
|
grpc_linked_mdelem *curr = head; |
|
|
|
/* Walk the linked list and get number of header fields */ |
|
|
|
/* Walk the linked list and get number of header fields */ |
|
|
|
size_t num_headers_available = 0; |
|
|
|
size_t num_headers_available = 0; |
|
|
@ -558,11 +570,20 @@ static void convert_metadata_to_cronet_headers( |
|
|
|
curr = curr->next; |
|
|
|
curr = curr->next; |
|
|
|
const char *key = grpc_mdstr_as_c_string(mdelem->key); |
|
|
|
const char *key = grpc_mdstr_as_c_string(mdelem->key); |
|
|
|
const char *value = grpc_mdstr_as_c_string(mdelem->value); |
|
|
|
const char *value = grpc_mdstr_as_c_string(mdelem->value); |
|
|
|
if (mdelem->key == GRPC_MDSTR_METHOD || mdelem->key == GRPC_MDSTR_SCHEME || |
|
|
|
if (mdelem->key == GRPC_MDSTR_SCHEME || |
|
|
|
mdelem->key == GRPC_MDSTR_AUTHORITY) { |
|
|
|
mdelem->key == GRPC_MDSTR_AUTHORITY) { |
|
|
|
/* Cronet populates these fields on its own */ |
|
|
|
/* Cronet populates these fields on its own */ |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (mdelem->key == GRPC_MDSTR_METHOD) { |
|
|
|
|
|
|
|
if (mdelem->value == GRPC_MDSTR_PUT) { |
|
|
|
|
|
|
|
*method = "PUT"; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
/* POST method in default*/ |
|
|
|
|
|
|
|
*method = "POST"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
if (mdelem->key == GRPC_MDSTR_PATH) { |
|
|
|
if (mdelem->key == GRPC_MDSTR_PATH) { |
|
|
|
/* Create URL by appending :path value to the hostname */ |
|
|
|
/* Create URL by appending :path value to the hostname */ |
|
|
|
gpr_asprintf(pp_url, "https://%s%s", host, value); |
|
|
|
gpr_asprintf(pp_url, "https://%s%s", host, value); |
|
|
@ -759,15 +780,16 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, |
|
|
|
s->cbs = cronet_bidirectional_stream_create(s->curr_ct.engine, s->curr_gs, |
|
|
|
s->cbs = cronet_bidirectional_stream_create(s->curr_ct.engine, s->curr_gs, |
|
|
|
&cronet_callbacks); |
|
|
|
&cronet_callbacks); |
|
|
|
CRONET_LOG(GPR_DEBUG, "%p = cronet_bidirectional_stream_create()", s->cbs); |
|
|
|
CRONET_LOG(GPR_DEBUG, "%p = cronet_bidirectional_stream_create()", s->cbs); |
|
|
|
char *url; |
|
|
|
char *url = NULL; |
|
|
|
|
|
|
|
const char *method = "POST"; |
|
|
|
s->header_array.headers = NULL; |
|
|
|
s->header_array.headers = NULL; |
|
|
|
convert_metadata_to_cronet_headers( |
|
|
|
convert_metadata_to_cronet_headers( |
|
|
|
stream_op->send_initial_metadata->list.head, s->curr_ct.host, &url, |
|
|
|
stream_op->send_initial_metadata->list.head, s->curr_ct.host, &url, |
|
|
|
&s->header_array.headers, &s->header_array.count); |
|
|
|
&s->header_array.headers, &s->header_array.count, &method); |
|
|
|
s->header_array.capacity = s->header_array.count; |
|
|
|
s->header_array.capacity = s->header_array.count; |
|
|
|
CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_start(%p, %s)", s->cbs, |
|
|
|
CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_start(%p, %s)", s->cbs, |
|
|
|
url); |
|
|
|
url); |
|
|
|
cronet_bidirectional_stream_start(s->cbs, url, 0, "POST", &s->header_array, |
|
|
|
cronet_bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, |
|
|
|
false); |
|
|
|
false); |
|
|
|
stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; |
|
|
|
stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; |
|
|
|
result = ACTION_TAKEN_WITH_CALLBACK; |
|
|
|
result = ACTION_TAKEN_WITH_CALLBACK; |
|
|
@ -901,6 +923,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, |
|
|
|
uint8_t *dst_p = GPR_SLICE_START_PTR(read_data_slice); |
|
|
|
uint8_t *dst_p = GPR_SLICE_START_PTR(read_data_slice); |
|
|
|
memcpy(dst_p, stream_state->rs.read_buffer, |
|
|
|
memcpy(dst_p, stream_state->rs.read_buffer, |
|
|
|
(size_t)stream_state->rs.length_field); |
|
|
|
(size_t)stream_state->rs.length_field); |
|
|
|
|
|
|
|
free_read_buffer(s); |
|
|
|
gpr_slice_buffer_init(&stream_state->rs.read_slice_buffer); |
|
|
|
gpr_slice_buffer_init(&stream_state->rs.read_slice_buffer); |
|
|
|
gpr_slice_buffer_add(&stream_state->rs.read_slice_buffer, |
|
|
|
gpr_slice_buffer_add(&stream_state->rs.read_slice_buffer, |
|
|
|
read_data_slice); |
|
|
|
read_data_slice); |
|
|
|