Skip to content

Commit

Permalink
mobile: Move some InternalEngine implementation from .h to .cc (envoy…
Browse files Browse the repository at this point in the history
…proxy#33195)

Risk Level: low
Testing: n/a
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: Fredy Wijaya <[email protected]>
  • Loading branch information
fredyw authored Mar 28, 2024
1 parent 2b49300 commit 87d34c4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
38 changes: 36 additions & 2 deletions mobile/library/common/internal_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace Envoy {

static std::atomic<envoy_stream_t> current_stream_handle_{0};

envoy_stream_t InternalEngine::initStream() { return current_stream_handle_++; }

InternalEngine::InternalEngine(std::unique_ptr<EngineCallbacks> callbacks,
std::unique_ptr<EnvoyLogger> logger,
std::unique_ptr<EnvoyEventTracker> event_tracker,
Expand Down Expand Up @@ -47,6 +45,42 @@ envoy_status_t InternalEngine::run(const std::string& config, const std::string&
return run(std::move(options));
}

envoy_stream_t InternalEngine::initStream() { return current_stream_handle_++; }

envoy_status_t InternalEngine::startStream(envoy_stream_t stream,
envoy_http_callbacks bridge_callbacks,
bool explicit_flow_control) {
return dispatcher_->post([&, stream, bridge_callbacks, explicit_flow_control]() {
http_client_->startStream(stream, bridge_callbacks, explicit_flow_control);
});
}

envoy_status_t InternalEngine::sendHeaders(envoy_stream_t stream, envoy_headers headers,
bool end_stream) {
return dispatcher_->post([&, stream, headers, end_stream]() {
http_client_->sendHeaders(stream, headers, end_stream);
});
}

envoy_status_t InternalEngine::readData(envoy_stream_t stream, size_t bytes_to_read) {
return dispatcher_->post(
[&, stream, bytes_to_read]() { http_client_->readData(stream, bytes_to_read); });
}

envoy_status_t InternalEngine::sendData(envoy_stream_t stream, envoy_data data, bool end_stream) {
return dispatcher_->post(
[&, stream, data, end_stream]() { http_client_->sendData(stream, data, end_stream); });
}

envoy_status_t InternalEngine::sendTrailers(envoy_stream_t stream, envoy_headers trailers) {
return dispatcher_->post(
[&, stream, trailers]() { http_client_->sendTrailers(stream, trailers); });
}

envoy_status_t InternalEngine::cancelStream(envoy_stream_t stream) {
return dispatcher_->post([&, stream]() { http_client_->cancelStream(stream); });
}

// This function takes a `std::shared_ptr` instead of `std::unique_ptr` because `std::function` is a
// copy-constructible type, so it's not possible to move capture `std::unique_ptr` with
// `std::function`.
Expand Down
36 changes: 10 additions & 26 deletions mobile/library/common/internal_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,16 @@ class InternalEngine : public Logger::Loggable<Logger::Id::main> {
// to http client functions of the same name after doing a dispatcher post
// (thread context switch)
envoy_status_t startStream(envoy_stream_t stream, envoy_http_callbacks bridge_callbacks,
bool explicit_flow_control) {
return dispatcher_->post([&, stream, bridge_callbacks, explicit_flow_control]() {
http_client_->startStream(stream, bridge_callbacks, explicit_flow_control);
});
}
envoy_status_t sendHeaders(envoy_stream_t stream, envoy_headers headers, bool end_stream) {
return dispatcher_->post([&, stream, headers, end_stream]() {
http_client_->sendHeaders(stream, headers, end_stream);
});
}
envoy_status_t readData(envoy_stream_t stream, size_t bytes_to_read) {
return dispatcher_->post(
[&, stream, bytes_to_read]() { http_client_->readData(stream, bytes_to_read); });
}
envoy_status_t sendData(envoy_stream_t stream, envoy_data data, bool end_stream) {
return dispatcher_->post(
[&, stream, data, end_stream]() { http_client_->sendData(stream, data, end_stream); });
}
envoy_status_t sendTrailers(envoy_stream_t stream, envoy_headers trailers) {
return dispatcher_->post(
[&, stream, trailers]() { http_client_->sendTrailers(stream, trailers); });
}

envoy_status_t cancelStream(envoy_stream_t stream) {
return dispatcher_->post([&, stream]() { http_client_->cancelStream(stream); });
}
bool explicit_flow_control);
envoy_status_t sendHeaders(envoy_stream_t stream, envoy_headers headers, bool end_stream);

envoy_status_t readData(envoy_stream_t stream, size_t bytes_to_read);

envoy_status_t sendData(envoy_stream_t stream, envoy_data data, bool end_stream);

envoy_status_t sendTrailers(envoy_stream_t stream, envoy_headers trailers);

envoy_status_t cancelStream(envoy_stream_t stream);

// These functions are wrappers around networkConnectivityManager functions, which hand off
// to networkConnectivityManager after doing a dispatcher post (thread context switch)
Expand Down

0 comments on commit 87d34c4

Please sign in to comment.