diff --git a/BUILD b/BUILD index e5555803049..c4c638ef07e 100644 --- a/BUILD +++ b/BUILD @@ -128,7 +128,7 @@ GRPC_PUBLIC_HDRS = [ ] GRPC_PUBLIC_EVENT_ENGINE_HDRS = [ - "include/grpc/event_engine/channel_args.h", + "include/grpc/event_engine/endpoint_config.h", "include/grpc/event_engine/event_engine.h", "include/grpc/event_engine/port.h", "include/grpc/event_engine/slice_allocator.h", @@ -792,6 +792,8 @@ grpc_cc_library( "src/core/lib/compression/stream_compression_identity.cc", "src/core/lib/debug/stats.cc", "src/core/lib/debug/stats_data.cc", + "src/core/lib/event_engine/endpoint_config.cc", + "src/core/lib/event_engine/event_engine.cc", "src/core/lib/event_engine/slice_allocator.cc", "src/core/lib/event_engine/sockaddr.cc", "src/core/lib/http/format_request.cc", @@ -804,6 +806,7 @@ grpc_cc_library( "src/core/lib/iomgr/dualstack_socket_posix.cc", "src/core/lib/iomgr/endpoint.cc", "src/core/lib/iomgr/endpoint_cfstream.cc", + "src/core/lib/iomgr/endpoint_pair_event_engine.cc", "src/core/lib/iomgr/endpoint_pair_posix.cc", "src/core/lib/iomgr/endpoint_pair_uv.cc", "src/core/lib/iomgr/endpoint_pair_windows.cc", @@ -815,6 +818,14 @@ grpc_cc_library( "src/core/lib/iomgr/ev_poll_posix.cc", "src/core/lib/iomgr/ev_posix.cc", "src/core/lib/iomgr/ev_windows.cc", + "src/core/lib/iomgr/event_engine/closure.cc", + "src/core/lib/iomgr/event_engine/endpoint.cc", + "src/core/lib/iomgr/event_engine/iomgr.cc", + "src/core/lib/iomgr/event_engine/pollset.cc", + "src/core/lib/iomgr/event_engine/resolved_address_internal.cc", + "src/core/lib/iomgr/event_engine/resolver.cc", + "src/core/lib/iomgr/event_engine/tcp.cc", + "src/core/lib/iomgr/event_engine/timer.cc", "src/core/lib/iomgr/exec_ctx.cc", "src/core/lib/iomgr/executor.cc", "src/core/lib/iomgr/executor/mpmcqueue.cc", @@ -958,6 +969,8 @@ grpc_cc_library( "src/core/lib/compression/stream_compression_identity.h", "src/core/lib/debug/stats.h", "src/core/lib/debug/stats_data.h", + "src/core/lib/event_engine/endpoint_config_internal.h", + "src/core/lib/event_engine/sockaddr.h", "src/core/lib/http/format_request.h", "src/core/lib/http/httpcli.h", "src/core/lib/http/parser.h", @@ -979,6 +992,12 @@ grpc_cc_library( "src/core/lib/iomgr/ev_epollex_linux.h", "src/core/lib/iomgr/ev_poll_posix.h", "src/core/lib/iomgr/ev_posix.h", + "src/core/lib/iomgr/event_engine/closure.h", + "src/core/lib/iomgr/event_engine/endpoint.h", + "src/core/lib/iomgr/event_engine/iomgr.h", + "src/core/lib/iomgr/event_engine/pollset.h", + "src/core/lib/iomgr/event_engine/promise.h", + "src/core/lib/iomgr/event_engine/resolved_address_internal.h", "src/core/lib/iomgr/exec_ctx.h", "src/core/lib/iomgr/executor.h", "src/core/lib/iomgr/executor/mpmcqueue.h", @@ -1075,6 +1094,7 @@ grpc_cc_library( external_deps = [ "madler_zlib", "absl/container:inlined_vector", + "absl/functional:bind_front", "absl/status", "absl/status:statusor", "absl/strings", @@ -1852,10 +1872,12 @@ grpc_cc_library( name = "grpc_resolver_dns_ares", srcs = [ "src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc", + "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc", + "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc", diff --git a/BUILD.gn b/BUILD.gn index 5aaee286c9f..47ebfa31ed7 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -225,7 +225,7 @@ config("grpc_config") { "include/grpc/byte_buffer_reader.h", "include/grpc/census.h", "include/grpc/compression.h", - "include/grpc/event_engine/channel_args.h", + "include/grpc/event_engine/endpoint_config.h", "include/grpc/event_engine/event_engine.h", "include/grpc/event_engine/port.h", "include/grpc/event_engine/slice_allocator.h", @@ -308,11 +308,13 @@ config("grpc_config") { "src/core/ext/filters/client_channel/resolver.h", "src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h", + "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h", + "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc", "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc", @@ -861,8 +863,12 @@ config("grpc_config") { "src/core/lib/debug/stats_data.h", "src/core/lib/debug/trace.cc", "src/core/lib/debug/trace.h", + "src/core/lib/event_engine/endpoint_config.cc", + "src/core/lib/event_engine/endpoint_config_internal.h", + "src/core/lib/event_engine/event_engine.cc", "src/core/lib/event_engine/slice_allocator.cc", "src/core/lib/event_engine/sockaddr.cc", + "src/core/lib/event_engine/sockaddr.h", "src/core/lib/gprpp/atomic.h", "src/core/lib/gprpp/dual_ref_counted.h", "src/core/lib/gprpp/orphanable.h", @@ -892,6 +898,7 @@ config("grpc_config") { "src/core/lib/iomgr/endpoint_cfstream.cc", "src/core/lib/iomgr/endpoint_cfstream.h", "src/core/lib/iomgr/endpoint_pair.h", + "src/core/lib/iomgr/endpoint_pair_event_engine.cc", "src/core/lib/iomgr/endpoint_pair_posix.cc", "src/core/lib/iomgr/endpoint_pair_uv.cc", "src/core/lib/iomgr/endpoint_pair_windows.cc", @@ -911,6 +918,20 @@ config("grpc_config") { "src/core/lib/iomgr/ev_posix.cc", "src/core/lib/iomgr/ev_posix.h", "src/core/lib/iomgr/ev_windows.cc", + "src/core/lib/iomgr/event_engine/closure.cc", + "src/core/lib/iomgr/event_engine/closure.h", + "src/core/lib/iomgr/event_engine/endpoint.cc", + "src/core/lib/iomgr/event_engine/endpoint.h", + "src/core/lib/iomgr/event_engine/iomgr.cc", + "src/core/lib/iomgr/event_engine/iomgr.h", + "src/core/lib/iomgr/event_engine/pollset.cc", + "src/core/lib/iomgr/event_engine/pollset.h", + "src/core/lib/iomgr/event_engine/promise.h", + "src/core/lib/iomgr/event_engine/resolved_address_internal.cc", + "src/core/lib/iomgr/event_engine/resolved_address_internal.h", + "src/core/lib/iomgr/event_engine/resolver.cc", + "src/core/lib/iomgr/event_engine/tcp.cc", + "src/core/lib/iomgr/event_engine/timer.cc", "src/core/lib/iomgr/exec_ctx.cc", "src/core/lib/iomgr/exec_ctx.h", "src/core/lib/iomgr/executor.cc", diff --git a/CMakeLists.txt b/CMakeLists.txt index 6185c17ff77..37bd8101b9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -846,6 +846,7 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx dual_ref_counted_test) add_dependencies(buildtests_cxx duplicate_header_bad_client_test) add_dependencies(buildtests_cxx end2end_test) + add_dependencies(buildtests_cxx endpoint_config_test) add_dependencies(buildtests_cxx error_details_test) add_dependencies(buildtests_cxx error_utils_test) add_dependencies(buildtests_cxx evaluate_args_test) @@ -1537,10 +1538,12 @@ add_library(grpc src/core/ext/filters/client_channel/proxy_mapper_registry.cc src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc @@ -1821,6 +1824,8 @@ add_library(grpc src/core/lib/debug/stats.cc src/core/lib/debug/stats_data.cc src/core/lib/debug/trace.cc + src/core/lib/event_engine/endpoint_config.cc + src/core/lib/event_engine/event_engine.cc src/core/lib/event_engine/slice_allocator.cc src/core/lib/event_engine/sockaddr.cc src/core/lib/http/format_request.cc @@ -1834,6 +1839,7 @@ add_library(grpc src/core/lib/iomgr/dualstack_socket_posix.cc src/core/lib/iomgr/endpoint.cc src/core/lib/iomgr/endpoint_cfstream.cc + src/core/lib/iomgr/endpoint_pair_event_engine.cc src/core/lib/iomgr/endpoint_pair_posix.cc src/core/lib/iomgr/endpoint_pair_uv.cc src/core/lib/iomgr/endpoint_pair_windows.cc @@ -1845,6 +1851,14 @@ add_library(grpc src/core/lib/iomgr/ev_poll_posix.cc src/core/lib/iomgr/ev_posix.cc src/core/lib/iomgr/ev_windows.cc + src/core/lib/iomgr/event_engine/closure.cc + src/core/lib/iomgr/event_engine/endpoint.cc + src/core/lib/iomgr/event_engine/iomgr.cc + src/core/lib/iomgr/event_engine/pollset.cc + src/core/lib/iomgr/event_engine/resolved_address_internal.cc + src/core/lib/iomgr/event_engine/resolver.cc + src/core/lib/iomgr/event_engine/tcp.cc + src/core/lib/iomgr/event_engine/timer.cc src/core/lib/iomgr/exec_ctx.cc src/core/lib/iomgr/executor.cc src/core/lib/iomgr/executor/mpmcqueue.cc @@ -2103,7 +2117,7 @@ foreach(_hdr include/grpc/byte_buffer_reader.h include/grpc/census.h include/grpc/compression.h - include/grpc/event_engine/channel_args.h + include/grpc/event_engine/endpoint_config.h include/grpc/event_engine/event_engine.h include/grpc/event_engine/port.h include/grpc/event_engine/slice_allocator.h @@ -2348,10 +2362,12 @@ add_library(grpc_unsecure src/core/ext/filters/client_channel/proxy_mapper_registry.cc src/core/ext/filters/client_channel/resolver.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc @@ -2445,6 +2461,8 @@ add_library(grpc_unsecure src/core/lib/debug/stats.cc src/core/lib/debug/stats_data.cc src/core/lib/debug/trace.cc + src/core/lib/event_engine/endpoint_config.cc + src/core/lib/event_engine/event_engine.cc src/core/lib/event_engine/slice_allocator.cc src/core/lib/event_engine/sockaddr.cc src/core/lib/http/format_request.cc @@ -2457,6 +2475,7 @@ add_library(grpc_unsecure src/core/lib/iomgr/dualstack_socket_posix.cc src/core/lib/iomgr/endpoint.cc src/core/lib/iomgr/endpoint_cfstream.cc + src/core/lib/iomgr/endpoint_pair_event_engine.cc src/core/lib/iomgr/endpoint_pair_posix.cc src/core/lib/iomgr/endpoint_pair_uv.cc src/core/lib/iomgr/endpoint_pair_windows.cc @@ -2468,6 +2487,14 @@ add_library(grpc_unsecure src/core/lib/iomgr/ev_poll_posix.cc src/core/lib/iomgr/ev_posix.cc src/core/lib/iomgr/ev_windows.cc + src/core/lib/iomgr/event_engine/closure.cc + src/core/lib/iomgr/event_engine/endpoint.cc + src/core/lib/iomgr/event_engine/iomgr.cc + src/core/lib/iomgr/event_engine/pollset.cc + src/core/lib/iomgr/event_engine/resolved_address_internal.cc + src/core/lib/iomgr/event_engine/resolver.cc + src/core/lib/iomgr/event_engine/tcp.cc + src/core/lib/iomgr/event_engine/timer.cc src/core/lib/iomgr/exec_ctx.cc src/core/lib/iomgr/executor.cc src/core/lib/iomgr/executor/mpmcqueue.cc @@ -2630,6 +2657,7 @@ target_link_libraries(grpc_unsecure ${_gRPC_ALLTARGETS_LIBRARIES} absl::flat_hash_map absl::inlined_vector + absl::bind_front absl::statusor gpr address_sorting @@ -2643,7 +2671,7 @@ foreach(_hdr include/grpc/byte_buffer_reader.h include/grpc/census.h include/grpc/compression.h - include/grpc/event_engine/channel_args.h + include/grpc/event_engine/endpoint_config.h include/grpc/event_engine/event_engine.h include/grpc/event_engine/port.h include/grpc/event_engine/slice_allocator.h @@ -10302,6 +10330,41 @@ target_link_libraries(end2end_test ) +endif() +if(gRPC_BUILD_TESTS) + +add_executable(endpoint_config_test + test/core/event_engine/endpoint_config_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + +target_include_directories(endpoint_config_test + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + ${_gRPC_RE2_INCLUDE_DIR} + ${_gRPC_SSL_INCLUDE_DIR} + ${_gRPC_UPB_GENERATED_DIR} + ${_gRPC_UPB_GRPC_GENERATED_DIR} + ${_gRPC_UPB_INCLUDE_DIR} + ${_gRPC_XXHASH_INCLUDE_DIR} + ${_gRPC_ZLIB_INCLUDE_DIR} + third_party/googletest/googletest/include + third_party/googletest/googletest + third_party/googletest/googlemock/include + third_party/googletest/googlemock + ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(endpoint_config_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util +) + + endif() if(gRPC_BUILD_TESTS) @@ -15812,7 +15875,7 @@ generate_pkgconfig( "gRPC unsecure" "high performance general RPC framework without SSL" "${gRPC_CORE_VERSION}" - "gpr absl_base absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time" + "gpr absl_base absl_bind_front absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time" "-lgrpc_unsecure" "" "grpc_unsecure.pc") @@ -15832,7 +15895,7 @@ generate_pkgconfig( "gRPC++ unsecure" "C++ wrapper for gRPC without SSL" "${gRPC_CPP_VERSION}" - "grpc_unsecure absl_base absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time" + "grpc_unsecure absl_base absl_bind_front absl_flat_hash_map absl_inlined_vector absl_memory absl_optional absl_status absl_statusor absl_str_format absl_strings absl_synchronization absl_time" "-lgrpc++_unsecure" "" "grpc++_unsecure.pc") diff --git a/Makefile b/Makefile index 3be8d784058..6b5e0829fc2 100644 --- a/Makefile +++ b/Makefile @@ -1083,10 +1083,12 @@ LIBGRPC_SRC = \ src/core/ext/filters/client_channel/proxy_mapper_registry.cc \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \ + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc \ + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc \ @@ -1367,6 +1369,8 @@ LIBGRPC_SRC = \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/debug/trace.cc \ + src/core/lib/event_engine/endpoint_config.cc \ + src/core/lib/event_engine/event_engine.cc \ src/core/lib/event_engine/slice_allocator.cc \ src/core/lib/event_engine/sockaddr.cc \ src/core/lib/http/format_request.cc \ @@ -1380,6 +1384,7 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/dualstack_socket_posix.cc \ src/core/lib/iomgr/endpoint.cc \ src/core/lib/iomgr/endpoint_cfstream.cc \ + src/core/lib/iomgr/endpoint_pair_event_engine.cc \ src/core/lib/iomgr/endpoint_pair_posix.cc \ src/core/lib/iomgr/endpoint_pair_uv.cc \ src/core/lib/iomgr/endpoint_pair_windows.cc \ @@ -1391,6 +1396,14 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/ev_poll_posix.cc \ src/core/lib/iomgr/ev_posix.cc \ src/core/lib/iomgr/ev_windows.cc \ + src/core/lib/iomgr/event_engine/closure.cc \ + src/core/lib/iomgr/event_engine/endpoint.cc \ + src/core/lib/iomgr/event_engine/iomgr.cc \ + src/core/lib/iomgr/event_engine/pollset.cc \ + src/core/lib/iomgr/event_engine/resolved_address_internal.cc \ + src/core/lib/iomgr/event_engine/resolver.cc \ + src/core/lib/iomgr/event_engine/tcp.cc \ + src/core/lib/iomgr/event_engine/timer.cc \ src/core/lib/iomgr/exec_ctx.cc \ src/core/lib/iomgr/executor.cc \ src/core/lib/iomgr/executor/mpmcqueue.cc \ @@ -1599,7 +1612,7 @@ PUBLIC_HEADERS_C += \ include/grpc/byte_buffer_reader.h \ include/grpc/census.h \ include/grpc/compression.h \ - include/grpc/event_engine/channel_args.h \ + include/grpc/event_engine/endpoint_config.h \ include/grpc/event_engine/event_engine.h \ include/grpc/event_engine/port.h \ include/grpc/event_engine/slice_allocator.h \ @@ -1745,10 +1758,12 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/filters/client_channel/proxy_mapper_registry.cc \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \ + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc \ + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc \ @@ -1842,6 +1857,8 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/debug/trace.cc \ + src/core/lib/event_engine/endpoint_config.cc \ + src/core/lib/event_engine/event_engine.cc \ src/core/lib/event_engine/slice_allocator.cc \ src/core/lib/event_engine/sockaddr.cc \ src/core/lib/http/format_request.cc \ @@ -1854,6 +1871,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/dualstack_socket_posix.cc \ src/core/lib/iomgr/endpoint.cc \ src/core/lib/iomgr/endpoint_cfstream.cc \ + src/core/lib/iomgr/endpoint_pair_event_engine.cc \ src/core/lib/iomgr/endpoint_pair_posix.cc \ src/core/lib/iomgr/endpoint_pair_uv.cc \ src/core/lib/iomgr/endpoint_pair_windows.cc \ @@ -1865,6 +1883,14 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/ev_poll_posix.cc \ src/core/lib/iomgr/ev_posix.cc \ src/core/lib/iomgr/ev_windows.cc \ + src/core/lib/iomgr/event_engine/closure.cc \ + src/core/lib/iomgr/event_engine/endpoint.cc \ + src/core/lib/iomgr/event_engine/iomgr.cc \ + src/core/lib/iomgr/event_engine/pollset.cc \ + src/core/lib/iomgr/event_engine/resolved_address_internal.cc \ + src/core/lib/iomgr/event_engine/resolver.cc \ + src/core/lib/iomgr/event_engine/tcp.cc \ + src/core/lib/iomgr/event_engine/timer.cc \ src/core/lib/iomgr/exec_ctx.cc \ src/core/lib/iomgr/executor.cc \ src/core/lib/iomgr/executor/mpmcqueue.cc \ @@ -1992,7 +2018,7 @@ PUBLIC_HEADERS_C += \ include/grpc/byte_buffer_reader.h \ include/grpc/census.h \ include/grpc/compression.h \ - include/grpc/event_engine/channel_args.h \ + include/grpc/event_engine/endpoint_config.h \ include/grpc/event_engine/event_engine.h \ include/grpc/event_engine/port.h \ include/grpc/event_engine/slice_allocator.h \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index c885a861575..c324c71f9dc 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -402,7 +402,7 @@ libs: - include/grpc/byte_buffer_reader.h - include/grpc/census.h - include/grpc/compression.h - - include/grpc/event_engine/channel_args.h + - include/grpc/event_engine/endpoint_config.h - include/grpc/event_engine/event_engine.h - include/grpc/event_engine/port.h - include/grpc/event_engine/slice_allocator.h @@ -718,6 +718,8 @@ libs: - src/core/lib/debug/stats.h - src/core/lib/debug/stats_data.h - src/core/lib/debug/trace.h + - src/core/lib/event_engine/endpoint_config_internal.h + - src/core/lib/event_engine/sockaddr.h - src/core/lib/gprpp/atomic.h - src/core/lib/gprpp/dual_ref_counted.h - src/core/lib/gprpp/orphanable.h @@ -744,6 +746,12 @@ libs: - src/core/lib/iomgr/ev_epollex_linux.h - src/core/lib/iomgr/ev_poll_posix.h - src/core/lib/iomgr/ev_posix.h + - src/core/lib/iomgr/event_engine/closure.h + - src/core/lib/iomgr/event_engine/endpoint.h + - src/core/lib/iomgr/event_engine/iomgr.h + - src/core/lib/iomgr/event_engine/pollset.h + - src/core/lib/iomgr/event_engine/promise.h + - src/core/lib/iomgr/event_engine/resolved_address_internal.h - src/core/lib/iomgr/exec_ctx.h - src/core/lib/iomgr/executor.h - src/core/lib/iomgr/executor/mpmcqueue.h @@ -949,10 +957,12 @@ libs: - src/core/ext/filters/client_channel/proxy_mapper_registry.cc - src/core/ext/filters/client_channel/resolver.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc + - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc + - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc @@ -1233,6 +1243,8 @@ libs: - src/core/lib/debug/stats.cc - src/core/lib/debug/stats_data.cc - src/core/lib/debug/trace.cc + - src/core/lib/event_engine/endpoint_config.cc + - src/core/lib/event_engine/event_engine.cc - src/core/lib/event_engine/slice_allocator.cc - src/core/lib/event_engine/sockaddr.cc - src/core/lib/http/format_request.cc @@ -1246,6 +1258,7 @@ libs: - src/core/lib/iomgr/dualstack_socket_posix.cc - src/core/lib/iomgr/endpoint.cc - src/core/lib/iomgr/endpoint_cfstream.cc + - src/core/lib/iomgr/endpoint_pair_event_engine.cc - src/core/lib/iomgr/endpoint_pair_posix.cc - src/core/lib/iomgr/endpoint_pair_uv.cc - src/core/lib/iomgr/endpoint_pair_windows.cc @@ -1257,6 +1270,14 @@ libs: - src/core/lib/iomgr/ev_poll_posix.cc - src/core/lib/iomgr/ev_posix.cc - src/core/lib/iomgr/ev_windows.cc + - src/core/lib/iomgr/event_engine/closure.cc + - src/core/lib/iomgr/event_engine/endpoint.cc + - src/core/lib/iomgr/event_engine/iomgr.cc + - src/core/lib/iomgr/event_engine/pollset.cc + - src/core/lib/iomgr/event_engine/resolved_address_internal.cc + - src/core/lib/iomgr/event_engine/resolver.cc + - src/core/lib/iomgr/event_engine/tcp.cc + - src/core/lib/iomgr/event_engine/timer.cc - src/core/lib/iomgr/exec_ctx.cc - src/core/lib/iomgr/executor.cc - src/core/lib/iomgr/executor/mpmcqueue.cc @@ -1594,7 +1615,7 @@ libs: - include/grpc/byte_buffer_reader.h - include/grpc/census.h - include/grpc/compression.h - - include/grpc/event_engine/channel_args.h + - include/grpc/event_engine/endpoint_config.h - include/grpc/event_engine/event_engine.h - include/grpc/event_engine/port.h - include/grpc/event_engine/slice_allocator.h @@ -1722,6 +1743,8 @@ libs: - src/core/lib/debug/stats.h - src/core/lib/debug/stats_data.h - src/core/lib/debug/trace.h + - src/core/lib/event_engine/endpoint_config_internal.h + - src/core/lib/event_engine/sockaddr.h - src/core/lib/gprpp/atomic.h - src/core/lib/gprpp/dual_ref_counted.h - src/core/lib/gprpp/orphanable.h @@ -1748,6 +1771,12 @@ libs: - src/core/lib/iomgr/ev_epollex_linux.h - src/core/lib/iomgr/ev_poll_posix.h - src/core/lib/iomgr/ev_posix.h + - src/core/lib/iomgr/event_engine/closure.h + - src/core/lib/iomgr/event_engine/endpoint.h + - src/core/lib/iomgr/event_engine/iomgr.h + - src/core/lib/iomgr/event_engine/pollset.h + - src/core/lib/iomgr/event_engine/promise.h + - src/core/lib/iomgr/event_engine/resolved_address_internal.h - src/core/lib/iomgr/exec_ctx.h - src/core/lib/iomgr/executor.h - src/core/lib/iomgr/executor/mpmcqueue.h @@ -1875,10 +1904,12 @@ libs: - src/core/ext/filters/client_channel/proxy_mapper_registry.cc - src/core/ext/filters/client_channel/resolver.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc + - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc + - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc - src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc @@ -1972,6 +2003,8 @@ libs: - src/core/lib/debug/stats.cc - src/core/lib/debug/stats_data.cc - src/core/lib/debug/trace.cc + - src/core/lib/event_engine/endpoint_config.cc + - src/core/lib/event_engine/event_engine.cc - src/core/lib/event_engine/slice_allocator.cc - src/core/lib/event_engine/sockaddr.cc - src/core/lib/http/format_request.cc @@ -1984,6 +2017,7 @@ libs: - src/core/lib/iomgr/dualstack_socket_posix.cc - src/core/lib/iomgr/endpoint.cc - src/core/lib/iomgr/endpoint_cfstream.cc + - src/core/lib/iomgr/endpoint_pair_event_engine.cc - src/core/lib/iomgr/endpoint_pair_posix.cc - src/core/lib/iomgr/endpoint_pair_uv.cc - src/core/lib/iomgr/endpoint_pair_windows.cc @@ -1995,6 +2029,14 @@ libs: - src/core/lib/iomgr/ev_poll_posix.cc - src/core/lib/iomgr/ev_posix.cc - src/core/lib/iomgr/ev_windows.cc + - src/core/lib/iomgr/event_engine/closure.cc + - src/core/lib/iomgr/event_engine/endpoint.cc + - src/core/lib/iomgr/event_engine/iomgr.cc + - src/core/lib/iomgr/event_engine/pollset.cc + - src/core/lib/iomgr/event_engine/resolved_address_internal.cc + - src/core/lib/iomgr/event_engine/resolver.cc + - src/core/lib/iomgr/event_engine/tcp.cc + - src/core/lib/iomgr/event_engine/timer.cc - src/core/lib/iomgr/exec_ctx.cc - src/core/lib/iomgr/executor.cc - src/core/lib/iomgr/executor/mpmcqueue.cc @@ -2119,6 +2161,7 @@ libs: deps: - absl/container:flat_hash_map - absl/container:inlined_vector + - absl/functional:bind_front - absl/status:statusor - gpr - address_sorting @@ -5070,6 +5113,15 @@ targets: deps: - grpc++_test - grpc++_test_util +- name: endpoint_config_test + gtest: true + build: test + language: c++ + headers: [] + src: + - test/core/event_engine/endpoint_config_test.cc + deps: + - grpc_test_util - name: error_details_test gtest: true build: test diff --git a/config.m4 b/config.m4 index 53ffe8ffaac..1064755c2ae 100644 --- a/config.m4 +++ b/config.m4 @@ -77,10 +77,12 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/filters/client_channel/proxy_mapper_registry.cc \ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \ + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc \ + src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc \ @@ -374,6 +376,8 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/debug/stats.cc \ src/core/lib/debug/stats_data.cc \ src/core/lib/debug/trace.cc \ + src/core/lib/event_engine/endpoint_config.cc \ + src/core/lib/event_engine/event_engine.cc \ src/core/lib/event_engine/slice_allocator.cc \ src/core/lib/event_engine/sockaddr.cc \ src/core/lib/gpr/alloc.cc \ @@ -431,6 +435,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/dualstack_socket_posix.cc \ src/core/lib/iomgr/endpoint.cc \ src/core/lib/iomgr/endpoint_cfstream.cc \ + src/core/lib/iomgr/endpoint_pair_event_engine.cc \ src/core/lib/iomgr/endpoint_pair_posix.cc \ src/core/lib/iomgr/endpoint_pair_uv.cc \ src/core/lib/iomgr/endpoint_pair_windows.cc \ @@ -442,6 +447,14 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/ev_poll_posix.cc \ src/core/lib/iomgr/ev_posix.cc \ src/core/lib/iomgr/ev_windows.cc \ + src/core/lib/iomgr/event_engine/closure.cc \ + src/core/lib/iomgr/event_engine/endpoint.cc \ + src/core/lib/iomgr/event_engine/iomgr.cc \ + src/core/lib/iomgr/event_engine/pollset.cc \ + src/core/lib/iomgr/event_engine/resolved_address_internal.cc \ + src/core/lib/iomgr/event_engine/resolver.cc \ + src/core/lib/iomgr/event_engine/tcp.cc \ + src/core/lib/iomgr/event_engine/timer.cc \ src/core/lib/iomgr/exec_ctx.cc \ src/core/lib/iomgr/executor.cc \ src/core/lib/iomgr/executor/mpmcqueue.cc \ @@ -1169,6 +1182,7 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/gprpp) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/http) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/iomgr) + PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/iomgr/event_engine) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/iomgr/executor) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/json) PHP_ADD_BUILD_DIR($ext_builddir/src/core/lib/matchers) diff --git a/config.w32 b/config.w32 index b0d41b86576..699e917a675 100644 --- a/config.w32 +++ b/config.w32 @@ -43,10 +43,12 @@ if (PHP_GRPC != "no") { "src\\core\\ext\\filters\\client_channel\\proxy_mapper_registry.cc " + "src\\core\\ext\\filters\\client_channel\\resolver.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\dns_resolver_ares.cc " + + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_ev_driver_event_engine.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_ev_driver_libuv.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_ev_driver_posix.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_ev_driver_windows.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_wrapper.cc " + + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_wrapper_event_engine.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_wrapper_libuv.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_wrapper_posix.cc " + "src\\core\\ext\\filters\\client_channel\\resolver\\dns\\c_ares\\grpc_ares_wrapper_windows.cc " + @@ -340,6 +342,8 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\debug\\stats.cc " + "src\\core\\lib\\debug\\stats_data.cc " + "src\\core\\lib\\debug\\trace.cc " + + "src\\core\\lib\\event_engine\\endpoint_config.cc " + + "src\\core\\lib\\event_engine\\event_engine.cc " + "src\\core\\lib\\event_engine\\slice_allocator.cc " + "src\\core\\lib\\event_engine\\sockaddr.cc " + "src\\core\\lib\\gpr\\alloc.cc " + @@ -397,6 +401,7 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\dualstack_socket_posix.cc " + "src\\core\\lib\\iomgr\\endpoint.cc " + "src\\core\\lib\\iomgr\\endpoint_cfstream.cc " + + "src\\core\\lib\\iomgr\\endpoint_pair_event_engine.cc " + "src\\core\\lib\\iomgr\\endpoint_pair_posix.cc " + "src\\core\\lib\\iomgr\\endpoint_pair_uv.cc " + "src\\core\\lib\\iomgr\\endpoint_pair_windows.cc " + @@ -408,6 +413,14 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\ev_poll_posix.cc " + "src\\core\\lib\\iomgr\\ev_posix.cc " + "src\\core\\lib\\iomgr\\ev_windows.cc " + + "src\\core\\lib\\iomgr\\event_engine\\closure.cc " + + "src\\core\\lib\\iomgr\\event_engine\\endpoint.cc " + + "src\\core\\lib\\iomgr\\event_engine\\iomgr.cc " + + "src\\core\\lib\\iomgr\\event_engine\\pollset.cc " + + "src\\core\\lib\\iomgr\\event_engine\\resolved_address_internal.cc " + + "src\\core\\lib\\iomgr\\event_engine\\resolver.cc " + + "src\\core\\lib\\iomgr\\event_engine\\tcp.cc " + + "src\\core\\lib\\iomgr\\event_engine\\timer.cc " + "src\\core\\lib\\iomgr\\exec_ctx.cc " + "src\\core\\lib\\iomgr\\executor.cc " + "src\\core\\lib\\iomgr\\executor\\mpmcqueue.cc " + @@ -1268,6 +1281,7 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\gprpp"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\http"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\iomgr"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\iomgr\\event_engine"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\iomgr\\executor"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\json"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\lib\\matchers"); diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 4291ea5a6ca..ae0655ad3d6 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -515,6 +515,8 @@ Pod::Spec.new do |s| 'src/core/lib/debug/stats.h', 'src/core/lib/debug/stats_data.h', 'src/core/lib/debug/trace.h', + 'src/core/lib/event_engine/endpoint_config_internal.h', + 'src/core/lib/event_engine/sockaddr.h', 'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/arena.h', 'src/core/lib/gpr/env.h', @@ -573,6 +575,12 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/ev_epollex_linux.h', 'src/core/lib/iomgr/ev_poll_posix.h', 'src/core/lib/iomgr/ev_posix.h', + 'src/core/lib/iomgr/event_engine/closure.h', + 'src/core/lib/iomgr/event_engine/endpoint.h', + 'src/core/lib/iomgr/event_engine/iomgr.h', + 'src/core/lib/iomgr/event_engine/pollset.h', + 'src/core/lib/iomgr/event_engine/promise.h', + 'src/core/lib/iomgr/event_engine/resolved_address_internal.h', 'src/core/lib/iomgr/exec_ctx.h', 'src/core/lib/iomgr/executor.h', 'src/core/lib/iomgr/executor/mpmcqueue.h', @@ -1159,6 +1167,8 @@ Pod::Spec.new do |s| 'src/core/lib/debug/stats.h', 'src/core/lib/debug/stats_data.h', 'src/core/lib/debug/trace.h', + 'src/core/lib/event_engine/endpoint_config_internal.h', + 'src/core/lib/event_engine/sockaddr.h', 'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/arena.h', 'src/core/lib/gpr/env.h', @@ -1217,6 +1227,12 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/ev_epollex_linux.h', 'src/core/lib/iomgr/ev_poll_posix.h', 'src/core/lib/iomgr/ev_posix.h', + 'src/core/lib/iomgr/event_engine/closure.h', + 'src/core/lib/iomgr/event_engine/endpoint.h', + 'src/core/lib/iomgr/event_engine/iomgr.h', + 'src/core/lib/iomgr/event_engine/pollset.h', + 'src/core/lib/iomgr/event_engine/promise.h', + 'src/core/lib/iomgr/event_engine/resolved_address_internal.h', 'src/core/lib/iomgr/exec_ctx.h', 'src/core/lib/iomgr/executor.h', 'src/core/lib/iomgr/executor/mpmcqueue.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 3a4dd54d33e..d8f07a41951 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -117,7 +117,10 @@ Pod::Spec.new do |s| 'include/grpc/byte_buffer_reader.h', 'include/grpc/census.h', 'include/grpc/compression.h', + 'include/grpc/event_engine/endpoint_config.h', + 'include/grpc/event_engine/event_engine.h', 'include/grpc/event_engine/port.h', + 'include/grpc/event_engine/slice_allocator.h', 'include/grpc/fork.h', 'include/grpc/grpc.h', 'include/grpc/grpc_posix.h', @@ -258,11 +261,13 @@ Pod::Spec.new do |s| 'src/core/ext/filters/client_channel/resolver.h', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc', @@ -837,6 +842,12 @@ Pod::Spec.new do |s| 'src/core/lib/debug/stats_data.h', 'src/core/lib/debug/trace.cc', 'src/core/lib/debug/trace.h', + 'src/core/lib/event_engine/endpoint_config.cc', + 'src/core/lib/event_engine/endpoint_config_internal.h', + 'src/core/lib/event_engine/event_engine.cc', + 'src/core/lib/event_engine/slice_allocator.cc', + 'src/core/lib/event_engine/sockaddr.cc', + 'src/core/lib/event_engine/sockaddr.h', 'src/core/lib/gpr/alloc.cc', 'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/arena.h', @@ -942,6 +953,7 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/endpoint_cfstream.cc', 'src/core/lib/iomgr/endpoint_cfstream.h', 'src/core/lib/iomgr/endpoint_pair.h', + 'src/core/lib/iomgr/endpoint_pair_event_engine.cc', 'src/core/lib/iomgr/endpoint_pair_posix.cc', 'src/core/lib/iomgr/endpoint_pair_uv.cc', 'src/core/lib/iomgr/endpoint_pair_windows.cc', @@ -961,6 +973,20 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/ev_posix.cc', 'src/core/lib/iomgr/ev_posix.h', 'src/core/lib/iomgr/ev_windows.cc', + 'src/core/lib/iomgr/event_engine/closure.cc', + 'src/core/lib/iomgr/event_engine/closure.h', + 'src/core/lib/iomgr/event_engine/endpoint.cc', + 'src/core/lib/iomgr/event_engine/endpoint.h', + 'src/core/lib/iomgr/event_engine/iomgr.cc', + 'src/core/lib/iomgr/event_engine/iomgr.h', + 'src/core/lib/iomgr/event_engine/pollset.cc', + 'src/core/lib/iomgr/event_engine/pollset.h', + 'src/core/lib/iomgr/event_engine/promise.h', + 'src/core/lib/iomgr/event_engine/resolved_address_internal.cc', + 'src/core/lib/iomgr/event_engine/resolved_address_internal.h', + 'src/core/lib/iomgr/event_engine/resolver.cc', + 'src/core/lib/iomgr/event_engine/tcp.cc', + 'src/core/lib/iomgr/event_engine/timer.cc', 'src/core/lib/iomgr/exec_ctx.cc', 'src/core/lib/iomgr/exec_ctx.h', 'src/core/lib/iomgr/executor.cc', @@ -1721,6 +1747,8 @@ Pod::Spec.new do |s| 'src/core/lib/debug/stats.h', 'src/core/lib/debug/stats_data.h', 'src/core/lib/debug/trace.h', + 'src/core/lib/event_engine/endpoint_config_internal.h', + 'src/core/lib/event_engine/sockaddr.h', 'src/core/lib/gpr/alloc.h', 'src/core/lib/gpr/arena.h', 'src/core/lib/gpr/env.h', @@ -1779,6 +1807,12 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/ev_epollex_linux.h', 'src/core/lib/iomgr/ev_poll_posix.h', 'src/core/lib/iomgr/ev_posix.h', + 'src/core/lib/iomgr/event_engine/closure.h', + 'src/core/lib/iomgr/event_engine/endpoint.h', + 'src/core/lib/iomgr/event_engine/iomgr.h', + 'src/core/lib/iomgr/event_engine/pollset.h', + 'src/core/lib/iomgr/event_engine/promise.h', + 'src/core/lib/iomgr/event_engine/resolved_address_internal.h', 'src/core/lib/iomgr/exec_ctx.h', 'src/core/lib/iomgr/executor.h', 'src/core/lib/iomgr/executor/mpmcqueue.h', diff --git a/grpc.gemspec b/grpc.gemspec index 22eeaada00f..62c4903e62c 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -53,7 +53,7 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/byte_buffer_reader.h ) s.files += %w( include/grpc/census.h ) s.files += %w( include/grpc/compression.h ) - s.files += %w( include/grpc/event_engine/channel_args.h ) + s.files += %w( include/grpc/event_engine/endpoint_config.h ) s.files += %w( include/grpc/event_engine/event_engine.h ) s.files += %w( include/grpc/event_engine/port.h ) s.files += %w( include/grpc/event_engine/slice_allocator.h ) @@ -177,11 +177,13 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/filters/client_channel/resolver.h ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h ) + s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h ) + s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc ) s.files += %w( src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc ) @@ -756,8 +758,12 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/debug/stats_data.h ) s.files += %w( src/core/lib/debug/trace.cc ) s.files += %w( src/core/lib/debug/trace.h ) + s.files += %w( src/core/lib/event_engine/endpoint_config.cc ) + s.files += %w( src/core/lib/event_engine/endpoint_config_internal.h ) + s.files += %w( src/core/lib/event_engine/event_engine.cc ) s.files += %w( src/core/lib/event_engine/slice_allocator.cc ) s.files += %w( src/core/lib/event_engine/sockaddr.cc ) + s.files += %w( src/core/lib/event_engine/sockaddr.h ) s.files += %w( src/core/lib/gpr/alloc.cc ) s.files += %w( src/core/lib/gpr/alloc.h ) s.files += %w( src/core/lib/gpr/arena.h ) @@ -863,6 +869,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/endpoint_cfstream.cc ) s.files += %w( src/core/lib/iomgr/endpoint_cfstream.h ) s.files += %w( src/core/lib/iomgr/endpoint_pair.h ) + s.files += %w( src/core/lib/iomgr/endpoint_pair_event_engine.cc ) s.files += %w( src/core/lib/iomgr/endpoint_pair_posix.cc ) s.files += %w( src/core/lib/iomgr/endpoint_pair_uv.cc ) s.files += %w( src/core/lib/iomgr/endpoint_pair_windows.cc ) @@ -882,6 +889,20 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/ev_posix.cc ) s.files += %w( src/core/lib/iomgr/ev_posix.h ) s.files += %w( src/core/lib/iomgr/ev_windows.cc ) + s.files += %w( src/core/lib/iomgr/event_engine/closure.cc ) + s.files += %w( src/core/lib/iomgr/event_engine/closure.h ) + s.files += %w( src/core/lib/iomgr/event_engine/endpoint.cc ) + s.files += %w( src/core/lib/iomgr/event_engine/endpoint.h ) + s.files += %w( src/core/lib/iomgr/event_engine/iomgr.cc ) + s.files += %w( src/core/lib/iomgr/event_engine/iomgr.h ) + s.files += %w( src/core/lib/iomgr/event_engine/pollset.cc ) + s.files += %w( src/core/lib/iomgr/event_engine/pollset.h ) + s.files += %w( src/core/lib/iomgr/event_engine/promise.h ) + s.files += %w( src/core/lib/iomgr/event_engine/resolved_address_internal.cc ) + s.files += %w( src/core/lib/iomgr/event_engine/resolved_address_internal.h ) + s.files += %w( src/core/lib/iomgr/event_engine/resolver.cc ) + s.files += %w( src/core/lib/iomgr/event_engine/tcp.cc ) + s.files += %w( src/core/lib/iomgr/event_engine/timer.cc ) s.files += %w( src/core/lib/iomgr/exec_ctx.cc ) s.files += %w( src/core/lib/iomgr/exec_ctx.h ) s.files += %w( src/core/lib/iomgr/executor.cc ) diff --git a/grpc.gyp b/grpc.gyp index 4ba61b2d88b..6c852682c9f 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -505,10 +505,12 @@ 'src/core/ext/filters/client_channel/proxy_mapper_registry.cc', 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc', @@ -789,6 +791,8 @@ 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/debug/trace.cc', + 'src/core/lib/event_engine/endpoint_config.cc', + 'src/core/lib/event_engine/event_engine.cc', 'src/core/lib/event_engine/slice_allocator.cc', 'src/core/lib/event_engine/sockaddr.cc', 'src/core/lib/http/format_request.cc', @@ -802,6 +806,7 @@ 'src/core/lib/iomgr/dualstack_socket_posix.cc', 'src/core/lib/iomgr/endpoint.cc', 'src/core/lib/iomgr/endpoint_cfstream.cc', + 'src/core/lib/iomgr/endpoint_pair_event_engine.cc', 'src/core/lib/iomgr/endpoint_pair_posix.cc', 'src/core/lib/iomgr/endpoint_pair_uv.cc', 'src/core/lib/iomgr/endpoint_pair_windows.cc', @@ -813,6 +818,14 @@ 'src/core/lib/iomgr/ev_poll_posix.cc', 'src/core/lib/iomgr/ev_posix.cc', 'src/core/lib/iomgr/ev_windows.cc', + 'src/core/lib/iomgr/event_engine/closure.cc', + 'src/core/lib/iomgr/event_engine/endpoint.cc', + 'src/core/lib/iomgr/event_engine/iomgr.cc', + 'src/core/lib/iomgr/event_engine/pollset.cc', + 'src/core/lib/iomgr/event_engine/resolved_address_internal.cc', + 'src/core/lib/iomgr/event_engine/resolver.cc', + 'src/core/lib/iomgr/event_engine/tcp.cc', + 'src/core/lib/iomgr/event_engine/timer.cc', 'src/core/lib/iomgr/exec_ctx.cc', 'src/core/lib/iomgr/executor.cc', 'src/core/lib/iomgr/executor/mpmcqueue.cc', @@ -1100,6 +1113,7 @@ 'dependencies': [ 'absl/container:flat_hash_map', 'absl/container:inlined_vector', + 'absl/functional:bind_front', 'absl/status:statusor', 'gpr', 'address_sorting', @@ -1138,10 +1152,12 @@ 'src/core/ext/filters/client_channel/proxy_mapper_registry.cc', 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc', @@ -1235,6 +1251,8 @@ 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/debug/trace.cc', + 'src/core/lib/event_engine/endpoint_config.cc', + 'src/core/lib/event_engine/event_engine.cc', 'src/core/lib/event_engine/slice_allocator.cc', 'src/core/lib/event_engine/sockaddr.cc', 'src/core/lib/http/format_request.cc', @@ -1247,6 +1265,7 @@ 'src/core/lib/iomgr/dualstack_socket_posix.cc', 'src/core/lib/iomgr/endpoint.cc', 'src/core/lib/iomgr/endpoint_cfstream.cc', + 'src/core/lib/iomgr/endpoint_pair_event_engine.cc', 'src/core/lib/iomgr/endpoint_pair_posix.cc', 'src/core/lib/iomgr/endpoint_pair_uv.cc', 'src/core/lib/iomgr/endpoint_pair_windows.cc', @@ -1258,6 +1277,14 @@ 'src/core/lib/iomgr/ev_poll_posix.cc', 'src/core/lib/iomgr/ev_posix.cc', 'src/core/lib/iomgr/ev_windows.cc', + 'src/core/lib/iomgr/event_engine/closure.cc', + 'src/core/lib/iomgr/event_engine/endpoint.cc', + 'src/core/lib/iomgr/event_engine/iomgr.cc', + 'src/core/lib/iomgr/event_engine/pollset.cc', + 'src/core/lib/iomgr/event_engine/resolved_address_internal.cc', + 'src/core/lib/iomgr/event_engine/resolver.cc', + 'src/core/lib/iomgr/event_engine/tcp.cc', + 'src/core/lib/iomgr/event_engine/timer.cc', 'src/core/lib/iomgr/exec_ctx.cc', 'src/core/lib/iomgr/executor.cc', 'src/core/lib/iomgr/executor/mpmcqueue.cc', diff --git a/include/grpc/event_engine/endpoint_config.h b/include/grpc/event_engine/endpoint_config.h new file mode 100644 index 00000000000..ea1e172f786 --- /dev/null +++ b/include/grpc/event_engine/endpoint_config.h @@ -0,0 +1,48 @@ +// 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_EVENT_ENGINE_ENDPOINT_CONFIG_H +#define GRPC_EVENT_ENGINE_ENDPOINT_CONFIG_H + +#include + +#include + +#include "absl/strings/string_view.h" +#include "absl/types/variant.h" + +namespace grpc_event_engine { +namespace experimental { + +/// A set of parameters used to configure an endpoint, either when initiating a +/// new connection on the client side or when listening for incoming connections +/// on the server side. An EndpointConfig contains a set of zero or more +/// Settings. Each setting has a unique name, which can be used to fetch that +/// Setting via the Get() method. Each Setting has a value, which can be an +/// integer, string, or void pointer. Each EE impl should define the set of +/// Settings that it supports being passed into it, along with the corresponding +/// type. +class EndpointConfig { + public: + virtual ~EndpointConfig() = default; + using Setting = absl::variant; + /// Returns an EndpointConfig Setting. If there is no Setting associated with + /// \a key in the EndpointConfig, an \a absl::monostate type will be + /// returned. Caller does not take ownership of resulting value. + virtual Setting Get(absl::string_view key) const = 0; +}; + +} // namespace experimental +} // namespace grpc_event_engine + +#endif // GRPC_EVENT_ENGINE_ENDPOINT_CONFIG_H diff --git a/include/grpc/event_engine/event_engine.h b/include/grpc/event_engine/event_engine.h index cdb59662f9f..af932aeb431 100644 --- a/include/grpc/event_engine/event_engine.h +++ b/include/grpc/event_engine/event_engine.h @@ -23,13 +23,11 @@ #include "absl/status/statusor.h" #include "absl/time/time.h" -#include "grpc/event_engine/channel_args.h" +#include "grpc/event_engine/endpoint_config.h" #include "grpc/event_engine/port.h" #include "grpc/event_engine/slice_allocator.h" -// TODO(hork): explicitly define lifetimes and ownership of all objects. // TODO(hork): Define the Endpoint::Write metrics collection system - namespace grpc_event_engine { namespace experimental { @@ -96,12 +94,14 @@ class EventEngine { static constexpr socklen_t MAX_SIZE_BYTES = 128; ResolvedAddress(const sockaddr* address, socklen_t size); + ResolvedAddress() = default; + ResolvedAddress(const ResolvedAddress&) = default; const struct sockaddr* address() const; socklen_t size() const; private: char address_[MAX_SIZE_BYTES]; - socklen_t size_; + socklen_t size_ = 0; }; /// An Endpoint represents one end of a connection between a gRPC client and @@ -144,9 +144,6 @@ class EventEngine { /// on endpoint shutdown. virtual void Write(Callback on_writable, SliceBuffer* data, absl::Time deadline) = 0; - // TODO(hork): define status codes for the callback - // TODO(hork): define cleanup operations, lifetimes, responsibilities. - virtual void Close(Callback on_close) = 0; /// These methods return an address in the format described in DNSResolver. /// The returned values are owned by the Endpoint and are expected to remain /// valid for the life of the Endpoint. @@ -199,7 +196,7 @@ class EventEngine { /// for Endpoint construction. virtual absl::StatusOr> CreateListener( Listener::AcceptCallback on_accept, Callback on_shutdown, - const ChannelArgs& args, + const EndpointConfig& args, SliceAllocatorFactory slice_allocator_factory) = 0; /// Creates a client network connection to a remote network listener. /// @@ -216,7 +213,7 @@ class EventEngine { /// SliceAllocator API for more information. virtual absl::Status Connect(OnConnectCallback on_connect, const ResolvedAddress& addr, - const ChannelArgs& args, + const EndpointConfig& args, SliceAllocator slice_allocator, absl::Time deadline) = 0; @@ -280,13 +277,16 @@ class EventEngine { virtual ~EventEngine() = default; + // TODO(nnoble): consider whether we can remove this method before we + // de-experimentalize this API. + virtual bool IsWorkerThread() = 0; + // TODO(hork): define return status codes /// Retrieves an instance of a DNSResolver. virtual absl::StatusOr> GetDNSResolver() = 0; /// Intended for future expansion of Task run functionality. struct RunOptions {}; - // TODO(hork): consider recommendation to make TaskHandle an output arg /// Run a callback as soon as possible. /// /// The \a fn callback's \a status argument is used to indicate whether it was @@ -324,11 +324,9 @@ class EventEngine { virtual void Shutdown(Callback on_shutdown_complete) = 0; }; -/// Lazily instantiate and return a default global EventEngine instance if no -/// custom instance is provided. If a custom EventEngine is provided for every -/// channel/server via ChannelArgs, this method should never be called, and the -/// default instance will never be instantiated. -std::shared_ptr GetDefaultEventEngine(); +// TODO(hork): finalize the API and document it. We need to firm up the story +// around user-provided EventEngines. +std::shared_ptr DefaultEventEngineFactory(); } // namespace experimental } // namespace grpc_event_engine diff --git a/include/grpc/event_engine/port.h b/include/grpc/event_engine/port.h index c24b8f90245..d54e65e630c 100644 --- a/include/grpc/event_engine/port.h +++ b/include/grpc/event_engine/port.h @@ -24,9 +24,11 @@ defined(GPR_AIX) || defined(GPR_NACL) || defined(GPR_FUCHSIA) || \ defined(GRPC_POSIX_SOCKET) #define GRPC_EVENT_ENGINE_POSIX +#include #include #include #include +#include #elif defined(GPR_WINDOWS) #include #include diff --git a/include/grpc/event_engine/slice_allocator.h b/include/grpc/event_engine/slice_allocator.h index 4370cd519ad..f7525411176 100644 --- a/include/grpc/event_engine/slice_allocator.h +++ b/include/grpc/event_engine/slice_allocator.h @@ -23,12 +23,17 @@ // forward-declaring an internal struct, not used publicly. struct grpc_resource_quota; struct grpc_resource_user; +struct grpc_slice_buffer; namespace grpc_event_engine { namespace experimental { -// TODO(nnoble): forward declared here, needs definition. -class SliceBuffer; +// TODO(hork): stubbed out here, to be replaced with a real version in next PR. +class SliceBuffer { + public: + SliceBuffer() { abort(); } + explicit SliceBuffer(grpc_slice_buffer*) { abort(); } +}; class SliceAllocator { public: @@ -38,15 +43,20 @@ class SliceAllocator { SliceAllocator(SliceAllocator& other) = delete; SliceAllocator& operator=(const SliceAllocator& other) = delete; // Moveable - SliceAllocator(SliceAllocator&& other) = default; - SliceAllocator& operator=(SliceAllocator&& other) = default; + SliceAllocator(SliceAllocator&& other) noexcept; + SliceAllocator& operator=(SliceAllocator&& other) noexcept; ~SliceAllocator(); using AllocateCallback = std::function; - // TODO(hork): explain what happens under resource exhaustion. /// Requests \a size bytes from gRPC, and populates \a dest with the allocated /// slices. Ownership of the \a SliceBuffer is not transferred. + /// + /// gRPC provides a ResourceQuota system to cap the amount of memory used by + /// the library. When a memory limit has been reached, slice allocation is + /// interrupted to attempt to reclaim memory from participating gRPC + /// internals. When there is sufficient memory available, slice allocation + /// proceeds as normal. absl::Status Allocate(size_t size, SliceBuffer* dest, SliceAllocator::AllocateCallback cb); @@ -62,8 +72,8 @@ class SliceAllocatorFactory { SliceAllocatorFactory(SliceAllocatorFactory& other) = delete; SliceAllocatorFactory& operator=(const SliceAllocatorFactory& other) = delete; // Moveable - SliceAllocatorFactory(SliceAllocatorFactory&& other) = default; - SliceAllocatorFactory& operator=(SliceAllocatorFactory&& other) = default; + SliceAllocatorFactory(SliceAllocatorFactory&& other) noexcept; + SliceAllocatorFactory& operator=(SliceAllocatorFactory&& other) noexcept; ~SliceAllocatorFactory(); /// On Endpoint creation, call \a CreateSliceAllocator with the name of the diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 613eff040ae..8a0d84ddb70 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -664,6 +664,21 @@ typedef unsigned __int64 uint64_t; #define __STDC_FORMAT_MACROS #endif +/* Selectively enable EventEngine on specific platforms. This default can be + * overridden using the GRPC_USE_EVENT_ENGINE compiler flag. + */ +#ifndef GRPC_USE_EVENT_ENGINE +/* Not enabled by default on any platforms yet. (2021.06) */ +#elif GRPC_USE_EVENT_ENGINE == 0 +/* Building with `-DGRPC_USE_EVENT_ENGINE=0` will override the default. */ +#undef GRPC_USE_EVENT_ENGINE +#endif /* GRPC_USE_EVENT_ENGINE */ + +#ifdef GRPC_USE_EVENT_ENGINE +#undef GPR_SUPPORT_CHANNELS_FROM_FD +#define GRPC_ARES 0 +#endif /* GRPC_USE_EVENT_ENGINE */ + #define GRPC_CALLBACK_API_NONEXPERIMENTAL #endif /* GRPC_IMPL_CODEGEN_PORT_PLATFORM_H */ diff --git a/package.xml b/package.xml index 887ef5d9e30..68eea73e477 100644 --- a/package.xml +++ b/package.xml @@ -33,7 +33,7 @@ - + @@ -157,11 +157,13 @@ + + @@ -736,8 +738,12 @@ + + + + @@ -843,6 +849,7 @@ + @@ -862,6 +869,20 @@ + + + + + + + + + + + + + + diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc new file mode 100644 index 00000000000..45c1464808c --- /dev/null +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc @@ -0,0 +1,31 @@ +// 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 + +#include "src/core/lib/iomgr/port.h" +#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 NewGrpcPolledFdFactory( + std::shared_ptr /* work_serializer */) { + return nullptr; +} + +} // namespace grpc_core + +#endif /* GRPC_ARES == 1 && defined(GRPC_USE_EVENT_ENGINE) */ diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc new file mode 100644 index 00000000000..fdd4e00c553 --- /dev/null +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc @@ -0,0 +1,28 @@ +// 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 + +#include "src/core/lib/iomgr/port.h" +#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) */ diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc index 4700093e310..4ac3a247e11 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc @@ -82,7 +82,8 @@ grpc_channel* grpc_insecure_channel_create_from_fd( #else // !GPR_SUPPORT_CHANNELS_FROM_FD grpc_channel* grpc_insecure_channel_create_from_fd( - const char* target, int fd, const grpc_channel_args* args) { + const char* /* target */, int /* fd */, + const grpc_channel_args* /* args */) { GPR_ASSERT(0); return nullptr; } diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc index fd57939f21b..836ade292c8 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc @@ -68,8 +68,9 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server* server, #else // !GPR_SUPPORT_CHANNELS_FROM_FD -void grpc_server_add_insecure_channel_from_fd(grpc_server* server, - void* reserved, int fd) { +void grpc_server_add_insecure_channel_from_fd(grpc_server* /* server */, + void* /* reserved */, + int /* fd */) { GPR_ASSERT(0); } diff --git a/src/core/lib/address_utils/sockaddr_utils.cc b/src/core/lib/address_utils/sockaddr_utils.cc index 888cd1aa09a..8bda08130b6 100644 --- a/src/core/lib/address_utils/sockaddr_utils.cc +++ b/src/core/lib/address_utils/sockaddr_utils.cc @@ -29,11 +29,13 @@ #include "absl/strings/str_cat.h" #include "absl/strings/str_format.h" +#include #include #include #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/host_port.h" +#include "src/core/lib/iomgr/event_engine/resolved_address_internal.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/socket_utils.h" #include "src/core/lib/iomgr/unix_sockets_posix.h" @@ -397,3 +399,14 @@ bool grpc_sockaddr_match_subnet(const grpc_resolved_address* address, } return false; } + +namespace grpc_event_engine { +namespace experimental { + +std::string ResolvedAddressToURI(const EventEngine::ResolvedAddress& addr) { + auto gra = CreateGRPCResolvedAddress(addr); + return grpc_sockaddr_to_uri(&gra); +} + +} // namespace experimental +} // namespace grpc_event_engine diff --git a/src/core/lib/address_utils/sockaddr_utils.h b/src/core/lib/address_utils/sockaddr_utils.h index e8bf79fd3fe..cf29fe7035c 100644 --- a/src/core/lib/address_utils/sockaddr_utils.h +++ b/src/core/lib/address_utils/sockaddr_utils.h @@ -23,6 +23,8 @@ #include +#include + #include "src/core/lib/iomgr/resolve_address.h" /* Returns true if addr is an IPv4-mapped IPv6 address within the @@ -97,4 +99,12 @@ bool grpc_sockaddr_match_subnet(const grpc_resolved_address* address, const grpc_resolved_address* subnet_address, uint32_t mask_bits); +namespace grpc_event_engine { +namespace experimental { + +std::string ResolvedAddressToURI(const EventEngine::ResolvedAddress& addr); + +} // namespace experimental +} // namespace grpc_event_engine + #endif /* GRPC_CORE_LIB_ADDRESS_UTILS_SOCKADDR_UTILS_H */ diff --git a/src/core/lib/event_engine/endpoint_config.cc b/src/core/lib/event_engine/endpoint_config.cc new file mode 100644 index 00000000000..78d28ecbb48 --- /dev/null +++ b/src/core/lib/event_engine/endpoint_config.cc @@ -0,0 +1,46 @@ +// 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 + +#include + +#include +#include + +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/event_engine/endpoint_config_internal.h" +#include "src/core/lib/gpr/useful.h" + +namespace grpc_event_engine { +namespace experimental { + +EndpointConfig::Setting ChannelArgsEndpointConfig::Get( + absl::string_view key) const { + const grpc_arg* arg = grpc_channel_args_find(args_, std::string(key).c_str()); + if (arg == nullptr) { + return absl::monostate(); + } + switch (arg->type) { + case GRPC_ARG_STRING: + return absl::string_view(arg->value.string); + case GRPC_ARG_INTEGER: + return arg->value.integer; + case GRPC_ARG_POINTER: + return arg->value.pointer.p; + } + GPR_UNREACHABLE_CODE(return absl::monostate()); +} + +} // namespace experimental +} // namespace grpc_event_engine diff --git a/src/core/lib/event_engine/endpoint_config_internal.h b/src/core/lib/event_engine/endpoint_config_internal.h new file mode 100644 index 00000000000..1f39ac4b8aa --- /dev/null +++ b/src/core/lib/event_engine/endpoint_config_internal.h @@ -0,0 +1,42 @@ +// 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_ENDPOINT_CONFIG_INTERNAL_H +#define GRPC_CORE_LIB_EVENT_ENGINE_ENDPOINT_CONFIG_INTERNAL_H + +#include + +#include + +#include "src/core/lib/channel/channel_args.h" + +namespace grpc_event_engine { +namespace experimental { + +/// A readonly \a EndpointConfig based on grpc_channel_args. This class does not +/// take ownership of the grpc_endpoint_args*, and instances of this class +/// should not be used after the underlying args are destroyed. +class ChannelArgsEndpointConfig : public EndpointConfig { + public: + explicit ChannelArgsEndpointConfig(const grpc_channel_args* args) + : args_(args) {} + Setting Get(absl::string_view key) const override; + + private: + const grpc_channel_args* args_; +}; + +} // namespace experimental +} // namespace grpc_event_engine + +#endif // GRPC_CORE_LIB_EVENT_ENGINE_ENDPOINT_CONFIG_INTERNAL_H diff --git a/src/core/lib/event_engine/event_engine.cc b/src/core/lib/event_engine/event_engine.cc new file mode 100644 index 00000000000..cfc270c07f1 --- /dev/null +++ b/src/core/lib/event_engine/event_engine.cc @@ -0,0 +1,50 @@ +// 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 + +#include +#include +#include +#include +#include + +#include "absl/strings/str_format.h" +#include "absl/strings/str_join.h" + +#include "src/core/lib/event_engine/sockaddr.h" + +namespace grpc_event_engine { +namespace experimental { + +EventEngine::ResolvedAddress::ResolvedAddress(const sockaddr* address, + socklen_t size) + : size_(size) { + GPR_ASSERT(size <= sizeof(address_)); + memcpy(&address_, address, size); +} + +const struct sockaddr* EventEngine::ResolvedAddress::address() const { + return reinterpret_cast(address_); +} + +socklen_t EventEngine::ResolvedAddress::size() const { return size_; } + +std::shared_ptr +DefaultEventEngineFactory() { + // TODO(nnoble): delete when uv-ee is merged + abort(); +} + +} // namespace experimental +} // namespace grpc_event_engine diff --git a/src/core/lib/event_engine/slice_allocator.cc b/src/core/lib/event_engine/slice_allocator.cc index 3ea615acdd7..ccf9facb490 100644 --- a/src/core/lib/event_engine/slice_allocator.cc +++ b/src/core/lib/event_engine/slice_allocator.cc @@ -29,11 +29,26 @@ SliceAllocator::SliceAllocator(grpc_resource_user* user) grpc_resource_user_ref(resource_user_); }; -SliceAllocator::~SliceAllocator() { grpc_resource_user_unref(resource_user_); }; +SliceAllocator::~SliceAllocator() { + if (resource_user_ != nullptr) { + grpc_resource_user_unref(resource_user_); + } +}; + +SliceAllocator::SliceAllocator(SliceAllocator&& other) noexcept + : resource_user_(other.resource_user_) { + other.resource_user_ = nullptr; +} + +SliceAllocator& SliceAllocator::operator=(SliceAllocator&& other) noexcept { + resource_user_ = other.resource_user_; + other.resource_user_ = nullptr; + return *this; +} absl::Status SliceAllocator::Allocate(size_t size, SliceBuffer* dest, SliceAllocator::AllocateCallback cb) { - // TODO(hork): implement + // TODO(hork): merge the implementation from the uv-ee branch. (void)size; (void)dest; (void)cb; @@ -46,7 +61,22 @@ SliceAllocatorFactory::SliceAllocatorFactory(grpc_resource_quota* quota) }; SliceAllocatorFactory::~SliceAllocatorFactory() { - grpc_resource_quota_unref_internal(resource_quota_); + if (resource_quota_ != nullptr) { + grpc_resource_quota_unref_internal(resource_quota_); + } +} + +SliceAllocatorFactory::SliceAllocatorFactory( + SliceAllocatorFactory&& other) noexcept + : resource_quota_(other.resource_quota_) { + other.resource_quota_ = nullptr; +} + +SliceAllocatorFactory& SliceAllocatorFactory::operator=( + SliceAllocatorFactory&& other) noexcept { + resource_quota_ = other.resource_quota_; + other.resource_quota_ = nullptr; + return *this; } SliceAllocator SliceAllocatorFactory::CreateSliceAllocator( diff --git a/src/core/lib/event_engine/sockaddr.cc b/src/core/lib/event_engine/sockaddr.cc index 811d351936a..9a784bd763d 100644 --- a/src/core/lib/event_engine/sockaddr.cc +++ b/src/core/lib/event_engine/sockaddr.cc @@ -13,26 +13,28 @@ // limitations under the License. #include +#ifdef GRPC_USE_EVENT_ENGINE #include #include "grpc/event_engine/event_engine.h" #include "grpc/event_engine/port.h" #include "grpc/support/log.h" -namespace grpc_event_engine { -namespace experimental { +uint16_t grpc_htons(uint16_t hostshort) { return htons(hostshort); } -EventEngine::ResolvedAddress::ResolvedAddress(const sockaddr* address, - socklen_t size) { - GPR_ASSERT(size <= sizeof(address_)); - memcpy(&address_, address, size); -} +uint16_t grpc_ntohs(uint16_t netshort) { return ntohs(netshort); } + +uint32_t grpc_htonl(uint32_t hostlong) { return htonl(hostlong); } -const struct sockaddr* EventEngine::ResolvedAddress::address() const { - return reinterpret_cast(address_); +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); } -socklen_t EventEngine::ResolvedAddress::size() const { return size_; } +const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { + inet_ntop(af, src, dst, size); + return dst; +} -} // namespace experimental -} // namespace grpc_event_engine +#endif // GRPC_USE_EVENT_ENGINE diff --git a/src/core/lib/event_engine/sockaddr.h b/src/core/lib/event_engine/sockaddr.h new file mode 100644 index 00000000000..23b83dde567 --- /dev/null +++ b/src/core/lib/event_engine/sockaddr.h @@ -0,0 +1,44 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include + +#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 diff --git a/src/core/lib/iomgr/endpoint_pair_event_engine.cc b/src/core/lib/iomgr/endpoint_pair_event_engine.cc new file mode 100644 index 00000000000..a0062e1abc2 --- /dev/null +++ b/src/core/lib/iomgr/endpoint_pair_event_engine.cc @@ -0,0 +1,33 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include "src/core/lib/iomgr/port.h" + +#include + +#include + +#include "src/core/lib/iomgr/endpoint_pair.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 diff --git a/src/core/lib/iomgr/event_engine/closure.cc b/src/core/lib/iomgr/event_engine/closure.cc new file mode 100644 index 00000000000..d9d0394d177 --- /dev/null +++ b/src/core/lib/iomgr/event_engine/closure.cc @@ -0,0 +1,54 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include + +#include "src/core/lib/iomgr/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 { + +EventEngine::Callback GrpcClosureToCallback(grpc_closure* closure, + grpc_error_handle error) { + return [closure, error](absl::Status status) { + grpc_error_handle new_error = + grpc_error_add_child(error, absl_status_to_grpc_error(status)); +#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, new_error); +#ifndef NDEBUG + if (grpc_trace_closure.enabled()) { + gpr_log(GPR_DEBUG, "EventEngine: closure %p finished", closure); + } +#endif + GRPC_ERROR_UNREF(error); + grpc_pollset_ee_broadcast_event(); + }; +} + +} // namespace experimental +} // namespace grpc_event_engine +#endif // GRPC_USE_EVENT_ENGINE diff --git a/src/core/lib/iomgr/event_engine/closure.h b/src/core/lib/iomgr/event_engine/closure.h new file mode 100644 index 00000000000..f1b4f7617cf --- /dev/null +++ b/src/core/lib/iomgr/event_engine/closure.h @@ -0,0 +1,33 @@ +// 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 + +#include + +#include "src/core/lib/iomgr/closure.h" +#include "src/core/lib/iomgr/error.h" + +namespace grpc_event_engine { +namespace experimental { + +EventEngine::Callback GrpcClosureToCallback(grpc_closure* closure, + grpc_error_handle error); + +} // namespace experimental +} // namespace grpc_event_engine + +#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_CLOSURE_H diff --git a/src/core/lib/iomgr/event_engine/endpoint.cc b/src/core/lib/iomgr/event_engine/endpoint.cc new file mode 100644 index 00000000000..ddd9566cdc0 --- /dev/null +++ b/src/core/lib/iomgr/event_engine/endpoint.cc @@ -0,0 +1,194 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include "src/core/lib/iomgr/event_engine/endpoint.h" + +#include +#include +#include +#include +#include "absl/strings/string_view.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/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 */) { + auto* eeep = reinterpret_cast(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(&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, absl::InfiniteFuture()); +} + +void endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* slices, + grpc_closure* cb, void* arg) { + // TODO(hork): adapt arg to some metrics collection mechanism. + (void)arg; + auto* eeep = reinterpret_cast(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(&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, absl::InfiniteFuture()); +} +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* why) { + auto* eeep = reinterpret_cast(ep); + if (GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace)) { + const char* str = grpc_error_string(why); + gpr_log(GPR_INFO, "TCP Endpoint %p shutdown why=%s", eeep->endpoint.get(), + str); + } + grpc_resource_user_shutdown(eeep->ru); + eeep->endpoint.reset(); +} + +void endpoint_destroy(grpc_endpoint* ep) { + auto* eeep = reinterpret_cast(ep); + grpc_resource_user_unref(eeep->ru); + delete eeep; +} + +grpc_resource_user* endpoint_get_resource_user(grpc_endpoint* ep) { + auto* eeep = reinterpret_cast(ep); + return eeep->ru; +} + +absl::string_view endpoint_get_peer(grpc_endpoint* ep) { + auto* eeep = reinterpret_cast(ep); + if (eeep->endpoint == nullptr) { + return ""; + } + if (eeep->peer_address.empty()) { + const EventEngine::ResolvedAddress* addr = eeep->endpoint->GetPeerAddress(); + GPR_ASSERT(addr != nullptr); + eeep->peer_address = ResolvedAddressToURI(*addr); + } + return eeep->peer_address; +} + +absl::string_view endpoint_get_local_address(grpc_endpoint* ep) { + auto* eeep = reinterpret_cast(ep); + if (eeep->endpoint == nullptr) { + return ""; + } + if (eeep->local_address.empty()) { + const EventEngine::ResolvedAddress* addr = + eeep->endpoint->GetLocalAddress(); + GPR_ASSERT(addr != nullptr); + eeep->local_address = ResolvedAddressToURI(*addr); + } + 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_resource_user, + 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 ee_endpoint) { + auto endpoint = new grpc_event_engine_endpoint; + endpoint->base.vtable = &grpc_event_engine_endpoint_vtable; + // TODO(hork): populate endpoint->ru from the uvEngine's subclass + 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; + grpc_resource_quota* resource_quota = + grpc_channel_args_find_pointer( + channel_args, GRPC_ARG_RESOURCE_QUOTA); + if (resource_quota != nullptr) { + grpc_resource_quota_ref_internal(resource_quota); + } else { + resource_quota = grpc_resource_quota_create(nullptr); + } + endpoint->ru = grpc_resource_user_create(resource_quota, + std::string(peer_address).c_str()); + grpc_resource_quota_unref_internal(resource_quota); + return &endpoint->base; +} + +#endif // GRPC_USE_EVENT_ENGINE diff --git a/src/core/lib/iomgr/event_engine/endpoint.h b/src/core/lib/iomgr/event_engine/endpoint.h new file mode 100644 index 00000000000..e4a729d8a48 --- /dev/null +++ b/src/core/lib/iomgr/event_engine/endpoint.h @@ -0,0 +1,53 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include + +#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 + endpoint; + std::string peer_address; + std::string local_address; + grpc_resource_user* ru = nullptr; + 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 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. +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 diff --git a/src/core/lib/iomgr/event_engine/iomgr.cc b/src/core/lib/iomgr/event_engine/iomgr.cc new file mode 100644 index 00000000000..eb067b1eb4c --- /dev/null +++ b/src/core/lib/iomgr/event_engine/iomgr.cc @@ -0,0 +1,105 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include "src/core/lib/iomgr/event_engine/iomgr.h" + +#include + +#include "src/core/lib/debug/trace.h" +#include "src/core/lib/iomgr/closure.h" +#include "src/core/lib/iomgr/event_engine/promise.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; +extern grpc_address_resolver_vtable grpc_event_engine_resolver_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::DefaultEventEngineFactory; +using ::grpc_event_engine::experimental::EventEngine; +using ::grpc_event_engine::experimental::Promise; + +// Note: This is a pointer to a shared_ptr, so it's trivially destructible. +std::shared_ptr* g_event_engine; + +void iomgr_platform_init(void) { + g_event_engine = + new std::shared_ptr(DefaultEventEngineFactory()); +} + +void iomgr_platform_flush(void) {} + +void iomgr_platform_shutdown(void) { + Promise shutdown_status_promise; + (*g_event_engine)->Shutdown([&shutdown_status_promise](absl::Status status) { + shutdown_status_promise.Set(std::move(status)); + }); + auto shutdown_status = shutdown_status_promise.Get(); + GPR_ASSERT(shutdown_status.ok()); + delete g_event_engine; + g_event_engine = nullptr; +} + +void iomgr_platform_shutdown_background_closure(void) {} + +bool iomgr_platform_is_any_background_poller_thread(void) { + return (*g_event_engine)->IsWorkerThread(); +} + +bool iomgr_platform_add_closure_to_background_poller( + grpc_closure* /* closure */, grpc_error* /* 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_set_resolver_impl(&grpc_event_engine_resolver_vtable); + grpc_set_iomgr_platform_vtable(&vtable); +} + +bool grpc_iomgr_run_in_background() { return false; } + +grpc_event_engine::experimental::EventEngine* grpc_iomgr_event_engine() { + return g_event_engine->get(); +} + +#endif // GRPC_USE_EVENT_ENGINE diff --git a/src/core/lib/iomgr/event_engine/iomgr.h b/src/core/lib/iomgr/event_engine/iomgr.h new file mode 100644 index 00000000000..96e97e59aee --- /dev/null +++ b/src/core/lib/iomgr/event_engine/iomgr.h @@ -0,0 +1,24 @@ +// 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_IOMGR_H +#define GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_IOMGR_H +#include + +#include + +// This can be called anywhere in the EE-based iomgr impl where we need to +// access the global EE instance. +grpc_event_engine::experimental::EventEngine* grpc_iomgr_event_engine(); + +#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_IOMGR_H diff --git a/src/core/lib/iomgr/event_engine/pollset.cc b/src/core/lib/iomgr/event_engine/pollset.cc new file mode 100644 index 00000000000..e635539a9ca --- /dev/null +++ b/src/core/lib/iomgr/event_engine/pollset.cc @@ -0,0 +1,87 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include + +#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* pollset_work(grpc_pollset* pollset, grpc_pollset_worker** worker, + grpc_millis deadline) { + (void)worker; + gpr_cv_wait(&g_cv, &g_mu, + grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME)); + return GRPC_ERROR_NONE; +} +grpc_error* 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 diff --git a/include/grpc/event_engine/channel_args.h b/src/core/lib/iomgr/event_engine/pollset.h similarity index 68% rename from include/grpc/event_engine/channel_args.h rename to src/core/lib/iomgr/event_engine/pollset.h index d809b1fb9f5..94a46c0a723 100644 --- a/include/grpc/event_engine/channel_args.h +++ b/src/core/lib/iomgr/event_engine/pollset.h @@ -11,18 +11,15 @@ // 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_EVENT_ENGINE_CHANNEL_ARGS_H -#define GRPC_EVENT_ENGINE_CHANNEL_ARGS_H +#ifndef GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_POLLSET_H +#define GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_POLLSET_H #include -namespace grpc_event_engine { -namespace experimental { +#ifdef GRPC_USE_EVENT_ENGINE -// TODO(hork): define -class ChannelArgs; +/// Signals pollset_work that some work has been done. +void grpc_pollset_ee_broadcast_event(); -} // namespace experimental -} // namespace grpc_event_engine - -#endif // GRPC_EVENT_ENGINE_CHANNEL_ARGS_H +#endif +#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_POLLSET_H diff --git a/src/core/lib/iomgr/event_engine/promise.h b/src/core/lib/iomgr/event_engine/promise.h new file mode 100644 index 00000000000..155534b8664 --- /dev/null +++ b/src/core/lib/iomgr/event_engine/promise.h @@ -0,0 +1,51 @@ +// 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 + +#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 +class Promise { + public: + T& Get() { + absl::MutexLock lock(&mu_); + cv_.Wait(&mu_); + return val_; + } + void Set(T&& val) { + absl::MutexLock lock(&mu_); + val_ = std::move(val); + cv_.Signal(); + } + + private: + absl::Mutex mu_; + absl::CondVar cv_; + T val_; +}; + +} // namespace experimental +} // namespace grpc_event_engine + +#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_PROMISE_H diff --git a/src/core/lib/iomgr/event_engine/resolved_address_internal.cc b/src/core/lib/iomgr/event_engine/resolved_address_internal.cc new file mode 100644 index 00000000000..561d91ed011 --- /dev/null +++ b/src/core/lib/iomgr/event_engine/resolved_address_internal.cc @@ -0,0 +1,41 @@ +// 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 + +#include "src/core/lib/iomgr/event_engine/resolved_address_internal.h" + +#include + +#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(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; +} + +} // namespace experimental +} // namespace grpc_event_engine diff --git a/src/core/lib/iomgr/event_engine/resolved_address_internal.h b/src/core/lib/iomgr/event_engine/resolved_address_internal.h new file mode 100644 index 00000000000..ae794805250 --- /dev/null +++ b/src/core/lib/iomgr/event_engine/resolved_address_internal.h @@ -0,0 +1,35 @@ +// 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 + +#include + +#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); + +} // namespace experimental +} // namespace grpc_event_engine + +#endif // GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_RESOLVED_ADDRESS_INTERNAL_H diff --git a/src/core/lib/iomgr/event_engine/resolver.cc b/src/core/lib/iomgr/event_engine/resolver.cc new file mode 100644 index 00000000000..36713026820 --- /dev/null +++ b/src/core/lib/iomgr/event_engine/resolver.cc @@ -0,0 +1,110 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include +#include "absl/functional/bind_front.h" + +#include "src/core/lib/address_utils/sockaddr_utils.h" +#include "src/core/lib/gprpp/sync.h" +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/event_engine/iomgr.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/resolve_address.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 { +using ::grpc_event_engine::experimental::CreateGRPCResolvedAddress; +using ::grpc_event_engine::experimental::EventEngine; +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 DnsRequest { + public: + DnsRequest(std::unique_ptr dns_resolver, + absl::string_view address, absl::string_view default_port, + grpc_closure* on_done, grpc_resolved_addresses** addresses) + : dns_resolver_(std::move(dns_resolver)), + cb_(on_done), + addresses_(addresses) { + dns_resolver_->LookupHostname( + absl::bind_front(&DnsRequest::OnLookupComplete, this), address, + default_port, absl::InfiniteFuture()); + } + + private: + void OnLookupComplete( + absl::StatusOr> addresses) { + grpc_core::ExecCtx exec_ctx; + // Convert addresses to iomgr form. + *addresses_ = static_cast( + gpr_malloc(sizeof(grpc_resolved_addresses))); + (*addresses_)->naddrs = addresses->size(); + (*addresses_)->addrs = static_cast( + gpr_malloc(sizeof(grpc_resolved_address) * addresses->size())); + for (size_t i = 0; i < addresses->size(); ++i) { + (*addresses_)->addrs[i] = CreateGRPCResolvedAddress((*addresses)[i]); + } + grpc_closure* cb = cb_; + delete this; + grpc_core::Closure::Run(DEBUG_LOCATION, cb, + absl_status_to_grpc_error(addresses.status())); + } + + std::unique_ptr dns_resolver_; + grpc_closure* cb_; + grpc_resolved_addresses** addresses_; +}; + +void resolve_address(const char* addr, const char* default_port, + grpc_pollset_set* /* interested_parties */, + grpc_closure* on_done, + grpc_resolved_addresses** addresses) { + auto dns_resolver = grpc_iomgr_event_engine()->GetDNSResolver(); + if (!dns_resolver.ok()) { + grpc_core::ExecCtx::Run(DEBUG_LOCATION, on_done, + absl_status_to_grpc_error(dns_resolver.status())); + return; + } + new DnsRequest(std::move(*dns_resolver), addr, default_port, on_done, + addresses); +} + +void blocking_handle_async_resolve_done(void* arg, grpc_error_handle error) { + static_cast*>(arg)->Set(std::move(error)); +} + +grpc_error* blocking_resolve_address(const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + grpc_closure on_done; + Promise evt; + GRPC_CLOSURE_INIT(&on_done, blocking_handle_async_resolve_done, &evt, + grpc_schedule_on_exec_ctx); + resolve_address(name, default_port, nullptr, &on_done, addresses); + return evt.Get(); +} + +} // namespace + +grpc_address_resolver_vtable grpc_event_engine_resolver_vtable{ + resolve_address, blocking_resolve_address}; + +#endif // GRPC_USE_EVENT_ENGINE diff --git a/src/core/lib/iomgr/event_engine/tcp.cc b/src/core/lib/iomgr/event_engine/tcp.cc new file mode 100644 index 00000000000..2815251b16e --- /dev/null +++ b/src/core/lib/iomgr/event_engine/tcp.cc @@ -0,0 +1,243 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include + +#include "src/core/lib/address_utils/sockaddr_utils.h" +#include "src/core/lib/event_engine/endpoint_config_internal.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/iomgr.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::GrpcClosureToCallback; +using ::grpc_event_engine::experimental::SliceAllocator; +using ::grpc_event_engine::experimental::SliceAllocatorFactory; +} // namespace + +struct grpc_tcp_server { + grpc_tcp_server(std::unique_ptr listener, + grpc_resource_quota* rq) + : refcount(1, GRPC_TRACE_FLAG_ENABLED(grpc_tcp_trace) ? "tcp" : nullptr), + listener(std::move(listener)), + resource_quota(rq) { + shutdown_starting.head = nullptr; + shutdown_starting.tail = nullptr; + }; + ~grpc_tcp_server() { + // TODO(nnoble): see if we can handle this in ~SliceAllocatorFactory + grpc_resource_quota_unref_internal(resource_quota); + grpc_core::ExecCtx::RunList(DEBUG_LOCATION, &shutdown_starting); + grpc_core::ExecCtx::Get()->Flush(); + } + grpc_core::RefCount refcount; + grpc_core::Mutex mu; + std::unique_ptr listener; + grpc_closure_list shutdown_starting ABSL_GUARDED_BY(mu); + grpc_resource_quota* resource_quota; + 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> endpoint) { + grpc_core::ExecCtx exec_ctx; + if (endpoint.ok()) { + auto* grpc_endpoint_out = + reinterpret_cast(*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_pollset_set* /* interested_parties */, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, grpc_millis deadline) { + grpc_event_engine_endpoint* ee_endpoint = + reinterpret_cast( + grpc_tcp_create(channel_args, grpc_sockaddr_to_uri(addr))); + *endpoint = &ee_endpoint->base; + EventEngine::OnConnectCallback ee_on_connect = + GrpcClosureToOnConnectCallback(on_connect, endpoint); + SliceAllocator sa(ee_endpoint->ru); + EventEngine::ResolvedAddress ra(reinterpret_cast(addr->addr), + addr->len); + absl::Time ee_deadline = grpc_core::ToAbslTime( + grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)); + ChannelArgsEndpointConfig endpoint_config(channel_args); + absl::Status connected = grpc_iomgr_event_engine()->Connect( + ee_on_connect, ra, endpoint_config, std::move(sa), 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* tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { + ChannelArgsEndpointConfig endpoint_config(args); + grpc_resource_quota* rq = grpc_resource_quota_from_channel_args(args); + if (rq == nullptr) { + rq = grpc_resource_quota_create(nullptr); + } + EventEngine* event_engine = grpc_iomgr_event_engine(); + absl::StatusOr> listener = + event_engine->CreateListener( + [server](std::unique_ptr ee_endpoint) { + 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( + 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(); + }, + GrpcClosureToCallback(shutdown_complete, GRPC_ERROR_NONE), + endpoint_config, SliceAllocatorFactory(rq)); + if (!listener.ok()) { + return absl_status_to_grpc_error(listener.status()); + } + *server = new grpc_tcp_server(std::move(*listener), rq); + return GRPC_ERROR_NONE; +} + +void tcp_server_start(grpc_tcp_server* server, + const std::vector* /* 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* tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* out_port) { + EventEngine::ResolvedAddress ra(reinterpret_cast(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 */, + const char* /* addr_str */) { + return nullptr; +} + +#endif // GRPC_USE_EVENT_ENGINE diff --git a/src/core/lib/iomgr/event_engine/timer.cc b/src/core/lib/iomgr/event_engine/timer.cc new file mode 100644 index 00000000000..b0a0047b530 --- /dev/null +++ b/src/core/lib/iomgr/event_engine/timer.cc @@ -0,0 +1,57 @@ +// 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 + +#ifdef GRPC_USE_EVENT_ENGINE +#include + +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/event_engine/closure.h" +#include "src/core/lib/iomgr/event_engine/iomgr.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::GrpcClosureToCallback; + +void timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { + timer->ee_task_handle = grpc_iomgr_event_engine()->RunAt( + grpc_core::ToAbslTime( + grpc_millis_to_timespec(deadline, GPR_CLOCK_REALTIME)), + GrpcClosureToCallback(closure, GRPC_ERROR_NONE), {}); +} + +void timer_cancel(grpc_timer* timer) { + auto handle = timer->ee_task_handle; + grpc_iomgr_event_engine()->TryCancel(handle); +} + +/* Internal API */ +grpc_timer_check_result timer_check(grpc_millis* /* 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 diff --git a/src/core/lib/iomgr/exec_ctx.cc b/src/core/lib/iomgr/exec_ctx.cc index 54ab9fdad59..b1ae7810eea 100644 --- a/src/core/lib/iomgr/exec_ctx.cc +++ b/src/core/lib/iomgr/exec_ctx.cc @@ -20,11 +20,14 @@ #include "src/core/lib/iomgr/exec_ctx.h" +#include #include #include #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/combiner.h" +#include "src/core/lib/iomgr/event_engine/closure.h" +#include "src/core/lib/iomgr/event_engine/iomgr.h" #include "src/core/lib/profiling/timers.h" static void exec_ctx_run(grpc_closure* closure, grpc_error_handle error) { @@ -47,8 +50,13 @@ static void exec_ctx_run(grpc_closure* closure, grpc_error_handle error) { } static void exec_ctx_sched(grpc_closure* closure, grpc_error_handle error) { +#if defined(GRPC_USE_EVENT_ENGINE) && \ + defined(GRPC_EVENT_ENGINE_REPLACE_EXEC_CTX) + grpc_iomgr_event_engine()->Run(GrpcClosureToCallback(closure, error), {}); +#else grpc_closure_list_append(grpc_core::ExecCtx::Get()->closure_list(), closure, error); +#endif } static gpr_timespec g_start_time; diff --git a/src/core/lib/iomgr/port.h b/src/core/lib/iomgr/port.h index 8d3cd98b046..5f14cd6b910 100644 --- a/src/core/lib/iomgr/port.h +++ b/src/core/lib/iomgr/port.h @@ -15,12 +15,11 @@ * limitations under the License. * */ - -#include - #ifndef GRPC_CORE_LIB_IOMGR_PORT_H #define GRPC_CORE_LIB_IOMGR_PORT_H +#include + #ifdef GRPC_UV #ifndef GRPC_CUSTOM_SOCKET #define GRPC_CUSTOM_SOCKET @@ -33,6 +32,8 @@ #endif #if defined(GRPC_CUSTOM_SOCKET) // Do Nothing +#elif defined(GRPC_USE_EVENT_ENGINE) +// Do Nothing #elif defined(GPR_WINDOWS) #define GRPC_WINSOCK_SOCKET 1 #define GRPC_WINDOWS_SOCKETUTILS 1 @@ -189,10 +190,11 @@ #endif #if defined(GRPC_POSIX_SOCKET) + defined(GRPC_WINSOCK_SOCKET) + \ - defined(GRPC_CUSTOM_SOCKET) + defined(GRPC_CFSTREAM) != \ + defined(GRPC_CUSTOM_SOCKET) + defined(GRPC_CFSTREAM) + \ + defined(GRPC_USE_EVENT_ENGINE) != \ 1 #error \ - "Must define exactly one of GRPC_POSIX_SOCKET, GRPC_WINSOCK_SOCKET, GRPC_CUSTOM_SOCKET, GRPC_CFSTREAM" + "Must define exactly one of GRPC_POSIX_SOCKET, GRPC_WINSOCK_SOCKET, GRPC_CUSTOM_SOCKET, GRPC_CFSTREAM, GRPC_USE_EVENT_ENGINE" #endif #ifdef GRPC_POSIX_SOCKET diff --git a/src/core/lib/iomgr/resolve_address.cc b/src/core/lib/iomgr/resolve_address.cc index 20bbab0303c..30c0db146f8 100644 --- a/src/core/lib/iomgr/resolve_address.cc +++ b/src/core/lib/iomgr/resolve_address.cc @@ -15,9 +15,9 @@ * limitations under the License. * */ - #include +#include #include #include "src/core/lib/iomgr/resolve_address.h" diff --git a/src/core/lib/iomgr/sockaddr.h b/src/core/lib/iomgr/sockaddr.h index 5edf735cd18..96a8f77f8e4 100644 --- a/src/core/lib/iomgr/sockaddr.h +++ b/src/core/lib/iomgr/sockaddr.h @@ -25,6 +25,7 @@ #include +#include "src/core/lib/event_engine/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_custom.h" #include "src/core/lib/iomgr/sockaddr_posix.h" #include "src/core/lib/iomgr/sockaddr_windows.h" diff --git a/src/core/lib/iomgr/timer.h b/src/core/lib/iomgr/timer.h index 11da1496523..5b55950044d 100644 --- a/src/core/lib/iomgr/timer.h +++ b/src/core/lib/iomgr/timer.h @@ -23,7 +23,9 @@ #include "src/core/lib/iomgr/port.h" +#include #include + #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/iomgr.h" @@ -40,7 +42,10 @@ typedef struct grpc_timer { #endif // Optional field used by custom timers - void* custom_timer; + union { + void* custom_timer; + grpc_event_engine::experimental::EventEngine::TaskHandle ee_task_handle; + }; } grpc_timer; typedef enum { diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 9e37ed160ee..19d353feec9 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -126,7 +126,6 @@ void grpc_register_plugin(void (*init)(void), void (*destroy)(void)) { } void grpc_init(void) { - int i; gpr_once_init(&g_basic_init, do_basic_init); grpc_core::MutexLock lock(g_init_mu); @@ -150,7 +149,7 @@ void grpc_init(void) { gpr_timers_global_init(); grpc_core::HandshakerRegistry::Init(); grpc_security_init(); - for (i = 0; i < g_number_of_plugins; i++) { + for (int i = 0; i < g_number_of_plugins; i++) { if (g_all_of_the_plugins[i].init != nullptr) { g_all_of_the_plugins[i].init(); } diff --git a/src/core/lib/surface/init.h b/src/core/lib/surface/init.h index 6eaa488d054..9e8bedcb519 100644 --- a/src/core/lib/surface/init.h +++ b/src/core/lib/surface/init.h @@ -15,10 +15,19 @@ * limitations under the License. * */ - #ifndef GRPC_CORE_LIB_SURFACE_INIT_H #define GRPC_CORE_LIB_SURFACE_INIT_H +#include + +#include + +namespace grpc_event_engine { +namespace experimental { +class EventEngine; +} +} // namespace grpc_event_engine + void grpc_register_security_filters(void); void grpc_security_pre_init(void); void grpc_security_init(void); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index e4fcc2b67b2..dff7fb1b5fb 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -52,10 +52,12 @@ CORE_SOURCE_FILES = [ 'src/core/ext/filters/client_channel/proxy_mapper_registry.cc', 'src/core/ext/filters/client_channel/resolver.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc', + 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc', 'src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc', @@ -349,6 +351,8 @@ CORE_SOURCE_FILES = [ 'src/core/lib/debug/stats.cc', 'src/core/lib/debug/stats_data.cc', 'src/core/lib/debug/trace.cc', + 'src/core/lib/event_engine/endpoint_config.cc', + 'src/core/lib/event_engine/event_engine.cc', 'src/core/lib/event_engine/slice_allocator.cc', 'src/core/lib/event_engine/sockaddr.cc', 'src/core/lib/gpr/alloc.cc', @@ -406,6 +410,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/dualstack_socket_posix.cc', 'src/core/lib/iomgr/endpoint.cc', 'src/core/lib/iomgr/endpoint_cfstream.cc', + 'src/core/lib/iomgr/endpoint_pair_event_engine.cc', 'src/core/lib/iomgr/endpoint_pair_posix.cc', 'src/core/lib/iomgr/endpoint_pair_uv.cc', 'src/core/lib/iomgr/endpoint_pair_windows.cc', @@ -417,6 +422,14 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/ev_poll_posix.cc', 'src/core/lib/iomgr/ev_posix.cc', 'src/core/lib/iomgr/ev_windows.cc', + 'src/core/lib/iomgr/event_engine/closure.cc', + 'src/core/lib/iomgr/event_engine/endpoint.cc', + 'src/core/lib/iomgr/event_engine/iomgr.cc', + 'src/core/lib/iomgr/event_engine/pollset.cc', + 'src/core/lib/iomgr/event_engine/resolved_address_internal.cc', + 'src/core/lib/iomgr/event_engine/resolver.cc', + 'src/core/lib/iomgr/event_engine/tcp.cc', + 'src/core/lib/iomgr/event_engine/timer.cc', 'src/core/lib/iomgr/exec_ctx.cc', 'src/core/lib/iomgr/executor.cc', 'src/core/lib/iomgr/executor/mpmcqueue.cc', diff --git a/templates/gRPC-Core.podspec.template b/templates/gRPC-Core.podspec.template index 254ebf50181..368f2efb6bf 100644 --- a/templates/gRPC-Core.podspec.template +++ b/templates/gRPC-Core.podspec.template @@ -59,30 +59,21 @@ files.update(lib.get(field, [])) return list(sorted(files)) - # Wrapped languages don't need to access EventEngine APIs. `port.h` is a - # special case - it's needed in some security code. - event_engine_files = [ - file - for file in list_lib_files("grpc", ("public_headers", "headers", "src")) - if '/event_engine/' in file - and not file.endswith('/port.h') - ] - # ObjectiveC doesn't use c-ares so we don't need address_sorting files at all address_sorting_unwanted_files = list_lib_files("address_sorting", ("public_headers", "headers", "src")) # ObjectiveC needs to obtain re2 explicitly unlike other languages; TODO @donnadionne make ObjC more consistent with others grpc_private_files = list( sorted((set(list_lib_files("grpc", ("headers", "src"))) - - set(address_sorting_unwanted_files) - set(event_engine_files)) + set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("headers", "src"))))) grpc_public_headers = list( sorted((set(list_lib_files("grpc", ("public_headers", ))) - - set(address_sorting_unwanted_files)) - set(event_engine_files) + set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("public_headers", ))))) grpc_private_headers = list( sorted((set(list_lib_files("grpc", ("headers", ))) - - set(address_sorting_unwanted_files)) - set(event_engine_files) + set(address_sorting_unwanted_files)) | set(list_lib_files("re2", ("headers", ))))) grpc_abseil_specs = list_abseil_specs("grpc") grpc_tests_abseil_specs = list(sorted(set(list_abseil_specs("end2end_tests")) - set(grpc_abseil_specs))) @@ -109,7 +100,6 @@ set(list_lib_files("end2end_tests", ("src", "headers"))) - set(grpc_private_files) - set(address_sorting_unwanted_files) - - set(event_engine_files) - set([ # Subprocess is not supported in tvOS and not needed by our tests. "test/core/util/subprocess_posix.cc", diff --git a/test/core/end2end/fixtures/h2_fd.cc b/test/core/end2end/fixtures/h2_fd.cc index abfefbc9844..9ef037573fa 100644 --- a/test/core/end2end/fixtures/h2_fd.cc +++ b/test/core/end2end/fixtures/h2_fd.cc @@ -119,6 +119,6 @@ int main(int argc, char** argv) { #else /* GRPC_POSIX_SOCKET */ -int main(int argc, char** argv) { return 1; } +int main(int /* argc */, char** /* argv */) { return 1; } #endif /* GRPC_POSIX_SOCKET */ diff --git a/test/core/event_engine/BUILD b/test/core/event_engine/BUILD new file mode 100644 index 00000000000..c752168c40b --- /dev/null +++ b/test/core/event_engine/BUILD @@ -0,0 +1,28 @@ +# Copyright 2017 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. + +load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") + +grpc_package(name = "test/core/event_engine") + +grpc_cc_test( + name = "endpoint_config_test", + srcs = ["endpoint_config_test.cc"], + external_deps = ["gtest"], + language = "C++", + deps = [ + "//:grpc", + "//test/core/util:grpc_test_util", + ], +) diff --git a/test/core/event_engine/endpoint_config_test.cc b/test/core/event_engine/endpoint_config_test.cc new file mode 100644 index 00000000000..bcae9c0a00b --- /dev/null +++ b/test/core/event_engine/endpoint_config_test.cc @@ -0,0 +1,46 @@ +// 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 + +#include "grpc/event_engine/endpoint_config.h" + +#include +#include +#include + +#include "test/core/util/test_config.h" + +#include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/event_engine/endpoint_config_internal.h" + +using ::grpc_event_engine::experimental::ChannelArgsEndpointConfig; + +TEST(EndpointConfigTest, CanSRetrieveValuesFromChannelArgs) { + grpc_arg arg = grpc_channel_arg_integer_create(const_cast("arst"), 3); + const grpc_channel_args args = {1, &arg}; + ChannelArgsEndpointConfig config(&args); + EXPECT_EQ(absl::get(config.Get("arst")), 3); +} + +TEST(EndpointConfigTest, ReturnsMonostateForMissingKeys) { + ChannelArgsEndpointConfig config(nullptr); + EXPECT_TRUE( + absl::holds_alternative(config.Get("nonexistent"))); +} + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + auto result = RUN_ALL_TESTS(); + return result; +} diff --git a/test/core/iomgr/resolve_address_test.cc b/test/core/iomgr/resolve_address_test.cc index c8a4d15917e..4a2c7146ad9 100644 --- a/test/core/iomgr/resolve_address_test.cc +++ b/test/core/iomgr/resolve_address_test.cc @@ -28,6 +28,7 @@ #include #include "src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h" +#include "src/core/lib/event_engine/sockaddr.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gprpp/sync.h" #include "src/core/lib/iomgr/executor.h" diff --git a/test/cpp/grpclb/grpclb_api_test.cc b/test/cpp/grpclb/grpclb_api_test.cc index 0623280425a..412bbed195e 100644 --- a/test/cpp/grpclb/grpclb_api_test.cc +++ b/test/cpp/grpclb/grpclb_api_test.cc @@ -25,6 +25,7 @@ #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h" #include "src/core/lib/address_utils/sockaddr_utils.h" +#include "src/core/lib/event_engine/sockaddr.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/proto/grpc/lb/v1/load_balancer.pb.h" // C++ version diff --git a/test/cpp/naming/dns_test_util.cc b/test/cpp/naming/dns_test_util.cc index ca97bf3e7f6..323079268cd 100644 --- a/test/cpp/naming/dns_test_util.cc +++ b/test/cpp/naming/dns_test_util.cc @@ -22,6 +22,7 @@ #include #include +#include "src/core/lib/event_engine/sockaddr.h" #include "test/cpp/naming/dns_test_util.h" #ifdef GPR_WINDOWS diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index b3afed4085c..e57a887bd96 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -881,7 +881,7 @@ include/grpc/byte_buffer.h \ include/grpc/byte_buffer_reader.h \ include/grpc/census.h \ include/grpc/compression.h \ -include/grpc/event_engine/channel_args.h \ +include/grpc/event_engine/endpoint_config.h \ include/grpc/event_engine/event_engine.h \ include/grpc/event_engine/port.h \ include/grpc/event_engine/slice_allocator.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index dbb35b91c21..88ff08fc8a6 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -881,7 +881,7 @@ include/grpc/byte_buffer.h \ include/grpc/byte_buffer_reader.h \ include/grpc/census.h \ include/grpc/compression.h \ -include/grpc/event_engine/channel_args.h \ +include/grpc/event_engine/endpoint_config.h \ include/grpc/event_engine/event_engine.h \ include/grpc/event_engine/port.h \ include/grpc/event_engine/slice_allocator.h \ @@ -1114,11 +1114,13 @@ src/core/ext/filters/client_channel/resolver.cc \ src/core/ext/filters/client_channel/resolver.h \ src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h \ +src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h \ +src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc \ @@ -1689,8 +1691,12 @@ src/core/lib/debug/stats_data.cc \ src/core/lib/debug/stats_data.h \ src/core/lib/debug/trace.cc \ src/core/lib/debug/trace.h \ +src/core/lib/event_engine/endpoint_config.cc \ +src/core/lib/event_engine/endpoint_config_internal.h \ +src/core/lib/event_engine/event_engine.cc \ src/core/lib/event_engine/slice_allocator.cc \ src/core/lib/event_engine/sockaddr.cc \ +src/core/lib/event_engine/sockaddr.h \ src/core/lib/gpr/alloc.cc \ src/core/lib/gpr/alloc.h \ src/core/lib/gpr/arena.h \ @@ -1796,6 +1802,7 @@ src/core/lib/iomgr/endpoint.h \ src/core/lib/iomgr/endpoint_cfstream.cc \ src/core/lib/iomgr/endpoint_cfstream.h \ src/core/lib/iomgr/endpoint_pair.h \ +src/core/lib/iomgr/endpoint_pair_event_engine.cc \ src/core/lib/iomgr/endpoint_pair_posix.cc \ src/core/lib/iomgr/endpoint_pair_uv.cc \ src/core/lib/iomgr/endpoint_pair_windows.cc \ @@ -1815,6 +1822,20 @@ src/core/lib/iomgr/ev_poll_posix.h \ src/core/lib/iomgr/ev_posix.cc \ src/core/lib/iomgr/ev_posix.h \ src/core/lib/iomgr/ev_windows.cc \ +src/core/lib/iomgr/event_engine/closure.cc \ +src/core/lib/iomgr/event_engine/closure.h \ +src/core/lib/iomgr/event_engine/endpoint.cc \ +src/core/lib/iomgr/event_engine/endpoint.h \ +src/core/lib/iomgr/event_engine/iomgr.cc \ +src/core/lib/iomgr/event_engine/iomgr.h \ +src/core/lib/iomgr/event_engine/pollset.cc \ +src/core/lib/iomgr/event_engine/pollset.h \ +src/core/lib/iomgr/event_engine/promise.h \ +src/core/lib/iomgr/event_engine/resolved_address_internal.cc \ +src/core/lib/iomgr/event_engine/resolved_address_internal.h \ +src/core/lib/iomgr/event_engine/resolver.cc \ +src/core/lib/iomgr/event_engine/tcp.cc \ +src/core/lib/iomgr/event_engine/timer.cc \ src/core/lib/iomgr/exec_ctx.cc \ src/core/lib/iomgr/exec_ctx.h \ src/core/lib/iomgr/executor.cc \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index 54fac3a5a00..96ff8c451bf 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -811,7 +811,7 @@ include/grpc/byte_buffer.h \ include/grpc/byte_buffer_reader.h \ include/grpc/census.h \ include/grpc/compression.h \ -include/grpc/event_engine/channel_args.h \ +include/grpc/event_engine/endpoint_config.h \ include/grpc/event_engine/event_engine.h \ include/grpc/event_engine/port.h \ include/grpc/event_engine/slice_allocator.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index c493e5291b0..53088a43aca 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -811,7 +811,7 @@ include/grpc/byte_buffer.h \ include/grpc/byte_buffer_reader.h \ include/grpc/census.h \ include/grpc/compression.h \ -include/grpc/event_engine/channel_args.h \ +include/grpc/event_engine/endpoint_config.h \ include/grpc/event_engine/event_engine.h \ include/grpc/event_engine/port.h \ include/grpc/event_engine/slice_allocator.h \ @@ -939,11 +939,13 @@ src/core/ext/filters/client_channel/resolver.h \ src/core/ext/filters/client_channel/resolver/README.md \ src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h \ +src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h \ +src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc \ src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc \ @@ -1525,8 +1527,12 @@ src/core/lib/debug/stats_data.cc \ src/core/lib/debug/stats_data.h \ src/core/lib/debug/trace.cc \ src/core/lib/debug/trace.h \ +src/core/lib/event_engine/endpoint_config.cc \ +src/core/lib/event_engine/endpoint_config_internal.h \ +src/core/lib/event_engine/event_engine.cc \ src/core/lib/event_engine/slice_allocator.cc \ src/core/lib/event_engine/sockaddr.cc \ +src/core/lib/event_engine/sockaddr.h \ src/core/lib/gpr/README.md \ src/core/lib/gpr/alloc.cc \ src/core/lib/gpr/alloc.h \ @@ -1635,6 +1641,7 @@ src/core/lib/iomgr/endpoint.h \ src/core/lib/iomgr/endpoint_cfstream.cc \ src/core/lib/iomgr/endpoint_cfstream.h \ src/core/lib/iomgr/endpoint_pair.h \ +src/core/lib/iomgr/endpoint_pair_event_engine.cc \ src/core/lib/iomgr/endpoint_pair_posix.cc \ src/core/lib/iomgr/endpoint_pair_uv.cc \ src/core/lib/iomgr/endpoint_pair_windows.cc \ @@ -1654,6 +1661,20 @@ src/core/lib/iomgr/ev_poll_posix.h \ src/core/lib/iomgr/ev_posix.cc \ src/core/lib/iomgr/ev_posix.h \ src/core/lib/iomgr/ev_windows.cc \ +src/core/lib/iomgr/event_engine/closure.cc \ +src/core/lib/iomgr/event_engine/closure.h \ +src/core/lib/iomgr/event_engine/endpoint.cc \ +src/core/lib/iomgr/event_engine/endpoint.h \ +src/core/lib/iomgr/event_engine/iomgr.cc \ +src/core/lib/iomgr/event_engine/iomgr.h \ +src/core/lib/iomgr/event_engine/pollset.cc \ +src/core/lib/iomgr/event_engine/pollset.h \ +src/core/lib/iomgr/event_engine/promise.h \ +src/core/lib/iomgr/event_engine/resolved_address_internal.cc \ +src/core/lib/iomgr/event_engine/resolved_address_internal.h \ +src/core/lib/iomgr/event_engine/resolver.cc \ +src/core/lib/iomgr/event_engine/tcp.cc \ +src/core/lib/iomgr/event_engine/timer.cc \ src/core/lib/iomgr/exec_ctx.cc \ src/core/lib/iomgr/exec_ctx.h \ src/core/lib/iomgr/executor.cc \ diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index ea9e7f84efb..1def94824d9 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -4393,6 +4393,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "endpoint_config_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false,