mirror of https://github.com/grpc/grpc.git
Delete the EventEngine-driven iomgr implementation (#29654)
This code is not compiled by default and has fallen out of sync with the rest of the codebase. There's a good chance it won't be used, given our current work to use an iomgr-drive EventEngine instead. This code will continue to live in git history, should we need to bring pieces of it back.pull/29743/merge
parent
944c0b2ce9
commit
1df32ca680
38 changed files with 5 additions and 1670 deletions
@ -1,31 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/iomgr/port.h" // IWYU pragma: keep |
||||
#if GRPC_ARES == 1 && defined(GRPC_USE_EVENT_ENGINE) |
||||
|
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h" |
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
std::unique_ptr<GrpcPolledFdFactory> NewGrpcPolledFdFactory( |
||||
std::shared_ptr<WorkSerializer> /* work_serializer */) { |
||||
return nullptr; |
||||
} |
||||
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif /* GRPC_ARES == 1 && defined(GRPC_USE_EVENT_ENGINE) */ |
@ -1,29 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/iomgr/port.h" // IWYU pragma: keep |
||||
|
||||
#if GRPC_ARES == 1 && defined(GRPC_USE_EVENT_ENGINE) |
||||
|
||||
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" |
||||
|
||||
bool grpc_ares_query_ipv6() { |
||||
/* The libuv grpc code currently does not have the code to probe for this,
|
||||
* so we assume for now that IPv6 is always available in contexts where this |
||||
* code will be used. */ |
||||
return true; |
||||
} |
||||
|
||||
#endif /* GRPC_ARES == 1 && defined(GRPC_USE_EVENT_ENGINE) */ |
@ -1,40 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <string.h> |
||||
|
||||
#include <grpc/event_engine/event_engine.h> |
||||
#include <grpc/event_engine/port.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
uint16_t grpc_htons(uint16_t hostshort) { return htons(hostshort); } |
||||
|
||||
uint16_t grpc_ntohs(uint16_t netshort) { return ntohs(netshort); } |
||||
|
||||
uint32_t grpc_htonl(uint32_t hostlong) { return htonl(hostlong); } |
||||
|
||||
uint32_t grpc_ntohl(uint32_t netlong) { return ntohl(netlong); } |
||||
|
||||
int grpc_inet_pton(int af, const char* src, void* dst) { |
||||
return inet_pton(af, src, dst); |
||||
} |
||||
|
||||
const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { |
||||
inet_ntop(af, src, dst, size); |
||||
return dst; |
||||
} |
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
@ -1,44 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef GRPC_CORE_LIB_EVENT_ENGINE_SOCKADDR_H |
||||
#define GRPC_CORE_LIB_EVENT_ENGINE_SOCKADDR_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <grpc/event_engine/port.h> |
||||
|
||||
#include "src/core/lib/iomgr/port.h" |
||||
|
||||
typedef struct sockaddr grpc_sockaddr; |
||||
typedef struct sockaddr_in grpc_sockaddr_in; |
||||
typedef struct sockaddr_in6 grpc_sockaddr_in6; |
||||
typedef struct in_addr grpc_in_addr; |
||||
typedef struct in6_addr grpc_in6_addr; |
||||
|
||||
#define GRPC_INET_ADDRSTRLEN INET_ADDRSTRLEN |
||||
#define GRPC_INET6_ADDRSTRLEN INET6_ADDRSTRLEN |
||||
|
||||
#define GRPC_SOCK_STREAM SOCK_STREAM |
||||
#define GRPC_SOCK_DGRAM SOCK_DGRAM |
||||
|
||||
#define GRPC_AF_UNSPEC AF_UNSPEC |
||||
#define GRPC_AF_UNIX AF_UNIX |
||||
#define GRPC_AF_INET AF_INET |
||||
#define GRPC_AF_INET6 AF_INET6 |
||||
|
||||
#define GRPC_AI_PASSIVE AI_PASSIVE |
||||
|
||||
#endif |
||||
#endif // GRPC_CORE_LIB_EVENT_ENGINE_SOCKADDR_H
|
@ -1,32 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <stdlib.h> |
||||
|
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/lib/iomgr/endpoint_pair.h" |
||||
#include "src/core/lib/iomgr/port.h" |
||||
|
||||
grpc_endpoint_pair grpc_iomgr_create_endpoint_pair( |
||||
const char* /* name */, grpc_channel_args* /* args */) { |
||||
// TODO(hork): determine what's needed here in the long run
|
||||
GPR_ASSERT( |
||||
false && |
||||
"grpc_iomgr_create_endpoint_pair is not suppoted with event_engine"); |
||||
} |
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
@ -1,77 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/iomgr/closure.h" |
||||
#include "src/core/lib/iomgr/event_engine/closure.h" |
||||
#include "src/core/lib/iomgr/event_engine/pollset.h" |
||||
#include "src/core/lib/transport/error_utils.h" |
||||
|
||||
namespace grpc_event_engine { |
||||
namespace experimental { |
||||
|
||||
namespace { |
||||
|
||||
void RunClosure(grpc_closure* closure, grpc_error_handle error) { |
||||
GPR_ASSERT(closure != nullptr); |
||||
#ifndef NDEBUG |
||||
closure->scheduled = false; |
||||
if (grpc_trace_closure.enabled()) { |
||||
gpr_log(GPR_DEBUG, |
||||
"EventEngine: running closure %p: created [%s:%d]: %s [%s:%d]", |
||||
closure, closure->file_created, closure->line_created, |
||||
closure->run ? "run" : "scheduled", closure->file_initiated, |
||||
closure->line_initiated); |
||||
} |
||||
#endif |
||||
closure->cb(closure->cb_arg, error); |
||||
#ifndef NDEBUG |
||||
if (grpc_trace_closure.enabled()) { |
||||
gpr_log(GPR_DEBUG, "EventEngine: closure %p finished", closure); |
||||
} |
||||
#endif |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
std::function<void(absl::Status)> GrpcClosureToStatusCallback( |
||||
grpc_closure* closure) { |
||||
return [closure](absl::Status status) { |
||||
RunClosure(closure, absl_status_to_grpc_error(status)); |
||||
grpc_pollset_ee_broadcast_event(); |
||||
}; |
||||
} |
||||
|
||||
std::function<void()> GrpcClosureToCallback(grpc_closure* closure) { |
||||
return [closure]() { |
||||
RunClosure(closure, GRPC_ERROR_NONE); |
||||
grpc_pollset_ee_broadcast_event(); |
||||
}; |
||||
} |
||||
|
||||
std::function<void()> GrpcClosureToCallback(grpc_closure* closure, |
||||
grpc_error_handle error) { |
||||
return [closure, error]() { |
||||
RunClosure(closure, error); |
||||
grpc_pollset_ee_broadcast_event(); |
||||
}; |
||||
} |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc_event_engine
|
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
@ -1,42 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_CLOSURE_H |
||||
#define GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_CLOSURE_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/iomgr/closure.h" |
||||
#include "src/core/lib/iomgr/error.h" |
||||
|
||||
namespace grpc_event_engine { |
||||
namespace experimental { |
||||
|
||||
/// Creates a callback that takes an error status argument.
|
||||
std::function<void(absl::Status)> GrpcClosureToStatusCallback( |
||||
grpc_closure* closure); |
||||
|
||||
/// Create a callback that *does not* take an error status argument.
|
||||
std::function<void()> GrpcClosureToCallback(grpc_closure* closure); |
||||
|
||||
/// Creates a callback that *does not* take an error status argument.
|
||||
/// This version has a pre-bound error.
|
||||
std::function<void()> GrpcClosureToCallback(grpc_closure* closure, |
||||
grpc_error_handle error); |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc_event_engine
|
||||
|
||||
#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_CLOSURE_H
|
@ -1,173 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include "absl/strings/string_view.h" |
||||
|
||||
#include <grpc/event_engine/event_engine.h> |
||||
#include <grpc/slice.h> |
||||
#include <grpc/slice_buffer.h> |
||||
#include <grpc/support/time.h> |
||||
|
||||
#include "src/core/lib/address_utils/sockaddr_utils.h" |
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/iomgr/endpoint.h" |
||||
#include "src/core/lib/iomgr/error.h" |
||||
#include "src/core/lib/iomgr/event_engine/closure.h" |
||||
#include "src/core/lib/iomgr/event_engine/endpoint.h" |
||||
#include "src/core/lib/iomgr/event_engine/pollset.h" |
||||
#include "src/core/lib/iomgr/pollset.h" |
||||
#include "src/core/lib/iomgr/pollset_set.h" |
||||
#include "src/core/lib/iomgr/resource_quota.h" |
||||
#include "src/core/lib/transport/error_utils.h" |
||||
|
||||
extern grpc_core::TraceFlag grpc_tcp_trace; |
||||
|
||||
namespace { |
||||
|
||||
using ::grpc_event_engine::experimental::EventEngine; |
||||
using ::grpc_event_engine::experimental::ResolvedAddressToURI; |
||||
using ::grpc_event_engine::experimental::SliceBuffer; |
||||
|
||||
void endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices, |
||||
grpc_closure* cb, bool /* urgent */, |
||||
int /* min_progress_size */) { |
||||
auto* eeep = reinterpret_cast<grpc_event_engine_endpoint*>(ep); |
||||
if (eeep->endpoint == nullptr) { |
||||
grpc_core::ExecCtx::Run(DEBUG_LOCATION, cb, GRPC_ERROR_CANCELLED); |
||||
return; |
||||
} |
||||
SliceBuffer* read_buffer = new (&eeep->read_buffer) SliceBuffer(slices); |
||||
eeep->endpoint->Read( |
||||
[eeep, cb](absl::Status status) { |
||||
auto* read_buffer = reinterpret_cast<SliceBuffer*>(&eeep->read_buffer); |
||||
read_buffer->~SliceBuffer(); |
||||
grpc_core::ExecCtx exec_ctx; |
||||
grpc_core::Closure::Run(DEBUG_LOCATION, cb, |
||||
absl_status_to_grpc_error(status)); |
||||
exec_ctx.Flush(); |
||||
grpc_pollset_ee_broadcast_event(); |
||||
}, |
||||
read_buffer); |
||||
} |
||||
|
||||
void endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices, |
||||
grpc_closure* cb, void* arg, int /*max_frame_size*/) { |
||||
// TODO(hork): adapt arg to some metrics collection mechanism.
|
||||
(void)arg; |
||||
auto* eeep = reinterpret_cast<grpc_event_engine_endpoint*>(ep); |
||||
if (eeep->endpoint == nullptr) { |
||||
grpc_core::ExecCtx::Run(DEBUG_LOCATION, cb, GRPC_ERROR_CANCELLED); |
||||
return; |
||||
} |
||||
SliceBuffer* write_buffer = new (&eeep->write_buffer) SliceBuffer(slices); |
||||
eeep->endpoint->Write( |
||||
[eeep, cb](absl::Status status) { |
||||
auto* write_buffer = |
||||
reinterpret_cast<SliceBuffer*>(&eeep->write_buffer); |
||||
write_buffer->~SliceBuffer(); |
||||
grpc_core::ExecCtx exec_ctx; |
||||
grpc_core::Closure::Run(DEBUG_LOCATION, cb, |
||||
absl_status_to_grpc_error(status)); |
||||
exec_ctx.Flush(); |
||||
grpc_pollset_ee_broadcast_event(); |
||||
}, |
||||
write_buffer); |
||||
} |
||||
void endpoint_add_to_pollset(grpc_endpoint* /* ep */, |
||||
grpc_pollset* /* pollset */) {} |
||||
void endpoint_add_to_pollset_set(grpc_endpoint* /* ep */, |
||||
grpc_pollset_set* /* pollset */) {} |
||||
void endpoint_delete_from_pollset_set(grpc_endpoint* /* ep */, |
||||
grpc_pollset_set* /* pollset */) {} |
||||
/// After shutdown, all endpoint operations except destroy are no-op,
|
||||
/// and will return some kind of sane default (empty strings, nullptrs, etc). It
|
||||
/// is the caller's responsibility to ensure that calls to endpoint_shutdown are
|
||||
/// synchronized.
|
||||
void endpoint_shutdown(grpc_endpoint* ep, grpc_error_handle why) { |
||||
auto* eeep = reinterpret_cast<grpc_event_engine_endpoint*>(ep); |
||||
if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { |
||||
std::string str = grpc_error_std_string(why); |
||||
gpr_log(GPR_INFO, "TCP Endpoint %p shutdown why=%s", eeep->endpoint.get(), |
||||
str.c_str()); |
||||
} |
||||
eeep->endpoint.reset(); |
||||
} |
||||
|
||||
void endpoint_destroy(grpc_endpoint* ep) { |
||||
auto* eeep = reinterpret_cast<grpc_event_engine_endpoint*>(ep); |
||||
delete eeep; |
||||
} |
||||
|
||||
absl::string_view endpoint_get_peer(grpc_endpoint* ep) { |
||||
auto* eeep = reinterpret_cast<grpc_event_engine_endpoint*>(ep); |
||||
if (eeep->endpoint == nullptr) { |
||||
return ""; |
||||
} |
||||
if (eeep->peer_address.empty()) { |
||||
const EventEngine::ResolvedAddress& addr = eeep->endpoint->GetPeerAddress(); |
||||
eeep->peer_address = ResolvedAddressToURI(addr).value(); |
||||
} |
||||
return eeep->peer_address; |
||||
} |
||||
|
||||
absl::string_view endpoint_get_local_address(grpc_endpoint* ep) { |
||||
auto* eeep = reinterpret_cast<grpc_event_engine_endpoint*>(ep); |
||||
if (eeep->endpoint == nullptr) { |
||||
return ""; |
||||
} |
||||
if (eeep->local_address.empty()) { |
||||
const EventEngine::ResolvedAddress& addr = |
||||
eeep->endpoint->GetLocalAddress(); |
||||
eeep->local_address = ResolvedAddressToURI(addr).value(); |
||||
} |
||||
return eeep->local_address; |
||||
} |
||||
|
||||
int endpoint_get_fd(grpc_endpoint* /* ep */) { return -1; } |
||||
|
||||
bool endpoint_can_track_err(grpc_endpoint* /* ep */) { return false; } |
||||
|
||||
grpc_endpoint_vtable grpc_event_engine_endpoint_vtable = { |
||||
endpoint_read, |
||||
endpoint_write, |
||||
endpoint_add_to_pollset, |
||||
endpoint_add_to_pollset_set, |
||||
endpoint_delete_from_pollset_set, |
||||
endpoint_shutdown, |
||||
endpoint_destroy, |
||||
endpoint_get_peer, |
||||
endpoint_get_local_address, |
||||
endpoint_get_fd, |
||||
endpoint_can_track_err}; |
||||
|
||||
} // namespace
|
||||
|
||||
grpc_event_engine_endpoint* grpc_tcp_server_endpoint_create( |
||||
std::unique_ptr<EventEngine::Endpoint> ee_endpoint) { |
||||
auto endpoint = new grpc_event_engine_endpoint; |
||||
endpoint->base.vtable = &grpc_event_engine_endpoint_vtable; |
||||
endpoint->endpoint = std::move(ee_endpoint); |
||||
return endpoint; |
||||
} |
||||
|
||||
grpc_endpoint* grpc_tcp_create(const grpc_channel_args* /* channel_args */, |
||||
absl::string_view /* peer_address */) { |
||||
auto endpoint = new grpc_event_engine_endpoint; |
||||
endpoint->base.vtable = &grpc_event_engine_endpoint_vtable; |
||||
return &endpoint->base; |
||||
} |
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
@ -1,52 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_ENDPOINT_H |
||||
#define GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_ENDPOINT_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/iomgr/endpoint.h" |
||||
#include "src/core/lib/iomgr/resource_quota.h" |
||||
|
||||
struct grpc_event_engine_endpoint { |
||||
grpc_endpoint base; |
||||
std::unique_ptr<grpc_event_engine::experimental::EventEngine::Endpoint> |
||||
endpoint; |
||||
std::string peer_address; |
||||
std::string local_address; |
||||
std::aligned_storage< |
||||
sizeof(grpc_event_engine::experimental::SliceBuffer), |
||||
alignof(grpc_event_engine::experimental::SliceBuffer)>::type read_buffer; |
||||
std::aligned_storage< |
||||
sizeof(grpc_event_engine::experimental::SliceBuffer), |
||||
alignof(grpc_event_engine::experimental::SliceBuffer)>::type write_buffer; |
||||
}; |
||||
|
||||
/// Creates an internal grpc_endpoint struct from an EventEngine Endpoint.
|
||||
/// Server code needs to create grpc_endpoints after the EventEngine has made
|
||||
/// connections.
|
||||
grpc_event_engine_endpoint* grpc_tcp_server_endpoint_create( |
||||
std::unique_ptr<grpc_event_engine::experimental::EventEngine::Endpoint> ee); |
||||
|
||||
/// Creates a new internal grpc_endpoint struct, when no EventEngine Endpoint
|
||||
/// has yet been created. This is used in client code before connections are
|
||||
/// established. Takes ownership of the slice_allocator.
|
||||
grpc_endpoint* grpc_tcp_create(const grpc_channel_args* channel_args, |
||||
absl::string_view peer_address); |
||||
|
||||
#endif |
||||
#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_ENDPOINT_H
|
@ -1,85 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/debug/trace.h" |
||||
#include "src/core/lib/iomgr/closure.h" |
||||
#include "src/core/lib/iomgr/event_engine/resolver.h" |
||||
#include "src/core/lib/iomgr/iomgr_internal.h" |
||||
#include "src/core/lib/iomgr/tcp_client.h" |
||||
#include "src/core/lib/iomgr/tcp_server.h" |
||||
#include "src/core/lib/iomgr/timer.h" |
||||
#include "src/core/lib/surface/init.h" |
||||
|
||||
extern grpc_tcp_client_vtable grpc_event_engine_tcp_client_vtable; |
||||
extern grpc_tcp_server_vtable grpc_event_engine_tcp_server_vtable; |
||||
extern grpc_timer_vtable grpc_event_engine_timer_vtable; |
||||
extern grpc_pollset_vtable grpc_event_engine_pollset_vtable; |
||||
extern grpc_pollset_set_vtable grpc_event_engine_pollset_set_vtable; |
||||
|
||||
// Disabled by default. grpc_polling_trace must be defined in all iomgr
|
||||
// implementations due to its usage in lockfree_event.
|
||||
grpc_core::DebugOnlyTraceFlag grpc_polling_trace(false, "polling"); |
||||
|
||||
namespace { |
||||
|
||||
using ::grpc_event_engine::experimental::EventEngine; |
||||
using ::grpc_event_engine::experimental::GetDefaultEventEngine; |
||||
|
||||
// TODO(nnoble): Instantiate the default EventEngine if none have been provided.
|
||||
void iomgr_platform_init(void) {} |
||||
|
||||
void iomgr_platform_flush(void) {} |
||||
|
||||
void iomgr_platform_shutdown(void) {} |
||||
|
||||
void iomgr_platform_shutdown_background_closure(void) {} |
||||
|
||||
bool iomgr_platform_is_any_background_poller_thread(void) { |
||||
return grpc_event_engine::experimental::GetDefaultEventEngine() |
||||
->IsWorkerThread(); |
||||
} |
||||
|
||||
bool iomgr_platform_add_closure_to_background_poller( |
||||
grpc_closure* /* closure */, grpc_error_handle /* error */) { |
||||
return false; |
||||
} |
||||
|
||||
grpc_iomgr_platform_vtable vtable = { |
||||
iomgr_platform_init, |
||||
iomgr_platform_flush, |
||||
iomgr_platform_shutdown, |
||||
iomgr_platform_shutdown_background_closure, |
||||
iomgr_platform_is_any_background_poller_thread, |
||||
iomgr_platform_add_closure_to_background_poller}; |
||||
|
||||
} // namespace
|
||||
|
||||
void grpc_set_default_iomgr_platform() { |
||||
grpc_set_tcp_client_impl(&grpc_event_engine_tcp_client_vtable); |
||||
grpc_set_tcp_server_impl(&grpc_event_engine_tcp_server_vtable); |
||||
grpc_set_timer_impl(&grpc_event_engine_timer_vtable); |
||||
grpc_set_pollset_vtable(&grpc_event_engine_pollset_vtable); |
||||
grpc_set_pollset_set_vtable(&grpc_event_engine_pollset_set_vtable); |
||||
grpc_core::SetDNSResolver( |
||||
grpc_core::experimental::EventEngineDNSResolver::GetOrCreate()); |
||||
grpc_set_iomgr_platform_vtable(&vtable); |
||||
} |
||||
|
||||
bool grpc_iomgr_run_in_background() { return false; } |
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
@ -1,87 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/iomgr/event_engine/pollset.h" |
||||
#include "src/core/lib/iomgr/iomgr_internal.h" |
||||
#include "src/core/lib/iomgr/pollset.h" |
||||
#include "src/core/lib/iomgr/pollset_set.h" |
||||
|
||||
namespace { |
||||
|
||||
static gpr_mu g_mu; |
||||
static gpr_cv g_cv; |
||||
|
||||
// --- pollset vtable API ---
|
||||
void pollset_global_init(void) { |
||||
gpr_mu_init(&g_mu); |
||||
gpr_cv_init(&g_cv); |
||||
} |
||||
void pollset_global_shutdown(void) { |
||||
gpr_cv_destroy(&g_cv); |
||||
gpr_mu_destroy(&g_mu); |
||||
} |
||||
void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { *mu = &g_mu; } |
||||
void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { |
||||
grpc_core::ExecCtx::Run(DEBUG_LOCATION, closure, GRPC_ERROR_NONE); |
||||
} |
||||
void pollset_destroy(grpc_pollset* pollset) {} |
||||
grpc_error_handle pollset_work(grpc_pollset* pollset, |
||||
grpc_pollset_worker** worker, |
||||
grpc_core::Timestamp deadline) { |
||||
(void)worker; |
||||
gpr_cv_wait(&g_cv, &g_mu, deadline.as_timespec(GPR_CLOCK_REALTIME)); |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
grpc_error_handle pollset_kick(grpc_pollset* pollset, |
||||
grpc_pollset_worker* specific_worker) { |
||||
(void)pollset; |
||||
(void)specific_worker; |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
size_t pollset_size(void) { return 1; } |
||||
|
||||
// --- pollset_set vtable API ---
|
||||
grpc_pollset_set* pollset_set_create(void) { return nullptr; } |
||||
void pollset_set_destroy(grpc_pollset_set* pollset_set) {} |
||||
void pollset_set_add_pollset(grpc_pollset_set* pollset_set, |
||||
grpc_pollset* pollset) {} |
||||
|
||||
void pollset_set_del_pollset(grpc_pollset_set* pollset_set, |
||||
grpc_pollset* pollset) {} |
||||
void pollset_set_add_pollset_set(grpc_pollset_set* bag, |
||||
grpc_pollset_set* item) {} |
||||
void pollset_set_del_pollset_set(grpc_pollset_set* bag, |
||||
grpc_pollset_set* item) {} |
||||
|
||||
} // namespace
|
||||
|
||||
void grpc_pollset_ee_broadcast_event() { gpr_cv_signal(&g_cv); } |
||||
|
||||
// --- vtables ---
|
||||
grpc_pollset_vtable grpc_event_engine_pollset_vtable = { |
||||
pollset_global_init, pollset_global_shutdown, |
||||
pollset_init, pollset_shutdown, |
||||
pollset_destroy, pollset_work, |
||||
pollset_kick, pollset_size}; |
||||
|
||||
grpc_pollset_set_vtable grpc_event_engine_pollset_set_vtable = { |
||||
pollset_set_create, pollset_set_destroy, |
||||
pollset_set_add_pollset, pollset_set_del_pollset, |
||||
pollset_set_add_pollset_set, pollset_set_del_pollset_set}; |
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
@ -1,25 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_POLLSET_H |
||||
#define GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_POLLSET_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
|
||||
/// Signals pollset_work that some work has been done.
|
||||
void grpc_pollset_ee_broadcast_event(); |
||||
|
||||
#endif |
||||
#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_POLLSET_H
|
@ -1,51 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_PROMISE_H |
||||
#define GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_PROMISE_H |
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/gprpp/sync.h" |
||||
|
||||
namespace grpc_event_engine { |
||||
namespace experimental { |
||||
|
||||
/// A minimal promise implementation.
|
||||
///
|
||||
/// This is light-duty, syntactical sugar around cv wait & signal, which is
|
||||
/// useful in some cases. A more robust implementation is being worked on
|
||||
/// separately.
|
||||
template <typename T> |
||||
class Promise { |
||||
public: |
||||
T& Get() { |
||||
grpc_core::MutexLock lock(&mu_); |
||||
cv_.Wait(&mu_); |
||||
return val_; |
||||
} |
||||
void Set(T&& val) { |
||||
grpc_core::MutexLock lock(&mu_); |
||||
val_ = std::move(val); |
||||
cv_.Signal(); |
||||
} |
||||
|
||||
private: |
||||
grpc_core::Mutex mu_; |
||||
grpc_core::CondVar cv_; |
||||
T val_; |
||||
}; |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc_event_engine
|
||||
|
||||
#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_PROMISE_H
|
@ -1,48 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/iomgr/event_engine/resolved_address_internal.h" |
||||
|
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/address_utils/sockaddr_utils.h" |
||||
#include "src/core/lib/iomgr/resolve_address.h" |
||||
|
||||
namespace grpc_event_engine { |
||||
namespace experimental { |
||||
|
||||
EventEngine::ResolvedAddress CreateResolvedAddress( |
||||
const grpc_resolved_address& addr) { |
||||
return EventEngine::ResolvedAddress( |
||||
reinterpret_cast<const sockaddr*>(addr.addr), addr.len); |
||||
} |
||||
|
||||
grpc_resolved_address CreateGRPCResolvedAddress( |
||||
const EventEngine::ResolvedAddress& ra) { |
||||
grpc_resolved_address grpc_addr; |
||||
memcpy(grpc_addr.addr, ra.address(), ra.size()); |
||||
grpc_addr.len = ra.size(); |
||||
return grpc_addr; |
||||
} |
||||
|
||||
// TODO(ctiller): Move this to somewhere more permanent as we're deleting iomgr.
|
||||
absl::StatusOr<std::string> ResolvedAddressToURI( |
||||
const EventEngine::ResolvedAddress& addr) { |
||||
auto gra = CreateGRPCResolvedAddress(addr); |
||||
return grpc_sockaddr_to_uri(&gra); |
||||
} |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc_event_engine
|
@ -1,38 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#ifndef GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_RESOLVED_ADDRESS_INTERNAL_H |
||||
#define GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_RESOLVED_ADDRESS_INTERNAL_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/iomgr/resolve_address.h" |
||||
|
||||
namespace grpc_event_engine { |
||||
namespace experimental { |
||||
|
||||
EventEngine::ResolvedAddress CreateResolvedAddress( |
||||
const grpc_resolved_address& addr); |
||||
|
||||
grpc_resolved_address CreateGRPCResolvedAddress( |
||||
const EventEngine::ResolvedAddress& ra); |
||||
|
||||
absl::StatusOr<std::string> ResolvedAddressToURI( |
||||
const EventEngine::ResolvedAddress& addr); |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc_event_engine
|
||||
|
||||
#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_RESOLVED_ADDRESS_INTERNAL_H
|
@ -1,133 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include "absl/functional/bind_front.h" |
||||
|
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/address_utils/sockaddr_utils.h" |
||||
#include "src/core/lib/event_engine/event_engine_factory.h" |
||||
#include "src/core/lib/gprpp/sync.h" |
||||
#include "src/core/lib/iomgr/error.h" |
||||
#include "src/core/lib/iomgr/event_engine/promise.h" |
||||
#include "src/core/lib/iomgr/event_engine/resolved_address_internal.h" |
||||
#include "src/core/lib/iomgr/event_engine/resolver.h" |
||||
#include "src/core/lib/iomgr/resolve_address.h" |
||||
#include "src/core/lib/iomgr/resolve_address_impl.h" |
||||
#include "src/core/lib/iomgr/work_serializer.h" |
||||
#include "src/core/lib/surface/init.h" |
||||
#include "src/core/lib/transport/error_utils.h" |
||||
|
||||
namespace grpc_core { |
||||
namespace experimental { |
||||
namespace { |
||||
using ::grpc_event_engine::experimental::CreateGRPCResolvedAddress; |
||||
using ::grpc_event_engine::experimental::EventEngine; |
||||
using ::grpc_event_engine::experimental::GetDefaultEventEngine; |
||||
using ::grpc_event_engine::experimental::Promise; |
||||
|
||||
/// A fire-and-forget class representing an individual DNS request.
|
||||
///
|
||||
/// This provides a place to store the ownership of the DNSResolver object until
|
||||
/// the request is complete.
|
||||
class EventEngineDNSRequest : DNSRequest { |
||||
public: |
||||
EventEngineDNSRequest(std::unique_ptr<EventEngine::DNSResolver> dns_resolver, |
||||
absl::string_view name, absl::string_view default_port, |
||||
grpc_closure* on_done, |
||||
std::vector<grpc_resolved_address>* addresses) |
||||
: dns_resolver_(std::move(dns_resolver)), |
||||
name_(std::string(name)), |
||||
default_port_(std::string(default_port)), |
||||
on_done_(std::move(on_done)) {} |
||||
|
||||
void Start() override { |
||||
if (dns_resolver_ == nullptr) { |
||||
new DNSCallbackExecCtxScheduler( |
||||
std::move(on_done_), |
||||
absl::UnknownError("Failed to get DNS Resolver.")); |
||||
return; |
||||
} |
||||
Ref().release(); // ref held by pending resolution
|
||||
dns_resolver_->LookupHostname( |
||||
absl::bind_front(&EventEngineDNSRequest::OnLookupComplete, this), name_, |
||||
default_port_, absl::InfiniteFuture()); |
||||
} |
||||
|
||||
// TODO(hork): implement cancellation; currently it's a no-op
|
||||
void Orphan() override { Unref(); } |
||||
|
||||
private: |
||||
void OnLookupComplete( |
||||
absl::StatusOr<std::vector<EventEngine::ResolvedAddress>> addresses) { |
||||
ExecCtx exec_ctx; |
||||
// Convert addresses to iomgr form.
|
||||
std::vector<grpc_resolved_address> result; |
||||
results.reserve(addresses->size()); |
||||
for (size_t i = 0; i < addresses->size(); ++i) { |
||||
results.push_back(CreateGRPCResolvedAddress(addresses[i])); |
||||
} |
||||
if (addresses.ok()) { |
||||
on_done_(std::move(result)); |
||||
} else { |
||||
on_done_(addresses.status()); |
||||
} |
||||
Unref(); |
||||
} |
||||
|
||||
std::unique_ptr<EventEngine::DNSResolver> dns_resolver_; |
||||
const std::string name_; |
||||
const std::string default_port_; |
||||
std::function<void(absl::StatusOr<std::vector<grpc_resolved_address>>)> |
||||
on_done_; |
||||
}; |
||||
|
||||
} // namespace
|
||||
|
||||
DNSResolver* EventEngineDNSResolver::GetOrCreate() { |
||||
static EventEngineDNSResolver* instance = new EventEngineDNSResolver(); |
||||
return instance; |
||||
} |
||||
|
||||
OrphanablePtr<DNSResolver::Request> EventEngineDNSResolver::ResolveName( |
||||
absl::string_view name, absl::string_view default_port, |
||||
grpc_pollset_set* /* interested_parties */, |
||||
std::function<void(absl::StatusOr<std::vector<grpc_resolved_address>>)> |
||||
on_done) { |
||||
std::unique_ptr<EventEngine::DNSResolver> dns_resolver = |
||||
GetDefaultEventEngine()->GetDNSResolver(); |
||||
return MakeOrphanable<EventEngineDNSRequest>( |
||||
std::move(dns_resolver), name, default_port, std::move(on_done)); |
||||
} |
||||
|
||||
absl::StatusOr<std::vector<grpc_resolved_address>> |
||||
EventEngineDNSResolver::ResolveNameBlocking(absl::string_view name, |
||||
absl::string_view default_port) { |
||||
grpc_closure on_done; |
||||
Promise<absl::StatusOr<std::vector<grpc_resolved_address>>> evt; |
||||
auto r = ResolveName( |
||||
name, default_port, |
||||
[&evt](void(absl::StatusOr<std::vector<grpc_resolved_address>> result) { |
||||
evt.Set(std::move(result)); |
||||
})); |
||||
r->Start(); |
||||
return evt.Get(); |
||||
} |
||||
|
||||
} // namespace experimental
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
@ -1,302 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/address_utils/sockaddr_utils.h" |
||||
#include "src/core/lib/event_engine/channel_args_endpoint_config.h" |
||||
#include "src/core/lib/event_engine/event_engine_factory.h" |
||||
#include "src/core/lib/event_engine/sockaddr.h" |
||||
#include "src/core/lib/gprpp/ref_counted.h" |
||||
#include "src/core/lib/iomgr/event_engine/closure.h" |
||||
#include "src/core/lib/iomgr/event_engine/endpoint.h" |
||||
#include "src/core/lib/iomgr/event_engine/pollset.h" |
||||
#include "src/core/lib/iomgr/resolve_address.h" |
||||
#include "src/core/lib/iomgr/tcp_client.h" |
||||
#include "src/core/lib/iomgr/tcp_server.h" |
||||
#include "src/core/lib/surface/init.h" |
||||
#include "src/core/lib/transport/error_utils.h" |
||||
|
||||
extern grpc_core::TraceFlag grpc_tcp_trace; |
||||
|
||||
namespace { |
||||
using ::grpc_event_engine::experimental::ChannelArgsEndpointConfig; |
||||
using ::grpc_event_engine::experimental::EventEngine; |
||||
using ::grpc_event_engine::experimental::GetDefaultEventEngine; |
||||
using ::grpc_event_engine::experimental::GrpcClosureToStatusCallback; |
||||
using ::grpc_event_engine::experimental::SliceAllocator; |
||||
using ::grpc_event_engine::experimental::SliceAllocatorFactory; |
||||
using ::grpc_event_engine::experimental::SliceBuffer; |
||||
} // namespace
|
||||
|
||||
class WrappedInternalSliceAllocator : public SliceAllocator { |
||||
public: |
||||
explicit WrappedInternalSliceAllocator(grpc_slice_allocator* slice_allocator) |
||||
: slice_allocator_(slice_allocator) {} |
||||
|
||||
~WrappedInternalSliceAllocator() { |
||||
grpc_slice_allocator_destroy(slice_allocator_); |
||||
} |
||||
|
||||
absl::Status Allocate(size_t size, SliceBuffer* dest, |
||||
SliceAllocator::AllocateCallback cb) override { |
||||
// TODO(nnoble): requires the SliceBuffer definition.
|
||||
grpc_slice_allocator_allocate( |
||||
slice_allocator_, size, 1, grpc_slice_allocator_intent::kReadBuffer, |
||||
dest->RawSliceBuffer(), |
||||
[](void* arg, grpc_error_handle error) { |
||||
auto cb = static_cast<SliceAllocator::AllocateCallback*>(arg); |
||||
(*cb)(grpc_error_to_absl_status(error)); |
||||
delete cb; |
||||
}, |
||||
new SliceAllocator::AllocateCallback(cb)); |
||||
return absl::OkStatus(); |
||||
} |
||||
|
||||
private: |
||||
grpc_slice_allocator* slice_allocator_; |
||||
}; |
||||
|
||||
class WrappedInternalSliceAllocatorFactory : public SliceAllocatorFactory { |
||||
public: |
||||
explicit WrappedInternalSliceAllocatorFactory( |
||||
grpc_slice_allocator_factory* slice_allocator_factory) |
||||
: slice_allocator_factory_(slice_allocator_factory) {} |
||||
|
||||
~WrappedInternalSliceAllocatorFactory() { |
||||
grpc_slice_allocator_factory_destroy(slice_allocator_factory_); |
||||
} |
||||
|
||||
std::unique_ptr<SliceAllocator> CreateSliceAllocator( |
||||
absl::string_view peer_name) override { |
||||
return absl::make_unique<WrappedInternalSliceAllocator>( |
||||
grpc_slice_allocator_factory_create_slice_allocator( |
||||
slice_allocator_factory_, peer_name)); |
||||
}; |
||||
|
||||
private: |
||||
grpc_slice_allocator_factory* slice_allocator_factory_; |
||||
}; |
||||
|
||||
struct grpc_tcp_server { |
||||
explicit grpc_tcp_server(std::unique_ptr<EventEngine::Listener> listener) |
||||
: refcount(1, GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace) ? "tcp" : nullptr), |
||||
listener(std::move(listener)) { |
||||
shutdown_starting.head = nullptr; |
||||
shutdown_starting.tail = nullptr; |
||||
}; |
||||
~grpc_tcp_server() { |
||||
grpc_core::ExecCtx::RunList(DEBUG_LOCATION, &shutdown_starting); |
||||
grpc_core::ExecCtx::Get()->Flush(); |
||||
} |
||||
grpc_core::RefCount refcount; |
||||
grpc_core::Mutex mu; |
||||
std::unique_ptr<EventEngine::Listener> listener; |
||||
grpc_closure_list shutdown_starting ABSL_GUARDED_BY(mu); |
||||
grpc_tcp_server_cb on_accept_internal; |
||||
void* on_accept_internal_arg; |
||||
}; |
||||
|
||||
namespace { |
||||
|
||||
/// Converts a grpc_closure to an EventEngine Callback. The closure is expected
|
||||
/// to already be initialized.
|
||||
EventEngine::OnConnectCallback GrpcClosureToOnConnectCallback( |
||||
grpc_closure* closure, grpc_endpoint** endpoint_ptr) { |
||||
return [closure, endpoint_ptr]( |
||||
absl::StatusOr<std::unique_ptr<EventEngine::Endpoint>> endpoint) { |
||||
grpc_core::ExecCtx exec_ctx; |
||||
if (endpoint.ok()) { |
||||
auto* grpc_endpoint_out = |
||||
reinterpret_cast<grpc_event_engine_endpoint*>(*endpoint_ptr); |
||||
grpc_endpoint_out->endpoint = std::move(*endpoint); |
||||
} else { |
||||
grpc_endpoint_destroy(*endpoint_ptr); |
||||
*endpoint_ptr = nullptr; |
||||
} |
||||
grpc_core::Closure::Run(DEBUG_LOCATION, closure, |
||||
absl_status_to_grpc_error(endpoint.status())); |
||||
exec_ctx.Flush(); |
||||
grpc_pollset_ee_broadcast_event(); |
||||
}; |
||||
} |
||||
|
||||
/// Usage note: this method does not take ownership of any pointer arguments.
|
||||
void tcp_connect(grpc_closure* on_connect, grpc_endpoint** endpoint, |
||||
grpc_slice_allocator* slice_allocator, |
||||
grpc_pollset_set* /* interested_parties */, |
||||
const grpc_channel_args* channel_args, |
||||
const grpc_resolved_address* addr, |
||||
grpc_core::Timestamp deadline) { |
||||
auto addr_uri = grpc_sockaddr_to_uri(addr); |
||||
if (!addr_uri.ok()) { |
||||
grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_connect, |
||||
absl_status_to_grpc_error(addr_uri.status())); |
||||
return; |
||||
} |
||||
grpc_event_engine_endpoint* ee_endpoint = |
||||
reinterpret_cast<grpc_event_engine_endpoint*>( |
||||
grpc_tcp_create(channel_args, addr_uri.value())); |
||||
*endpoint = &ee_endpoint->base; |
||||
EventEngine::OnConnectCallback ee_on_connect = |
||||
GrpcClosureToOnConnectCallback(on_connect, endpoint); |
||||
auto ee_slice_allocator = |
||||
absl::make_unique<WrappedInternalSliceAllocator>(slice_allocator); |
||||
EventEngine::ResolvedAddress ra(reinterpret_cast<const sockaddr*>(addr->addr), |
||||
addr->len); |
||||
absl::Time ee_deadline = |
||||
grpc_core::ToAbslTime(deadline.as_timespec(GPR_CLOCK_MONOTONIC)); |
||||
ChannelArgsEndpointConfig endpoint_config(channel_args); |
||||
absl::Status connected = GetDefaultEventEngine()->Connect( |
||||
ee_on_connect, ra, endpoint_config, std::move(ee_slice_allocator), |
||||
ee_deadline); |
||||
if (!connected.ok()) { |
||||
// EventEngine failed to start an asynchronous connect.
|
||||
grpc_endpoint_destroy(*endpoint); |
||||
*endpoint = nullptr; |
||||
grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_connect, |
||||
absl_status_to_grpc_error(connected)); |
||||
} |
||||
} |
||||
|
||||
grpc_error_handle tcp_server_create( |
||||
grpc_closure* shutdown_complete, const grpc_channel_args* args, |
||||
grpc_slice_allocator_factory* slice_allocator_factory, |
||||
grpc_tcp_server** server) { |
||||
ChannelArgsEndpointConfig endpoint_config(args); |
||||
auto ee_slice_allocator_factory = |
||||
absl::make_unique<WrappedInternalSliceAllocatorFactory>( |
||||
slice_allocator_factory); |
||||
EventEngine* event_engine = GetDefaultEventEngine(); |
||||
absl::StatusOr<std::unique_ptr<EventEngine::Listener>> listener = |
||||
event_engine->CreateListener( |
||||
[server](std::unique_ptr<EventEngine::Endpoint> ee_endpoint, |
||||
const SliceAllocator& /*slice_allocator*/) { |
||||
grpc_core::ExecCtx exec_ctx; |
||||
GPR_ASSERT((*server)->on_accept_internal != nullptr); |
||||
grpc_event_engine_endpoint* iomgr_endpoint = |
||||
grpc_tcp_server_endpoint_create(std::move(ee_endpoint)); |
||||
grpc_tcp_server_acceptor* acceptor = |
||||
static_cast<grpc_tcp_server_acceptor*>( |
||||
gpr_zalloc(sizeof(*acceptor))); |
||||
acceptor->from_server = *server; |
||||
acceptor->external_connection = false; |
||||
(*server)->on_accept_internal((*server)->on_accept_internal_arg, |
||||
&iomgr_endpoint->base, nullptr, |
||||
acceptor); |
||||
exec_ctx.Flush(); |
||||
grpc_pollset_ee_broadcast_event(); |
||||
}, |
||||
GrpcClosureToStatusCallback(shutdown_complete), endpoint_config, |
||||
std::move(ee_slice_allocator_factory)); |
||||
if (!listener.ok()) { |
||||
return absl_status_to_grpc_error(listener.status()); |
||||
} |
||||
*server = new grpc_tcp_server(std::move(*listener)); |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
|
||||
void tcp_server_start(grpc_tcp_server* server, |
||||
const std::vector<grpc_pollset*>* /* pollsets */, |
||||
grpc_tcp_server_cb on_accept_cb, void* cb_arg) { |
||||
server->on_accept_internal = on_accept_cb; |
||||
server->on_accept_internal_arg = cb_arg; |
||||
// The iomgr API does not handle situations where the server cannot start, so
|
||||
// a crash may be preferable for now.
|
||||
GPR_ASSERT(server->listener->Start().ok()); |
||||
} |
||||
|
||||
grpc_error_handle tcp_server_add_port(grpc_tcp_server* s, |
||||
const grpc_resolved_address* addr, |
||||
int* out_port) { |
||||
EventEngine::ResolvedAddress ra(reinterpret_cast<const sockaddr*>(addr->addr), |
||||
addr->len); |
||||
auto port = s->listener->Bind(ra); |
||||
if (!port.ok()) { |
||||
return absl_status_to_grpc_error(port.status()); |
||||
} |
||||
*out_port = *port; |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
|
||||
grpc_core::TcpServerFdHandler* tcp_server_create_fd_handler( |
||||
grpc_tcp_server* /* s */) { |
||||
// EventEngine-iomgr does not support fds.
|
||||
return nullptr; |
||||
} |
||||
|
||||
unsigned tcp_server_port_fd_count(grpc_tcp_server* /* s */, |
||||
unsigned /* port_index */) { |
||||
return 0; |
||||
} |
||||
|
||||
int tcp_server_port_fd(grpc_tcp_server* /* s */, unsigned /* port_index */, |
||||
unsigned /* fd_index */) { |
||||
// Note: only used internally
|
||||
return -1; |
||||
} |
||||
|
||||
grpc_tcp_server* tcp_server_ref(grpc_tcp_server* s) { |
||||
s->refcount.Ref(DEBUG_LOCATION, "server ref"); |
||||
return s; |
||||
} |
||||
|
||||
void tcp_server_shutdown_starting_add(grpc_tcp_server* s, |
||||
grpc_closure* shutdown_starting) { |
||||
grpc_core::MutexLock lock(&s->mu); |
||||
grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, |
||||
GRPC_ERROR_NONE); |
||||
} |
||||
|
||||
void tcp_server_unref(grpc_tcp_server* s) { |
||||
if (GPR_UNLIKELY(s->refcount.Unref(DEBUG_LOCATION, "server unref"))) { |
||||
delete s; |
||||
} |
||||
} |
||||
|
||||
// No-op, all are handled on listener unref
|
||||
void tcp_server_shutdown_listeners(grpc_tcp_server* /* s */) {} |
||||
|
||||
} // namespace
|
||||
|
||||
grpc_tcp_client_vtable grpc_event_engine_tcp_client_vtable = {tcp_connect}; |
||||
grpc_tcp_server_vtable grpc_event_engine_tcp_server_vtable = { |
||||
tcp_server_create, tcp_server_start, |
||||
tcp_server_add_port, tcp_server_create_fd_handler, |
||||
tcp_server_port_fd_count, tcp_server_port_fd, |
||||
tcp_server_ref, tcp_server_shutdown_starting_add, |
||||
tcp_server_unref, tcp_server_shutdown_listeners}; |
||||
|
||||
// Methods that are expected to exist elsewhere in the codebase.
|
||||
|
||||
struct grpc_fd { |
||||
int fd; |
||||
}; |
||||
|
||||
grpc_fd* grpc_fd_create(int /* fd */, const char* /* name */, |
||||
bool /* track_err */) { |
||||
return nullptr; |
||||
} |
||||
|
||||
grpc_endpoint* grpc_tcp_client_create_from_fd( |
||||
grpc_fd* /* fd */, const grpc_channel_args* /* channel_args */, |
||||
absl::string_view /* addr_str */, |
||||
grpc_slice_allocator* slice_allocator /* slice_allocator */) { |
||||
grpc_slice_allocator_destroy(slice_allocator); |
||||
return nullptr; |
||||
} |
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
@ -1,62 +0,0 @@ |
||||
// Copyright 2021 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#ifdef GRPC_USE_EVENT_ENGINE |
||||
#include <grpc/event_engine/event_engine.h> |
||||
|
||||
#include "src/core/lib/event_engine/event_engine_factory.h" |
||||
#include "src/core/lib/iomgr/error.h" |
||||
#include "src/core/lib/iomgr/event_engine/closure.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
#include "src/core/lib/iomgr/timer.h" |
||||
#include "src/core/lib/surface/init.h" |
||||
#include "src/core/lib/transport/error_utils.h" |
||||
|
||||
namespace { |
||||
using ::grpc_event_engine::experimental::EventEngine; |
||||
using ::grpc_event_engine::experimental::GetDefaultEventEngine; |
||||
using ::grpc_event_engine::experimental::GrpcClosureToCallback; |
||||
|
||||
void timer_init(grpc_timer* timer, grpc_core::Timestamp deadline, |
||||
grpc_closure* closure) { |
||||
timer->ee_task_handle = GetDefaultEventEngine()->RunAt( |
||||
grpc_core::ToAbslTime(deadline.as_timespec(GPR_CLOCK_REALTIME)), |
||||
GrpcClosureToCallback(closure)); |
||||
timer->closure = closure; |
||||
} |
||||
|
||||
void timer_cancel(grpc_timer* timer) { |
||||
auto handle = timer->ee_task_handle; |
||||
if (!GetDefaultEventEngine()->Cancel(handle)) { |
||||
grpc_core::ExecCtx::Run(DEBUG_LOCATION, timer->closure, |
||||
GRPC_ERROR_CANCELLED); |
||||
} |
||||
} |
||||
|
||||
/* Internal API */ |
||||
grpc_timer_check_result timer_check(grpc_core::Timestamp* /* next */) { |
||||
return GRPC_TIMERS_NOT_CHECKED; |
||||
} |
||||
void timer_list_init() {} |
||||
void timer_list_shutdown(void) {} |
||||
void timer_consume_kick(void) {} |
||||
|
||||
} // namespace
|
||||
|
||||
grpc_timer_vtable grpc_event_engine_timer_vtable = { |
||||
timer_init, timer_cancel, timer_check, |
||||
timer_list_init, timer_list_shutdown, timer_consume_kick}; |
||||
|
||||
#endif // GRPC_USE_EVENT_ENGINE
|
Loading…
Reference in new issue