aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/filters/client_channel/http_connect_handshaker.cc
diff options
context:
space:
mode:
authorGravatar Yash Tibrewal <yashkt@google.com>2017-12-06 09:05:05 -0800
committerGravatar GitHub <noreply@github.com>2017-12-06 09:05:05 -0800
commitad4d2dde0052efbbf49d64b0843c45f0381cfeb3 (patch)
tree6a657f8c6179d873b34505cdc24bce9462ca68eb /src/core/ext/filters/client_channel/http_connect_handshaker.cc
parenta3df36cc2505a89c2f481eea4a66a87b3002844a (diff)
Revert "All instances of exec_ctx being passed around in src/core removed"
Diffstat (limited to 'src/core/ext/filters/client_channel/http_connect_handshaker.cc')
-rw-r--r--src/core/ext/filters/client_channel/http_connect_handshaker.cc84
1 files changed, 48 insertions, 36 deletions
diff --git a/src/core/ext/filters/client_channel/http_connect_handshaker.cc b/src/core/ext/filters/client_channel/http_connect_handshaker.cc
index 556a3bc6a1..b7cb2e3eba 100644
--- a/src/core/ext/filters/client_channel/http_connect_handshaker.cc
+++ b/src/core/ext/filters/client_channel/http_connect_handshaker.cc
@@ -61,38 +61,41 @@ typedef struct http_connect_handshaker {
} http_connect_handshaker;
// Unref and clean up handshaker.
-static void http_connect_handshaker_unref(http_connect_handshaker* handshaker) {
+static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx,
+ http_connect_handshaker* handshaker) {
if (gpr_unref(&handshaker->refcount)) {
gpr_mu_destroy(&handshaker->mu);
if (handshaker->endpoint_to_destroy != nullptr) {
- grpc_endpoint_destroy(handshaker->endpoint_to_destroy);
+ grpc_endpoint_destroy(exec_ctx, handshaker->endpoint_to_destroy);
}
if (handshaker->read_buffer_to_destroy != nullptr) {
- grpc_slice_buffer_destroy_internal(handshaker->read_buffer_to_destroy);
+ grpc_slice_buffer_destroy_internal(exec_ctx,
+ handshaker->read_buffer_to_destroy);
gpr_free(handshaker->read_buffer_to_destroy);
}
- grpc_slice_buffer_destroy_internal(&handshaker->write_buffer);
+ grpc_slice_buffer_destroy_internal(exec_ctx, &handshaker->write_buffer);
grpc_http_parser_destroy(&handshaker->http_parser);
grpc_http_response_destroy(&handshaker->http_response);
gpr_free(handshaker);
}
}
-// Set args fields to nullptr, saving the endpoint and read buffer for
+// Set args fields to NULL, saving the endpoint and read buffer for
// later destruction.
static void cleanup_args_for_failure_locked(
- http_connect_handshaker* handshaker) {
+ grpc_exec_ctx* exec_ctx, http_connect_handshaker* handshaker) {
handshaker->endpoint_to_destroy = handshaker->args->endpoint;
handshaker->args->endpoint = nullptr;
handshaker->read_buffer_to_destroy = handshaker->args->read_buffer;
handshaker->args->read_buffer = nullptr;
- grpc_channel_args_destroy(handshaker->args->args);
+ grpc_channel_args_destroy(exec_ctx, handshaker->args->args);
handshaker->args->args = nullptr;
}
// If the handshake failed or we're shutting down, clean up and invoke the
// callback with the error.
-static void handshake_failed_locked(http_connect_handshaker* handshaker,
+static void handshake_failed_locked(grpc_exec_ctx* exec_ctx,
+ http_connect_handshaker* handshaker,
grpc_error* error) {
if (error == GRPC_ERROR_NONE) {
// If we were shut down after an endpoint operation succeeded but
@@ -105,32 +108,34 @@ static void handshake_failed_locked(http_connect_handshaker* handshaker,
// before destroying them, even if we know that there are no
// pending read/write callbacks. This should be fixed, at which
// point this can be removed.
- grpc_endpoint_shutdown(handshaker->args->endpoint, GRPC_ERROR_REF(error));
+ grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint,
+ GRPC_ERROR_REF(error));
// Not shutting down, so the handshake failed. Clean up before
// invoking the callback.
- cleanup_args_for_failure_locked(handshaker);
+ cleanup_args_for_failure_locked(exec_ctx, handshaker);
// Set shutdown to true so that subsequent calls to
// http_connect_handshaker_shutdown() do nothing.
handshaker->shutdown = true;
}
// Invoke callback.
- GRPC_CLOSURE_SCHED(handshaker->on_handshake_done, error);
+ GRPC_CLOSURE_SCHED(exec_ctx, handshaker->on_handshake_done, error);
}
// Callback invoked when finished writing HTTP CONNECT request.
-static void on_write_done(void* arg, grpc_error* error) {
+static void on_write_done(grpc_exec_ctx* exec_ctx, void* arg,
+ grpc_error* error) {
http_connect_handshaker* handshaker = (http_connect_handshaker*)arg;
gpr_mu_lock(&handshaker->mu);
if (error != GRPC_ERROR_NONE || handshaker->shutdown) {
// If the write failed or we're shutting down, clean up and invoke the
// callback with the error.
- handshake_failed_locked(handshaker, GRPC_ERROR_REF(error));
+ handshake_failed_locked(exec_ctx, handshaker, GRPC_ERROR_REF(error));
gpr_mu_unlock(&handshaker->mu);
- http_connect_handshaker_unref(handshaker);
+ http_connect_handshaker_unref(exec_ctx, handshaker);
} else {
// Otherwise, read the response.
// The read callback inherits our ref to the handshaker.
- grpc_endpoint_read(handshaker->args->endpoint,
+ grpc_endpoint_read(exec_ctx, handshaker->args->endpoint,
handshaker->args->read_buffer,
&handshaker->response_read_closure);
gpr_mu_unlock(&handshaker->mu);
@@ -138,13 +143,14 @@ static void on_write_done(void* arg, grpc_error* error) {
}
// Callback invoked for reading HTTP CONNECT response.
-static void on_read_done(void* arg, grpc_error* error) {
+static void on_read_done(grpc_exec_ctx* exec_ctx, void* arg,
+ grpc_error* error) {
http_connect_handshaker* handshaker = (http_connect_handshaker*)arg;
gpr_mu_lock(&handshaker->mu);
if (error != GRPC_ERROR_NONE || handshaker->shutdown) {
// If the read failed or we're shutting down, clean up and invoke the
// callback with the error.
- handshake_failed_locked(handshaker, GRPC_ERROR_REF(error));
+ handshake_failed_locked(exec_ctx, handshaker, GRPC_ERROR_REF(error));
goto done;
}
// Add buffer to parser.
@@ -155,7 +161,7 @@ static void on_read_done(void* arg, grpc_error* error) {
handshaker->args->read_buffer->slices[i],
&body_start_offset);
if (error != GRPC_ERROR_NONE) {
- handshake_failed_locked(handshaker, error);
+ handshake_failed_locked(exec_ctx, handshaker, error);
goto done;
}
if (handshaker->http_parser.state == GRPC_HTTP_BODY) {
@@ -174,7 +180,7 @@ static void on_read_done(void* arg, grpc_error* error) {
&handshaker->args->read_buffer->slices[i + 1],
handshaker->args->read_buffer->count - i - 1);
grpc_slice_buffer_swap(handshaker->args->read_buffer, &tmp_buffer);
- grpc_slice_buffer_destroy_internal(&tmp_buffer);
+ grpc_slice_buffer_destroy_internal(exec_ctx, &tmp_buffer);
break;
}
}
@@ -191,8 +197,9 @@ static void on_read_done(void* arg, grpc_error* error) {
// complete (e.g., handling chunked transfer encoding or looking
// at the Content-Length: header).
if (handshaker->http_parser.state != GRPC_HTTP_BODY) {
- grpc_slice_buffer_reset_and_unref_internal(handshaker->args->read_buffer);
- grpc_endpoint_read(handshaker->args->endpoint,
+ grpc_slice_buffer_reset_and_unref_internal(exec_ctx,
+ handshaker->args->read_buffer);
+ grpc_endpoint_read(exec_ctx, handshaker->args->endpoint,
handshaker->args->read_buffer,
&handshaker->response_read_closure);
gpr_mu_unlock(&handshaker->mu);
@@ -206,44 +213,48 @@ static void on_read_done(void* arg, grpc_error* error) {
handshaker->http_response.status);
error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
gpr_free(msg);
- handshake_failed_locked(handshaker, error);
+ handshake_failed_locked(exec_ctx, handshaker, error);
goto done;
}
// Success. Invoke handshake-done callback.
- GRPC_CLOSURE_SCHED(handshaker->on_handshake_done, error);
+ GRPC_CLOSURE_SCHED(exec_ctx, handshaker->on_handshake_done, error);
done:
// Set shutdown to true so that subsequent calls to
// http_connect_handshaker_shutdown() do nothing.
handshaker->shutdown = true;
gpr_mu_unlock(&handshaker->mu);
- http_connect_handshaker_unref(handshaker);
+ http_connect_handshaker_unref(exec_ctx, handshaker);
}
//
// Public handshaker methods
//
-static void http_connect_handshaker_destroy(grpc_handshaker* handshaker_in) {
+static void http_connect_handshaker_destroy(grpc_exec_ctx* exec_ctx,
+ grpc_handshaker* handshaker_in) {
http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in;
- http_connect_handshaker_unref(handshaker);
+ http_connect_handshaker_unref(exec_ctx, handshaker);
}
-static void http_connect_handshaker_shutdown(grpc_handshaker* handshaker_in,
+static void http_connect_handshaker_shutdown(grpc_exec_ctx* exec_ctx,
+ grpc_handshaker* handshaker_in,
grpc_error* why) {
http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in;
gpr_mu_lock(&handshaker->mu);
if (!handshaker->shutdown) {
handshaker->shutdown = true;
- grpc_endpoint_shutdown(handshaker->args->endpoint, GRPC_ERROR_REF(why));
- cleanup_args_for_failure_locked(handshaker);
+ grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint,
+ GRPC_ERROR_REF(why));
+ cleanup_args_for_failure_locked(exec_ctx, handshaker);
}
gpr_mu_unlock(&handshaker->mu);
GRPC_ERROR_UNREF(why);
}
static void http_connect_handshaker_do_handshake(
- grpc_handshaker* handshaker_in, grpc_tcp_server_acceptor* acceptor,
- grpc_closure* on_handshake_done, grpc_handshaker_args* args) {
+ grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker_in,
+ grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done,
+ grpc_handshaker_args* args) {
http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in;
// Check for HTTP CONNECT channel arg.
// If not found, invoke on_handshake_done without doing anything.
@@ -255,7 +266,7 @@ static void http_connect_handshaker_do_handshake(
gpr_mu_lock(&handshaker->mu);
handshaker->shutdown = true;
gpr_mu_unlock(&handshaker->mu);
- GRPC_CLOSURE_SCHED(on_handshake_done, GRPC_ERROR_NONE);
+ GRPC_CLOSURE_SCHED(exec_ctx, on_handshake_done, GRPC_ERROR_NONE);
return;
}
GPR_ASSERT(arg->type == GRPC_ARG_STRING);
@@ -313,7 +324,7 @@ static void http_connect_handshaker_do_handshake(
gpr_free(header_strings);
// Take a new ref to be held by the write callback.
gpr_ref(&handshaker->refcount);
- grpc_endpoint_write(args->endpoint, &handshaker->write_buffer,
+ grpc_endpoint_write(exec_ctx, args->endpoint, &handshaker->write_buffer,
&handshaker->request_done_closure);
gpr_mu_unlock(&handshaker->mu);
}
@@ -344,13 +355,14 @@ static grpc_handshaker* grpc_http_connect_handshaker_create() {
//
static void handshaker_factory_add_handshakers(
- grpc_handshaker_factory* factory, const grpc_channel_args* args,
- grpc_handshake_manager* handshake_mgr) {
+ grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* factory,
+ const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) {
grpc_handshake_manager_add(handshake_mgr,
grpc_http_connect_handshaker_create());
}
-static void handshaker_factory_destroy(grpc_handshaker_factory* factory) {}
+static void handshaker_factory_destroy(grpc_exec_ctx* exec_ctx,
+ grpc_handshaker_factory* factory) {}
static const grpc_handshaker_factory_vtable handshaker_factory_vtable = {
handshaker_factory_add_handshakers, handshaker_factory_destroy};