From 539f5068bd14e3d07b58309b657222919e94aba5 Mon Sep 17 00:00:00 2001 From: kpayson64 Date: Mon, 12 Mar 2018 19:16:30 -0700 Subject: [PATCH] Abstract libuv implementation Structures the libuv implementation to allow for a plugable BSD style socket implementation to allow for other IO Managers --- BUILD | 31 +- CMakeLists.txt | 114 +- MANIFEST.md | 4 - Makefile | 114 +- build.yaml | 31 +- config.m4 | 19 +- config.w32 | 19 +- gRPC-C++.podspec | 24 +- gRPC-Core.podspec | 43 +- grpc.gemspec | 31 +- grpc.gyp | 76 +- include/grpc/impl/codegen/slice.h | 2 +- package.xml | 31 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 15 +- .../filters/client_channel/parse_address.cc | 26 +- .../resolver/dns/c_ares/dns_resolver_ares.cc | 24 +- .../chttp2/server/insecure/server_chttp2.cc | 1 - src/core/lib/iomgr/endpoint.cc | 2 + src/core/lib/iomgr/endpoint_pair_windows.cc | 9 +- src/core/lib/iomgr/ev_posix.cc | 52 +- src/core/lib/iomgr/exec_ctx.h | 7 +- src/core/lib/iomgr/iomgr.cc | 1 + src/core/lib/iomgr/iomgr_custom.cc | 63 + .../lib/iomgr/{iomgr_uv.h => iomgr_custom.h} | 24 +- src/core/lib/iomgr/iomgr_internal.cc | 43 + src/core/lib/iomgr/iomgr_internal.h | 12 + src/core/lib/iomgr/iomgr_posix.cc | 31 +- src/core/lib/iomgr/iomgr_uv.cc | 35 +- src/core/lib/iomgr/iomgr_windows.cc | 30 +- src/core/lib/iomgr/pollset.cc | 56 + src/core/lib/iomgr/pollset.h | 18 + src/core/lib/iomgr/pollset_custom.cc | 106 ++ src/core/lib/iomgr/pollset_custom.h | 35 + .../{pollset_set_uv.cc => pollset_set.cc} | 36 +- src/core/lib/iomgr/pollset_set.h | 11 + src/core/lib/iomgr/pollset_set_custom.cc | 48 + .../{timer_uv.h => pollset_set_custom.h} | 18 +- src/core/lib/iomgr/pollset_set_windows.cc | 25 +- src/core/lib/iomgr/pollset_uv.cc | 145 +-- src/core/lib/iomgr/pollset_uv.h | 9 +- src/core/lib/iomgr/pollset_windows.cc | 28 +- src/core/lib/iomgr/port.h | 27 +- src/core/lib/iomgr/resolve_address.cc | 50 + src/core/lib/iomgr/resolve_address.h | 29 +- src/core/lib/iomgr/resolve_address_custom.cc | 187 +++ src/core/lib/iomgr/resolve_address_custom.h | 43 + src/core/lib/iomgr/resolve_address_posix.cc | 28 +- src/core/lib/iomgr/resolve_address_uv.cc | 286 ----- src/core/lib/iomgr/resolve_address_windows.cc | 28 +- src/core/lib/iomgr/resource_quota.h | 4 - src/core/lib/iomgr/sockaddr.h | 14 +- src/core/lib/iomgr/sockaddr_custom.h | 54 + src/core/lib/iomgr/sockaddr_posix.h | 24 + src/core/lib/iomgr/sockaddr_utils.cc | 156 +-- src/core/lib/iomgr/sockaddr_utils.h | 2 + src/core/lib/iomgr/sockaddr_windows.h | 19 + src/core/lib/iomgr/socket_utils.h | 9 + .../lib/iomgr/socket_utils_common_posix.cc | 18 +- src/core/lib/iomgr/socket_utils_linux.cc | 3 +- src/core/lib/iomgr/socket_utils_posix.cc | 2 +- src/core/lib/iomgr/socket_utils_uv.cc | 17 +- src/core/lib/iomgr/socket_utils_windows.cc | 8 + src/core/lib/iomgr/tcp_client.cc | 36 + src/core/lib/iomgr/tcp_client.h | 11 + src/core/lib/iomgr/tcp_client_custom.cc | 151 +++ src/core/lib/iomgr/tcp_client_posix.cc | 30 +- src/core/lib/iomgr/tcp_client_uv.cc | 177 --- src/core/lib/iomgr/tcp_client_windows.cc | 31 +- src/core/lib/iomgr/tcp_custom.cc | 365 ++++++ src/core/lib/iomgr/tcp_custom.h | 83 ++ src/core/lib/iomgr/tcp_posix.cc | 2 +- src/core/lib/iomgr/tcp_server.cc | 73 ++ src/core/lib/iomgr/tcp_server.h | 22 + src/core/lib/iomgr/tcp_server_custom.cc | 479 +++++++ src/core/lib/iomgr/tcp_server_posix.cc | 49 +- .../iomgr/tcp_server_utils_posix_common.cc | 5 +- .../iomgr/tcp_server_utils_posix_ifaddrs.cc | 8 +- src/core/lib/iomgr/tcp_server_uv.cc | 473 ------- src/core/lib/iomgr/tcp_server_windows.cc | 62 +- src/core/lib/iomgr/tcp_uv.cc | 627 +++++----- src/core/lib/iomgr/tcp_uv.h | 53 - src/core/lib/iomgr/tcp_windows.cc | 2 +- src/core/lib/iomgr/timer.cc | 45 + src/core/lib/iomgr/timer.h | 48 +- src/core/lib/iomgr/timer_custom.cc | 93 ++ src/core/lib/iomgr/timer_custom.h | 43 + src/core/lib/iomgr/timer_generic.cc | 20 +- src/core/lib/iomgr/timer_heap.cc | 4 - src/core/lib/iomgr/timer_uv.cc | 62 +- src/core/lib/iomgr/udp_server.cc | 15 +- src/core/lib/iomgr/unix_sockets_posix.cc | 12 +- src/python/grpcio/grpc_core_dependencies.py | 19 +- .../core/client_channel/parse_address_test.cc | 27 +- .../dns_resolver_connectivity_test.cc | 5 +- .../resolvers/dns_resolver_cooldown_test.cc | 33 +- .../end2end/fixtures/http_proxy_fixture.cc | 6 +- test/core/end2end/fuzzers/api_fuzzer.cc | 15 +- test/core/end2end/goaway_server_test.cc | 46 +- test/core/end2end/tests/request_with_flags.cc | 8 +- test/core/iomgr/sockaddr_utils_test.cc | 46 +- test/core/iomgr/timer_heap_test.cc | 9 - test/core/iomgr/timer_list_test.cc | 11 +- test/core/iomgr/wakeup_fd_cv_test.cc | 2 +- .../surface/concurrent_connectivity_test.cc | 5 +- test/core/util/test_tcp_server.cc | 9 +- test/cpp/end2end/client_lb_end2end_test.cc | 19 +- tools/doxygen/Doxyfile.c++.internal | 12 +- tools/doxygen/Doxyfile.core.internal | 31 +- .../generated/sources_and_headers.json | 43 +- tools/run_tests/run_tests.py | 2 +- vsprojects/vcxproj/grpc++/grpc++.vcxproj | 646 ++++++++++ .../vcxproj/grpc++/grpc++.vcxproj.filters | 1096 +++++++++++++++++ .../grpc++_unsecure/grpc++_unsecure.vcxproj | 630 ++++++++++ .../grpc++_unsecure.vcxproj.filters | 1063 ++++++++++++++++ vsprojects/vcxproj/grpc/grpc.vcxproj | 46 +- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 79 +- .../grpc_test_util/grpc_test_util.vcxproj | 38 +- .../grpc_test_util.vcxproj.filters | 50 +- .../grpc_test_util_unsecure.vcxproj | 649 ++++++++++ .../grpc_test_util_unsecure.vcxproj.filters | 946 ++++++++++++++ .../grpc_unsecure/grpc_unsecure.vcxproj | 44 +- .../grpc_unsecure.vcxproj.filters | 64 +- 122 files changed, 8987 insertions(+), 2250 deletions(-) create mode 100644 src/core/lib/iomgr/iomgr_custom.cc rename src/core/lib/iomgr/{iomgr_uv.h => iomgr_custom.h} (53%) create mode 100644 src/core/lib/iomgr/iomgr_internal.cc create mode 100644 src/core/lib/iomgr/pollset.cc create mode 100644 src/core/lib/iomgr/pollset_custom.cc create mode 100644 src/core/lib/iomgr/pollset_custom.h rename src/core/lib/iomgr/{pollset_set_uv.cc => pollset_set.cc} (51%) create mode 100644 src/core/lib/iomgr/pollset_set_custom.cc rename src/core/lib/iomgr/{timer_uv.h => pollset_set_custom.h} (61%) create mode 100644 src/core/lib/iomgr/resolve_address.cc create mode 100644 src/core/lib/iomgr/resolve_address_custom.cc create mode 100644 src/core/lib/iomgr/resolve_address_custom.h delete mode 100644 src/core/lib/iomgr/resolve_address_uv.cc create mode 100644 src/core/lib/iomgr/sockaddr_custom.h create mode 100644 src/core/lib/iomgr/tcp_client.cc create mode 100644 src/core/lib/iomgr/tcp_client_custom.cc delete mode 100644 src/core/lib/iomgr/tcp_client_uv.cc create mode 100644 src/core/lib/iomgr/tcp_custom.cc create mode 100644 src/core/lib/iomgr/tcp_custom.h create mode 100644 src/core/lib/iomgr/tcp_server.cc create mode 100644 src/core/lib/iomgr/tcp_server_custom.cc delete mode 100644 src/core/lib/iomgr/tcp_server_uv.cc delete mode 100644 src/core/lib/iomgr/tcp_uv.h create mode 100644 src/core/lib/iomgr/timer.cc create mode 100644 src/core/lib/iomgr/timer_custom.cc create mode 100644 src/core/lib/iomgr/timer_custom.h create mode 100644 vsprojects/vcxproj/grpc++/grpc++.vcxproj create mode 100644 vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters create mode 100644 vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj create mode 100644 vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters create mode 100644 vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj create mode 100644 vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj.filters diff --git a/BUILD b/BUILD index bfda84e0f40..6c18ad94d73 100644 --- a/BUILD +++ b/BUILD @@ -713,20 +713,25 @@ grpc_cc_library( "src/core/lib/iomgr/gethostname_sysconf.cc", "src/core/lib/iomgr/iocp_windows.cc", "src/core/lib/iomgr/iomgr.cc", + "src/core/lib/iomgr/iomgr_custom.cc", + "src/core/lib/iomgr/iomgr_internal.cc", "src/core/lib/iomgr/iomgr_posix.cc", - "src/core/lib/iomgr/iomgr_uv.cc", "src/core/lib/iomgr/iomgr_windows.cc", "src/core/lib/iomgr/is_epollexclusive_available.cc", "src/core/lib/iomgr/load_file.cc", "src/core/lib/iomgr/lockfree_event.cc", "src/core/lib/iomgr/network_status_tracker.cc", "src/core/lib/iomgr/polling_entity.cc", - "src/core/lib/iomgr/pollset_set_uv.cc", + "src/core/lib/iomgr/pollset.cc", + "src/core/lib/iomgr/pollset_custom.cc", + "src/core/lib/iomgr/pollset_set.cc", + "src/core/lib/iomgr/pollset_set_custom.cc", "src/core/lib/iomgr/pollset_set_windows.cc", "src/core/lib/iomgr/pollset_uv.cc", "src/core/lib/iomgr/pollset_windows.cc", + "src/core/lib/iomgr/resolve_address.cc", + "src/core/lib/iomgr/resolve_address_custom.cc", "src/core/lib/iomgr/resolve_address_posix.cc", - "src/core/lib/iomgr/resolve_address_uv.cc", "src/core/lib/iomgr/resolve_address_windows.cc", "src/core/lib/iomgr/resource_quota.cc", "src/core/lib/iomgr/sockaddr_utils.cc", @@ -735,22 +740,26 @@ grpc_cc_library( "src/core/lib/iomgr/socket_utils_common_posix.cc", "src/core/lib/iomgr/socket_utils_linux.cc", "src/core/lib/iomgr/socket_utils_posix.cc", - "src/core/lib/iomgr/socket_utils_uv.cc", "src/core/lib/iomgr/socket_utils_windows.cc", "src/core/lib/iomgr/socket_windows.cc", + "src/core/lib/iomgr/tcp_client.cc", + "src/core/lib/iomgr/tcp_client_custom.cc", "src/core/lib/iomgr/tcp_client_posix.cc", - "src/core/lib/iomgr/tcp_client_uv.cc", "src/core/lib/iomgr/tcp_client_windows.cc", + "src/core/lib/iomgr/tcp_custom.cc", "src/core/lib/iomgr/tcp_posix.cc", + "src/core/lib/iomgr/tcp_server.cc", + "src/core/lib/iomgr/tcp_server_custom.cc", "src/core/lib/iomgr/tcp_server_posix.cc", "src/core/lib/iomgr/tcp_server_utils_posix_common.cc", "src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc", "src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc", - "src/core/lib/iomgr/tcp_server_uv.cc", "src/core/lib/iomgr/tcp_server_windows.cc", "src/core/lib/iomgr/tcp_uv.cc", "src/core/lib/iomgr/tcp_windows.cc", "src/core/lib/iomgr/time_averaged_stats.cc", + "src/core/lib/iomgr/timer.cc", + "src/core/lib/iomgr/timer_custom.cc", "src/core/lib/iomgr/timer_generic.cc", "src/core/lib/iomgr/timer_heap.cc", "src/core/lib/iomgr/timer_manager.cc", @@ -845,9 +854,9 @@ grpc_cc_library( "src/core/lib/iomgr/gethostname.h", "src/core/lib/iomgr/iocp_windows.h", "src/core/lib/iomgr/iomgr.h", + "src/core/lib/iomgr/iomgr_custom.h", "src/core/lib/iomgr/iomgr_internal.h", "src/core/lib/iomgr/iomgr_posix.h", - "src/core/lib/iomgr/iomgr_uv.h", "src/core/lib/iomgr/is_epollexclusive_available.h", "src/core/lib/iomgr/load_file.h", "src/core/lib/iomgr/lockfree_event.h", @@ -855,14 +864,18 @@ grpc_cc_library( "src/core/lib/iomgr/network_status_tracker.h", "src/core/lib/iomgr/polling_entity.h", "src/core/lib/iomgr/pollset.h", + "src/core/lib/iomgr/pollset_custom.h", "src/core/lib/iomgr/pollset_set.h", + "src/core/lib/iomgr/pollset_set_custom.h", "src/core/lib/iomgr/pollset_set_windows.h", "src/core/lib/iomgr/pollset_uv.h", "src/core/lib/iomgr/pollset_windows.h", "src/core/lib/iomgr/port.h", "src/core/lib/iomgr/resolve_address.h", + "src/core/lib/iomgr/resolve_address_custom.h", "src/core/lib/iomgr/resource_quota.h", "src/core/lib/iomgr/sockaddr.h", + "src/core/lib/iomgr/sockaddr_custom.h", "src/core/lib/iomgr/sockaddr_posix.h", "src/core/lib/iomgr/sockaddr_utils.h", "src/core/lib/iomgr/sockaddr_windows.h", @@ -874,17 +887,17 @@ grpc_cc_library( "src/core/lib/iomgr/sys_epoll_wrapper.h", "src/core/lib/iomgr/tcp_client.h", "src/core/lib/iomgr/tcp_client_posix.h", + "src/core/lib/iomgr/tcp_custom.h", "src/core/lib/iomgr/tcp_posix.h", "src/core/lib/iomgr/tcp_server.h", "src/core/lib/iomgr/tcp_server_utils_posix.h", - "src/core/lib/iomgr/tcp_uv.h", "src/core/lib/iomgr/tcp_windows.h", "src/core/lib/iomgr/time_averaged_stats.h", "src/core/lib/iomgr/timer.h", + "src/core/lib/iomgr/timer_custom.h", "src/core/lib/iomgr/timer_generic.h", "src/core/lib/iomgr/timer_heap.h", "src/core/lib/iomgr/timer_manager.h", - "src/core/lib/iomgr/timer_uv.h", "src/core/lib/iomgr/udp_server.h", "src/core/lib/iomgr/unix_sockets_posix.h", "src/core/lib/iomgr/wakeup_fd_cv.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index e0724d10aad..3e58593fb19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -893,6 +893,8 @@ add_library(grpc src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -901,12 +903,16 @@ add_library(grpc src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -918,19 +924,24 @@ add_library(grpc src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -1268,6 +1279,8 @@ add_library(grpc_cronet src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -1276,12 +1289,16 @@ add_library(grpc_cronet src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -1293,19 +1310,24 @@ add_library(grpc_cronet src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -1634,6 +1656,8 @@ add_library(grpc_test_util src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -1642,12 +1666,16 @@ add_library(grpc_test_util src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -1659,19 +1687,24 @@ add_library(grpc_test_util src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -1923,6 +1956,8 @@ add_library(grpc_test_util_unsecure src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -1931,12 +1966,16 @@ add_library(grpc_test_util_unsecure src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -1948,19 +1987,24 @@ add_library(grpc_test_util_unsecure src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -2192,6 +2236,8 @@ add_library(grpc_unsecure src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -2200,12 +2246,16 @@ add_library(grpc_unsecure src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -2217,19 +2267,24 @@ add_library(grpc_unsecure src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc @@ -2995,6 +3050,8 @@ add_library(grpc++_cronet src/core/lib/iomgr/gethostname_sysconf.cc src/core/lib/iomgr/iocp_windows.cc src/core/lib/iomgr/iomgr.cc + src/core/lib/iomgr/iomgr_custom.cc + src/core/lib/iomgr/iomgr_internal.cc src/core/lib/iomgr/iomgr_posix.cc src/core/lib/iomgr/iomgr_uv.cc src/core/lib/iomgr/iomgr_windows.cc @@ -3003,12 +3060,16 @@ add_library(grpc++_cronet src/core/lib/iomgr/lockfree_event.cc src/core/lib/iomgr/network_status_tracker.cc src/core/lib/iomgr/polling_entity.cc - src/core/lib/iomgr/pollset_set_uv.cc + src/core/lib/iomgr/pollset.cc + src/core/lib/iomgr/pollset_custom.cc + src/core/lib/iomgr/pollset_set.cc + src/core/lib/iomgr/pollset_set_custom.cc src/core/lib/iomgr/pollset_set_windows.cc src/core/lib/iomgr/pollset_uv.cc src/core/lib/iomgr/pollset_windows.cc + src/core/lib/iomgr/resolve_address.cc + src/core/lib/iomgr/resolve_address_custom.cc src/core/lib/iomgr/resolve_address_posix.cc - src/core/lib/iomgr/resolve_address_uv.cc src/core/lib/iomgr/resolve_address_windows.cc src/core/lib/iomgr/resource_quota.cc src/core/lib/iomgr/sockaddr_utils.cc @@ -3020,19 +3081,24 @@ add_library(grpc++_cronet src/core/lib/iomgr/socket_utils_uv.cc src/core/lib/iomgr/socket_utils_windows.cc src/core/lib/iomgr/socket_windows.cc + src/core/lib/iomgr/tcp_client.cc + src/core/lib/iomgr/tcp_client_custom.cc src/core/lib/iomgr/tcp_client_posix.cc - src/core/lib/iomgr/tcp_client_uv.cc src/core/lib/iomgr/tcp_client_windows.cc + src/core/lib/iomgr/tcp_custom.cc src/core/lib/iomgr/tcp_posix.cc + src/core/lib/iomgr/tcp_server.cc + src/core/lib/iomgr/tcp_server_custom.cc src/core/lib/iomgr/tcp_server_posix.cc src/core/lib/iomgr/tcp_server_utils_posix_common.cc src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - src/core/lib/iomgr/tcp_server_uv.cc src/core/lib/iomgr/tcp_server_windows.cc src/core/lib/iomgr/tcp_uv.cc src/core/lib/iomgr/tcp_windows.cc src/core/lib/iomgr/time_averaged_stats.cc + src/core/lib/iomgr/timer.cc + src/core/lib/iomgr/timer_custom.cc src/core/lib/iomgr/timer_generic.cc src/core/lib/iomgr/timer_heap.cc src/core/lib/iomgr/timer_manager.cc diff --git a/MANIFEST.md b/MANIFEST.md index a0e79e85327..9581e1c993d 100644 --- a/MANIFEST.md +++ b/MANIFEST.md @@ -3,10 +3,6 @@ ## Bazel * [grpc.bzl](grpc.bzl) -## Node -* [binding.gyp](binding.gyp) -* [package.json](package.json) - ## Objective-C * [gRPC.podspec](gRPC.podspec) diff --git a/Makefile b/Makefile index 8341fba0944..625248ea301 100644 --- a/Makefile +++ b/Makefile @@ -3202,6 +3202,8 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -3210,12 +3212,16 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -3227,19 +3233,24 @@ LIBGRPC_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -3579,6 +3590,8 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -3587,12 +3600,16 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -3604,19 +3621,24 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -3946,6 +3968,8 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -3954,12 +3978,16 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -3971,19 +3999,24 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -4228,6 +4261,8 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -4236,12 +4271,16 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -4253,19 +4292,24 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -4477,6 +4521,8 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -4485,12 +4531,16 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -4502,19 +4552,24 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ @@ -5279,6 +5334,8 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -5287,12 +5344,16 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -5304,19 +5365,24 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ diff --git a/build.yaml b/build.yaml index 3bb85a88c9f..02a1e6186e8 100644 --- a/build.yaml +++ b/build.yaml @@ -269,6 +269,8 @@ filegroups: - src/core/lib/iomgr/gethostname_sysconf.cc - src/core/lib/iomgr/iocp_windows.cc - src/core/lib/iomgr/iomgr.cc + - src/core/lib/iomgr/iomgr_custom.cc + - src/core/lib/iomgr/iomgr_internal.cc - src/core/lib/iomgr/iomgr_posix.cc - src/core/lib/iomgr/iomgr_uv.cc - src/core/lib/iomgr/iomgr_windows.cc @@ -277,12 +279,16 @@ filegroups: - src/core/lib/iomgr/lockfree_event.cc - src/core/lib/iomgr/network_status_tracker.cc - src/core/lib/iomgr/polling_entity.cc - - src/core/lib/iomgr/pollset_set_uv.cc + - src/core/lib/iomgr/pollset.cc + - src/core/lib/iomgr/pollset_custom.cc + - src/core/lib/iomgr/pollset_set.cc + - src/core/lib/iomgr/pollset_set_custom.cc - src/core/lib/iomgr/pollset_set_windows.cc - src/core/lib/iomgr/pollset_uv.cc - src/core/lib/iomgr/pollset_windows.cc + - src/core/lib/iomgr/resolve_address.cc + - src/core/lib/iomgr/resolve_address_custom.cc - src/core/lib/iomgr/resolve_address_posix.cc - - src/core/lib/iomgr/resolve_address_uv.cc - src/core/lib/iomgr/resolve_address_windows.cc - src/core/lib/iomgr/resource_quota.cc - src/core/lib/iomgr/sockaddr_utils.cc @@ -294,19 +300,24 @@ filegroups: - src/core/lib/iomgr/socket_utils_uv.cc - src/core/lib/iomgr/socket_utils_windows.cc - src/core/lib/iomgr/socket_windows.cc + - src/core/lib/iomgr/tcp_client.cc + - src/core/lib/iomgr/tcp_client_custom.cc - src/core/lib/iomgr/tcp_client_posix.cc - - src/core/lib/iomgr/tcp_client_uv.cc - src/core/lib/iomgr/tcp_client_windows.cc + - src/core/lib/iomgr/tcp_custom.cc - src/core/lib/iomgr/tcp_posix.cc + - src/core/lib/iomgr/tcp_server.cc + - src/core/lib/iomgr/tcp_server_custom.cc - src/core/lib/iomgr/tcp_server_posix.cc - src/core/lib/iomgr/tcp_server_utils_posix_common.cc - src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc - src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc - - src/core/lib/iomgr/tcp_server_uv.cc - src/core/lib/iomgr/tcp_server_windows.cc - src/core/lib/iomgr/tcp_uv.cc - src/core/lib/iomgr/tcp_windows.cc - src/core/lib/iomgr/time_averaged_stats.cc + - src/core/lib/iomgr/timer.cc + - src/core/lib/iomgr/timer_custom.cc - src/core/lib/iomgr/timer_generic.cc - src/core/lib/iomgr/timer_heap.cc - src/core/lib/iomgr/timer_manager.cc @@ -427,9 +438,9 @@ filegroups: - src/core/lib/iomgr/gethostname.h - src/core/lib/iomgr/iocp_windows.h - src/core/lib/iomgr/iomgr.h + - src/core/lib/iomgr/iomgr_custom.h - src/core/lib/iomgr/iomgr_internal.h - src/core/lib/iomgr/iomgr_posix.h - - src/core/lib/iomgr/iomgr_uv.h - src/core/lib/iomgr/is_epollexclusive_available.h - src/core/lib/iomgr/load_file.h - src/core/lib/iomgr/lockfree_event.h @@ -437,14 +448,17 @@ filegroups: - src/core/lib/iomgr/network_status_tracker.h - src/core/lib/iomgr/polling_entity.h - src/core/lib/iomgr/pollset.h + - src/core/lib/iomgr/pollset_custom.h - src/core/lib/iomgr/pollset_set.h + - src/core/lib/iomgr/pollset_set_custom.h - src/core/lib/iomgr/pollset_set_windows.h - - src/core/lib/iomgr/pollset_uv.h - src/core/lib/iomgr/pollset_windows.h - src/core/lib/iomgr/port.h - src/core/lib/iomgr/resolve_address.h + - src/core/lib/iomgr/resolve_address_custom.h - src/core/lib/iomgr/resource_quota.h - src/core/lib/iomgr/sockaddr.h + - src/core/lib/iomgr/sockaddr_custom.h - src/core/lib/iomgr/sockaddr_posix.h - src/core/lib/iomgr/sockaddr_utils.h - src/core/lib/iomgr/sockaddr_windows.h @@ -456,17 +470,16 @@ filegroups: - src/core/lib/iomgr/sys_epoll_wrapper.h - src/core/lib/iomgr/tcp_client.h - src/core/lib/iomgr/tcp_client_posix.h + - src/core/lib/iomgr/tcp_custom.h - src/core/lib/iomgr/tcp_posix.h - src/core/lib/iomgr/tcp_server.h - src/core/lib/iomgr/tcp_server_utils_posix.h - - src/core/lib/iomgr/tcp_uv.h - src/core/lib/iomgr/tcp_windows.h - src/core/lib/iomgr/time_averaged_stats.h - src/core/lib/iomgr/timer.h - - src/core/lib/iomgr/timer_generic.h + - src/core/lib/iomgr/timer_custom.h - src/core/lib/iomgr/timer_heap.h - src/core/lib/iomgr/timer_manager.h - - src/core/lib/iomgr/timer_uv.h - src/core/lib/iomgr/udp_server.h - src/core/lib/iomgr/unix_sockets_posix.h - src/core/lib/iomgr/wakeup_fd_cv.h diff --git a/config.m4 b/config.m4 index 7270051b0b0..2f17d0c4b78 100644 --- a/config.m4 +++ b/config.m4 @@ -121,6 +121,8 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/gethostname_sysconf.cc \ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iomgr.cc \ + src/core/lib/iomgr/iomgr_custom.cc \ + src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_uv.cc \ src/core/lib/iomgr/iomgr_windows.cc \ @@ -129,12 +131,16 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/lockfree_event.cc \ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/polling_entity.cc \ - src/core/lib/iomgr/pollset_set_uv.cc \ + src/core/lib/iomgr/pollset.cc \ + src/core/lib/iomgr/pollset_custom.cc \ + src/core/lib/iomgr/pollset_set.cc \ + src/core/lib/iomgr/pollset_set_custom.cc \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_uv.cc \ src/core/lib/iomgr/pollset_windows.cc \ + src/core/lib/iomgr/resolve_address.cc \ + src/core/lib/iomgr/resolve_address_custom.cc \ src/core/lib/iomgr/resolve_address_posix.cc \ - src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/sockaddr_utils.cc \ @@ -146,19 +152,24 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/iomgr/socket_utils_uv.cc \ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ + src/core/lib/iomgr/tcp_client.cc \ + src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ - src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ + src/core/lib/iomgr/tcp_custom.cc \ src/core/lib/iomgr/tcp_posix.cc \ + src/core/lib/iomgr/tcp_server.cc \ + src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ - src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/time_averaged_stats.cc \ + src/core/lib/iomgr/timer.cc \ + src/core/lib/iomgr/timer_custom.cc \ src/core/lib/iomgr/timer_generic.cc \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_manager.cc \ diff --git a/config.w32 b/config.w32 index d73acc11186..78f2fe079d1 100644 --- a/config.w32 +++ b/config.w32 @@ -98,6 +98,8 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\gethostname_sysconf.cc " + "src\\core\\lib\\iomgr\\iocp_windows.cc " + "src\\core\\lib\\iomgr\\iomgr.cc " + + "src\\core\\lib\\iomgr\\iomgr_custom.cc " + + "src\\core\\lib\\iomgr\\iomgr_internal.cc " + "src\\core\\lib\\iomgr\\iomgr_posix.cc " + "src\\core\\lib\\iomgr\\iomgr_uv.cc " + "src\\core\\lib\\iomgr\\iomgr_windows.cc " + @@ -106,12 +108,16 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\lockfree_event.cc " + "src\\core\\lib\\iomgr\\network_status_tracker.cc " + "src\\core\\lib\\iomgr\\polling_entity.cc " + - "src\\core\\lib\\iomgr\\pollset_set_uv.cc " + + "src\\core\\lib\\iomgr\\pollset.cc " + + "src\\core\\lib\\iomgr\\pollset_custom.cc " + + "src\\core\\lib\\iomgr\\pollset_set.cc " + + "src\\core\\lib\\iomgr\\pollset_set_custom.cc " + "src\\core\\lib\\iomgr\\pollset_set_windows.cc " + "src\\core\\lib\\iomgr\\pollset_uv.cc " + "src\\core\\lib\\iomgr\\pollset_windows.cc " + + "src\\core\\lib\\iomgr\\resolve_address.cc " + + "src\\core\\lib\\iomgr\\resolve_address_custom.cc " + "src\\core\\lib\\iomgr\\resolve_address_posix.cc " + - "src\\core\\lib\\iomgr\\resolve_address_uv.cc " + "src\\core\\lib\\iomgr\\resolve_address_windows.cc " + "src\\core\\lib\\iomgr\\resource_quota.cc " + "src\\core\\lib\\iomgr\\sockaddr_utils.cc " + @@ -123,19 +129,24 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\iomgr\\socket_utils_uv.cc " + "src\\core\\lib\\iomgr\\socket_utils_windows.cc " + "src\\core\\lib\\iomgr\\socket_windows.cc " + + "src\\core\\lib\\iomgr\\tcp_client.cc " + + "src\\core\\lib\\iomgr\\tcp_client_custom.cc " + "src\\core\\lib\\iomgr\\tcp_client_posix.cc " + - "src\\core\\lib\\iomgr\\tcp_client_uv.cc " + "src\\core\\lib\\iomgr\\tcp_client_windows.cc " + + "src\\core\\lib\\iomgr\\tcp_custom.cc " + "src\\core\\lib\\iomgr\\tcp_posix.cc " + + "src\\core\\lib\\iomgr\\tcp_server.cc " + + "src\\core\\lib\\iomgr\\tcp_server_custom.cc " + "src\\core\\lib\\iomgr\\tcp_server_posix.cc " + "src\\core\\lib\\iomgr\\tcp_server_utils_posix_common.cc " + "src\\core\\lib\\iomgr\\tcp_server_utils_posix_ifaddrs.cc " + "src\\core\\lib\\iomgr\\tcp_server_utils_posix_noifaddrs.cc " + - "src\\core\\lib\\iomgr\\tcp_server_uv.cc " + "src\\core\\lib\\iomgr\\tcp_server_windows.cc " + "src\\core\\lib\\iomgr\\tcp_uv.cc " + "src\\core\\lib\\iomgr\\tcp_windows.cc " + "src\\core\\lib\\iomgr\\time_averaged_stats.cc " + + "src\\core\\lib\\iomgr\\timer.cc " + + "src\\core\\lib\\iomgr\\timer_custom.cc " + "src\\core\\lib\\iomgr\\timer_generic.cc " + "src\\core\\lib\\iomgr\\timer_heap.cc " + "src\\core\\lib\\iomgr\\timer_manager.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 65a5dc66b4c..e1282611b0a 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -382,9 +382,9 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname.h', 'src/core/lib/iomgr/iocp_windows.h', 'src/core/lib/iomgr/iomgr.h', + 'src/core/lib/iomgr/iomgr_custom.h', 'src/core/lib/iomgr/iomgr_internal.h', 'src/core/lib/iomgr/iomgr_posix.h', - 'src/core/lib/iomgr/iomgr_uv.h', 'src/core/lib/iomgr/is_epollexclusive_available.h', 'src/core/lib/iomgr/load_file.h', 'src/core/lib/iomgr/lockfree_event.h', @@ -392,14 +392,17 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/network_status_tracker.h', 'src/core/lib/iomgr/polling_entity.h', 'src/core/lib/iomgr/pollset.h', + 'src/core/lib/iomgr/pollset_custom.h', 'src/core/lib/iomgr/pollset_set.h', + 'src/core/lib/iomgr/pollset_set_custom.h', 'src/core/lib/iomgr/pollset_set_windows.h', - 'src/core/lib/iomgr/pollset_uv.h', 'src/core/lib/iomgr/pollset_windows.h', 'src/core/lib/iomgr/port.h', 'src/core/lib/iomgr/resolve_address.h', + 'src/core/lib/iomgr/resolve_address_custom.h', 'src/core/lib/iomgr/resource_quota.h', 'src/core/lib/iomgr/sockaddr.h', + 'src/core/lib/iomgr/sockaddr_custom.h', 'src/core/lib/iomgr/sockaddr_posix.h', 'src/core/lib/iomgr/sockaddr_utils.h', 'src/core/lib/iomgr/sockaddr_windows.h', @@ -411,17 +414,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/sys_epoll_wrapper.h', 'src/core/lib/iomgr/tcp_client.h', 'src/core/lib/iomgr/tcp_client_posix.h', + 'src/core/lib/iomgr/tcp_custom.h', 'src/core/lib/iomgr/tcp_posix.h', 'src/core/lib/iomgr/tcp_server.h', 'src/core/lib/iomgr/tcp_server_utils_posix.h', - 'src/core/lib/iomgr/tcp_uv.h', 'src/core/lib/iomgr/tcp_windows.h', 'src/core/lib/iomgr/time_averaged_stats.h', 'src/core/lib/iomgr/timer.h', - 'src/core/lib/iomgr/timer_generic.h', + 'src/core/lib/iomgr/timer_custom.h', 'src/core/lib/iomgr/timer_heap.h', 'src/core/lib/iomgr/timer_manager.h', - 'src/core/lib/iomgr/timer_uv.h', 'src/core/lib/iomgr/udp_server.h', 'src/core/lib/iomgr/unix_sockets_posix.h', 'src/core/lib/iomgr/wakeup_fd_cv.h', @@ -561,9 +563,9 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname.h', 'src/core/lib/iomgr/iocp_windows.h', 'src/core/lib/iomgr/iomgr.h', + 'src/core/lib/iomgr/iomgr_custom.h', 'src/core/lib/iomgr/iomgr_internal.h', 'src/core/lib/iomgr/iomgr_posix.h', - 'src/core/lib/iomgr/iomgr_uv.h', 'src/core/lib/iomgr/is_epollexclusive_available.h', 'src/core/lib/iomgr/load_file.h', 'src/core/lib/iomgr/lockfree_event.h', @@ -571,14 +573,17 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/network_status_tracker.h', 'src/core/lib/iomgr/polling_entity.h', 'src/core/lib/iomgr/pollset.h', + 'src/core/lib/iomgr/pollset_custom.h', 'src/core/lib/iomgr/pollset_set.h', + 'src/core/lib/iomgr/pollset_set_custom.h', 'src/core/lib/iomgr/pollset_set_windows.h', - 'src/core/lib/iomgr/pollset_uv.h', 'src/core/lib/iomgr/pollset_windows.h', 'src/core/lib/iomgr/port.h', 'src/core/lib/iomgr/resolve_address.h', + 'src/core/lib/iomgr/resolve_address_custom.h', 'src/core/lib/iomgr/resource_quota.h', 'src/core/lib/iomgr/sockaddr.h', + 'src/core/lib/iomgr/sockaddr_custom.h', 'src/core/lib/iomgr/sockaddr_posix.h', 'src/core/lib/iomgr/sockaddr_utils.h', 'src/core/lib/iomgr/sockaddr_windows.h', @@ -590,17 +595,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/sys_epoll_wrapper.h', 'src/core/lib/iomgr/tcp_client.h', 'src/core/lib/iomgr/tcp_client_posix.h', + 'src/core/lib/iomgr/tcp_custom.h', 'src/core/lib/iomgr/tcp_posix.h', 'src/core/lib/iomgr/tcp_server.h', 'src/core/lib/iomgr/tcp_server_utils_posix.h', - 'src/core/lib/iomgr/tcp_uv.h', 'src/core/lib/iomgr/tcp_windows.h', 'src/core/lib/iomgr/time_averaged_stats.h', 'src/core/lib/iomgr/timer.h', - 'src/core/lib/iomgr/timer_generic.h', + 'src/core/lib/iomgr/timer_custom.h', 'src/core/lib/iomgr/timer_heap.h', 'src/core/lib/iomgr/timer_manager.h', - 'src/core/lib/iomgr/timer_uv.h', 'src/core/lib/iomgr/udp_server.h', 'src/core/lib/iomgr/unix_sockets_posix.h', 'src/core/lib/iomgr/wakeup_fd_cv.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 72020d2d109..39433ff8195 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -393,9 +393,9 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname.h', 'src/core/lib/iomgr/iocp_windows.h', 'src/core/lib/iomgr/iomgr.h', + 'src/core/lib/iomgr/iomgr_custom.h', 'src/core/lib/iomgr/iomgr_internal.h', 'src/core/lib/iomgr/iomgr_posix.h', - 'src/core/lib/iomgr/iomgr_uv.h', 'src/core/lib/iomgr/is_epollexclusive_available.h', 'src/core/lib/iomgr/load_file.h', 'src/core/lib/iomgr/lockfree_event.h', @@ -403,14 +403,17 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/network_status_tracker.h', 'src/core/lib/iomgr/polling_entity.h', 'src/core/lib/iomgr/pollset.h', + 'src/core/lib/iomgr/pollset_custom.h', 'src/core/lib/iomgr/pollset_set.h', + 'src/core/lib/iomgr/pollset_set_custom.h', 'src/core/lib/iomgr/pollset_set_windows.h', - 'src/core/lib/iomgr/pollset_uv.h', 'src/core/lib/iomgr/pollset_windows.h', 'src/core/lib/iomgr/port.h', 'src/core/lib/iomgr/resolve_address.h', + 'src/core/lib/iomgr/resolve_address_custom.h', 'src/core/lib/iomgr/resource_quota.h', 'src/core/lib/iomgr/sockaddr.h', + 'src/core/lib/iomgr/sockaddr_custom.h', 'src/core/lib/iomgr/sockaddr_posix.h', 'src/core/lib/iomgr/sockaddr_utils.h', 'src/core/lib/iomgr/sockaddr_windows.h', @@ -422,17 +425,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/sys_epoll_wrapper.h', 'src/core/lib/iomgr/tcp_client.h', 'src/core/lib/iomgr/tcp_client_posix.h', + 'src/core/lib/iomgr/tcp_custom.h', 'src/core/lib/iomgr/tcp_posix.h', 'src/core/lib/iomgr/tcp_server.h', 'src/core/lib/iomgr/tcp_server_utils_posix.h', - 'src/core/lib/iomgr/tcp_uv.h', 'src/core/lib/iomgr/tcp_windows.h', 'src/core/lib/iomgr/time_averaged_stats.h', 'src/core/lib/iomgr/timer.h', - 'src/core/lib/iomgr/timer_generic.h', + 'src/core/lib/iomgr/timer_custom.h', 'src/core/lib/iomgr/timer_heap.h', 'src/core/lib/iomgr/timer_manager.h', - 'src/core/lib/iomgr/timer_uv.h', 'src/core/lib/iomgr/udp_server.h', 'src/core/lib/iomgr/unix_sockets_posix.h', 'src/core/lib/iomgr/wakeup_fd_cv.h', @@ -535,6 +537,8 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -543,12 +547,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -560,19 +568,24 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', @@ -947,9 +960,9 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/gethostname.h', 'src/core/lib/iomgr/iocp_windows.h', 'src/core/lib/iomgr/iomgr.h', + 'src/core/lib/iomgr/iomgr_custom.h', 'src/core/lib/iomgr/iomgr_internal.h', 'src/core/lib/iomgr/iomgr_posix.h', - 'src/core/lib/iomgr/iomgr_uv.h', 'src/core/lib/iomgr/is_epollexclusive_available.h', 'src/core/lib/iomgr/load_file.h', 'src/core/lib/iomgr/lockfree_event.h', @@ -957,14 +970,17 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/network_status_tracker.h', 'src/core/lib/iomgr/polling_entity.h', 'src/core/lib/iomgr/pollset.h', + 'src/core/lib/iomgr/pollset_custom.h', 'src/core/lib/iomgr/pollset_set.h', + 'src/core/lib/iomgr/pollset_set_custom.h', 'src/core/lib/iomgr/pollset_set_windows.h', - 'src/core/lib/iomgr/pollset_uv.h', 'src/core/lib/iomgr/pollset_windows.h', 'src/core/lib/iomgr/port.h', 'src/core/lib/iomgr/resolve_address.h', + 'src/core/lib/iomgr/resolve_address_custom.h', 'src/core/lib/iomgr/resource_quota.h', 'src/core/lib/iomgr/sockaddr.h', + 'src/core/lib/iomgr/sockaddr_custom.h', 'src/core/lib/iomgr/sockaddr_posix.h', 'src/core/lib/iomgr/sockaddr_utils.h', 'src/core/lib/iomgr/sockaddr_windows.h', @@ -976,17 +992,16 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/sys_epoll_wrapper.h', 'src/core/lib/iomgr/tcp_client.h', 'src/core/lib/iomgr/tcp_client_posix.h', + 'src/core/lib/iomgr/tcp_custom.h', 'src/core/lib/iomgr/tcp_posix.h', 'src/core/lib/iomgr/tcp_server.h', 'src/core/lib/iomgr/tcp_server_utils_posix.h', - 'src/core/lib/iomgr/tcp_uv.h', 'src/core/lib/iomgr/tcp_windows.h', 'src/core/lib/iomgr/time_averaged_stats.h', 'src/core/lib/iomgr/timer.h', - 'src/core/lib/iomgr/timer_generic.h', + 'src/core/lib/iomgr/timer_custom.h', 'src/core/lib/iomgr/timer_heap.h', 'src/core/lib/iomgr/timer_manager.h', - 'src/core/lib/iomgr/timer_uv.h', 'src/core/lib/iomgr/udp_server.h', 'src/core/lib/iomgr/unix_sockets_posix.h', 'src/core/lib/iomgr/wakeup_fd_cv.h', diff --git a/grpc.gemspec b/grpc.gemspec index 89a3812376e..3a578299435 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -323,9 +323,9 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/gethostname.h ) s.files += %w( src/core/lib/iomgr/iocp_windows.h ) s.files += %w( src/core/lib/iomgr/iomgr.h ) + s.files += %w( src/core/lib/iomgr/iomgr_custom.h ) s.files += %w( src/core/lib/iomgr/iomgr_internal.h ) s.files += %w( src/core/lib/iomgr/iomgr_posix.h ) - s.files += %w( src/core/lib/iomgr/iomgr_uv.h ) s.files += %w( src/core/lib/iomgr/is_epollexclusive_available.h ) s.files += %w( src/core/lib/iomgr/load_file.h ) s.files += %w( src/core/lib/iomgr/lockfree_event.h ) @@ -333,14 +333,17 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/network_status_tracker.h ) s.files += %w( src/core/lib/iomgr/polling_entity.h ) s.files += %w( src/core/lib/iomgr/pollset.h ) + s.files += %w( src/core/lib/iomgr/pollset_custom.h ) s.files += %w( src/core/lib/iomgr/pollset_set.h ) + s.files += %w( src/core/lib/iomgr/pollset_set_custom.h ) s.files += %w( src/core/lib/iomgr/pollset_set_windows.h ) - s.files += %w( src/core/lib/iomgr/pollset_uv.h ) s.files += %w( src/core/lib/iomgr/pollset_windows.h ) s.files += %w( src/core/lib/iomgr/port.h ) s.files += %w( src/core/lib/iomgr/resolve_address.h ) + s.files += %w( src/core/lib/iomgr/resolve_address_custom.h ) s.files += %w( src/core/lib/iomgr/resource_quota.h ) s.files += %w( src/core/lib/iomgr/sockaddr.h ) + s.files += %w( src/core/lib/iomgr/sockaddr_custom.h ) s.files += %w( src/core/lib/iomgr/sockaddr_posix.h ) s.files += %w( src/core/lib/iomgr/sockaddr_utils.h ) s.files += %w( src/core/lib/iomgr/sockaddr_windows.h ) @@ -352,17 +355,16 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/sys_epoll_wrapper.h ) s.files += %w( src/core/lib/iomgr/tcp_client.h ) s.files += %w( src/core/lib/iomgr/tcp_client_posix.h ) + s.files += %w( src/core/lib/iomgr/tcp_custom.h ) s.files += %w( src/core/lib/iomgr/tcp_posix.h ) s.files += %w( src/core/lib/iomgr/tcp_server.h ) s.files += %w( src/core/lib/iomgr/tcp_server_utils_posix.h ) - s.files += %w( src/core/lib/iomgr/tcp_uv.h ) s.files += %w( src/core/lib/iomgr/tcp_windows.h ) s.files += %w( src/core/lib/iomgr/time_averaged_stats.h ) s.files += %w( src/core/lib/iomgr/timer.h ) - s.files += %w( src/core/lib/iomgr/timer_generic.h ) + s.files += %w( src/core/lib/iomgr/timer_custom.h ) s.files += %w( src/core/lib/iomgr/timer_heap.h ) s.files += %w( src/core/lib/iomgr/timer_manager.h ) - s.files += %w( src/core/lib/iomgr/timer_uv.h ) s.files += %w( src/core/lib/iomgr/udp_server.h ) s.files += %w( src/core/lib/iomgr/unix_sockets_posix.h ) s.files += %w( src/core/lib/iomgr/wakeup_fd_cv.h ) @@ -465,6 +467,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/gethostname_sysconf.cc ) s.files += %w( src/core/lib/iomgr/iocp_windows.cc ) s.files += %w( src/core/lib/iomgr/iomgr.cc ) + s.files += %w( src/core/lib/iomgr/iomgr_custom.cc ) + s.files += %w( src/core/lib/iomgr/iomgr_internal.cc ) s.files += %w( src/core/lib/iomgr/iomgr_posix.cc ) s.files += %w( src/core/lib/iomgr/iomgr_uv.cc ) s.files += %w( src/core/lib/iomgr/iomgr_windows.cc ) @@ -473,12 +477,16 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/lockfree_event.cc ) s.files += %w( src/core/lib/iomgr/network_status_tracker.cc ) s.files += %w( src/core/lib/iomgr/polling_entity.cc ) - s.files += %w( src/core/lib/iomgr/pollset_set_uv.cc ) + s.files += %w( src/core/lib/iomgr/pollset.cc ) + s.files += %w( src/core/lib/iomgr/pollset_custom.cc ) + s.files += %w( src/core/lib/iomgr/pollset_set.cc ) + s.files += %w( src/core/lib/iomgr/pollset_set_custom.cc ) s.files += %w( src/core/lib/iomgr/pollset_set_windows.cc ) s.files += %w( src/core/lib/iomgr/pollset_uv.cc ) s.files += %w( src/core/lib/iomgr/pollset_windows.cc ) + s.files += %w( src/core/lib/iomgr/resolve_address.cc ) + s.files += %w( src/core/lib/iomgr/resolve_address_custom.cc ) s.files += %w( src/core/lib/iomgr/resolve_address_posix.cc ) - s.files += %w( src/core/lib/iomgr/resolve_address_uv.cc ) s.files += %w( src/core/lib/iomgr/resolve_address_windows.cc ) s.files += %w( src/core/lib/iomgr/resource_quota.cc ) s.files += %w( src/core/lib/iomgr/sockaddr_utils.cc ) @@ -490,19 +498,24 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/socket_utils_uv.cc ) s.files += %w( src/core/lib/iomgr/socket_utils_windows.cc ) s.files += %w( src/core/lib/iomgr/socket_windows.cc ) + s.files += %w( src/core/lib/iomgr/tcp_client.cc ) + s.files += %w( src/core/lib/iomgr/tcp_client_custom.cc ) s.files += %w( src/core/lib/iomgr/tcp_client_posix.cc ) - s.files += %w( src/core/lib/iomgr/tcp_client_uv.cc ) s.files += %w( src/core/lib/iomgr/tcp_client_windows.cc ) + s.files += %w( src/core/lib/iomgr/tcp_custom.cc ) s.files += %w( src/core/lib/iomgr/tcp_posix.cc ) + s.files += %w( src/core/lib/iomgr/tcp_server.cc ) + s.files += %w( src/core/lib/iomgr/tcp_server_custom.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_posix.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_utils_posix_common.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc ) - s.files += %w( src/core/lib/iomgr/tcp_server_uv.cc ) s.files += %w( src/core/lib/iomgr/tcp_server_windows.cc ) s.files += %w( src/core/lib/iomgr/tcp_uv.cc ) s.files += %w( src/core/lib/iomgr/tcp_windows.cc ) s.files += %w( src/core/lib/iomgr/time_averaged_stats.cc ) + s.files += %w( src/core/lib/iomgr/timer.cc ) + s.files += %w( src/core/lib/iomgr/timer_custom.cc ) s.files += %w( src/core/lib/iomgr/timer_generic.cc ) s.files += %w( src/core/lib/iomgr/timer_heap.cc ) s.files += %w( src/core/lib/iomgr/timer_manager.cc ) diff --git a/grpc.gyp b/grpc.gyp index c5401f32b36..403d32831b1 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -274,6 +274,8 @@ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -282,12 +284,16 @@ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -299,19 +305,24 @@ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', @@ -606,6 +617,8 @@ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -614,12 +627,16 @@ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -631,19 +648,24 @@ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', @@ -823,6 +845,8 @@ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -831,12 +855,16 @@ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -848,19 +876,24 @@ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', @@ -1019,6 +1052,8 @@ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -1027,12 +1062,16 @@ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -1044,19 +1083,24 @@ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index a3cd1f1bbeb..90dbfd3b1f8 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -95,7 +95,7 @@ struct grpc_slice { /** Represents an expandable array of slices, to be interpreted as a single item. */ -typedef struct { +typedef struct grpc_slice_buffer { /** This is for internal use only. External users (i.e any code outside grpc * core) MUST NOT use this field */ grpc_slice* base_slices; diff --git a/package.xml b/package.xml index fc7ba68e8ba..8f0dc55dbf8 100644 --- a/package.xml +++ b/package.xml @@ -330,9 +330,9 @@ + - @@ -340,14 +340,17 @@ + + - + + @@ -359,17 +362,16 @@ + - - + - @@ -472,6 +474,8 @@ + + @@ -480,12 +484,16 @@ - + + + + + + - @@ -497,19 +505,24 @@ + + - + + + - + + diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index cb39e4224e3..47e1deef129 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -61,6 +61,7 @@ #include #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #include @@ -417,20 +418,20 @@ void ParseServer(const grpc_grpclb_server* server, grpc_resolved_address* addr) { memset(addr, 0, sizeof(*addr)); if (server->drop) return; - const uint16_t netorder_port = htons((uint16_t)server->port); + const uint16_t netorder_port = grpc_htons((uint16_t)server->port); /* the addresses are given in binary format (a in(6)_addr struct) in * server->ip_address.bytes. */ const grpc_grpclb_ip_address* ip = &server->ip_address; if (ip->size == 4) { - addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in* addr4 = (struct sockaddr_in*)&addr->addr; - addr4->sin_family = AF_INET; + addr->len = sizeof(grpc_sockaddr_in); + grpc_sockaddr_in* addr4 = reinterpret_cast(&addr->addr); + addr4->sin_family = GRPC_AF_INET; memcpy(&addr4->sin_addr, ip->bytes, ip->size); addr4->sin_port = netorder_port; } else if (ip->size == 16) { - addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6* addr6 = (struct sockaddr_in6*)&addr->addr; - addr6->sin6_family = AF_INET6; + addr->len = sizeof(grpc_sockaddr_in6); + grpc_sockaddr_in6* addr6 = (grpc_sockaddr_in6*)&addr->addr; + addr6->sin6_family = GRPC_AF_INET6; memcpy(&addr6->sin6_addr, ip->bytes, ip->size); addr6->sin6_port = netorder_port; } diff --git a/src/core/ext/filters/client_channel/parse_address.cc b/src/core/ext/filters/client_channel/parse_address.cc index e78dc99e0b3..92ea259cf0a 100644 --- a/src/core/ext/filters/client_channel/parse_address.cc +++ b/src/core/ext/filters/client_channel/parse_address.cc @@ -20,6 +20,7 @@ #include "src/core/ext/filters/client_channel/parse_address.h" #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #include @@ -71,10 +72,10 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, if (!gpr_split_host_port(hostport, &host, &port)) return false; // Parse IP address. memset(addr, 0, sizeof(*addr)); - addr->len = sizeof(struct sockaddr_in); - struct sockaddr_in* in = reinterpret_cast(addr->addr); - in->sin_family = AF_INET; - if (inet_pton(AF_INET, host, &in->sin_addr) == 0) { + addr->len = sizeof(grpc_sockaddr_in); + grpc_sockaddr_in* in = reinterpret_cast(addr->addr); + in->sin_family = GRPC_AF_INET; + if (grpc_inet_pton(GRPC_AF_INET, host, &in->sin_addr) == 0) { if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host); goto done; } @@ -88,7 +89,7 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr, if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); goto done; } - in->sin_port = htons(static_cast(port_num)); + in->sin_port = grpc_htons(static_cast(port_num)); success = true; done: gpr_free(host); @@ -117,19 +118,20 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, if (!gpr_split_host_port(hostport, &host, &port)) return false; // Parse IP address. memset(addr, 0, sizeof(*addr)); - addr->len = sizeof(struct sockaddr_in6); - struct sockaddr_in6* in6 = reinterpret_cast(addr->addr); - in6->sin6_family = AF_INET6; + addr->len = sizeof(grpc_sockaddr_in6); + grpc_sockaddr_in6* in6 = reinterpret_cast(addr->addr); + in6->sin6_family = GRPC_AF_INET6; // Handle the RFC6874 syntax for IPv6 zone identifiers. char* host_end = static_cast(gpr_memrchr(host, '%', strlen(host))); if (host_end != nullptr) { GPR_ASSERT(host_end >= host); - char host_without_scope[INET6_ADDRSTRLEN]; + char host_without_scope[GRPC_INET6_ADDRSTRLEN]; size_t host_without_scope_len = static_cast(host_end - host); uint32_t sin6_scope_id = 0; strncpy(host_without_scope, host, host_without_scope_len); host_without_scope[host_without_scope_len] = '\0'; - if (inet_pton(AF_INET6, host_without_scope, &in6->sin6_addr) == 0) { + if (grpc_inet_pton(GRPC_AF_INET6, host_without_scope, &in6->sin6_addr) == + 0) { gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host_without_scope); goto done; } @@ -142,7 +144,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, // Handle "sin6_scope_id" being type "u_long". See grpc issue #10027. in6->sin6_scope_id = sin6_scope_id; } else { - if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) { + if (grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) == 0) { gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host); goto done; } @@ -157,7 +159,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr, if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); goto done; } - in6->sin6_port = htons(static_cast(port_num)); + in6->sin6_port = grpc_htons(static_cast(port_num)); success = true; done: gpr_free(host); diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index aa93e5d8de7..a895afa7843 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -440,6 +440,27 @@ class AresDnsResolverFactory : public ResolverFactory { } // namespace grpc_core +extern grpc_address_resolver_vtable* grpc_resolve_address_impl; +static grpc_address_resolver_vtable* default_resolver; + +static void resolve_address_ares(const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addrs) { + grpc_resolve_address_ares(addr, default_port, interested_parties, on_done, + addrs); +} + +static grpc_error* blocking_resolve_address_ares( + const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + return default_resolver->blocking_resolve_address(name, default_port, + addresses); +} + +static grpc_address_resolver_vtable ares_resolver = { + resolve_address_ares, blocking_resolve_address_ares}; + void grpc_resolver_dns_ares_init() { char* resolver_env = gpr_getenv("GRPC_DNS_RESOLVER"); /* TODO(zyc): Turn on c-ares based resolver by default after the address @@ -450,7 +471,8 @@ void grpc_resolver_dns_ares_init() { GRPC_LOG_IF_ERROR("ares_library_init() failed", error); return; } - grpc_resolve_address = grpc_resolve_address_ares; + default_resolver = grpc_resolve_address_impl; + grpc_set_resolver_impl(&ares_resolver); grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( grpc_core::UniquePtr( grpc_core::New())); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc index 822236dd2d7..99f18cdf39f 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc @@ -41,6 +41,5 @@ int grpc_server_add_insecure_http2_port(grpc_server* server, const char* addr) { GRPC_ERROR_UNREF(err); } - return port_num; } diff --git a/src/core/lib/iomgr/endpoint.cc b/src/core/lib/iomgr/endpoint.cc index e22c21e4bdc..92e79301114 100644 --- a/src/core/lib/iomgr/endpoint.cc +++ b/src/core/lib/iomgr/endpoint.cc @@ -20,6 +20,8 @@ #include "src/core/lib/iomgr/endpoint.h" +grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); + void grpc_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { ep->vtable->read(ep, slices, cb); diff --git a/src/core/lib/iomgr/endpoint_pair_windows.cc b/src/core/lib/iomgr/endpoint_pair_windows.cc index 416c9d88a17..177331d6812 100644 --- a/src/core/lib/iomgr/endpoint_pair_windows.cc +++ b/src/core/lib/iomgr/endpoint_pair_windows.cc @@ -22,6 +22,7 @@ #ifdef GRPC_WINSOCK_SOCKET #include "src/core/lib/iomgr/endpoint_pair.h" +#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include @@ -46,19 +47,19 @@ static void create_sockets(SOCKET sv[2]) { memset(&addr, 0, sizeof(addr)); addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_family = AF_INET; - GPR_ASSERT(bind(lst_sock, (struct sockaddr*)&addr, sizeof(addr)) != + GPR_ASSERT(bind(lst_sock, (grpc_sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR); GPR_ASSERT(listen(lst_sock, SOMAXCONN) != SOCKET_ERROR); - GPR_ASSERT(getsockname(lst_sock, (struct sockaddr*)&addr, &addr_len) != + GPR_ASSERT(getsockname(lst_sock, (grpc_sockaddr*)&addr, &addr_len) != SOCKET_ERROR); cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); GPR_ASSERT(cli_sock != INVALID_SOCKET); - GPR_ASSERT(WSAConnect(cli_sock, (struct sockaddr*)&addr, addr_len, NULL, NULL, + GPR_ASSERT(WSAConnect(cli_sock, (grpc_sockaddr*)&addr, addr_len, NULL, NULL, NULL, NULL) == 0); - svr_sock = accept(lst_sock, (struct sockaddr*)&addr, &addr_len); + svr_sock = accept(lst_sock, (grpc_sockaddr*)&addr, &addr_len); GPR_ASSERT(svr_sock != INVALID_SOCKET); closesocket(lst_sock); diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index 39ce459f1ef..8b800702653 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -224,26 +224,26 @@ void grpc_fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { g_event_engine->fd_notify_on_write(fd, closure); } -size_t grpc_pollset_size(void) { return g_event_engine->pollset_size; } +static size_t pollset_size(void) { return g_event_engine->pollset_size; } -void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { +static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { GRPC_POLLING_API_TRACE("pollset_init(%p)", pollset); g_event_engine->pollset_init(pollset, mu); } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { GRPC_POLLING_API_TRACE("pollset_shutdown(%p)", pollset); g_event_engine->pollset_shutdown(pollset, closure); } -void grpc_pollset_destroy(grpc_pollset* pollset) { +static void pollset_destroy(grpc_pollset* pollset) { GRPC_POLLING_API_TRACE("pollset_destroy(%p)", pollset); g_event_engine->pollset_destroy(pollset); } -grpc_error* grpc_pollset_work(grpc_pollset* pollset, - grpc_pollset_worker** worker, - grpc_millis deadline) { +static grpc_error* pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker, + grpc_millis deadline) { GRPC_POLLING_API_TRACE("pollset_work(%p, %" PRIdPTR ") begin", pollset, deadline); grpc_error* err = g_event_engine->pollset_work(pollset, worker, deadline); @@ -252,8 +252,8 @@ grpc_error* grpc_pollset_work(grpc_pollset* pollset, return err; } -grpc_error* grpc_pollset_kick(grpc_pollset* pollset, - grpc_pollset_worker* specific_worker) { +static grpc_error* pollset_kick(grpc_pollset* pollset, + grpc_pollset_worker* specific_worker) { GRPC_POLLING_API_TRACE("pollset_kick(%p, %p)", pollset, specific_worker); return g_event_engine->pollset_kick(pollset, specific_worker); } @@ -264,43 +264,57 @@ void grpc_pollset_add_fd(grpc_pollset* pollset, struct grpc_fd* fd) { g_event_engine->pollset_add_fd(pollset, fd); } -grpc_pollset_set* grpc_pollset_set_create(void) { +void pollset_global_init() {} +void pollset_global_shutdown() {} + +grpc_pollset_vtable grpc_posix_pollset_vtable = { + pollset_global_init, pollset_global_shutdown, + pollset_init, pollset_shutdown, + pollset_destroy, pollset_work, + pollset_kick, pollset_size}; + +static grpc_pollset_set* pollset_set_create(void) { grpc_pollset_set* pss = g_event_engine->pollset_set_create(); GRPC_POLLING_API_TRACE("pollset_set_create(%p)", pss); return pss; } -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) { +static void pollset_set_destroy(grpc_pollset_set* pollset_set) { GRPC_POLLING_API_TRACE("pollset_set_destroy(%p)", pollset_set); g_event_engine->pollset_set_destroy(pollset_set); } -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) { +static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) { GRPC_POLLING_API_TRACE("pollset_set_add_pollset(%p, %p)", pollset_set, pollset); g_event_engine->pollset_set_add_pollset(pollset_set, pollset); } -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) { +static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) { GRPC_POLLING_API_TRACE("pollset_set_del_pollset(%p, %p)", pollset_set, pollset); g_event_engine->pollset_set_del_pollset(pollset_set, pollset); } -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) { +static void pollset_set_add_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) { GRPC_POLLING_API_TRACE("pollset_set_add_pollset_set(%p, %p)", bag, item); g_event_engine->pollset_set_add_pollset_set(bag, item); } -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) { +static void pollset_set_del_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) { GRPC_POLLING_API_TRACE("pollset_set_del_pollset_set(%p, %p)", bag, item); g_event_engine->pollset_set_del_pollset_set(bag, item); } +grpc_pollset_set_vtable grpc_posix_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}; + void grpc_pollset_set_add_fd(grpc_pollset_set* pollset_set, grpc_fd* fd) { GRPC_POLLING_API_TRACE("pollset_set_add_fd(%p, %d)", pollset_set, grpc_fd_wrapped_fd(fd)); diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index de97164f02c..e4edcf67f4e 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -171,6 +171,10 @@ on outside context */ return reinterpret_cast(gpr_tls_get(&exec_ctx_)); } + static void Set(ExecCtx* exec_ctx) { + gpr_tls_set(&exec_ctx_, reinterpret_cast(exec_ctx)); + } + protected: /** Check if ready to finish */ virtual bool CheckReadyToFinish() { return false; } @@ -180,9 +184,6 @@ on outside context */ private: /** Set exec_ctx_ to exec_ctx */ - void Set(ExecCtx* exec_ctx) { - gpr_tls_set(&exec_ctx_, reinterpret_cast(exec_ctx)); - } grpc_closure_list closure_list_ = GRPC_CLOSURE_LIST_INIT; CombinerData combiner_data_ = {nullptr, nullptr}; diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 3c2b83a5496..468814eaee0 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -47,6 +47,7 @@ static grpc_iomgr_object g_root_object; void grpc_iomgr_init() { grpc_core::ExecCtx exec_ctx; + grpc_determine_iomgr_platform(); g_shutdown = 0; gpr_mu_init(&g_mu); gpr_cv_init(&g_rcv); diff --git a/src/core/lib/iomgr/iomgr_custom.cc b/src/core/lib/iomgr/iomgr_custom.cc new file mode 100644 index 00000000000..d34c8e7cd14 --- /dev/null +++ b/src/core/lib/iomgr/iomgr_custom.cc @@ -0,0 +1,63 @@ +/* + * + * Copyright 2018 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" + +#include + +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/iomgr/executor.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/iomgr_internal.h" +#include "src/core/lib/iomgr/pollset_custom.h" +#include "src/core/lib/iomgr/pollset_set_custom.h" +#include "src/core/lib/iomgr/resolve_address_custom.h" + +gpr_thd_id g_init_thread; + +static void iomgr_platform_init(void) { + grpc_core::ExecCtx exec_ctx; + grpc_executor_set_threading(false); + g_init_thread = gpr_thd_currentid(); + grpc_pollset_global_init(); +} +static void iomgr_platform_flush(void) {} +static void iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); } + +static grpc_iomgr_platform_vtable vtable = { + iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown}; + +void grpc_custom_iomgr_init(grpc_socket_vtable* socket, + grpc_custom_resolver_vtable* resolver, + grpc_custom_timer_vtable* timer, + grpc_custom_poller_vtable* poller) { + grpc_custom_endpoint_init(socket); + grpc_custom_timer_init(timer); + grpc_custom_pollset_init(poller); + grpc_custom_pollset_set_init(); + grpc_custom_resolver_init(resolver); + grpc_set_iomgr_platform_vtable(&vtable); +} + +#ifdef GRPC_CUSTOM_SOCKET +grpc_iomgr_platform_vtable* grpc_default_iomgr_platform_vtable() { + return &vtable; +} +#endif diff --git a/src/core/lib/iomgr/iomgr_uv.h b/src/core/lib/iomgr/iomgr_custom.h similarity index 53% rename from src/core/lib/iomgr/iomgr_uv.h rename to src/core/lib/iomgr/iomgr_custom.h index 4d62f00ad6e..ceb6c65db24 100644 --- a/src/core/lib/iomgr/iomgr_uv.h +++ b/src/core/lib/iomgr/iomgr_custom.h @@ -16,24 +16,32 @@ * */ -#ifndef GRPC_CORE_LIB_IOMGR_IOMGR_UV_H -#define GRPC_CORE_LIB_IOMGR_IOMGR_UV_H +#ifndef GRPC_CORE_LIB_IOMGR_IOMGR_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_IOMGR_CUSTOM_H #include -#include "src/core/lib/iomgr/iomgr_internal.h" +#include "src/core/lib/iomgr/pollset_custom.h" +#include "src/core/lib/iomgr/resolve_address_custom.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/timer_custom.h" #include /* The thread ID of the thread on which grpc was initialized. Used to verify - * that all calls into libuv are made on that same thread */ + * that all calls into the custom iomgr are made on that same thread */ extern gpr_thd_id g_init_thread; -#ifdef GRPC_UV_THREAD_CHECK -#define GRPC_UV_ASSERT_SAME_THREAD() \ +#ifdef GRPC_CUSTOM_IOMGR_THREAD_CHECK +#define GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD() \ GPR_ASSERT(gpr_thd_currentid() == g_init_thread) #else -#define GRPC_UV_ASSERT_SAME_THREAD() +#define GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD() #endif /* GRPC_UV_THREAD_CHECK */ -#endif /* GRPC_CORE_LIB_IOMGR_IOMGR_UV_H */ +void grpc_custom_iomgr_init(grpc_socket_vtable* socket, + grpc_custom_resolver_vtable* resolver, + grpc_custom_timer_vtable* timer, + grpc_custom_poller_vtable* poller); + +#endif /* GRPC_CORE_LIB_IOMGR_IOMGR_CUSTOM_H */ diff --git a/src/core/lib/iomgr/iomgr_internal.cc b/src/core/lib/iomgr/iomgr_internal.cc new file mode 100644 index 00000000000..32dbabb79dc --- /dev/null +++ b/src/core/lib/iomgr/iomgr_internal.cc @@ -0,0 +1,43 @@ +/* + * + * Copyright 2018 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 "src/core/lib/iomgr/iomgr_internal.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/iomgr/timer_manager.h" + +static grpc_iomgr_platform_vtable* iomgr_platform_vtable = nullptr; + +void grpc_set_iomgr_platform_vtable(grpc_iomgr_platform_vtable* vtable) { + iomgr_platform_vtable = vtable; +} + +void grpc_determine_iomgr_platform() { + if (iomgr_platform_vtable == nullptr) { + grpc_set_default_iomgr_platform(); + } +} + +void grpc_iomgr_platform_init() { iomgr_platform_vtable->init(); } + +void grpc_iomgr_platform_flush() { iomgr_platform_vtable->flush(); } + +void grpc_iomgr_platform_shutdown() { iomgr_platform_vtable->shutdown(); } diff --git a/src/core/lib/iomgr/iomgr_internal.h b/src/core/lib/iomgr/iomgr_internal.h index 644219fb4dc..b011d9c7b19 100644 --- a/src/core/lib/iomgr/iomgr_internal.h +++ b/src/core/lib/iomgr/iomgr_internal.h @@ -31,9 +31,21 @@ typedef struct grpc_iomgr_object { struct grpc_iomgr_object* prev; } grpc_iomgr_object; +typedef struct grpc_iomgr_platform_vtable { + void (*init)(void); + void (*flush)(void); + void (*shutdown)(void); +} grpc_iomgr_platform_vtable; + void grpc_iomgr_register_object(grpc_iomgr_object* obj, const char* name); void grpc_iomgr_unregister_object(grpc_iomgr_object* obj); +void grpc_determine_iomgr_platform(); + +void grpc_set_iomgr_platform_vtable(grpc_iomgr_platform_vtable* vtable); + +void grpc_set_default_iomgr_platform(); + void grpc_iomgr_platform_init(void); /** flush any globally queued work from iomgr */ void grpc_iomgr_platform_flush(void); diff --git a/src/core/lib/iomgr/iomgr_posix.cc b/src/core/lib/iomgr/iomgr_posix.cc index 35b8adf01e0..66c9cb7ff7c 100644 --- a/src/core/lib/iomgr/iomgr_posix.cc +++ b/src/core/lib/iomgr/iomgr_posix.cc @@ -24,19 +24,44 @@ #include "src/core/lib/debug/trace.h" #include "src/core/lib/iomgr/ev_posix.h" +#include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/iomgr_posix.h" +#include "src/core/lib/iomgr/resolve_address.h" +#include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/tcp_posix.h" +#include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/lib/iomgr/timer.h" -void grpc_iomgr_platform_init(void) { +extern grpc_tcp_server_vtable grpc_posix_tcp_server_vtable; +extern grpc_tcp_client_vtable grpc_posix_tcp_client_vtable; +extern grpc_timer_vtable grpc_generic_timer_vtable; +extern grpc_pollset_vtable grpc_posix_pollset_vtable; +extern grpc_pollset_set_vtable grpc_posix_pollset_set_vtable; +extern grpc_address_resolver_vtable grpc_posix_resolver_vtable; + +static void iomgr_platform_init(void) { grpc_wakeup_fd_global_init(); grpc_event_engine_init(); } -void grpc_iomgr_platform_flush(void) {} +static void iomgr_platform_flush(void) {} -void grpc_iomgr_platform_shutdown(void) { +static void iomgr_platform_shutdown(void) { grpc_event_engine_shutdown(); grpc_wakeup_fd_global_destroy(); } +static grpc_iomgr_platform_vtable vtable = { + iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown}; + +void grpc_set_default_iomgr_platform() { + grpc_set_tcp_client_impl(&grpc_posix_tcp_client_vtable); + grpc_set_tcp_server_impl(&grpc_posix_tcp_server_vtable); + grpc_set_timer_impl(&grpc_generic_timer_vtable); + grpc_set_pollset_vtable(&grpc_posix_pollset_vtable); + grpc_set_pollset_set_vtable(&grpc_posix_pollset_set_vtable); + grpc_set_resolver_impl(&grpc_posix_resolver_vtable); + grpc_set_iomgr_platform_vtable(&vtable); +} + #endif /* GRPC_POSIX_SOCKET */ diff --git a/src/core/lib/iomgr/iomgr_uv.cc b/src/core/lib/iomgr/iomgr_uv.cc index c11c37ca205..4a984446dba 100644 --- a/src/core/lib/iomgr/iomgr_uv.cc +++ b/src/core/lib/iomgr/iomgr_uv.cc @@ -1,6 +1,6 @@ /* * - * Copyright 2016 gRPC authors. + * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,26 +20,21 @@ #include "src/core/lib/iomgr/port.h" -#ifdef GRPC_UV +#if defined(GRPC_CUSTOM_SOCKET) && defined(GRPC_UV) -#include +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/iomgr_internal.h" +#include "src/core/lib/iomgr/pollset_custom.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/timer_custom.h" -#include "src/core/lib/debug/trace.h" -#include "src/core/lib/iomgr/executor.h" -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/pollset_uv.h" -#include "src/core/lib/iomgr/tcp_uv.h" +extern grpc_socket_vtable grpc_uv_socket_vtable; +extern grpc_custom_resolver_vtable uv_resolver_vtable; +extern grpc_custom_timer_vtable uv_timer_vtable; +extern grpc_custom_poller_vtable uv_pollset_vtable; -gpr_thd_id g_init_thread; - -void grpc_iomgr_platform_init(void) { - grpc_core::ExecCtx exec_ctx; - grpc_pollset_global_init(); - - grpc_executor_set_threading(false); - g_init_thread = gpr_thd_currentid(); +void grpc_set_default_iomgr_platform() { + grpc_custom_iomgr_init(&grpc_uv_socket_vtable, &uv_resolver_vtable, + &uv_timer_vtable, &uv_pollset_vtable); } -void grpc_iomgr_platform_flush(void) {} -void grpc_iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); } - -#endif /* GRPC_UV */ +#endif diff --git a/src/core/lib/iomgr/iomgr_windows.cc b/src/core/lib/iomgr/iomgr_windows.cc index 8c4888ca970..cdef89cbf04 100644 --- a/src/core/lib/iomgr/iomgr_windows.cc +++ b/src/core/lib/iomgr/iomgr_windows.cc @@ -29,7 +29,18 @@ #include "src/core/lib/iomgr/iocp_windows.h" #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/pollset_windows.h" +#include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/socket_windows.h" +#include "src/core/lib/iomgr/tcp_client.h" +#include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/lib/iomgr/timer.h" + +extern grpc_tcp_server_vtable grpc_windows_tcp_server_vtable; +extern grpc_tcp_client_vtable grpc_windows_tcp_client_vtable; +extern grpc_timer_vtable grpc_generic_timer_vtable; +extern grpc_pollset_vtable grpc_windows_pollset_vtable; +extern grpc_pollset_set_vtable grpc_windows_pollset_set_vtable; +extern grpc_address_resolver_vtable grpc_windows_resolver_vtable; /* Windows' io manager is going to be fully designed using IO completion ports. All of what we're doing here is basically make sure that @@ -46,18 +57,31 @@ static void winsock_shutdown(void) { GPR_ASSERT(status == 0); } -void grpc_iomgr_platform_init(void) { +static void iomgr_platform_init(void) { winsock_init(); grpc_iocp_init(); grpc_pollset_global_init(); } -void grpc_iomgr_platform_flush(void) { grpc_iocp_flush(); } +static void iomgr_platform_flush(void) { grpc_iocp_flush(); } -void grpc_iomgr_platform_shutdown(void) { +static void iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); grpc_iocp_shutdown(); winsock_shutdown(); } +static grpc_iomgr_platform_vtable vtable = { + iomgr_platform_init, iomgr_platform_flush, iomgr_platform_shutdown}; + +void grpc_set_default_iomgr_platform() { + grpc_set_tcp_client_impl(&grpc_windows_tcp_client_vtable); + grpc_set_tcp_server_impl(&grpc_windows_tcp_server_vtable); + grpc_set_timer_impl(&grpc_generic_timer_vtable); + grpc_set_pollset_vtable(&grpc_windows_pollset_vtable); + grpc_set_pollset_set_vtable(&grpc_windows_pollset_set_vtable); + grpc_set_resolver_impl(&grpc_windows_resolver_vtable); + grpc_set_iomgr_platform_vtable(&vtable); +} + #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/pollset.cc b/src/core/lib/iomgr/pollset.cc new file mode 100644 index 00000000000..ebfef1dbc76 --- /dev/null +++ b/src/core/lib/iomgr/pollset.cc @@ -0,0 +1,56 @@ +/* + * + * Copyright 2018 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/pollset.h" + +grpc_pollset_vtable* grpc_pollset_impl; + +void grpc_set_pollset_vtable(grpc_pollset_vtable* vtable) { + grpc_pollset_impl = vtable; +} + +void grpc_pollset_global_init() { grpc_pollset_impl->global_init(); } + +void grpc_pollset_global_shutdown() { grpc_pollset_impl->global_shutdown(); } + +void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { + grpc_pollset_impl->init(pollset, mu); +} + +void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { + grpc_pollset_impl->shutdown(pollset, closure); +} + +void grpc_pollset_destroy(grpc_pollset* pollset) { + grpc_pollset_impl->destroy(pollset); +} + +grpc_error* grpc_pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker, + grpc_millis deadline) { + return grpc_pollset_impl->work(pollset, worker, deadline); +} + +grpc_error* grpc_pollset_kick(grpc_pollset* pollset, + grpc_pollset_worker* specific_worker) { + return grpc_pollset_impl->kick(pollset, specific_worker); +} + +size_t grpc_pollset_size(void) { return grpc_pollset_impl->pollset_size(); } diff --git a/src/core/lib/iomgr/pollset.h b/src/core/lib/iomgr/pollset.h index 9cc3e4c7fac..28472b360d6 100644 --- a/src/core/lib/iomgr/pollset.h +++ b/src/core/lib/iomgr/pollset.h @@ -38,6 +38,24 @@ extern grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount; typedef struct grpc_pollset grpc_pollset; typedef struct grpc_pollset_worker grpc_pollset_worker; +typedef struct grpc_pollset_vtable { + void (*global_init)(void); + void (*global_shutdown)(void); + void (*init)(grpc_pollset* pollset, gpr_mu** mu); + void (*shutdown)(grpc_pollset* pollset, grpc_closure* closure); + void (*destroy)(grpc_pollset* pollset); + grpc_error* (*work)(grpc_pollset* pollset, grpc_pollset_worker** worker, + grpc_millis deadline); + grpc_error* (*kick)(grpc_pollset* pollset, + grpc_pollset_worker* specific_worker); + size_t (*pollset_size)(void); +} grpc_pollset_vtable; + +void grpc_set_pollset_vtable(grpc_pollset_vtable* vtable); + +void grpc_pollset_global_init(void); +void grpc_pollset_global_shutdown(void); + size_t grpc_pollset_size(void); /* Initialize a pollset: assumes *pollset contains all zeros */ void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu); diff --git a/src/core/lib/iomgr/pollset_custom.cc b/src/core/lib/iomgr/pollset_custom.cc new file mode 100644 index 00000000000..04bd1040552 --- /dev/null +++ b/src/core/lib/iomgr/pollset_custom.cc @@ -0,0 +1,106 @@ +/* + * + * Copyright 2018 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" + +#include +#include + +#include +#include +#include + +#include "src/core/lib/iomgr/closure.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/pollset.h" +#include "src/core/lib/iomgr/pollset_custom.h" +#include "src/core/lib/iomgr/timer.h" + +#include "src/core/lib/debug/trace.h" + +static grpc_custom_poller_vtable* poller_vtable; + +struct grpc_pollset { + gpr_mu mu; +}; + +static size_t pollset_size() { return sizeof(grpc_pollset); } + +static void pollset_global_init() { poller_vtable->init(); } + +static void pollset_global_shutdown() { poller_vtable->shutdown(); } + +static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + gpr_mu_init(&pollset->mu); + *mu = &pollset->mu; +} + +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); +} + +static void pollset_destroy(grpc_pollset* pollset) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + gpr_mu_destroy(&pollset->mu); +} + +static grpc_error* pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker_hdl, + grpc_millis deadline) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + gpr_mu_unlock(&pollset->mu); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + size_t timeout = 0; + if (deadline > now) { + timeout = deadline - now; + } + // We yield here because the poll() call might yield + // control back to the application + grpc_core::ExecCtx* curr = grpc_core::ExecCtx::Get(); + grpc_core::ExecCtx::Set(nullptr); + poller_vtable->poll(timeout); + grpc_core::ExecCtx::Set(curr); + grpc_core::ExecCtx::Get()->InvalidateNow(); + if (grpc_core::ExecCtx::Get()->HasWork()) { + grpc_core::ExecCtx::Get()->Flush(); + } + gpr_mu_lock(&pollset->mu); + return GRPC_ERROR_NONE; +} + +static grpc_error* pollset_kick(grpc_pollset* pollset, + grpc_pollset_worker* specific_worker) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + poller_vtable->kick(); + return GRPC_ERROR_NONE; +} + +grpc_pollset_vtable custom_pollset_vtable = { + pollset_global_init, pollset_global_shutdown, + pollset_init, pollset_shutdown, + pollset_destroy, pollset_work, + pollset_kick, pollset_size}; + +void grpc_custom_pollset_init(grpc_custom_poller_vtable* vtable) { + poller_vtable = vtable; + grpc_set_pollset_vtable(&custom_pollset_vtable); +} diff --git a/src/core/lib/iomgr/pollset_custom.h b/src/core/lib/iomgr/pollset_custom.h new file mode 100644 index 00000000000..9e2027f7f4a --- /dev/null +++ b/src/core/lib/iomgr/pollset_custom.h @@ -0,0 +1,35 @@ +/* + * + * Copyright 2018 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_POLLSET_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_POLLSET_CUSTOM_H + +#include + +#include + +typedef struct grpc_custom_poller_vtable { + void (*init)(); + void (*poll)(size_t timeout_ms); + void (*kick)(); + void (*shutdown)(); +} grpc_custom_poller_vtable; + +void grpc_custom_pollset_init(grpc_custom_poller_vtable* vtable); + +#endif /* GRPC_CORE_LIB_IOMGR_POLLSET_CUSTOM_H */ diff --git a/src/core/lib/iomgr/pollset_set_uv.cc b/src/core/lib/iomgr/pollset_set.cc similarity index 51% rename from src/core/lib/iomgr/pollset_set_uv.cc rename to src/core/lib/iomgr/pollset_set.cc index 50814c1f0a4..42a647a7376 100644 --- a/src/core/lib/iomgr/pollset_set_uv.cc +++ b/src/core/lib/iomgr/pollset_set.cc @@ -1,6 +1,6 @@ /* * - * Copyright 2016 gRPC authors. + * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,28 +18,38 @@ #include -#include "src/core/lib/iomgr/port.h" +#include "src/core/lib/iomgr/pollset_set.h" -#ifdef GRPC_UV +grpc_pollset_set_vtable* grpc_pollset_set_impl; -#include "src/core/lib/iomgr/pollset_set.h" +void grpc_set_pollset_set_vtable(grpc_pollset_set_vtable* vtable) { + grpc_pollset_set_impl = vtable; +} -grpc_pollset_set* grpc_pollset_set_create(void) { - return (grpc_pollset_set*)((intptr_t)0xdeafbeef); +grpc_pollset_set* grpc_pollset_set_create() { + return grpc_pollset_set_impl->create(); } -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} +void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) { + grpc_pollset_set_impl->destroy(pollset_set); +} void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) {} + grpc_pollset* pollset) { + grpc_pollset_set_impl->add_pollset(pollset_set, pollset); +} void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) {} + grpc_pollset* pollset) { + grpc_pollset_set_impl->del_pollset(pollset_set, pollset); +} void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) {} + grpc_pollset_set* item) { + grpc_pollset_set_impl->add_pollset_set(bag, item); +} void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) {} - -#endif /* GRPC_UV */ + grpc_pollset_set* item) { + grpc_pollset_set_impl->del_pollset_set(bag, item); +} diff --git a/src/core/lib/iomgr/pollset_set.h b/src/core/lib/iomgr/pollset_set.h index 18f30aa94ed..d3355b8ff8c 100644 --- a/src/core/lib/iomgr/pollset_set.h +++ b/src/core/lib/iomgr/pollset_set.h @@ -30,6 +30,17 @@ typedef struct grpc_pollset_set grpc_pollset_set; +typedef struct grpc_pollset_set_vtable { + grpc_pollset_set* (*create)(void); + void (*destroy)(grpc_pollset_set* pollset_set); + void (*add_pollset)(grpc_pollset_set* pollset_set, grpc_pollset* pollset); + void (*del_pollset)(grpc_pollset_set* pollset_set, grpc_pollset* pollset); + void (*add_pollset_set)(grpc_pollset_set* bag, grpc_pollset_set* item); + void (*del_pollset_set)(grpc_pollset_set* bag, grpc_pollset_set* item); +} grpc_pollset_set_vtable; + +void grpc_set_pollset_set_vtable(grpc_pollset_set_vtable* vtable); + grpc_pollset_set* grpc_pollset_set_create(void); void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set); void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, diff --git a/src/core/lib/iomgr/pollset_set_custom.cc b/src/core/lib/iomgr/pollset_set_custom.cc new file mode 100644 index 00000000000..b1ee66020d9 --- /dev/null +++ b/src/core/lib/iomgr/pollset_set_custom.cc @@ -0,0 +1,48 @@ +/* + * + * Copyright 2016 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" + +#include "src/core/lib/iomgr/pollset_set.h" + +grpc_pollset_set* pollset_set_create(void) { + return (grpc_pollset_set*)((intptr_t)0xdeafbeef); +} + +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) {} + +static grpc_pollset_set_vtable 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}; + +void grpc_custom_pollset_set_init() { grpc_set_pollset_set_vtable(&vtable); } diff --git a/src/core/lib/iomgr/timer_uv.h b/src/core/lib/iomgr/pollset_set_custom.h similarity index 61% rename from src/core/lib/iomgr/timer_uv.h rename to src/core/lib/iomgr/pollset_set_custom.h index 093b2d085db..80e19a1fef9 100644 --- a/src/core/lib/iomgr/timer_uv.h +++ b/src/core/lib/iomgr/pollset_set_custom.h @@ -1,6 +1,6 @@ /* * - * Copyright 2016 gRPC authors. + * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,19 +16,11 @@ * */ -#ifndef GRPC_CORE_LIB_IOMGR_TIMER_UV_H -#define GRPC_CORE_LIB_IOMGR_TIMER_UV_H +#ifndef GRPC_CORE_LIB_IOMGR_POLLSET_SET_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_POLLSET_SET_CUSTOM_H #include -#include "src/core/lib/iomgr/exec_ctx.h" +void grpc_custom_pollset_set_init(); -struct grpc_timer { - grpc_closure* closure; - /* This is actually a uv_timer_t*, but we want to keep platform-specific - types out of headers */ - void* uv_timer; - int pending; -}; - -#endif /* GRPC_CORE_LIB_IOMGR_TIMER_UV_H */ +#endif /* GRPC_CORE_LIB_IOMGR_POLLSET_SET_CUSTOM_H */ diff --git a/src/core/lib/iomgr/pollset_set_windows.cc b/src/core/lib/iomgr/pollset_set_windows.cc index ff3f6a944e4..bb9e7f5d28d 100644 --- a/src/core/lib/iomgr/pollset_set_windows.cc +++ b/src/core/lib/iomgr/pollset_set_windows.cc @@ -25,22 +25,27 @@ #include "src/core/lib/iomgr/pollset_set_windows.h" -grpc_pollset_set* grpc_pollset_set_create(void) { +static grpc_pollset_set* pollset_set_create(void) { return (grpc_pollset_set*)((intptr_t)0xdeafbeef); } -void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} +static void pollset_set_destroy(grpc_pollset_set* pollset_set) {} -void grpc_pollset_set_add_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) {} +static void pollset_set_add_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) {} -void grpc_pollset_set_del_pollset(grpc_pollset_set* pollset_set, - grpc_pollset* pollset) {} +static void pollset_set_del_pollset(grpc_pollset_set* pollset_set, + grpc_pollset* pollset) {} -void grpc_pollset_set_add_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) {} +static void pollset_set_add_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) {} -void grpc_pollset_set_del_pollset_set(grpc_pollset_set* bag, - grpc_pollset_set* item) {} +static void pollset_set_del_pollset_set(grpc_pollset_set* bag, + grpc_pollset_set* item) {} + +grpc_pollset_set_vtable grpc_windows_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_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/pollset_uv.cc b/src/core/lib/iomgr/pollset_uv.cc index c6a2f43bf13..bade6eae6c5 100644 --- a/src/core/lib/iomgr/pollset_uv.cc +++ b/src/core/lib/iomgr/pollset_uv.cc @@ -22,137 +22,72 @@ #ifdef GRPC_UV -#include - -#include - #include #include -#include - -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/pollset.h" -#include "src/core/lib/iomgr/pollset_uv.h" +#include "src/core/lib/iomgr/pollset_custom.h" -#include "src/core/lib/debug/trace.h" - -grpc_core::DebugOnlyTraceFlag grpc_trace_fd_refcount(false, "fd_refcount"); - -struct grpc_pollset { - uv_timer_t* timer; - int shutting_down; -}; +#include /* Indicates that grpc_pollset_work should run an iteration of the UV loop before running callbacks. This defaults to 1, and should be disabled if grpc_pollset_work will be called within the callstack of uv_run */ -int grpc_pollset_work_run_loop; - -gpr_mu grpc_polling_mu; +int grpc_pollset_work_run_loop = 1; -/* This is used solely to kick the uv loop, by setting a callback to be run - immediately in the next loop iteration. - Note: In the future, if there is a bug that involves missing wakeups in the - future, try adding a uv_async_t to kick the loop differently */ -uv_timer_t* dummy_uv_handle; +static bool g_kicked = false; -size_t grpc_pollset_size() { return sizeof(grpc_pollset); } +typedef struct uv_poller_handle { + uv_timer_t poll_timer; + uv_timer_t kick_timer; + int refs; +} uv_poller_handle; -void dummy_timer_cb(uv_timer_t* handle) {} +static uv_poller_handle* g_handle; -void dummy_handle_close_cb(uv_handle_t* handle) { gpr_free(handle); } - -void grpc_pollset_global_init(void) { - gpr_mu_init(&grpc_polling_mu); - dummy_uv_handle = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); - uv_timer_init(uv_default_loop(), dummy_uv_handle); - grpc_pollset_work_run_loop = 1; -} - -void grpc_pollset_global_shutdown(void) { - GRPC_UV_ASSERT_SAME_THREAD(); - gpr_mu_destroy(&grpc_polling_mu); - uv_close((uv_handle_t*)dummy_uv_handle, dummy_handle_close_cb); +static void init() { + g_handle = (uv_poller_handle*)gpr_malloc(sizeof(uv_poller_handle)); + g_handle->refs = 2; + uv_timer_init(uv_default_loop(), &g_handle->poll_timer); + uv_timer_init(uv_default_loop(), &g_handle->kick_timer); } -static void timer_run_cb(uv_timer_t* timer) {} +static void empty_timer_cb(uv_timer_t* handle) {} -static void timer_close_cb(uv_handle_t* handle) { - handle->data = (void*)1; - gpr_free(handle); -} +static void kick_timer_cb(uv_timer_t* handle) { g_kicked = false; } -void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { - GRPC_UV_ASSERT_SAME_THREAD(); - *mu = &grpc_polling_mu; - pollset->timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); - uv_timer_init(uv_default_loop(), pollset->timer); - pollset->shutting_down = 0; +static void run_loop(size_t timeout) { + if (grpc_pollset_work_run_loop) { + if (timeout == 0) { + uv_run(uv_default_loop(), UV_RUN_NOWAIT); + } else { + uv_timer_start(&g_handle->poll_timer, empty_timer_cb, timeout, 0); + uv_run(uv_default_loop(), UV_RUN_ONCE); + uv_timer_stop(&g_handle->poll_timer); + } + } } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { - GPR_ASSERT(!pollset->shutting_down); - GRPC_UV_ASSERT_SAME_THREAD(); - pollset->shutting_down = 1; - if (grpc_pollset_work_run_loop) { - // Drain any pending UV callbacks without blocking - uv_run(uv_default_loop(), UV_RUN_NOWAIT); - } else { - // kick the loop once - uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0); +static void kick() { + if (!g_kicked) { + g_kicked = true; + uv_timer_start(&g_handle->kick_timer, kick_timer_cb, 0, 0); } - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); } -void grpc_pollset_destroy(grpc_pollset* pollset) { - GRPC_UV_ASSERT_SAME_THREAD(); - uv_close((uv_handle_t*)pollset->timer, timer_close_cb); - // timer.data is a boolean indicating that the timer has finished closing - pollset->timer->data = (void*)0; - if (grpc_pollset_work_run_loop) { - while (!pollset->timer->data) { - uv_run(uv_default_loop(), UV_RUN_NOWAIT); - } +static void close_timer_cb(uv_handle_t* handle) { + g_handle->refs--; + if (g_handle->refs == 0) { + gpr_free(g_handle); } } -grpc_error* grpc_pollset_work(grpc_pollset* pollset, - grpc_pollset_worker** worker_hdl, - grpc_millis deadline) { - uint64_t timeout; - GRPC_UV_ASSERT_SAME_THREAD(); - gpr_mu_unlock(&grpc_polling_mu); +static void shutdown() { + uv_close((uv_handle_t*)&g_handle->poll_timer, close_timer_cb); + uv_close((uv_handle_t*)&g_handle->kick_timer, close_timer_cb); if (grpc_pollset_work_run_loop) { - grpc_millis now = grpc_core::ExecCtx::Get()->Now(); - if (deadline >= now) { - timeout = deadline - now; - } else { - timeout = 0; - } - /* We special-case timeout=0 so that we don't bother with the timer when - the loop won't block anyway */ - if (timeout > 0) { - uv_timer_start(pollset->timer, timer_run_cb, timeout, 0); - /* Run until there is some I/O activity or the timer triggers. It doesn't - matter which happens */ - uv_run(uv_default_loop(), UV_RUN_ONCE); - uv_timer_stop(pollset->timer); - } else { - uv_run(uv_default_loop(), UV_RUN_NOWAIT); - } - } - if (!grpc_closure_list_empty(*grpc_core::ExecCtx::Get()->closure_list())) { - grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(uv_run(uv_default_loop(), UV_RUN_DEFAULT) == 0); } - gpr_mu_lock(&grpc_polling_mu); - return GRPC_ERROR_NONE; } -grpc_error* grpc_pollset_kick(grpc_pollset* pollset, - grpc_pollset_worker* specific_worker) { - GRPC_UV_ASSERT_SAME_THREAD(); - uv_timer_start(dummy_uv_handle, dummy_timer_cb, 0, 0); - return GRPC_ERROR_NONE; -} +grpc_custom_poller_vtable uv_pollset_vtable = {init, run_loop, kick, shutdown}; #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/pollset_uv.h b/src/core/lib/iomgr/pollset_uv.h index 566c110ca6c..de82bcc1d31 100644 --- a/src/core/lib/iomgr/pollset_uv.h +++ b/src/core/lib/iomgr/pollset_uv.h @@ -21,7 +21,12 @@ extern int grpc_pollset_work_run_loop; -void grpc_pollset_global_init(void); -void grpc_pollset_global_shutdown(void); +typedef struct grpc_custom_poller_vtable { + void (*init)(void); + void (*run_loop)(int blocking); +} grpc_custom_poller_vtable; + +void grpc_custom_pollset_global_init(grpc_custom_poller_vtable* vtable); +void grpc_custom_pollset_global_shutdown(void); #endif /* GRPC_CORE_LIB_IOMGR_POLLSET_UV_H */ diff --git a/src/core/lib/iomgr/pollset_windows.cc b/src/core/lib/iomgr/pollset_windows.cc index c1b83ddc147..e9a808d8ad9 100644 --- a/src/core/lib/iomgr/pollset_windows.cc +++ b/src/core/lib/iomgr/pollset_windows.cc @@ -38,7 +38,7 @@ gpr_mu grpc_polling_mu; static grpc_pollset_worker* g_active_poller; static grpc_pollset_worker g_global_root_worker; -void grpc_pollset_global_init(void) { +static void pollset_global_init(void) { gpr_mu_init(&grpc_polling_mu); g_active_poller = NULL; g_global_root_worker.links[GRPC_POLLSET_WORKER_LINK_GLOBAL].next = @@ -46,7 +46,7 @@ void grpc_pollset_global_init(void) { &g_global_root_worker; } -void grpc_pollset_global_shutdown(void) { gpr_mu_destroy(&grpc_polling_mu); } +static void pollset_global_shutdown(void) { gpr_mu_destroy(&grpc_polling_mu); } static void remove_worker(grpc_pollset_worker* worker, grpc_pollset_worker_link_type type) { @@ -80,21 +80,21 @@ static void push_front_worker(grpc_pollset_worker* root, worker->links[type].next->links[type].prev = worker; } -size_t grpc_pollset_size(void) { return sizeof(grpc_pollset); } +static size_t pollset_size(void) { return sizeof(grpc_pollset); } /* There isn't really any such thing as a pollset under Windows, due to the nature of the IO completion ports. We're still going to provide a minimal set of features for the sake of the rest of grpc. But grpc_pollset_work won't actually do any polling, and return as quickly as possible. */ -void grpc_pollset_init(grpc_pollset* pollset, gpr_mu** mu) { +static void pollset_init(grpc_pollset* pollset, gpr_mu** mu) { *mu = &grpc_polling_mu; pollset->root_worker.links[GRPC_POLLSET_WORKER_LINK_POLLSET].next = pollset->root_worker.links[GRPC_POLLSET_WORKER_LINK_POLLSET].prev = &pollset->root_worker; } -void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { +static void pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { pollset->shutting_down = 1; grpc_pollset_kick(pollset, GRPC_POLLSET_KICK_BROADCAST); if (!pollset->is_iocp_worker) { @@ -104,11 +104,11 @@ void grpc_pollset_shutdown(grpc_pollset* pollset, grpc_closure* closure) { } } -void grpc_pollset_destroy(grpc_pollset* pollset) {} +static void pollset_destroy(grpc_pollset* pollset) {} -grpc_error* grpc_pollset_work(grpc_pollset* pollset, - grpc_pollset_worker** worker_hdl, - grpc_millis deadline) { +static grpc_error* pollset_work(grpc_pollset* pollset, + grpc_pollset_worker** worker_hdl, + grpc_millis deadline) { grpc_pollset_worker worker; if (worker_hdl) *worker_hdl = &worker; @@ -182,8 +182,8 @@ done: return GRPC_ERROR_NONE; } -grpc_error* grpc_pollset_kick(grpc_pollset* p, - grpc_pollset_worker* specific_worker) { +static grpc_error* pollset_kick(grpc_pollset* p, + grpc_pollset_worker* specific_worker) { if (specific_worker != NULL) { if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) { for (specific_worker = @@ -220,4 +220,10 @@ grpc_error* grpc_pollset_kick(grpc_pollset* p, return GRPC_ERROR_NONE; } +grpc_pollset_vtable grpc_windows_pollset_vtable = { + pollset_global_init, pollset_global_shutdown, + pollset_init, pollset_shutdown, + pollset_destroy, pollset_work, + pollset_kick, pollset_size}; + #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/port.h b/src/core/lib/iomgr/port.h index 25090898ed1..c1dcc52618d 100644 --- a/src/core/lib/iomgr/port.h +++ b/src/core/lib/iomgr/port.h @@ -21,8 +21,11 @@ #ifndef GRPC_CORE_LIB_IOMGR_PORT_H #define GRPC_CORE_LIB_IOMGR_PORT_H -#if defined(GRPC_UV) -// Do nothing +#ifdef GRPC_UV +#define GRPC_CUSTOM_SOCKET +#endif +#if defined(GRPC_CUSTOM_SOCKET) +// Do Nothing #elif defined(GPR_MANYLINUX1) #define GRPC_HAVE_ARPA_NAMESER 1 #define GRPC_HAVE_IFADDRS 1 @@ -33,13 +36,10 @@ #define GRPC_POSIX_FORK 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #define GRPC_LINUX_EPOLL 1 #elif defined(GPR_WINDOWS) -#define GRPC_TIMER_USE_GENERIC 1 #define GRPC_WINSOCK_SOCKET 1 #define GRPC_WINDOWS_SOCKETUTILS 1 #elif defined(GPR_ANDROID) @@ -49,10 +49,8 @@ #define GRPC_HAVE_UNIX_SOCKET 1 #define GRPC_LINUX_EVENTFD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif defined(GPR_LINUX) #define GRPC_HAVE_ARPA_NAMESER 1 #define GRPC_HAVE_IFADDRS 1 @@ -64,9 +62,7 @@ #define GRPC_POSIX_FORK 1 #define GRPC_POSIX_HOST_NAME_MAX 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #ifdef __GLIBC_PREREQ #if __GLIBC_PREREQ(2, 4) #define GRPC_LINUX_EPOLL 1 @@ -100,11 +96,9 @@ #define GRPC_POSIX_FORK 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_SYSCONF 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif defined(GPR_FREEBSD) #define GRPC_HAVE_ARPA_NAMESER 1 #define GRPC_HAVE_IFADDRS 1 @@ -114,36 +108,31 @@ #define GRPC_POSIX_FORK 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif defined(GPR_OPENBSD) #define GRPC_HAVE_IFADDRS 1 #define GRPC_HAVE_IPV6_RECVPKTINFO 1 #define GRPC_HAVE_UNIX_SOCKET 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif defined(GPR_NACL) #define GRPC_HAVE_ARPA_NAMESER 1 #define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 #define GRPC_POSIX_SOCKET 1 -#define GRPC_POSIX_SOCKETADDR 1 #define GRPC_POSIX_SOCKETUTILS 1 #define GRPC_POSIX_WAKEUP_FD 1 -#define GRPC_TIMER_USE_GENERIC 1 #elif !defined(GPR_NO_AUTODETECT_PLATFORM) #error "Platform not recognized" #endif #if defined(GRPC_POSIX_SOCKET) + defined(GRPC_WINSOCK_SOCKET) + \ - defined(GRPC_CUSTOM_SOCKET) + defined(GRPC_UV) != \ + defined(GRPC_CUSTOM_SOCKET) != \ 1 -#error Must define exactly one of GRPC_POSIX_SOCKET, GRPC_WINSOCK_SOCKET, GPR_CUSTOM_SOCKET +#error \ + "Must define exactly one of GRPC_POSIX_SOCKET, GRPC_WINSOCK_SOCKET, GRPC_CUSTOM_SOCKET" #endif #if defined(GRPC_POSIX_HOST_NAME_MAX) && defined(GRPC_POSIX_SYSCONF) diff --git a/src/core/lib/iomgr/resolve_address.cc b/src/core/lib/iomgr/resolve_address.cc new file mode 100644 index 00000000000..f2a4676369a --- /dev/null +++ b/src/core/lib/iomgr/resolve_address.cc @@ -0,0 +1,50 @@ +/* + * + * Copyright 2018 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 "src/core/lib/iomgr/resolve_address.h" + +grpc_address_resolver_vtable* grpc_resolve_address_impl; + +void grpc_set_resolver_impl(grpc_address_resolver_vtable* vtable) { + grpc_resolve_address_impl = vtable; +} + +void grpc_resolve_address(const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses) { + grpc_resolve_address_impl->resolve_address( + addr, default_port, interested_parties, on_done, addresses); +} + +void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { + if (addrs != nullptr) { + gpr_free(addrs->addrs); + } + gpr_free(addrs); +} + +grpc_error* grpc_blocking_resolve_address(const char* name, + const char* default_port, + grpc_resolved_addresses** addresses) { + return grpc_resolve_address_impl->blocking_resolve_address(name, default_port, + addresses); +} diff --git a/src/core/lib/iomgr/resolve_address.h b/src/core/lib/iomgr/resolve_address.h index 10a78226548..7da5caaa8ee 100644 --- a/src/core/lib/iomgr/resolve_address.h +++ b/src/core/lib/iomgr/resolve_address.h @@ -37,20 +37,33 @@ typedef struct { grpc_resolved_address* addrs; } grpc_resolved_addresses; +typedef struct grpc_address_resolver_vtable { + void (*resolve_address)(const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses); + grpc_error* (*blocking_resolve_address)(const char* name, + const char* default_port, + grpc_resolved_addresses** addresses); +} grpc_address_resolver_vtable; + +void grpc_set_resolver_impl(grpc_address_resolver_vtable* vtable); + /* Asynchronously resolve addr. Use default_port if a port isn't designated in addr, otherwise use the port in addr. */ /* TODO(ctiller): add a timeout here */ -extern void (*grpc_resolve_address)(const char* addr, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addresses); +void grpc_resolve_address(const char* addr, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses); + /* Destroy resolved addresses */ void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addresses); -/* Resolve addr in a blocking fashion. Returns NULL on failure. On success, +/* Resolve addr in a blocking fashion. On success, result must be freed with grpc_resolved_addresses_destroy. */ -extern grpc_error* (*grpc_blocking_resolve_address)( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses); +grpc_error* grpc_blocking_resolve_address(const char* name, + const char* default_port, + grpc_resolved_addresses** addresses); #endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */ diff --git a/src/core/lib/iomgr/resolve_address_custom.cc b/src/core/lib/iomgr/resolve_address_custom.cc new file mode 100644 index 00000000000..9cf7817f66e --- /dev/null +++ b/src/core/lib/iomgr/resolve_address_custom.cc @@ -0,0 +1,187 @@ +/* + * + * Copyright 2018 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" + +#include +#include + +#include +#include "src/core/lib/gpr/host_port.h" +#include "src/core/lib/gpr/string.h" +#include "src/core/lib/gpr/useful.h" + +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/resolve_address_custom.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" + +#include + +typedef struct grpc_custom_resolver { + grpc_closure* on_done; + grpc_resolved_addresses** addresses; + char* host; + char* port; +} grpc_custom_resolver; + +static grpc_custom_resolver_vtable* resolve_address_vtable = nullptr; + +static int retry_named_port_failure(grpc_custom_resolver* r, + grpc_resolved_addresses** res) { + // This loop is copied from resolve_address_posix.c + const char* svc[][2] = {{"http", "80"}, {"https", "443"}}; + for (size_t i = 0; i < GPR_ARRAY_SIZE(svc); i++) { + if (strcmp(r->port, svc[i][0]) == 0) { + gpr_free(r->port); + r->port = gpr_strdup(svc[i][1]); + if (res) { + grpc_error* error = + resolve_address_vtable->resolve(r->host, r->port, res); + if (error != GRPC_ERROR_NONE) { + GRPC_ERROR_UNREF(error); + return 0; + } + } else { + resolve_address_vtable->resolve_async(r, r->host, r->port); + } + return 1; + } + } + return 0; +} + +void grpc_custom_resolve_callback(grpc_custom_resolver* r, + grpc_resolved_addresses* result, + grpc_error* error) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + grpc_core::ExecCtx exec_ctx; + if (error == GRPC_ERROR_NONE) { + *r->addresses = result; + } else if (retry_named_port_failure(r, nullptr)) { + return; + } + if (r->on_done) { + GRPC_CLOSURE_SCHED(r->on_done, error); + } + gpr_free(r->host); + gpr_free(r->port); + gpr_free(r); +} + +static grpc_error* try_split_host_port(const char* name, + const char* default_port, char** host, + char** port) { + /* parse name, splitting it into host and port parts */ + grpc_error* error; + gpr_split_host_port(name, host, port); + if (*host == nullptr) { + char* msg; + gpr_asprintf(&msg, "unparseable host:port: '%s'", name); + error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + gpr_free(msg); + return error; + } + if (*port == nullptr) { + // TODO(murgatroid99): add tests for this case + if (default_port == nullptr) { + char* msg; + gpr_asprintf(&msg, "no port in name '%s'", name); + error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); + gpr_free(msg); + return error; + } + *port = gpr_strdup(default_port); + } + return GRPC_ERROR_NONE; +} + +static grpc_error* blocking_resolve_address_impl( + const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + char* host; + char* port; + grpc_error* err; + + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + + err = try_split_host_port(name, default_port, &host, &port); + if (err != GRPC_ERROR_NONE) { + gpr_free(host); + gpr_free(port); + return err; + } + + /* Call getaddrinfo */ + grpc_custom_resolver resolver; + resolver.host = host; + resolver.port = port; + + grpc_resolved_addresses* addrs; + grpc_core::ExecCtx* curr = grpc_core::ExecCtx::Get(); + grpc_core::ExecCtx::Set(nullptr); + err = resolve_address_vtable->resolve(host, port, &addrs); + if (err != GRPC_ERROR_NONE) { + if (retry_named_port_failure(&resolver, &addrs)) { + GRPC_ERROR_UNREF(err); + err = GRPC_ERROR_NONE; + } + } + grpc_core::ExecCtx::Set(curr); + if (err == GRPC_ERROR_NONE) { + *addresses = addrs; + } + gpr_free(resolver.host); + gpr_free(resolver.port); + return err; +} + +static void resolve_address_impl(const char* name, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addrs) { + grpc_custom_resolver* r = nullptr; + char* host = nullptr; + char* port = nullptr; + grpc_error* err; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + err = try_split_host_port(name, default_port, &host, &port); + if (err != GRPC_ERROR_NONE) { + GRPC_CLOSURE_SCHED(on_done, err); + gpr_free(host); + gpr_free(port); + return; + } + r = (grpc_custom_resolver*)gpr_malloc(sizeof(grpc_custom_resolver)); + r->on_done = on_done; + r->addresses = addrs; + r->host = host; + r->port = port; + + /* Call getaddrinfo */ + resolve_address_vtable->resolve_async(r, r->host, r->port); +} + +static grpc_address_resolver_vtable custom_resolver_vtable = { + resolve_address_impl, blocking_resolve_address_impl}; + +void grpc_custom_resolver_init(grpc_custom_resolver_vtable* impl) { + resolve_address_vtable = impl; + grpc_set_resolver_impl(&custom_resolver_vtable); +} diff --git a/src/core/lib/iomgr/resolve_address_custom.h b/src/core/lib/iomgr/resolve_address_custom.h new file mode 100644 index 00000000000..e0c6714087a --- /dev/null +++ b/src/core/lib/iomgr/resolve_address_custom.h @@ -0,0 +1,43 @@ +/* + * + * Copyright 2018 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_RESOLVE_ADDRESS_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_CUSTOM_H + +#include + +#include "src/core/lib/iomgr/port.h" + +#include "src/core/lib/iomgr/resolve_address.h" +#include "src/core/lib/iomgr/sockaddr.h" + +typedef struct grpc_custom_resolver grpc_custom_resolver; + +typedef struct grpc_custom_resolver_vtable { + grpc_error* (*resolve)(char* host, char* port, grpc_resolved_addresses** res); + void (*resolve_async)(grpc_custom_resolver* resolver, char* host, char* port); +} grpc_custom_resolver_vtable; + +void grpc_custom_resolve_callback(grpc_custom_resolver* resolver, + grpc_resolved_addresses* result, + grpc_error* error); + +/* Internal APIs */ +void grpc_custom_resolver_init(grpc_custom_resolver_vtable* impl); + +#endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_CUSTOM_H */ diff --git a/src/core/lib/iomgr/resolve_address_posix.cc b/src/core/lib/iomgr/resolve_address_posix.cc index 2f68dbe214d..a82075542f9 100644 --- a/src/core/lib/iomgr/resolve_address_posix.cc +++ b/src/core/lib/iomgr/resolve_address_posix.cc @@ -42,7 +42,7 @@ #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/unix_sockets_posix.h" -static grpc_error* blocking_resolve_address_impl( +static grpc_error* posix_blocking_resolve_address( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { grpc_core::ExecCtx exec_ctx; @@ -141,10 +141,6 @@ done: return err; } -grpc_error* (*grpc_blocking_resolve_address)( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses) = blocking_resolve_address_impl; - typedef struct { char* name; char* default_port; @@ -165,17 +161,10 @@ static void do_request_thread(void* rp, grpc_error* error) { gpr_free(r); } -void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { - if (addrs != nullptr) { - gpr_free(addrs->addrs); - } - gpr_free(addrs); -} - -static void resolve_address_impl(const char* name, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addrs) { +static void posix_resolve_address(const char* name, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addrs) { request* r = static_cast(gpr_malloc(sizeof(request))); GRPC_CLOSURE_INIT(&r->request_closure, do_request_thread, r, grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)); @@ -186,9 +175,6 @@ static void resolve_address_impl(const char* name, const char* default_port, GRPC_CLOSURE_SCHED(&r->request_closure, GRPC_ERROR_NONE); } -void (*grpc_resolve_address)( - const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_resolved_addresses** addrs) = resolve_address_impl; - +grpc_address_resolver_vtable grpc_posix_resolver_vtable = { + posix_resolve_address, posix_blocking_resolve_address}; #endif diff --git a/src/core/lib/iomgr/resolve_address_uv.cc b/src/core/lib/iomgr/resolve_address_uv.cc deleted file mode 100644 index 4d8ea596f38..00000000000 --- a/src/core/lib/iomgr/resolve_address_uv.cc +++ /dev/null @@ -1,286 +0,0 @@ -/* - * - * Copyright 2016 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" -#ifdef GRPC_UV - -#include - -#include -#include -#include - -#include "src/core/lib/gpr/host_port.h" -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/iomgr/closure.h" -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/resolve_address.h" -#include "src/core/lib/iomgr/sockaddr.h" -#include "src/core/lib/iomgr/sockaddr_utils.h" - -#include - -typedef struct request { - grpc_closure* on_done; - grpc_resolved_addresses** addresses; - struct addrinfo* hints; - char* host; - char* port; -} request; - -static int retry_named_port_failure(int status, request* r, - uv_getaddrinfo_cb getaddrinfo_cb) { - if (status != 0) { - // This loop is copied from resolve_address_posix.c - const char* svc[][2] = {{"http", "80"}, {"https", "443"}}; - for (size_t i = 0; i < GPR_ARRAY_SIZE(svc); i++) { - if (strcmp(r->port, svc[i][0]) == 0) { - int retry_status; - uv_getaddrinfo_t* req = - (uv_getaddrinfo_t*)gpr_malloc(sizeof(uv_getaddrinfo_t)); - req->data = r; - r->port = gpr_strdup(svc[i][1]); - retry_status = uv_getaddrinfo(uv_default_loop(), req, getaddrinfo_cb, - r->host, r->port, r->hints); - if (retry_status < 0 || getaddrinfo_cb == NULL) { - // The callback will not be called - gpr_free(req); - } - return retry_status; - } - } - } - /* If this function calls uv_getaddrinfo, it will return that function's - return value. That function only returns numbers <=0, so we can safely - return 1 to indicate that we never retried */ - return 1; -} - -static grpc_error* handle_addrinfo_result(int status, struct addrinfo* result, - grpc_resolved_addresses** addresses) { - struct addrinfo* resp; - size_t i; - if (status != 0) { - grpc_error* error; - *addresses = NULL; - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getaddrinfo failed"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - (*addresses) = - (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses)); - (*addresses)->naddrs = 0; - for (resp = result; resp != NULL; resp = resp->ai_next) { - (*addresses)->naddrs++; - } - (*addresses)->addrs = (grpc_resolved_address*)gpr_malloc( - sizeof(grpc_resolved_address) * (*addresses)->naddrs); - i = 0; - for (resp = result; resp != NULL; resp = resp->ai_next) { - memcpy(&(*addresses)->addrs[i].addr, resp->ai_addr, resp->ai_addrlen); - (*addresses)->addrs[i].len = resp->ai_addrlen; - i++; - } - - { - for (i = 0; i < (*addresses)->naddrs; i++) { - char* buf; - grpc_sockaddr_to_string(&buf, &(*addresses)->addrs[i], 0); - gpr_free(buf); - } - } - return GRPC_ERROR_NONE; -} - -static void getaddrinfo_callback(uv_getaddrinfo_t* req, int status, - struct addrinfo* res) { - request* r = (request*)req->data; - grpc_core::ExecCtx exec_ctx; - grpc_error* error; - int retry_status; - char* port = r->port; - - gpr_free(req); - retry_status = retry_named_port_failure(status, r, getaddrinfo_callback); - if (retry_status == 0) { - /* The request is being retried. It is using its own port string, so we free - * the original one */ - gpr_free(port); - return; - } - /* Either no retry was attempted, or the retry failed. Either way, the - original error probably has more interesting information */ - error = handle_addrinfo_result(status, res, r->addresses); - GRPC_CLOSURE_SCHED(r->on_done, error); - - gpr_free(r->hints); - gpr_free(r->host); - gpr_free(r->port); - gpr_free(r); - uv_freeaddrinfo(res); -} - -static grpc_error* try_split_host_port(const char* name, - const char* default_port, char** host, - char** port) { - /* parse name, splitting it into host and port parts */ - grpc_error* error; - gpr_split_host_port(name, host, port); - if (*host == NULL) { - char* msg; - gpr_asprintf(&msg, "unparseable host:port: '%s'", name); - error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); - gpr_free(msg); - return error; - } - if (*port == NULL) { - // TODO(murgatroid99): add tests for this case - if (default_port == NULL) { - char* msg; - gpr_asprintf(&msg, "no port in name '%s'", name); - error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg); - gpr_free(msg); - return error; - } - *port = gpr_strdup(default_port); - } - return GRPC_ERROR_NONE; -} - -static grpc_error* blocking_resolve_address_impl( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses) { - char* host; - char* port; - struct addrinfo hints; - uv_getaddrinfo_t req; - int s; - grpc_error* err; - int retry_status; - request r; - - GRPC_UV_ASSERT_SAME_THREAD(); - - req.addrinfo = NULL; - - err = try_split_host_port(name, default_port, &host, &port); - if (err != GRPC_ERROR_NONE) { - goto done; - } - - /* Call getaddrinfo */ - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; /* ipv4 or ipv6 */ - hints.ai_socktype = SOCK_STREAM; /* stream socket */ - hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ - - s = uv_getaddrinfo(uv_default_loop(), &req, NULL, host, port, &hints); - r.addresses = addresses; - r.hints = &hints; - r.host = host; - r.port = port; - retry_status = retry_named_port_failure(s, &r, NULL); - if (retry_status <= 0) { - s = retry_status; - } - err = handle_addrinfo_result(s, req.addrinfo, addresses); - -done: - gpr_free(host); - gpr_free(port); - if (req.addrinfo) { - uv_freeaddrinfo(req.addrinfo); - } - return err; -} - -grpc_error* (*grpc_blocking_resolve_address)( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses) = blocking_resolve_address_impl; - -void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { - if (addrs != NULL) { - gpr_free(addrs->addrs); - } - gpr_free(addrs); -} - -static void resolve_address_impl(const char* name, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addrs) { - uv_getaddrinfo_t* req = NULL; - request* r = NULL; - struct addrinfo* hints = NULL; - char* host = NULL; - char* port = NULL; - grpc_error* err; - int s; - GRPC_UV_ASSERT_SAME_THREAD(); - err = try_split_host_port(name, default_port, &host, &port); - if (err != GRPC_ERROR_NONE) { - GRPC_CLOSURE_SCHED(on_done, err); - gpr_free(host); - gpr_free(port); - return; - } - r = (request*)gpr_malloc(sizeof(request)); - r->on_done = on_done; - r->addresses = addrs; - r->host = host; - r->port = port; - req = (uv_getaddrinfo_t*)gpr_malloc(sizeof(uv_getaddrinfo_t)); - req->data = r; - - /* Call getaddrinfo */ - hints = (addrinfo*)gpr_malloc(sizeof(struct addrinfo)); - memset(hints, 0, sizeof(struct addrinfo)); - hints->ai_family = AF_UNSPEC; /* ipv4 or ipv6 */ - hints->ai_socktype = SOCK_STREAM; /* stream socket */ - hints->ai_flags = AI_PASSIVE; /* for wildcard IP address */ - r->hints = hints; - - s = uv_getaddrinfo(uv_default_loop(), req, getaddrinfo_callback, host, port, - hints); - - if (s != 0) { - *addrs = NULL; - err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getaddrinfo failed"); - err = grpc_error_set_str(err, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(s))); - GRPC_CLOSURE_SCHED(on_done, err); - gpr_free(r); - gpr_free(req); - gpr_free(hints); - gpr_free(host); - gpr_free(port); - } -} - -void (*grpc_resolve_address)( - const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_resolved_addresses** addrs) = resolve_address_impl; - -#endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/resolve_address_windows.cc b/src/core/lib/iomgr/resolve_address_windows.cc index 7a62c887206..71c92615ad6 100644 --- a/src/core/lib/iomgr/resolve_address_windows.cc +++ b/src/core/lib/iomgr/resolve_address_windows.cc @@ -51,7 +51,7 @@ typedef struct { grpc_resolved_addresses** addresses; } request; -static grpc_error* blocking_resolve_address_impl( +static grpc_error* windows_blocking_resolve_address( const char* name, const char* default_port, grpc_resolved_addresses** addresses) { grpc_core::ExecCtx exec_ctx; @@ -130,10 +130,6 @@ done: return error; } -grpc_error* (*grpc_blocking_resolve_address)( - const char* name, const char* default_port, - grpc_resolved_addresses** addresses) = blocking_resolve_address_impl; - /* Callback to be passed to grpc_executor to asynch-ify * grpc_blocking_resolve_address */ static void do_request_thread(void* rp, grpc_error* error) { @@ -150,17 +146,10 @@ static void do_request_thread(void* rp, grpc_error* error) { gpr_free(r); } -void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addrs) { - if (addrs != NULL) { - gpr_free(addrs->addrs); - } - gpr_free(addrs); -} - -static void resolve_address_impl(const char* name, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addresses) { +static void windows_resolve_address(const char* name, const char* default_port, + grpc_pollset_set* interested_parties, + grpc_closure* on_done, + grpc_resolved_addresses** addresses) { request* r = (request*)gpr_malloc(sizeof(request)); GRPC_CLOSURE_INIT(&r->request_closure, do_request_thread, r, grpc_executor_scheduler(GRPC_EXECUTOR_SHORT)); @@ -171,9 +160,6 @@ static void resolve_address_impl(const char* name, const char* default_port, GRPC_CLOSURE_SCHED(&r->request_closure, GRPC_ERROR_NONE); } -void (*grpc_resolve_address)( - const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_resolved_addresses** addresses) = resolve_address_impl; - +grpc_address_resolver_vtable grpc_windows_resolver_vtable = { + windows_resolve_address, windows_blocking_resolve_address}; #endif diff --git a/src/core/lib/iomgr/resource_quota.h b/src/core/lib/iomgr/resource_quota.h index 4e1c651278d..89e8a391189 100644 --- a/src/core/lib/iomgr/resource_quota.h +++ b/src/core/lib/iomgr/resource_quota.h @@ -139,8 +139,4 @@ void grpc_resource_user_alloc_slices( grpc_resource_user_slice_allocator* slice_allocator, size_t length, size_t count, grpc_slice_buffer* dest); -/* Allocate one slice of length \a size synchronously. */ -grpc_slice grpc_resource_user_slice_malloc(grpc_resource_user* resource_user, - size_t size); - #endif /* GRPC_CORE_LIB_IOMGR_RESOURCE_QUOTA_H */ diff --git a/src/core/lib/iomgr/sockaddr.h b/src/core/lib/iomgr/sockaddr.h index 3b30da8a7db..5edf735cd18 100644 --- a/src/core/lib/iomgr/sockaddr.h +++ b/src/core/lib/iomgr/sockaddr.h @@ -25,18 +25,8 @@ #include -#include "src/core/lib/iomgr/port.h" - -#ifdef GRPC_UV -#include -#endif - -#ifdef GPR_WINDOWS -#include "src/core/lib/iomgr/sockaddr_windows.h" -#endif - -#ifdef GRPC_POSIX_SOCKETADDR +#include "src/core/lib/iomgr/sockaddr_custom.h" #include "src/core/lib/iomgr/sockaddr_posix.h" -#endif +#include "src/core/lib/iomgr/sockaddr_windows.h" #endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_H */ diff --git a/src/core/lib/iomgr/sockaddr_custom.h b/src/core/lib/iomgr/sockaddr_custom.h new file mode 100644 index 00000000000..d85cc504d3e --- /dev/null +++ b/src/core/lib/iomgr/sockaddr_custom.h @@ -0,0 +1,54 @@ +/* + * + * Copyright 2018 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_SOCKADDR_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_SOCKADDR_CUSTOM_H + +#include + +#include +#include "src/core/lib/iomgr/port.h" + +#ifdef GRPC_UV + +#include + +// TODO(kpayson) It would be nice to abstract this so we don't +// depend on anything uv specific +typedef struct sockaddr grpc_sockaddr; +typedef struct sockaddr_in grpc_sockaddr_in; +typedef struct in_addr grpc_in_addr; +typedef struct sockaddr_in6 grpc_sockaddr_in6; +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 // GRPC_UV + +#endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_CUSTOM_H */ diff --git a/src/core/lib/iomgr/sockaddr_posix.h b/src/core/lib/iomgr/sockaddr_posix.h index 83981e0aa56..5b18bbc4651 100644 --- a/src/core/lib/iomgr/sockaddr_posix.h +++ b/src/core/lib/iomgr/sockaddr_posix.h @@ -21,6 +21,9 @@ #include +#include "src/core/lib/iomgr/port.h" + +#ifdef GRPC_POSIX_SOCKET #include #include #include @@ -28,4 +31,25 @@ #include #include +typedef struct sockaddr grpc_sockaddr; +typedef struct sockaddr_in grpc_sockaddr_in; +typedef struct in_addr grpc_in_addr; +typedef struct sockaddr_in6 grpc_sockaddr_in6; +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_IOMGR_SOCKADDR_POSIX_H */ diff --git a/src/core/lib/iomgr/sockaddr_utils.cc b/src/core/lib/iomgr/sockaddr_utils.cc index 88f9b2ffd97..bc3550a6792 100644 --- a/src/core/lib/iomgr/sockaddr_utils.cc +++ b/src/core/lib/iomgr/sockaddr_utils.cc @@ -40,25 +40,25 @@ static const uint8_t kV4MappedPrefix[] = {0, 0, 0, 0, 0, 0, int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, grpc_resolved_address* resolved_addr4_out) { GPR_ASSERT(resolved_addr != resolved_addr4_out); - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); - struct sockaddr_in* addr4_out = + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); + grpc_sockaddr_in* addr4_out = resolved_addr4_out == nullptr ? nullptr - : reinterpret_cast(resolved_addr4_out->addr); - if (addr->sa_family == AF_INET6) { - const struct sockaddr_in6* addr6 = - reinterpret_cast(addr); + : reinterpret_cast(resolved_addr4_out->addr); + if (addr->sa_family == GRPC_AF_INET6) { + const grpc_sockaddr_in6* addr6 = + reinterpret_cast(addr); if (memcmp(addr6->sin6_addr.s6_addr, kV4MappedPrefix, sizeof(kV4MappedPrefix)) == 0) { if (resolved_addr4_out != nullptr) { /* Normalize ::ffff:0.0.0.0/96 to IPv4. */ memset(resolved_addr4_out, 0, sizeof(*resolved_addr4_out)); - addr4_out->sin_family = AF_INET; + addr4_out->sin_family = GRPC_AF_INET; /* s6_addr32 would be nice, but it's non-standard. */ memcpy(&addr4_out->sin_addr, &addr6->sin6_addr.s6_addr[12], 4); addr4_out->sin_port = addr6->sin6_port; - resolved_addr4_out->len = sizeof(struct sockaddr_in); + resolved_addr4_out->len = sizeof(grpc_sockaddr_in); } return 1; } @@ -69,19 +69,19 @@ int grpc_sockaddr_is_v4mapped(const grpc_resolved_address* resolved_addr, int grpc_sockaddr_to_v4mapped(const grpc_resolved_address* resolved_addr, grpc_resolved_address* resolved_addr6_out) { GPR_ASSERT(resolved_addr != resolved_addr6_out); - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); - struct sockaddr_in6* addr6_out = - reinterpret_cast(resolved_addr6_out->addr); - if (addr->sa_family == AF_INET) { - const struct sockaddr_in* addr4 = - reinterpret_cast(addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); + grpc_sockaddr_in6* addr6_out = + reinterpret_cast(resolved_addr6_out->addr); + if (addr->sa_family == GRPC_AF_INET) { + const grpc_sockaddr_in* addr4 = + reinterpret_cast(addr); memset(resolved_addr6_out, 0, sizeof(*resolved_addr6_out)); - addr6_out->sin6_family = AF_INET6; + addr6_out->sin6_family = GRPC_AF_INET6; memcpy(&addr6_out->sin6_addr.s6_addr[0], kV4MappedPrefix, 12); memcpy(&addr6_out->sin6_addr.s6_addr[12], &addr4->sin_addr, 4); addr6_out->sin6_port = addr4->sin_port; - resolved_addr6_out->len = sizeof(struct sockaddr_in6); + resolved_addr6_out->len = sizeof(grpc_sockaddr_in6); return 1; } return 0; @@ -89,32 +89,32 @@ int grpc_sockaddr_to_v4mapped(const grpc_resolved_address* resolved_addr, int grpc_sockaddr_is_wildcard(const grpc_resolved_address* resolved_addr, int* port_out) { - const struct sockaddr* addr; + const grpc_sockaddr* addr; grpc_resolved_address addr4_normalized; if (grpc_sockaddr_is_v4mapped(resolved_addr, &addr4_normalized)) { resolved_addr = &addr4_normalized; } - addr = reinterpret_cast(resolved_addr->addr); - if (addr->sa_family == AF_INET) { + addr = reinterpret_cast(resolved_addr->addr); + if (addr->sa_family == GRPC_AF_INET) { /* Check for 0.0.0.0 */ - const struct sockaddr_in* addr4 = - reinterpret_cast(addr); + const grpc_sockaddr_in* addr4 = + reinterpret_cast(addr); if (addr4->sin_addr.s_addr != 0) { return 0; } - *port_out = ntohs(addr4->sin_port); + *port_out = grpc_ntohs(addr4->sin_port); return 1; - } else if (addr->sa_family == AF_INET6) { + } else if (addr->sa_family == GRPC_AF_INET6) { /* Check for :: */ - const struct sockaddr_in6* addr6 = - reinterpret_cast(addr); + const grpc_sockaddr_in6* addr6 = + reinterpret_cast(addr); int i; for (i = 0; i < 16; i++) { if (addr6->sin6_addr.s6_addr[i] != 0) { return 0; } } - *port_out = ntohs(addr6->sin6_port); + *port_out = grpc_ntohs(addr6->sin6_port); return 1; } else { return 0; @@ -129,33 +129,33 @@ void grpc_sockaddr_make_wildcards(int port, grpc_resolved_address* wild4_out, void grpc_sockaddr_make_wildcard4(int port, grpc_resolved_address* resolved_wild_out) { - struct sockaddr_in* wild_out = - reinterpret_cast(resolved_wild_out->addr); + grpc_sockaddr_in* wild_out = + reinterpret_cast(resolved_wild_out->addr); GPR_ASSERT(port >= 0 && port < 65536); memset(resolved_wild_out, 0, sizeof(*resolved_wild_out)); - wild_out->sin_family = AF_INET; - wild_out->sin_port = htons(static_cast(port)); - resolved_wild_out->len = sizeof(struct sockaddr_in); + wild_out->sin_family = GRPC_AF_INET; + wild_out->sin_port = grpc_htons(static_cast(port)); + resolved_wild_out->len = sizeof(grpc_sockaddr_in); } void grpc_sockaddr_make_wildcard6(int port, grpc_resolved_address* resolved_wild_out) { - struct sockaddr_in6* wild_out = - reinterpret_cast(resolved_wild_out->addr); + grpc_sockaddr_in6* wild_out = + reinterpret_cast(resolved_wild_out->addr); GPR_ASSERT(port >= 0 && port < 65536); memset(resolved_wild_out, 0, sizeof(*resolved_wild_out)); - wild_out->sin6_family = AF_INET6; - wild_out->sin6_port = htons(static_cast(port)); - resolved_wild_out->len = sizeof(struct sockaddr_in6); + wild_out->sin6_family = GRPC_AF_INET6; + wild_out->sin6_port = grpc_htons(static_cast(port)); + resolved_wild_out->len = sizeof(grpc_sockaddr_in6); } int grpc_sockaddr_to_string(char** out, const grpc_resolved_address* resolved_addr, int normalize) { - const struct sockaddr* addr; + const grpc_sockaddr* addr; const int save_errno = errno; grpc_resolved_address addr_normalized; - char ntop_buf[INET6_ADDRSTRLEN]; + char ntop_buf[GRPC_INET6_ADDRSTRLEN]; const void* ip = nullptr; int port = 0; uint32_t sin6_scope_id = 0; @@ -165,17 +165,17 @@ int grpc_sockaddr_to_string(char** out, if (normalize && grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) { resolved_addr = &addr_normalized; } - addr = reinterpret_cast(resolved_addr->addr); - if (addr->sa_family == AF_INET) { - const struct sockaddr_in* addr4 = - reinterpret_cast(addr); + addr = reinterpret_cast(resolved_addr->addr); + if (addr->sa_family == GRPC_AF_INET) { + const grpc_sockaddr_in* addr4 = + reinterpret_cast(addr); ip = &addr4->sin_addr; - port = ntohs(addr4->sin_port); - } else if (addr->sa_family == AF_INET6) { - const struct sockaddr_in6* addr6 = - reinterpret_cast(addr); + port = grpc_ntohs(addr4->sin_port); + } else if (addr->sa_family == GRPC_AF_INET6) { + const grpc_sockaddr_in6* addr6 = + reinterpret_cast(addr); ip = &addr6->sin6_addr; - port = ntohs(addr6->sin6_port); + port = grpc_ntohs(addr6->sin6_port); sin6_scope_id = addr6->sin6_scope_id; } if (ip != nullptr && grpc_inet_ntop(addr->sa_family, ip, ntop_buf, @@ -197,6 +197,22 @@ int grpc_sockaddr_to_string(char** out, return ret; } +void grpc_string_to_sockaddr(grpc_resolved_address* out, char* addr, int port) { + grpc_sockaddr_in6* addr6 = (grpc_sockaddr_in6*)out->addr; + grpc_sockaddr_in* addr4 = (grpc_sockaddr_in*)out->addr; + + if (grpc_inet_pton(GRPC_AF_INET6, addr, &addr6->sin6_addr) == 1) { + addr6->sin6_family = GRPC_AF_INET6; + out->len = sizeof(grpc_sockaddr_in6); + } else if (grpc_inet_pton(GRPC_AF_INET, addr, &addr4->sin_addr) == 1) { + addr4->sin_family = GRPC_AF_INET; + out->len = sizeof(grpc_sockaddr_in); + } else { + GPR_ASSERT(0); + } + grpc_sockaddr_set_port(out, port); +} + char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) { grpc_resolved_address addr_normalized; if (grpc_sockaddr_is_v4mapped(resolved_addr, &addr_normalized)) { @@ -219,33 +235,33 @@ char* grpc_sockaddr_to_uri(const grpc_resolved_address* resolved_addr) { const char* grpc_sockaddr_get_uri_scheme( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { - case AF_INET: + case GRPC_AF_INET: return "ipv4"; - case AF_INET6: + case GRPC_AF_INET6: return "ipv6"; - case AF_UNIX: + case GRPC_AF_UNIX: return "unix"; } return nullptr; } int grpc_sockaddr_get_family(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); return addr->sa_family; } int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { - case AF_INET: - return ntohs(((struct sockaddr_in*)addr)->sin_port); - case AF_INET6: - return ntohs(((struct sockaddr_in6*)addr)->sin6_port); + case GRPC_AF_INET: + return grpc_ntohs(((grpc_sockaddr_in*)addr)->sin_port); + case GRPC_AF_INET6: + return grpc_ntohs(((grpc_sockaddr_in6*)addr)->sin6_port); default: if (grpc_is_unix_socket(resolved_addr)) { return 1; @@ -258,18 +274,18 @@ int grpc_sockaddr_get_port(const grpc_resolved_address* resolved_addr) { int grpc_sockaddr_set_port(const grpc_resolved_address* resolved_addr, int port) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); switch (addr->sa_family) { - case AF_INET: + case GRPC_AF_INET: GPR_ASSERT(port >= 0 && port < 65536); - ((struct sockaddr_in*)addr)->sin_port = - htons(static_cast(port)); + ((grpc_sockaddr_in*)addr)->sin_port = + grpc_htons(static_cast(port)); return 1; - case AF_INET6: + case GRPC_AF_INET6: GPR_ASSERT(port >= 0 && port < 65536); - ((struct sockaddr_in6*)addr)->sin6_port = - htons(static_cast(port)); + ((grpc_sockaddr_in6*)addr)->sin6_port = + grpc_htons(static_cast(port)); return 1; default: gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port", diff --git a/src/core/lib/iomgr/sockaddr_utils.h b/src/core/lib/iomgr/sockaddr_utils.h index ace54a2a800..a4e90a73ab3 100644 --- a/src/core/lib/iomgr/sockaddr_utils.h +++ b/src/core/lib/iomgr/sockaddr_utils.h @@ -71,6 +71,8 @@ int grpc_sockaddr_set_port(const grpc_resolved_address* addr, int port); int grpc_sockaddr_to_string(char** out, const grpc_resolved_address* addr, int normalize); +void grpc_string_to_sockaddr(grpc_resolved_address* out, char* addr, int port); + /* Returns the URI string corresponding to \a addr */ char* grpc_sockaddr_to_uri(const grpc_resolved_address* addr); diff --git a/src/core/lib/iomgr/sockaddr_windows.h b/src/core/lib/iomgr/sockaddr_windows.h index 3a4fcc9e8ab..4d637251a18 100644 --- a/src/core/lib/iomgr/sockaddr_windows.h +++ b/src/core/lib/iomgr/sockaddr_windows.h @@ -31,6 +31,25 @@ // must be included after the above #include +typedef struct sockaddr grpc_sockaddr; +typedef struct sockaddr_in grpc_sockaddr_in; +typedef struct in_addr grpc_in_addr; +typedef struct sockaddr_in6 grpc_sockaddr_in6; +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_IOMGR_SOCKADDR_WINDOWS_H */ diff --git a/src/core/lib/iomgr/socket_utils.h b/src/core/lib/iomgr/socket_utils.h index e96eb97a7e8..cf1a7be6489 100644 --- a/src/core/lib/iomgr/socket_utils.h +++ b/src/core/lib/iomgr/socket_utils.h @@ -23,6 +23,15 @@ #include +/* A wrapper for htons on POSIX and Windows */ +uint16_t grpc_htons(uint16_t hostshort); + +/* A wrapper for ntohs on POSIX and WINDOWS */ +uint16_t grpc_ntohs(uint16_t netshort); + +/* A wrapper for inet_pton on POSIX and WINDOWS */ +int grpc_inet_pton(int af, const char* src, void* dst); + /* A wrapper for inet_ntop on POSIX systems and InetNtop on Windows systems */ const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size); diff --git a/src/core/lib/iomgr/socket_utils_common_posix.cc b/src/core/lib/iomgr/socket_utils_common_posix.cc index 4fb6c7ad633..c52e237fa83 100644 --- a/src/core/lib/iomgr/socket_utils_common_posix.cc +++ b/src/core/lib/iomgr/socket_utils_common_posix.cc @@ -43,6 +43,7 @@ #include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" +#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" /* set a socket to non blocking mode */ @@ -215,12 +216,11 @@ static void probe_ipv6_once(void) { if (fd < 0) { gpr_log(GPR_INFO, "Disabling AF_INET6 sockets because socket() failed."); } else { - struct sockaddr_in6 addr; + grpc_sockaddr_in6 addr; memset(&addr, 0, sizeof(addr)); addr.sin6_family = AF_INET6; addr.sin6_addr.s6_addr[15] = 1; /* [::1]:0 */ - if (bind(fd, reinterpret_cast(&addr), sizeof(addr)) == - 0) { + if (bind(fd, reinterpret_cast(&addr), sizeof(addr)) == 0) { g_ipv6_loopback_available = 1; } else { gpr_log(GPR_INFO, @@ -280,8 +280,8 @@ static int create_socket(grpc_socket_factory* factory, int domain, int type, grpc_error* grpc_create_dualstack_socket_using_factory( grpc_socket_factory* factory, const grpc_resolved_address* resolved_addr, int type, int protocol, grpc_dualstack_mode* dsmode, int* newfd) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); int family = addr->sa_family; if (family == AF_INET6) { if (grpc_ipv6_loopback_available()) { @@ -311,6 +311,14 @@ grpc_error* grpc_create_dualstack_socket_using_factory( return error_for_fd(*newfd, resolved_addr); } +uint16_t grpc_htons(uint16_t hostshort) { return htons(hostshort); } + +uint16_t grpc_ntohs(uint16_t netshort) { return ntohs(netshort); } + +int grpc_inet_pton(int af, const char* src, void* dst) { + return inet_pton(af, src, dst); +} + const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { GPR_ASSERT(size <= (socklen_t)-1); return inet_ntop(af, src, dst, static_cast(size)); diff --git a/src/core/lib/iomgr/socket_utils_linux.cc b/src/core/lib/iomgr/socket_utils_linux.cc index deb7c552679..1364cd35f6e 100644 --- a/src/core/lib/iomgr/socket_utils_linux.cc +++ b/src/core/lib/iomgr/socket_utils_linux.cc @@ -37,8 +37,7 @@ int grpc_accept4(int sockfd, grpc_resolved_address* resolved_addr, int nonblock, GPR_ASSERT(resolved_addr->len <= (socklen_t)-1); flags |= nonblock ? SOCK_NONBLOCK : 0; flags |= cloexec ? SOCK_CLOEXEC : 0; - return accept4(sockfd, - reinterpret_cast(resolved_addr->addr), + return accept4(sockfd, reinterpret_cast(resolved_addr->addr), reinterpret_cast(&resolved_addr->len), flags); } diff --git a/src/core/lib/iomgr/socket_utils_posix.cc b/src/core/lib/iomgr/socket_utils_posix.cc index c856f641e36..d5d00af9760 100644 --- a/src/core/lib/iomgr/socket_utils_posix.cc +++ b/src/core/lib/iomgr/socket_utils_posix.cc @@ -36,7 +36,7 @@ int grpc_accept4(int sockfd, grpc_resolved_address* resolved_addr, int nonblock, int fd, flags; GPR_ASSERT(sizeof(socklen_t) <= sizeof(size_t)); GPR_ASSERT(resolved_addr->len <= (socklen_t)-1); - fd = accept(sockfd, (struct sockaddr*)resolved_addr->addr, + fd = accept(sockfd, (grpc_sockaddr*)resolved_addr->addr, (socklen_t*)&resolved_addr->len); if (fd >= 0) { if (nonblock) { diff --git a/src/core/lib/iomgr/socket_utils_uv.cc b/src/core/lib/iomgr/socket_utils_uv.cc index 3f650eef668..8538abc7e4f 100644 --- a/src/core/lib/iomgr/socket_utils_uv.cc +++ b/src/core/lib/iomgr/socket_utils_uv.cc @@ -22,15 +22,24 @@ #ifdef GRPC_UV -#include - +#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/socket_utils.h" #include +#include + +uint16_t grpc_htons(uint16_t hostshort) { return htons(hostshort); } + +uint16_t grpc_ntohs(uint16_t netshort) { return ntohs(netshort); } + +int grpc_inet_pton(int af, const char* src, void* dst) { + return inet_pton(af, src, dst); +} + const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { - uv_inet_ntop(af, src, dst, size); - return dst; + /* Windows InetNtopA wants a mutable ip pointer */ + return inet_ntop(af, src, dst, (socklen_t)size); } #endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/socket_utils_windows.cc b/src/core/lib/iomgr/socket_utils_windows.cc index 5fc3b7617ef..3e7b5b812db 100644 --- a/src/core/lib/iomgr/socket_utils_windows.cc +++ b/src/core/lib/iomgr/socket_utils_windows.cc @@ -27,6 +27,14 @@ #include +uint16_t grpc_htons(uint16_t hostshort) { return htons(hostshort); } + +uint16_t grpc_ntohs(uint16_t netshort) { return ntohs(netshort); } + +int grpc_inet_pton(int af, const char* src, void* dst) { + return inet_pton(af, src, dst); +} + const char* grpc_inet_ntop(int af, const void* src, char* dst, size_t size) { /* Windows InetNtopA wants a mutable ip pointer */ return InetNtopA(af, (void*)src, dst, size); diff --git a/src/core/lib/iomgr/tcp_client.cc b/src/core/lib/iomgr/tcp_client.cc new file mode 100644 index 00000000000..6c0ba40781b --- /dev/null +++ b/src/core/lib/iomgr/tcp_client.cc @@ -0,0 +1,36 @@ +/* + * + * Copyright 2018 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/tcp_client.h" + +grpc_tcp_client_vtable* grpc_tcp_client_impl; + +void grpc_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, + grpc_millis deadline) { + grpc_tcp_client_impl->connect(closure, ep, interested_parties, channel_args, + addr, deadline); +} + +void grpc_set_tcp_client_impl(grpc_tcp_client_vtable* impl) { + grpc_tcp_client_impl = impl; +} diff --git a/src/core/lib/iomgr/tcp_client.h b/src/core/lib/iomgr/tcp_client.h index a6b99e63c2c..d209eeb8c23 100644 --- a/src/core/lib/iomgr/tcp_client.h +++ b/src/core/lib/iomgr/tcp_client.h @@ -27,6 +27,13 @@ #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/iomgr/resolve_address.h" +typedef struct grpc_tcp_client_vtable { + void (*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_tcp_client_vtable; + /* Asynchronously connect to an address (specified as (addr, len)), and call cb with arg and the completed connection when done (or call cb with arg and NULL on failure). @@ -38,4 +45,8 @@ void grpc_tcp_client_connect(grpc_closure* on_connect, grpc_endpoint** endpoint, const grpc_resolved_address* addr, grpc_millis deadline); +void grpc_tcp_client_global_init(); + +void grpc_set_tcp_client_impl(grpc_tcp_client_vtable* impl); + #endif /* GRPC_CORE_LIB_IOMGR_TCP_CLIENT_H */ diff --git a/src/core/lib/iomgr/tcp_client_custom.cc b/src/core/lib/iomgr/tcp_client_custom.cc new file mode 100644 index 00000000000..55632a55a19 --- /dev/null +++ b/src/core/lib/iomgr/tcp_client_custom.cc @@ -0,0 +1,151 @@ +/* + * + * Copyright 2018 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" + +#include + +#include +#include + +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" +#include "src/core/lib/iomgr/tcp_client.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/timer.h" + +extern grpc_core::TraceFlag grpc_tcp_trace; +extern grpc_socket_vtable* grpc_custom_socket_vtable; + +struct grpc_custom_tcp_connect { + grpc_custom_socket* socket; + grpc_timer alarm; + grpc_closure on_alarm; + grpc_closure* closure; + grpc_endpoint** endpoint; + int refs; + char* addr_name; + grpc_resource_quota* resource_quota; +}; + +static void custom_tcp_connect_cleanup(grpc_custom_tcp_connect* connect) { + grpc_custom_socket* socket = connect->socket; + grpc_resource_quota_unref_internal(connect->resource_quota); + gpr_free(connect->addr_name); + gpr_free(connect); + socket->refs--; + if (socket->refs == 0) { + grpc_custom_socket_vtable->destroy(socket); + gpr_free(socket); + } +} + +static void custom_close_callback(grpc_custom_socket* socket) {} + +static void on_alarm(void* acp, grpc_error* error) { + int done; + grpc_custom_socket* socket = (grpc_custom_socket*)acp; + grpc_custom_tcp_connect* connect = socket->connector; + if (grpc_tcp_trace.enabled()) { + const char* str = grpc_error_string(error); + gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", + connect->addr_name, str); + } + if (error == GRPC_ERROR_NONE) { + /* error == NONE implies that the timer ran out, and wasn't cancelled. If + it was cancelled, then the handler that cancelled it also should close + the handle, if applicable */ + grpc_custom_socket_vtable->close(socket, custom_close_callback); + } + done = (--connect->refs == 0); + if (done) { + custom_tcp_connect_cleanup(connect); + } +} + +static void custom_connect_callback(grpc_custom_socket* socket, + grpc_error* error) { + grpc_core::ExecCtx exec_ctx; + grpc_custom_tcp_connect* connect = socket->connector; + int done; + grpc_closure* closure = connect->closure; + grpc_timer_cancel(&connect->alarm); + if (error == GRPC_ERROR_NONE) { + *connect->endpoint = custom_tcp_endpoint_create( + socket, connect->resource_quota, connect->addr_name); + } + done = (--connect->refs == 0); + if (done) { + grpc_core::ExecCtx::Get()->Flush(); + custom_tcp_connect_cleanup(connect); + } + GRPC_CLOSURE_SCHED(closure, error); +} + +static void tcp_connect(grpc_closure* closure, grpc_endpoint** ep, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* resolved_addr, + grpc_millis deadline) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + (void)channel_args; + (void)interested_parties; + grpc_custom_tcp_connect* connect; + grpc_resource_quota* resource_quota = grpc_resource_quota_create(nullptr); + if (channel_args != nullptr) { + for (size_t i = 0; i < channel_args->num_args; i++) { + if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { + grpc_resource_quota_unref_internal(resource_quota); + resource_quota = grpc_resource_quota_ref_internal( + (grpc_resource_quota*)channel_args->args[i].value.pointer.p); + } + } + } + grpc_custom_socket* socket = + (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + socket->refs = 2; + grpc_custom_socket_vtable->init(socket, GRPC_AF_UNSPEC); + connect = + (grpc_custom_tcp_connect*)gpr_malloc(sizeof(grpc_custom_tcp_connect)); + connect->closure = closure; + connect->endpoint = ep; + connect->addr_name = grpc_sockaddr_to_uri(resolved_addr); + connect->resource_quota = resource_quota; + connect->socket = socket; + socket->connector = connect; + socket->endpoint = nullptr; + socket->listener = nullptr; + connect->refs = 2; + + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %p %s: asynchronously connecting", + socket, connect->addr_name); + } + + grpc_custom_socket_vtable->connect( + socket, (const grpc_sockaddr*)resolved_addr->addr, resolved_addr->len, + custom_connect_callback); + GRPC_CLOSURE_INIT(&connect->on_alarm, on_alarm, socket, + grpc_schedule_on_exec_ctx); + grpc_timer_init(&connect->alarm, deadline, &connect->on_alarm); +} + +grpc_tcp_client_vtable custom_tcp_client_vtable = {tcp_connect}; diff --git a/src/core/lib/iomgr/tcp_client_posix.cc b/src/core/lib/iomgr/tcp_client_posix.cc index 3fe2989c6b5..c21fb40ab1a 100644 --- a/src/core/lib/iomgr/tcp_client_posix.cc +++ b/src/core/lib/iomgr/tcp_client_posix.cc @@ -38,6 +38,7 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/iomgr_posix.h" +#include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/socket_mutator.h" #include "src/core/lib/iomgr/socket_utils_posix.h" @@ -293,7 +294,7 @@ void grpc_tcp_client_create_from_prepared_fd( async_connect* ac; do { GPR_ASSERT(addr->len < ~(socklen_t)0); - err = connect(fd, reinterpret_cast(addr->addr), + err = connect(fd, reinterpret_cast(addr->addr), static_cast(addr->len)); } while (err < 0 && errno == EINTR); if (err >= 0) { @@ -336,11 +337,11 @@ void grpc_tcp_client_create_from_prepared_fd( gpr_mu_unlock(&ac->mu); } -static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { +static void tcp_connect(grpc_closure* closure, grpc_endpoint** ep, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, + grpc_millis deadline) { grpc_resolved_address mapped_addr; grpc_fd* fdobj = nullptr; grpc_error* error; @@ -355,20 +356,5 @@ static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, ep); } -// overridden by api_fuzzer.c -void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) = tcp_client_connect_impl; - -void grpc_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { - grpc_tcp_client_connect_impl(closure, ep, interested_parties, channel_args, - addr, deadline); -} - +grpc_tcp_client_vtable grpc_posix_tcp_client_vtable = {tcp_connect}; #endif diff --git a/src/core/lib/iomgr/tcp_client_uv.cc b/src/core/lib/iomgr/tcp_client_uv.cc deleted file mode 100644 index d29d6c8f418..00000000000 --- a/src/core/lib/iomgr/tcp_client_uv.cc +++ /dev/null @@ -1,177 +0,0 @@ -/* - * - * Copyright 2016 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" - -#ifdef GRPC_UV - -#include - -#include -#include - -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/sockaddr_utils.h" -#include "src/core/lib/iomgr/tcp_client.h" -#include "src/core/lib/iomgr/tcp_uv.h" -#include "src/core/lib/iomgr/timer.h" - -extern grpc_core::TraceFlag grpc_tcp_trace; - -typedef struct grpc_uv_tcp_connect { - uv_connect_t connect_req; - grpc_timer alarm; - grpc_closure on_alarm; - uv_tcp_t* tcp_handle; - grpc_closure* closure; - grpc_endpoint** endpoint; - int refs; - char* addr_name; - grpc_resource_quota* resource_quota; -} grpc_uv_tcp_connect; - -static void uv_tcp_connect_cleanup(grpc_uv_tcp_connect* connect) { - grpc_resource_quota_unref_internal(connect->resource_quota); - gpr_free(connect->addr_name); - gpr_free(connect); -} - -static void tcp_close_callback(uv_handle_t* handle) { gpr_free(handle); } - -static void uv_tc_on_alarm(void* acp, grpc_error* error) { - int done; - grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)acp; - if (grpc_tcp_trace.enabled()) { - const char* str = grpc_error_string(error); - gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", - connect->addr_name, str); - } - if (error == GRPC_ERROR_NONE) { - /* error == NONE implies that the timer ran out, and wasn't cancelled. If - it was cancelled, then the handler that cancelled it also should close - the handle, if applicable */ - uv_close((uv_handle_t*)connect->tcp_handle, tcp_close_callback); - } - done = (--connect->refs == 0); - if (done) { - uv_tcp_connect_cleanup(connect); - } -} - -static void uv_tc_on_connect(uv_connect_t* req, int status) { - grpc_uv_tcp_connect* connect = (grpc_uv_tcp_connect*)req->data; - grpc_core::ExecCtx exec_ctx; - grpc_error* error = GRPC_ERROR_NONE; - int done; - grpc_closure* closure = connect->closure; - grpc_timer_cancel(&connect->alarm); - if (status == 0) { - *connect->endpoint = grpc_tcp_create( - connect->tcp_handle, connect->resource_quota, connect->addr_name); - } else { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Failed to connect to remote host"); - error = grpc_error_set_int(error, GRPC_ERROR_INT_ERRNO, -status); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - if (status == UV_ECANCELED) { - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string("Timeout occurred")); - // This should only happen if the handle is already closed - } else { - error = grpc_error_set_str( - error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - uv_close((uv_handle_t*)connect->tcp_handle, tcp_close_callback); - } - } - done = (--connect->refs == 0); - if (done) { - grpc_core::ExecCtx::Get()->Flush(); - uv_tcp_connect_cleanup(connect); - } - GRPC_CLOSURE_SCHED(closure, error); -} - -static void tcp_client_connect_impl(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* resolved_addr, - grpc_millis deadline) { - grpc_uv_tcp_connect* connect; - grpc_resource_quota* resource_quota = grpc_resource_quota_create(NULL); - (void)channel_args; - (void)interested_parties; - - GRPC_UV_ASSERT_SAME_THREAD(); - - if (channel_args != NULL) { - for (size_t i = 0; i < channel_args->num_args; i++) { - if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_RESOURCE_QUOTA)) { - grpc_resource_quota_unref_internal(resource_quota); - resource_quota = grpc_resource_quota_ref_internal( - (grpc_resource_quota*)channel_args->args[i].value.pointer.p); - } - } - } - - connect = (grpc_uv_tcp_connect*)gpr_zalloc(sizeof(grpc_uv_tcp_connect)); - connect->closure = closure; - connect->endpoint = ep; - connect->tcp_handle = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); - connect->addr_name = grpc_sockaddr_to_uri(resolved_addr); - connect->resource_quota = resource_quota; - uv_tcp_init(uv_default_loop(), connect->tcp_handle); - connect->connect_req.data = connect; - connect->refs = 2; // One for the connect operation, one for the timer. - - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: asynchronously connecting", - connect->addr_name); - } - - // TODO(murgatroid99): figure out what the return value here means - uv_tcp_connect(&connect->connect_req, connect->tcp_handle, - (const struct sockaddr*)resolved_addr->addr, uv_tc_on_connect); - GRPC_CLOSURE_INIT(&connect->on_alarm, uv_tc_on_alarm, connect, - grpc_schedule_on_exec_ctx); - grpc_timer_init(&connect->alarm, deadline, &connect->on_alarm); -} - -// overridden by api_fuzzer.c -void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) = tcp_client_connect_impl; - -void grpc_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { - grpc_tcp_client_connect_impl(closure, ep, interested_parties, channel_args, - addr, deadline); -} - -#endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/tcp_client_windows.cc b/src/core/lib/iomgr/tcp_client_windows.cc index 70c2495350f..e5b5502597e 100644 --- a/src/core/lib/iomgr/tcp_client_windows.cc +++ b/src/core/lib/iomgr/tcp_client_windows.cc @@ -122,12 +122,11 @@ static void on_connect(void* acp, grpc_error* error) { /* Tries to issue one async connection, then schedules both an IOCP notification request for the connection, and one timeout alert. */ -static void tcp_client_connect_impl(grpc_closure* on_done, - grpc_endpoint** endpoint, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { +static void tcp_connect(grpc_closure* on_done, grpc_endpoint** endpoint, + grpc_pollset_set* interested_parties, + const grpc_channel_args* channel_args, + const grpc_resolved_address* addr, + grpc_millis deadline) { SOCKET sock = INVALID_SOCKET; BOOL success; int status; @@ -175,7 +174,7 @@ static void tcp_client_connect_impl(grpc_closure* on_done, grpc_sockaddr_make_wildcard6(0, &local_address); status = - bind(sock, (struct sockaddr*)&local_address.addr, (int)local_address.len); + bind(sock, (grpc_sockaddr*)&local_address.addr, (int)local_address.len); if (status != 0) { error = GRPC_WSA_ERROR(WSAGetLastError(), "bind"); goto failure; @@ -183,7 +182,7 @@ static void tcp_client_connect_impl(grpc_closure* on_done, socket = grpc_winsocket_create(sock, "client"); info = &socket->write_info; - success = ConnectEx(sock, (struct sockaddr*)&addr->addr, (int)addr->len, NULL, + success = ConnectEx(sock, (grpc_sockaddr*)&addr->addr, (int)addr->len, NULL, 0, NULL, &info->overlapped); /* It wouldn't be unusual to get a success immediately. But we'll still get @@ -227,20 +226,6 @@ failure: GRPC_CLOSURE_SCHED(on_done, final_error); } -// overridden by api_fuzzer.c -void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) = tcp_client_connect_impl; - -void grpc_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, - const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, - grpc_millis deadline) { - grpc_tcp_client_connect_impl(closure, ep, interested_parties, channel_args, - addr, deadline); -} +grpc_tcp_client_vtable grpc_windows_tcp_client_vtable = {tcp_connect}; #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/tcp_custom.cc b/src/core/lib/iomgr/tcp_custom.cc new file mode 100644 index 00000000000..2b1fc930285 --- /dev/null +++ b/src/core/lib/iomgr/tcp_custom.cc @@ -0,0 +1,365 @@ +/* + * + * Copyright 2018 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" + +#include +#include + +#include + +#include +#include +#include + +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/network_status_tracker.h" +#include "src/core/lib/iomgr/resource_quota.h" +#include "src/core/lib/iomgr/tcp_client.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/tcp_server.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" + +#define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192 + +extern grpc_core::TraceFlag grpc_tcp_trace; + +grpc_socket_vtable* grpc_custom_socket_vtable = nullptr; +extern grpc_tcp_server_vtable custom_tcp_server_vtable; +extern grpc_tcp_client_vtable custom_tcp_client_vtable; + +void grpc_custom_endpoint_init(grpc_socket_vtable* impl) { + grpc_custom_socket_vtable = impl; + grpc_set_tcp_client_impl(&custom_tcp_client_vtable); + grpc_set_tcp_server_impl(&custom_tcp_server_vtable); +} + +typedef struct { + grpc_endpoint base; + gpr_refcount refcount; + grpc_custom_socket* socket; + + grpc_closure* read_cb; + grpc_closure* write_cb; + + grpc_slice_buffer* read_slices; + grpc_slice_buffer* write_slices; + + grpc_resource_user* resource_user; + grpc_resource_user_slice_allocator slice_allocator; + + bool shutting_down; + + char* peer_string; +} custom_tcp_endpoint; + +static void tcp_free(grpc_custom_socket* s) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)s->endpoint; + grpc_resource_user_unref(tcp->resource_user); + gpr_free(tcp->peer_string); + gpr_free(tcp); + s->refs--; + if (s->refs == 0) { + grpc_custom_socket_vtable->destroy(s); + gpr_free(s); + } +} + +#ifndef NDEBUG +#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) +#define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) +static void tcp_unref(custom_tcp_endpoint* tcp, const char* reason, + const char* file, int line) { + if (grpc_tcp_trace.enabled()) { + gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); + gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, + "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp->socket, reason, + val, val - 1); + } + if (gpr_unref(&tcp->refcount)) { + tcp_free(tcp->socket); + } +} + +static void tcp_ref(custom_tcp_endpoint* tcp, const char* reason, + const char* file, int line) { + if (grpc_tcp_trace.enabled()) { + gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); + gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, + "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp->socket, reason, + val, val + 1); + } + gpr_ref(&tcp->refcount); +} +#else +#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) +#define TCP_REF(tcp, reason) tcp_ref((tcp)) +static void tcp_unref(custom_tcp_endpoint* tcp) { + if (gpr_unref(&tcp->refcount)) { + tcp_free(tcp->socket); + } +} + +static void tcp_ref(custom_tcp_endpoint* tcp) { gpr_ref(&tcp->refcount); } +#endif + +static void call_read_cb(custom_tcp_endpoint* tcp, grpc_error* error) { + grpc_closure* cb = tcp->read_cb; + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp->socket, cb, cb->cb, + cb->cb_arg); + size_t i; + const char* str = grpc_error_string(error); + gpr_log(GPR_DEBUG, "read: error=%s", str); + + for (i = 0; i < tcp->read_slices->count; i++) { + char* dump = grpc_dump_slice(tcp->read_slices->slices[i], + GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_DEBUG, "READ %p (peer=%s): %s", tcp, tcp->peer_string, dump); + gpr_free(dump); + } + } + TCP_UNREF(tcp, "read"); + tcp->read_slices = nullptr; + tcp->read_cb = nullptr; + GRPC_CLOSURE_RUN(cb, error); +} + +static void custom_read_callback(grpc_custom_socket* socket, size_t nread, + grpc_error* error) { + grpc_core::ExecCtx exec_ctx; + grpc_slice_buffer garbage; + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + if (error == GRPC_ERROR_NONE && nread == 0) { + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"); + } + if (error == GRPC_ERROR_NONE) { + // Successful read + if ((size_t)nread < tcp->read_slices->length) { + /* TODO(murgatroid99): Instead of discarding the unused part of the read + * buffer, reuse it as the next read buffer. */ + grpc_slice_buffer_init(&garbage); + grpc_slice_buffer_trim_end( + tcp->read_slices, tcp->read_slices->length - (size_t)nread, &garbage); + grpc_slice_buffer_reset_and_unref_internal(&garbage); + } + } else { + grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + } + call_read_cb(tcp, error); +} + +static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)tcpp; + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp->socket, + grpc_error_string(error)); + } + if (error == GRPC_ERROR_NONE) { + /* Before calling read, we allocate a buffer with exactly one slice + * to tcp->read_slices and wait for the callback indicating that the + * allocation was successful. So slices[0] should always exist here */ + char* buffer = (char*)GRPC_SLICE_START_PTR(tcp->read_slices->slices[0]); + size_t len = GRPC_SLICE_LENGTH(tcp->read_slices->slices[0]); + grpc_custom_socket_vtable->read(tcp->socket, buffer, len, + custom_read_callback); + } else { + grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + call_read_cb(tcp, GRPC_ERROR_REF(error)); + } + if (grpc_tcp_trace.enabled()) { + const char* str = grpc_error_string(error); + gpr_log(GPR_DEBUG, "Initiating read on %p: error=%s", tcp->socket, str); + } +} + +static void endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, + grpc_closure* cb) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + GPR_ASSERT(tcp->read_cb == nullptr); + tcp->read_cb = cb; + tcp->read_slices = read_slices; + grpc_slice_buffer_reset_and_unref_internal(read_slices); + TCP_REF(tcp, "read"); + grpc_resource_user_alloc_slices(&tcp->slice_allocator, + GRPC_TCP_DEFAULT_READ_SLICE_SIZE, 1, + tcp->read_slices); +} + +static void custom_write_callback(grpc_custom_socket* socket, + grpc_error* error) { + grpc_core::ExecCtx exec_ctx; + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + grpc_closure* cb = tcp->write_cb; + tcp->write_cb = nullptr; + if (grpc_tcp_trace.enabled()) { + const char* str = grpc_error_string(error); + gpr_log(GPR_DEBUG, "write complete on %p: error=%s", tcp->socket, str); + } + TCP_UNREF(tcp, "write"); + GRPC_CLOSURE_SCHED(cb, error); +} + +static void endpoint_write(grpc_endpoint* ep, grpc_slice_buffer* write_slices, + grpc_closure* cb) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + + if (grpc_tcp_trace.enabled()) { + size_t j; + + for (j = 0; j < write_slices->count; j++) { + char* data = grpc_dump_slice(write_slices->slices[j], + GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_DEBUG, "WRITE %p (peer=%s): %s", tcp->socket, + tcp->peer_string, data); + gpr_free(data); + } + } + + if (tcp->shutting_down) { + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "TCP socket is shutting down")); + return; + } + + GPR_ASSERT(tcp->write_cb == nullptr); + tcp->write_slices = write_slices; + GPR_ASSERT(tcp->write_slices->count <= UINT_MAX); + if (tcp->write_slices->count == 0) { + // No slices means we don't have to do anything, + // and libuv doesn't like empty writes + GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); + return; + } + tcp->write_cb = cb; + TCP_REF(tcp, "write"); + grpc_custom_socket_vtable->write(tcp->socket, tcp->write_slices, + custom_write_callback); +} + +static void endpoint_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { + // No-op. We're ignoring pollsets currently + (void)ep; + (void)pollset; +} + +static void endpoint_add_to_pollset_set(grpc_endpoint* ep, + grpc_pollset_set* pollset) { + // No-op. We're ignoring pollsets currently + (void)ep; + (void)pollset; +} + +static void endpoint_delete_from_pollset_set(grpc_endpoint* ep, + grpc_pollset_set* pollset) { + // No-op. We're ignoring pollsets currently + (void)ep; + (void)pollset; +} + +static void endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + if (!tcp->shutting_down) { + if (grpc_tcp_trace.enabled()) { + const char* str = grpc_error_string(why); + gpr_log(GPR_DEBUG, "TCP %p shutdown why=%s", tcp->socket, str); + } + tcp->shutting_down = true; + // GRPC_CLOSURE_SCHED(tcp->read_cb, GRPC_ERROR_REF(why)); + // GRPC_CLOSURE_SCHED(tcp->write_cb, GRPC_ERROR_REF(why)); + // tcp->read_cb = nullptr; + // tcp->write_cb = nullptr; + grpc_resource_user_shutdown(tcp->resource_user); + grpc_custom_socket_vtable->shutdown(tcp->socket); + } + GRPC_ERROR_UNREF(why); +} + +static void custom_close_callback(grpc_custom_socket* socket) { + socket->refs--; + if (socket->refs == 0) { + grpc_custom_socket_vtable->destroy(socket); + gpr_free(socket); + } else if (socket->endpoint) { + grpc_core::ExecCtx exec_ctx; + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)socket->endpoint; + TCP_UNREF(tcp, "destroy"); + } +} + +static void endpoint_destroy(grpc_endpoint* ep) { + grpc_network_status_unregister_endpoint(ep); + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + grpc_custom_socket_vtable->close(tcp->socket, custom_close_callback); +} + +static char* endpoint_get_peer(grpc_endpoint* ep) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + return gpr_strdup(tcp->peer_string); +} + +static grpc_resource_user* endpoint_get_resource_user(grpc_endpoint* ep) { + custom_tcp_endpoint* tcp = (custom_tcp_endpoint*)ep; + return tcp->resource_user; +} + +static int endpoint_get_fd(grpc_endpoint* ep) { return -1; } + +static grpc_endpoint_vtable 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_fd}; + +grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket, + grpc_resource_quota* resource_quota, + char* peer_string) { + custom_tcp_endpoint* tcp = + (custom_tcp_endpoint*)gpr_malloc(sizeof(custom_tcp_endpoint)); + grpc_core::ExecCtx exec_ctx; + + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", socket); + } + memset(tcp, 0, sizeof(custom_tcp_endpoint)); + socket->refs++; + socket->endpoint = (grpc_endpoint*)tcp; + tcp->socket = socket; + tcp->base.vtable = &vtable; + gpr_ref_init(&tcp->refcount, 1); + tcp->peer_string = gpr_strdup(peer_string); + tcp->shutting_down = false; + tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string); + grpc_resource_user_slice_allocator_init( + &tcp->slice_allocator, tcp->resource_user, tcp_read_allocation_done, tcp); + /* Tell network status tracking code about the new endpoint */ + grpc_network_status_register_endpoint(&tcp->base); + + return &tcp->base; +} diff --git a/src/core/lib/iomgr/tcp_custom.h b/src/core/lib/iomgr/tcp_custom.h new file mode 100644 index 00000000000..22caa149f84 --- /dev/null +++ b/src/core/lib/iomgr/tcp_custom.h @@ -0,0 +1,83 @@ +/* + * + * Copyright 2018 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_TCP_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H + +#include + +#include "src/core/lib/iomgr/endpoint.h" +#include "src/core/lib/iomgr/sockaddr.h" + +typedef struct grpc_tcp_listener grpc_tcp_listener; +typedef struct grpc_custom_tcp_connect grpc_custom_tcp_connect; + +typedef struct grpc_custom_socket { + // Implementation defined + void* impl; + grpc_endpoint* endpoint; + grpc_tcp_listener* listener; + grpc_custom_tcp_connect* connector; + int refs; +} grpc_custom_socket; + +typedef void (*grpc_custom_connect_callback)(grpc_custom_socket* socket, + grpc_error* error); +typedef void (*grpc_custom_write_callback)(grpc_custom_socket* socket, + grpc_error* error); +typedef void (*grpc_custom_read_callback)(grpc_custom_socket* socket, + size_t nread, grpc_error* error); +typedef void (*grpc_custom_accept_callback)(grpc_custom_socket* socket, + grpc_custom_socket* client, + grpc_error* error); +typedef void (*grpc_custom_close_callback)(grpc_custom_socket* socket); + +typedef struct grpc_socket_vtable { + grpc_error* (*init)(grpc_custom_socket* socket, int domain); + void (*connect)(grpc_custom_socket* socket, const grpc_sockaddr* addr, + size_t len, grpc_custom_connect_callback cb); + void (*destroy)(grpc_custom_socket* socket); + void (*shutdown)(grpc_custom_socket* socket); + void (*close)(grpc_custom_socket* socket, grpc_custom_close_callback cb); + void (*write)(grpc_custom_socket* socket, grpc_slice_buffer* slices, + grpc_custom_write_callback cb); + void (*read)(grpc_custom_socket* socket, char* buffer, size_t length, + grpc_custom_read_callback cb); + grpc_error* (*getpeername)(grpc_custom_socket* socket, + const grpc_sockaddr* addr, int* len); + grpc_error* (*getsockname)(grpc_custom_socket* socket, + const grpc_sockaddr* addr, int* len); + grpc_error* (*setsockopt)(grpc_custom_socket* socket, int level, int optname, + const void* optval, uint32_t optlen); + grpc_error* (*bind)(grpc_custom_socket* socket, const grpc_sockaddr* addr, + size_t len, int flags); + grpc_error* (*listen)(grpc_custom_socket* socket); + void (*accept)(grpc_custom_socket* socket, grpc_custom_socket* client, + grpc_custom_accept_callback cb); +} grpc_socket_vtable; + +/* Internal APIs */ +void grpc_custom_endpoint_init(grpc_socket_vtable* impl); + +void grpc_custom_close_server_callback(grpc_tcp_listener* listener); + +grpc_endpoint* custom_tcp_endpoint_create(grpc_custom_socket* socket, + grpc_resource_quota* resource_quota, + char* peer_string); + +#endif /* GRPC_CORE_LIB_IOMGR_TCP_CUSTOM_H */ diff --git a/src/core/lib/iomgr/tcp_posix.cc b/src/core/lib/iomgr/tcp_posix.cc index ca0046b83ba..205af225315 100644 --- a/src/core/lib/iomgr/tcp_posix.cc +++ b/src/core/lib/iomgr/tcp_posix.cc @@ -63,7 +63,7 @@ typedef GRPC_MSG_IOVLEN_TYPE msg_iovlen_type; typedef size_t msg_iovlen_type; #endif -grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); +extern grpc_core::TraceFlag grpc_tcp_trace; namespace { struct grpc_tcp { diff --git a/src/core/lib/iomgr/tcp_server.cc b/src/core/lib/iomgr/tcp_server.cc new file mode 100644 index 00000000000..ea745f266b9 --- /dev/null +++ b/src/core/lib/iomgr/tcp_server.cc @@ -0,0 +1,73 @@ +/* + * + * Copyright 2018 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/tcp_server.h" + +grpc_tcp_server_vtable* grpc_tcp_server_impl; + +grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { + return grpc_tcp_server_impl->create(shutdown_complete, args, server); +} + +void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, + size_t pollset_count, + grpc_tcp_server_cb on_accept_cb, void* cb_arg) { + grpc_tcp_server_impl->start(server, pollsets, pollset_count, on_accept_cb, + cb_arg); +} + +grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* out_port) { + return grpc_tcp_server_impl->add_port(s, addr, out_port); +} + +unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s, + unsigned port_index) { + return grpc_tcp_server_impl->port_fd_count(s, port_index); +} + +int grpc_tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, + unsigned fd_index) { + return grpc_tcp_server_impl->port_fd(s, port_index, fd_index); +} + +grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { + return grpc_tcp_server_impl->ref(s); +} + +void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { + grpc_tcp_server_impl->shutdown_starting_add(s, shutdown_starting); +} + +void grpc_tcp_server_unref(grpc_tcp_server* s) { + grpc_tcp_server_impl->unref(s); +} + +void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) { + grpc_tcp_server_impl->shutdown_listeners(s); +} + +void grpc_set_tcp_server_impl(grpc_tcp_server_vtable* impl) { + grpc_tcp_server_impl = impl; +} diff --git a/src/core/lib/iomgr/tcp_server.h b/src/core/lib/iomgr/tcp_server.h index 965d97407fa..8fcbb2f6807 100644 --- a/src/core/lib/iomgr/tcp_server.h +++ b/src/core/lib/iomgr/tcp_server.h @@ -45,6 +45,24 @@ typedef void (*grpc_tcp_server_cb)(void* arg, grpc_endpoint* ep, grpc_pollset* accepting_pollset, grpc_tcp_server_acceptor* acceptor); +typedef struct grpc_tcp_server_vtable { + grpc_error* (*create)(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server); + void (*start)(grpc_tcp_server* server, grpc_pollset** pollsets, + size_t pollset_count, grpc_tcp_server_cb on_accept_cb, + void* cb_arg); + grpc_error* (*add_port)(grpc_tcp_server* s, const grpc_resolved_address* addr, + int* out_port); + unsigned (*port_fd_count)(grpc_tcp_server* s, unsigned port_index); + int (*port_fd)(grpc_tcp_server* s, unsigned port_index, unsigned fd_index); + grpc_tcp_server* (*ref)(grpc_tcp_server* s); + void (*shutdown_starting_add)(grpc_tcp_server* s, + grpc_closure* shutdown_starting); + void (*unref)(grpc_tcp_server* s); + void (*shutdown_listeners)(grpc_tcp_server* s); +} grpc_tcp_server_vtable; + /* Create a server, initially not bound to any ports. The caller owns one ref. If shutdown_complete is not NULL, it will be used by grpc_tcp_server_unref() when the ref count reaches zero. */ @@ -97,4 +115,8 @@ void grpc_tcp_server_unref(grpc_tcp_server* s); /* Shutdown the fds of listeners. */ void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s); +void grpc_tcp_server_global_init(); + +void grpc_set_tcp_server_impl(grpc_tcp_server_vtable* impl); + #endif /* GRPC_CORE_LIB_IOMGR_TCP_SERVER_H */ diff --git a/src/core/lib/iomgr/tcp_server_custom.cc b/src/core/lib/iomgr/tcp_server_custom.cc new file mode 100644 index 00000000000..be92e61b623 --- /dev/null +++ b/src/core/lib/iomgr/tcp_server_custom.cc @@ -0,0 +1,479 @@ +/* + * + * Copyright 2018 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" + +#include +#include + +#include +#include + +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" +#include "src/core/lib/iomgr/tcp_custom.h" +#include "src/core/lib/iomgr/tcp_server.h" + +extern grpc_core::TraceFlag grpc_tcp_trace; + +extern grpc_socket_vtable* grpc_custom_socket_vtable; + +/* one listening port */ +struct grpc_tcp_listener { + grpc_tcp_server* server; + unsigned port_index; + int port; + + grpc_custom_socket* socket; + + /* linked list */ + struct grpc_tcp_listener* next; + + bool closed; +}; + +struct grpc_tcp_server { + gpr_refcount refs; + + /* Called whenever accept() succeeds on a server port. */ + grpc_tcp_server_cb on_accept_cb; + void* on_accept_cb_arg; + + int open_ports; + + /* linked list of server ports */ + grpc_tcp_listener* head; + grpc_tcp_listener* tail; + + /* List of closures passed to shutdown_starting_add(). */ + grpc_closure_list shutdown_starting; + + /* shutdown callback */ + grpc_closure* shutdown_complete; + + bool shutdown; + + grpc_resource_quota* resource_quota; +}; + +static grpc_error* tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { + grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); + s->resource_quota = grpc_resource_quota_create(nullptr); + for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) { + if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { + if (args->args[i].type == GRPC_ARG_POINTER) { + grpc_resource_quota_unref_internal(s->resource_quota); + s->resource_quota = grpc_resource_quota_ref_internal( + (grpc_resource_quota*)args->args[i].value.pointer.p); + } else { + grpc_resource_quota_unref_internal(s->resource_quota); + gpr_free(s); + return GRPC_ERROR_CREATE_FROM_STATIC_STRING( + GRPC_ARG_RESOURCE_QUOTA " must be a pointer to a buffer pool"); + } + } + } + gpr_ref_init(&s->refs, 1); + s->on_accept_cb = nullptr; + s->on_accept_cb_arg = nullptr; + s->open_ports = 0; + s->head = nullptr; + s->tail = nullptr; + s->shutdown_starting.head = nullptr; + s->shutdown_starting.tail = nullptr; + s->shutdown_complete = shutdown_complete; + s->shutdown = false; + *server = s; + return GRPC_ERROR_NONE; +} + +static grpc_tcp_server* tcp_server_ref(grpc_tcp_server* s) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + gpr_ref(&s->refs); + return s; +} + +static void tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { + grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, + GRPC_ERROR_NONE); +} + +static void finish_shutdown(grpc_tcp_server* s) { + GPR_ASSERT(s->shutdown); + if (s->shutdown_complete != nullptr) { + GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); + } + + while (s->head) { + grpc_tcp_listener* sp = s->head; + s->head = sp->next; + sp->next = nullptr; + gpr_free(sp); + } + grpc_resource_quota_unref_internal(s->resource_quota); + gpr_free(s); +} + +static void custom_close_callback(grpc_custom_socket* socket) { + grpc_tcp_listener* sp = socket->listener; + if (sp) { + grpc_core::ExecCtx exec_ctx; + sp->server->open_ports--; + if (sp->server->open_ports == 0 && sp->server->shutdown) { + finish_shutdown(sp->server); + } + } + socket->refs--; + if (socket->refs == 0) { + grpc_custom_socket_vtable->destroy(socket); + gpr_free(socket); + } +} + +void grpc_custom_close_server_callback(grpc_tcp_listener* sp) { + if (sp) { + grpc_core::ExecCtx exec_ctx; + sp->server->open_ports--; + if (sp->server->open_ports == 0 && sp->server->shutdown) { + finish_shutdown(sp->server); + } + } +} + +static void close_listener(grpc_tcp_listener* sp) { + grpc_custom_socket* socket = sp->socket; + if (!sp->closed) { + sp->closed = true; + grpc_custom_socket_vtable->close(socket, custom_close_callback); + } +} + +static void tcp_server_destroy(grpc_tcp_server* s) { + int immediately_done = 0; + grpc_tcp_listener* sp; + + GPR_ASSERT(!s->shutdown); + s->shutdown = true; + + if (s->open_ports == 0) { + immediately_done = 1; + } + for (sp = s->head; sp; sp = sp->next) { + close_listener(sp); + } + + if (immediately_done) { + finish_shutdown(s); + } +} + +static void tcp_server_unref(grpc_tcp_server* s) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + if (gpr_unref(&s->refs)) { + /* Complete shutdown_starting work before destroying. */ + grpc_core::ExecCtx exec_ctx; + GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); + grpc_core::ExecCtx::Get()->Flush(); + tcp_server_destroy(s); + } +} + +static void finish_accept(grpc_tcp_listener* sp, grpc_custom_socket* socket) { + grpc_tcp_server_acceptor* acceptor = + (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); + grpc_endpoint* ep = nullptr; + grpc_resolved_address peer_name; + char* peer_name_string; + grpc_error* err; + + peer_name_string = nullptr; + memset(&peer_name, 0, sizeof(grpc_resolved_address)); + peer_name.len = GRPC_MAX_SOCKADDR_SIZE; + err = grpc_custom_socket_vtable->getpeername( + socket, (grpc_sockaddr*)&peer_name.addr, (int*)&peer_name.len); + if (err == GRPC_ERROR_NONE) { + peer_name_string = grpc_sockaddr_to_uri(&peer_name); + } else { + GRPC_LOG_IF_ERROR("getpeername error", err); + GRPC_ERROR_UNREF(err); + } + if (grpc_tcp_trace.enabled()) { + if (peer_name_string) { + gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection: %s", + sp->server, peer_name_string); + } else { + gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection", sp->server); + } + } + ep = custom_tcp_endpoint_create(socket, sp->server->resource_quota, + peer_name_string); + acceptor->from_server = sp->server; + acceptor->port_index = sp->port_index; + acceptor->fd_index = 0; + sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, nullptr, acceptor); + gpr_free(peer_name_string); +} + +static void custom_accept_callback(grpc_custom_socket* socket, + grpc_custom_socket* client, + grpc_error* error); + +static void custom_accept_callback(grpc_custom_socket* socket, + grpc_custom_socket* client, + grpc_error* error) { + grpc_core::ExecCtx exec_ctx; + grpc_tcp_listener* sp = socket->listener; + if (error != GRPC_ERROR_NONE) { + if (!sp->closed) { + gpr_log(GPR_ERROR, "Accept failed: %s", grpc_error_string(error)); + } + gpr_free(client); + GRPC_ERROR_UNREF(error); + return; + } + finish_accept(sp, client); + if (!sp->closed) { + grpc_custom_socket* new_socket = + (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + new_socket->endpoint = nullptr; + new_socket->listener = nullptr; + new_socket->connector = nullptr; + new_socket->refs = 1; + grpc_custom_socket_vtable->accept(sp->socket, new_socket, + custom_accept_callback); + } +} + +static grpc_error* add_socket_to_server(grpc_tcp_server* s, + grpc_custom_socket* socket, + const grpc_resolved_address* addr, + unsigned port_index, + grpc_tcp_listener** listener) { + grpc_tcp_listener* sp = nullptr; + int port = -1; + grpc_error* error; + grpc_resolved_address sockname_temp; + + // The last argument to uv_tcp_bind is flags + error = grpc_custom_socket_vtable->bind(socket, (grpc_sockaddr*)addr->addr, + addr->len, 0); + if (error != GRPC_ERROR_NONE) { + return error; + } + + error = grpc_custom_socket_vtable->listen(socket); + if (error != GRPC_ERROR_NONE) { + return error; + } + + sockname_temp.len = GRPC_MAX_SOCKADDR_SIZE; + error = grpc_custom_socket_vtable->getsockname( + socket, (grpc_sockaddr*)&sockname_temp.addr, (int*)&sockname_temp.len); + if (error != GRPC_ERROR_NONE) { + return error; + } + + port = grpc_sockaddr_get_port(&sockname_temp); + + GPR_ASSERT(port >= 0); + GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server"); + sp = (grpc_tcp_listener*)gpr_zalloc(sizeof(grpc_tcp_listener)); + sp->next = nullptr; + if (s->head == nullptr) { + s->head = sp; + } else { + s->tail->next = sp; + } + s->tail = sp; + sp->server = s; + sp->socket = socket; + sp->port = port; + sp->port_index = port_index; + sp->closed = false; + s->open_ports++; + *listener = sp; + + return GRPC_ERROR_NONE; +} + +static grpc_error* tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* port) { + // This function is mostly copied from tcp_server_windows.c + grpc_tcp_listener* sp = nullptr; + grpc_custom_socket* socket; + grpc_resolved_address addr6_v4mapped; + grpc_resolved_address wildcard; + grpc_resolved_address* allocated_addr = nullptr; + grpc_resolved_address sockname_temp; + unsigned port_index = 0; + grpc_error* error = GRPC_ERROR_NONE; + int family; + + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + + if (s->tail != nullptr) { + port_index = s->tail->port_index + 1; + } + + /* Check if this is a wildcard port, and if so, try to keep the port the same + as some previously created listener. */ + if (grpc_sockaddr_get_port(addr) == 0) { + for (sp = s->head; sp; sp = sp->next) { + socket = sp->socket; + sockname_temp.len = GRPC_MAX_SOCKADDR_SIZE; + if (nullptr == grpc_custom_socket_vtable->getsockname( + socket, (grpc_sockaddr*)&sockname_temp.addr, + (int*)&sockname_temp.len)) { + *port = grpc_sockaddr_get_port(&sockname_temp); + if (*port > 0) { + allocated_addr = + (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address)); + memcpy(allocated_addr, addr, sizeof(grpc_resolved_address)); + grpc_sockaddr_set_port(allocated_addr, *port); + addr = allocated_addr; + break; + } + } + } + } + + if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) { + addr = &addr6_v4mapped; + } + + /* Treat :: or 0.0.0.0 as a family-agnostic wildcard. */ + if (grpc_sockaddr_is_wildcard(addr, port)) { + grpc_sockaddr_make_wildcard6(*port, &wildcard); + + addr = &wildcard; + } + + if (grpc_tcp_trace.enabled()) { + char* port_string; + grpc_sockaddr_to_string(&port_string, addr, 0); + const char* str = grpc_error_string(error); + if (port_string) { + gpr_log(GPR_DEBUG, "SERVER %p add_port %s error=%s", s, port_string, str); + gpr_free(port_string); + } else { + gpr_log(GPR_DEBUG, "SERVER %p add_port error=%s", s, str); + } + } + + family = grpc_sockaddr_get_family(addr); + socket = (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + socket->refs = 1; + socket->endpoint = nullptr; + socket->listener = nullptr; + socket->connector = nullptr; + grpc_custom_socket_vtable->init(socket, family); + + if (error == GRPC_ERROR_NONE) { +#if defined(GPR_LINUX) && defined(SO_REUSEPORT) + if (family == AF_INET || family == AF_INET6) { + int enable = 1; + grpc_custom_socket_vtable->setsockopt(socket, SOL_SOCKET, SO_REUSEPORT, + &enable, sizeof(enable)); + } +#endif /* GPR_LINUX && SO_REUSEPORT */ + error = add_socket_to_server(s, socket, addr, port_index, &sp); + } + gpr_free(allocated_addr); + + if (error != GRPC_ERROR_NONE) { + grpc_error* error_out = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( + "Failed to add port to server", &error, 1); + GRPC_ERROR_UNREF(error); + error = error_out; + *port = -1; + } else { + GPR_ASSERT(sp != nullptr); + *port = sp->port; + } + socket->listener = sp; + return error; +} + +static void tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, + size_t pollset_count, + grpc_tcp_server_cb on_accept_cb, void* cb_arg) { + grpc_tcp_listener* sp; + (void)pollsets; + (void)pollset_count; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + if (grpc_tcp_trace.enabled()) { + gpr_log(GPR_DEBUG, "SERVER_START %p", server); + } + GPR_ASSERT(on_accept_cb); + GPR_ASSERT(!server->on_accept_cb); + server->on_accept_cb = on_accept_cb; + server->on_accept_cb_arg = cb_arg; + for (sp = server->head; sp; sp = sp->next) { + grpc_custom_socket* new_socket = + (grpc_custom_socket*)gpr_malloc(sizeof(grpc_custom_socket)); + new_socket->endpoint = nullptr; + new_socket->listener = nullptr; + new_socket->connector = nullptr; + new_socket->refs = 1; + grpc_custom_socket_vtable->accept(sp->socket, new_socket, + custom_accept_callback); + } +} + +static unsigned tcp_server_port_fd_count(grpc_tcp_server* s, + unsigned port_index) { + return 0; +} + +static int tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, + unsigned fd_index) { + return -1; +} + +static void tcp_server_shutdown_listeners(grpc_tcp_server* s) { + for (grpc_tcp_listener* sp = s->head; sp; sp = sp->next) { + if (!sp->closed) { + sp->closed = true; + grpc_custom_socket_vtable->close(sp->socket, custom_close_callback); + } + } +} + +grpc_tcp_server_vtable custom_tcp_server_vtable = { + tcp_server_create, + tcp_server_start, + tcp_server_add_port, + tcp_server_port_fd_count, + tcp_server_port_fd, + tcp_server_ref, + tcp_server_shutdown_starting_add, + tcp_server_unref, + tcp_server_shutdown_listeners}; + +#ifdef GRPC_UV_TEST +grpc_tcp_server_vtable* default_tcp_server_vtable = &custom_tcp_server_vtable; +#endif diff --git a/src/core/lib/iomgr/tcp_server_posix.cc b/src/core/lib/iomgr/tcp_server_posix.cc index a609c09ea7e..aba5d6cdb05 100644 --- a/src/core/lib/iomgr/tcp_server_posix.cc +++ b/src/core/lib/iomgr/tcp_server_posix.cc @@ -69,9 +69,9 @@ static void init(void) { #endif } -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, - const grpc_channel_args* args, - grpc_tcp_server** server) { +static grpc_error* tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { gpr_once_init(&check_init, init); grpc_tcp_server* s = @@ -392,9 +392,9 @@ static grpc_error* clone_port(grpc_tcp_listener* listener, unsigned count) { return GRPC_ERROR_NONE; } -grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, - const grpc_resolved_address* addr, - int* out_port) { +static grpc_error* tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* out_port) { grpc_tcp_listener* sp; grpc_resolved_address sockname_temp; grpc_resolved_address addr6_v4mapped; @@ -415,7 +415,7 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, sockname_temp.len = sizeof(struct sockaddr_storage); if (0 == getsockname(sp->fd, - reinterpret_cast(&sockname_temp.addr), + reinterpret_cast(&sockname_temp.addr), reinterpret_cast(&sockname_temp.len))) { int used_port = grpc_sockaddr_get_port(&sockname_temp); if (used_port > 0) { @@ -458,8 +458,7 @@ static grpc_tcp_listener* get_port_index(grpc_tcp_server* s, return nullptr; } -unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s, - unsigned port_index) { +unsigned tcp_server_port_fd_count(grpc_tcp_server* s, unsigned port_index) { unsigned num_fds = 0; gpr_mu_lock(&s->mu); grpc_tcp_listener* sp = get_port_index(s, port_index); @@ -470,8 +469,8 @@ unsigned grpc_tcp_server_port_fd_count(grpc_tcp_server* s, return num_fds; } -int grpc_tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, - unsigned fd_index) { +static int tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, + unsigned fd_index) { gpr_mu_lock(&s->mu); grpc_tcp_listener* sp = get_port_index(s, port_index); for (; sp; sp = sp->sibling, --fd_index) { @@ -484,10 +483,10 @@ int grpc_tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, return -1; } -void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, - size_t pollset_count, - grpc_tcp_server_cb on_accept_cb, - void* on_accept_cb_arg) { +static void tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, + size_t pollset_count, + grpc_tcp_server_cb on_accept_cb, + void* on_accept_cb_arg) { size_t i; grpc_tcp_listener* sp; GPR_ASSERT(on_accept_cb); @@ -526,20 +525,20 @@ void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollsets, gpr_mu_unlock(&s->mu); } -grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { +grpc_tcp_server* tcp_server_ref(grpc_tcp_server* s) { gpr_ref_non_zero(&s->refs); return s; } -void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, - grpc_closure* shutdown_starting) { +static void tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { gpr_mu_lock(&s->mu); grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, GRPC_ERROR_NONE); gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_unref(grpc_tcp_server* s) { +static void tcp_server_unref(grpc_tcp_server* s) { if (gpr_unref(&s->refs)) { grpc_tcp_server_shutdown_listeners(s); gpr_mu_lock(&s->mu); @@ -549,7 +548,7 @@ void grpc_tcp_server_unref(grpc_tcp_server* s) { } } -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) { +static void tcp_server_shutdown_listeners(grpc_tcp_server* s) { gpr_mu_lock(&s->mu); s->shutdown_listeners = true; /* shutdown all fd's */ @@ -563,4 +562,14 @@ void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) { gpr_mu_unlock(&s->mu); } +grpc_tcp_server_vtable grpc_posix_tcp_server_vtable = { + tcp_server_create, + tcp_server_start, + tcp_server_add_port, + tcp_server_port_fd_count, + tcp_server_port_fd, + tcp_server_ref, + tcp_server_shutdown_starting_add, + tcp_server_unref, + tcp_server_shutdown_listeners}; #endif diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc index 846f9cccb7f..76d3d629405 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_common.cc @@ -171,8 +171,7 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd, if (err != GRPC_ERROR_NONE) goto error; GPR_ASSERT(addr->len < ~(socklen_t)0); - if (bind(fd, - reinterpret_cast(const_cast(addr->addr)), + if (bind(fd, reinterpret_cast(const_cast(addr->addr)), static_cast(addr->len)) < 0) { err = GRPC_OS_ERROR(errno, "bind"); goto error; @@ -185,7 +184,7 @@ grpc_error* grpc_tcp_server_prepare_socket(int fd, sockname_temp.len = sizeof(struct sockaddr_storage); - if (getsockname(fd, reinterpret_cast(sockname_temp.addr), + if (getsockname(fd, reinterpret_cast(sockname_temp.addr), reinterpret_cast(&sockname_temp.len)) < 0) { err = GRPC_OS_ERROR(errno, "getsockname"); goto error; diff --git a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc index 308ff0f8a6f..29ff9ecda1e 100644 --- a/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +++ b/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc @@ -68,13 +68,13 @@ static grpc_error* get_unused_port(int* port) { if (dsmode == GRPC_DSMODE_IPV4) { grpc_sockaddr_make_wildcard4(0, &wild); } - if (bind(fd, reinterpret_cast(wild.addr), + if (bind(fd, reinterpret_cast(wild.addr), static_cast(wild.len)) != 0) { err = GRPC_OS_ERROR(errno, "bind"); close(fd); return err; } - if (getsockname(fd, reinterpret_cast(wild.addr), + if (getsockname(fd, reinterpret_cast(wild.addr), reinterpret_cast(&wild.len)) != 0) { err = GRPC_OS_ERROR(errno, "getsockname"); close(fd); @@ -119,9 +119,9 @@ grpc_error* grpc_tcp_server_add_all_local_addrs(grpc_tcp_server* s, if (ifa_it->ifa_addr == nullptr) { continue; } else if (ifa_it->ifa_addr->sa_family == AF_INET) { - addr.len = sizeof(struct sockaddr_in); + addr.len = sizeof(grpc_sockaddr_in); } else if (ifa_it->ifa_addr->sa_family == AF_INET6) { - addr.len = sizeof(struct sockaddr_in6); + addr.len = sizeof(grpc_sockaddr_in6); } else { continue; } diff --git a/src/core/lib/iomgr/tcp_server_uv.cc b/src/core/lib/iomgr/tcp_server_uv.cc deleted file mode 100644 index aa423766c7f..00000000000 --- a/src/core/lib/iomgr/tcp_server_uv.cc +++ /dev/null @@ -1,473 +0,0 @@ -/* - * - * Copyright 2015 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" - -#ifdef GRPC_UV - -#include -#include - -#include -#include - -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/iomgr/iomgr_uv.h" -#include "src/core/lib/iomgr/sockaddr.h" -#include "src/core/lib/iomgr/sockaddr_utils.h" -#include "src/core/lib/iomgr/tcp_server.h" -#include "src/core/lib/iomgr/tcp_uv.h" - -/* one listening port */ -typedef struct grpc_tcp_listener grpc_tcp_listener; -struct grpc_tcp_listener { - uv_tcp_t* handle; - grpc_tcp_server* server; - unsigned port_index; - int port; - /* linked list */ - struct grpc_tcp_listener* next; - - bool closed; - - bool has_pending_connection; -}; - -struct grpc_tcp_server { - gpr_refcount refs; - - /* Called whenever accept() succeeds on a server port. */ - grpc_tcp_server_cb on_accept_cb; - void* on_accept_cb_arg; - - int open_ports; - - /* linked list of server ports */ - grpc_tcp_listener* head; - grpc_tcp_listener* tail; - - /* List of closures passed to shutdown_starting_add(). */ - grpc_closure_list shutdown_starting; - - /* shutdown callback */ - grpc_closure* shutdown_complete; - - bool shutdown; - - grpc_resource_quota* resource_quota; -}; - -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, - const grpc_channel_args* args, - grpc_tcp_server** server) { - grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); - s->resource_quota = grpc_resource_quota_create(NULL); - for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) { - if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) { - if (args->args[i].type == GRPC_ARG_POINTER) { - grpc_resource_quota_unref_internal(s->resource_quota); - s->resource_quota = grpc_resource_quota_ref_internal( - (grpc_resource_quota*)args->args[i].value.pointer.p); - } else { - grpc_resource_quota_unref_internal(s->resource_quota); - gpr_free(s); - return GRPC_ERROR_CREATE_FROM_STATIC_STRING( - GRPC_ARG_RESOURCE_QUOTA " must be a pointer to a buffer pool"); - } - } - } - gpr_ref_init(&s->refs, 1); - s->on_accept_cb = NULL; - s->on_accept_cb_arg = NULL; - s->open_ports = 0; - s->head = NULL; - s->tail = NULL; - s->shutdown_starting.head = NULL; - s->shutdown_starting.tail = NULL; - s->shutdown_complete = shutdown_complete; - s->shutdown = false; - *server = s; - return GRPC_ERROR_NONE; -} - -grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { - GRPC_UV_ASSERT_SAME_THREAD(); - gpr_ref(&s->refs); - return s; -} - -void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, - grpc_closure* shutdown_starting) { - grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, - GRPC_ERROR_NONE); -} - -static void finish_shutdown(grpc_tcp_server* s) { - GPR_ASSERT(s->shutdown); - if (s->shutdown_complete != NULL) { - GRPC_CLOSURE_SCHED(s->shutdown_complete, GRPC_ERROR_NONE); - } - - while (s->head) { - grpc_tcp_listener* sp = s->head; - s->head = sp->next; - sp->next = NULL; - gpr_free(sp->handle); - gpr_free(sp); - } - grpc_resource_quota_unref_internal(s->resource_quota); - gpr_free(s); -} - -static void handle_close_callback(uv_handle_t* handle) { - grpc_tcp_listener* sp = (grpc_tcp_listener*)handle->data; - grpc_core::ExecCtx exec_ctx; - sp->server->open_ports--; - if (sp->server->open_ports == 0 && sp->server->shutdown) { - finish_shutdown(sp->server); - } -} - -static void close_listener(grpc_tcp_listener* sp) { - if (!sp->closed) { - sp->closed = true; - uv_close((uv_handle_t*)sp->handle, handle_close_callback); - } -} - -static void tcp_server_destroy(grpc_tcp_server* s) { - int immediately_done = 0; - grpc_tcp_listener* sp; - - GPR_ASSERT(!s->shutdown); - s->shutdown = true; - - if (s->open_ports == 0) { - immediately_done = 1; - } - for (sp = s->head; sp; sp = sp->next) { - close_listener(sp); - } - - if (immediately_done) { - finish_shutdown(s); - } -} - -void grpc_tcp_server_unref(grpc_tcp_server* s) { - GRPC_UV_ASSERT_SAME_THREAD(); - if (gpr_unref(&s->refs)) { - /* Complete shutdown_starting work before destroying. */ - grpc_core::ExecCtx exec_ctx; - GRPC_CLOSURE_LIST_SCHED(&s->shutdown_starting); - grpc_core::ExecCtx::Get()->Flush(); - tcp_server_destroy(s); - } -} - -static void finish_accept(grpc_tcp_listener* sp) { - grpc_tcp_server_acceptor* acceptor = - (grpc_tcp_server_acceptor*)gpr_malloc(sizeof(*acceptor)); - uv_tcp_t* client = NULL; - grpc_endpoint* ep = NULL; - grpc_resolved_address peer_name; - char* peer_name_string; - int err; - uv_tcp_t* server = sp->handle; - - client = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); - uv_tcp_init(uv_default_loop(), client); - // UV documentation says this is guaranteed to succeed - uv_accept((uv_stream_t*)server, (uv_stream_t*)client); - peer_name_string = NULL; - memset(&peer_name, 0, sizeof(grpc_resolved_address)); - peer_name.len = sizeof(struct sockaddr_storage); - err = uv_tcp_getpeername(client, (struct sockaddr*)&peer_name.addr, - (int*)&peer_name.len); - if (err == 0) { - peer_name_string = grpc_sockaddr_to_uri(&peer_name); - } else { - gpr_log(GPR_INFO, "uv_tcp_getpeername error: %s", uv_strerror(err)); - } - if (grpc_tcp_trace.enabled()) { - if (peer_name_string) { - gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection: %s", - sp->server, peer_name_string); - } else { - gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p accepted connection", sp->server); - } - } - ep = grpc_tcp_create(client, sp->server->resource_quota, peer_name_string); - acceptor->from_server = sp->server; - acceptor->port_index = sp->port_index; - acceptor->fd_index = 0; - sp->server->on_accept_cb(sp->server->on_accept_cb_arg, ep, NULL, acceptor); - gpr_free(peer_name_string); -} - -static void on_connect(uv_stream_t* server, int status) { - grpc_tcp_listener* sp = (grpc_tcp_listener*)server->data; - grpc_core::ExecCtx exec_ctx; - - if (status < 0) { - switch (status) { - case UV_EINTR: - case UV_EAGAIN: - return; - default: - close_listener(sp); - return; - } - } - - GPR_ASSERT(!sp->has_pending_connection); - - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "SERVER_CONNECT: %p incoming connection", sp->server); - } - - // Create acceptor. - if (sp->server->on_accept_cb) { - finish_accept(sp); - } else { - sp->has_pending_connection = true; - } -} - -static grpc_error* add_addr_to_server(grpc_tcp_server* s, - const grpc_resolved_address* addr, - unsigned port_index, - grpc_tcp_listener** listener) { - grpc_tcp_listener* sp = NULL; - int port = -1; - int status; - grpc_error* error; - grpc_resolved_address sockname_temp; - uv_tcp_t* handle = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); - int family = grpc_sockaddr_get_family(addr); - - status = uv_tcp_init_ex(uv_default_loop(), handle, (unsigned int)family); -#if defined(GPR_LINUX) && defined(SO_REUSEPORT) - if (family == AF_INET || family == AF_INET6) { - int fd; - uv_fileno((uv_handle_t*)handle, &fd); - int enable = 1; - setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &enable, sizeof(enable)); - } -#endif /* GPR_LINUX && SO_REUSEPORT */ - - if (status != 0) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Failed to initialize UV tcp handle"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - - // The last argument to uv_tcp_bind is flags - status = uv_tcp_bind(handle, (struct sockaddr*)addr->addr, 0); - if (status != 0) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to bind to port"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - - status = uv_listen((uv_stream_t*)handle, SOMAXCONN, on_connect); - if (status != 0) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to listen to port"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - - sockname_temp.len = (int)sizeof(struct sockaddr_storage); - status = uv_tcp_getsockname(handle, (struct sockaddr*)&sockname_temp.addr, - (int*)&sockname_temp.len); - if (status != 0) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("getsockname failed"); - error = - grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - return error; - } - - port = grpc_sockaddr_get_port(&sockname_temp); - - GPR_ASSERT(port >= 0); - GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server"); - sp = (grpc_tcp_listener*)gpr_zalloc(sizeof(grpc_tcp_listener)); - sp->next = NULL; - if (s->head == NULL) { - s->head = sp; - } else { - s->tail->next = sp; - } - s->tail = sp; - sp->server = s; - sp->handle = handle; - sp->port = port; - sp->port_index = port_index; - sp->closed = false; - handle->data = sp; - s->open_ports++; - GPR_ASSERT(sp->handle); - *listener = sp; - - return GRPC_ERROR_NONE; -} - -static grpc_error* add_wildcard_addrs_to_server(grpc_tcp_server* s, - unsigned port_index, - int requested_port, - grpc_tcp_listener** listener) { - grpc_resolved_address wild4; - grpc_resolved_address wild6; - grpc_tcp_listener* sp = nullptr; - grpc_tcp_listener* sp2 = nullptr; - grpc_error* v6_err = GRPC_ERROR_NONE; - grpc_error* v4_err = GRPC_ERROR_NONE; - - grpc_sockaddr_make_wildcards(requested_port, &wild4, &wild6); - /* Try listening on IPv6 first. */ - if ((v6_err = add_addr_to_server(s, &wild6, port_index, &sp)) == - GRPC_ERROR_NONE) { - *listener = sp; - return GRPC_ERROR_NONE; - } - - if ((v4_err = add_addr_to_server(s, &wild4, port_index, &sp2)) == - GRPC_ERROR_NONE) { - *listener = sp2; - return GRPC_ERROR_NONE; - } - - grpc_error* root_err = GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "Failed to add any wildcard listeners"); - root_err = grpc_error_add_child(root_err, v6_err); - root_err = grpc_error_add_child(root_err, v4_err); - return root_err; -} - -grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, - const grpc_resolved_address* addr, - int* port) { - // This function is mostly copied from tcp_server_windows.c - grpc_tcp_listener* sp = NULL; - grpc_resolved_address addr6_v4mapped; - grpc_resolved_address* allocated_addr = NULL; - grpc_resolved_address sockname_temp; - unsigned port_index = 0; - grpc_error* error = GRPC_ERROR_NONE; - - GRPC_UV_ASSERT_SAME_THREAD(); - - if (s->tail != NULL) { - port_index = s->tail->port_index + 1; - } - - /* Check if this is a wildcard port, and if so, try to keep the port the same - as some previously created listener. */ - if (grpc_sockaddr_get_port(addr) == 0) { - for (sp = s->head; sp; sp = sp->next) { - sockname_temp.len = sizeof(struct sockaddr_storage); - if (0 == uv_tcp_getsockname(sp->handle, - (struct sockaddr*)&sockname_temp.addr, - (int*)&sockname_temp.len)) { - *port = grpc_sockaddr_get_port(&sockname_temp); - if (*port > 0) { - allocated_addr = - (grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address)); - memcpy(allocated_addr, addr, sizeof(grpc_resolved_address)); - grpc_sockaddr_set_port(allocated_addr, *port); - addr = allocated_addr; - break; - } - } - } - } - - /* Treat :: or 0.0.0.0 as a family-agnostic wildcard. */ - if (grpc_sockaddr_is_wildcard(addr, port)) { - error = add_wildcard_addrs_to_server(s, port_index, *port, &sp); - } else { - if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) { - addr = &addr6_v4mapped; - } - - error = add_addr_to_server(s, addr, port_index, &sp); - } - - gpr_free(allocated_addr); - - if (grpc_tcp_trace.enabled()) { - char* port_string; - grpc_sockaddr_to_string(&port_string, addr, 0); - const char* str = grpc_error_string(error); - if (port_string) { - gpr_log(GPR_DEBUG, "SERVER %p add_port %s error=%s", s, port_string, str); - gpr_free(port_string); - } else { - gpr_log(GPR_DEBUG, "SERVER %p add_port error=%s", s, str); - } - } - - if (error != GRPC_ERROR_NONE) { - grpc_error* error_out = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING( - "Failed to add port to server", &error, 1); - GRPC_ERROR_UNREF(error); - error = error_out; - *port = -1; - } else { - GPR_ASSERT(sp != NULL); - *port = sp->port; - } - return error; -} - -void grpc_tcp_server_start(grpc_tcp_server* server, grpc_pollset** pollsets, - size_t pollset_count, - grpc_tcp_server_cb on_accept_cb, void* cb_arg) { - grpc_tcp_listener* sp; - (void)pollsets; - (void)pollset_count; - GRPC_UV_ASSERT_SAME_THREAD(); - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "SERVER_START %p", server); - } - GPR_ASSERT(on_accept_cb); - GPR_ASSERT(!server->on_accept_cb); - server->on_accept_cb = on_accept_cb; - server->on_accept_cb_arg = cb_arg; - for (sp = server->head; sp; sp = sp->next) { - if (sp->has_pending_connection) { - finish_accept(sp); - sp->has_pending_connection = false; - } - } -} - -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} - -#endif /* GRPC_UV */ diff --git a/src/core/lib/iomgr/tcp_server_windows.cc b/src/core/lib/iomgr/tcp_server_windows.cc index 6d19c1c4d72..77f3811dcae 100644 --- a/src/core/lib/iomgr/tcp_server_windows.cc +++ b/src/core/lib/iomgr/tcp_server_windows.cc @@ -50,7 +50,7 @@ typedef struct grpc_tcp_listener grpc_tcp_listener; struct grpc_tcp_listener { /* This seemingly magic number comes from AcceptEx's documentation. each address buffer needs to have at least 16 more bytes at their end. */ - uint8_t addresses[(sizeof(struct sockaddr_in6) + 16) * 2]; + uint8_t addresses[(sizeof(grpc_sockaddr_in6) + 16) * 2]; /* This will hold the socket for the next accept. */ SOCKET new_socket; /* The listener winsocket. */ @@ -96,9 +96,9 @@ struct grpc_tcp_server { /* Public function. Allocates the proper data structures to hold a grpc_tcp_server. */ -grpc_error* grpc_tcp_server_create(grpc_closure* shutdown_complete, - const grpc_channel_args* args, - grpc_tcp_server** server) { +static grpc_error* tcp_server_create(grpc_closure* shutdown_complete, + const grpc_channel_args* args, + grpc_tcp_server** server) { grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server)); s->channel_args = grpc_channel_args_copy(args); gpr_ref_init(&s->refs, 1); @@ -142,13 +142,13 @@ static void finish_shutdown_locked(grpc_tcp_server* s) { GRPC_ERROR_NONE); } -grpc_tcp_server* grpc_tcp_server_ref(grpc_tcp_server* s) { +static grpc_tcp_server* tcp_server_ref(grpc_tcp_server* s) { gpr_ref_non_zero(&s->refs); return s; } -void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server* s, - grpc_closure* shutdown_starting) { +static void tcp_server_shutdown_starting_add(grpc_tcp_server* s, + grpc_closure* shutdown_starting) { gpr_mu_lock(&s->mu); grpc_closure_list_append(&s->shutdown_starting, shutdown_starting, GRPC_ERROR_NONE); @@ -172,7 +172,7 @@ static void tcp_server_destroy(grpc_tcp_server* s) { gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_unref(grpc_tcp_server* s) { +static void tcp_server_unref(grpc_tcp_server* s) { if (gpr_unref(&s->refs)) { grpc_tcp_server_shutdown_listeners(s); gpr_mu_lock(&s->mu); @@ -195,7 +195,7 @@ static grpc_error* prepare_socket(SOCKET sock, goto failure; } - if (bind(sock, (const struct sockaddr*)addr->addr, (int)addr->len) == + if (bind(sock, (const grpc_sockaddr*)addr->addr, (int)addr->len) == SOCKET_ERROR) { error = GRPC_WSA_ERROR(WSAGetLastError(), "bind"); goto failure; @@ -207,7 +207,7 @@ static grpc_error* prepare_socket(SOCKET sock, } sockname_temp_len = sizeof(struct sockaddr_storage); - if (getsockname(sock, (struct sockaddr*)sockname_temp.addr, + if (getsockname(sock, (grpc_sockaddr*)sockname_temp.addr, &sockname_temp_len) == SOCKET_ERROR) { error = GRPC_WSA_ERROR(WSAGetLastError(), "getsockname"); goto failure; @@ -245,7 +245,7 @@ static void decrement_active_ports_and_notify_locked(grpc_tcp_listener* sp) { static grpc_error* start_accept_locked(grpc_tcp_listener* port) { SOCKET sock = INVALID_SOCKET; BOOL success; - DWORD addrlen = sizeof(struct sockaddr_in6) + 16; + DWORD addrlen = sizeof(grpc_sockaddr_in6) + 16; DWORD bytes_received = 0; grpc_error* error = GRPC_ERROR_NONE; @@ -343,7 +343,7 @@ static void on_accept(void* arg, grpc_error* error) { gpr_free(utf8_message); } int peer_name_len = (int)peer_name.len; - err = getpeername(sock, (struct sockaddr*)peer_name.addr, &peer_name_len); + err = getpeername(sock, (grpc_sockaddr*)peer_name.addr, &peer_name_len); peer_name.len = (size_t)peer_name_len; if (!err) { peer_name_string = grpc_sockaddr_to_uri(&peer_name); @@ -442,9 +442,9 @@ static grpc_error* add_socket_to_server(grpc_tcp_server* s, SOCKET sock, return GRPC_ERROR_NONE; } -grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, - const grpc_resolved_address* addr, - int* port) { +static grpc_error* tcp_server_add_port(grpc_tcp_server* s, + const grpc_resolved_address* addr, + int* port) { grpc_tcp_listener* sp = NULL; SOCKET sock; grpc_resolved_address addr6_v4mapped; @@ -464,7 +464,7 @@ grpc_error* grpc_tcp_server_add_port(grpc_tcp_server* s, for (sp = s->head; sp; sp = sp->next) { int sockname_temp_len = sizeof(struct sockaddr_storage); if (0 == getsockname(sp->socket->socket, - (struct sockaddr*)sockname_temp.addr, + (grpc_sockaddr*)sockname_temp.addr, &sockname_temp_len)) { sockname_temp.len = (size_t)sockname_temp_len; *port = grpc_sockaddr_get_port(&sockname_temp); @@ -516,10 +516,10 @@ done: return error; } -void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, - size_t pollset_count, - grpc_tcp_server_cb on_accept_cb, - void* on_accept_cb_arg) { +static void tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, + size_t pollset_count, + grpc_tcp_server_cb on_accept_cb, + void* on_accept_cb_arg) { grpc_tcp_listener* sp; GPR_ASSERT(on_accept_cb); gpr_mu_lock(&s->mu); @@ -534,6 +534,26 @@ void grpc_tcp_server_start(grpc_tcp_server* s, grpc_pollset** pollset, gpr_mu_unlock(&s->mu); } -void grpc_tcp_server_shutdown_listeners(grpc_tcp_server* s) {} +static unsigned tcp_server_port_fd_count(grpc_tcp_server* s, + unsigned port_index) { + return 0; +} + +static int tcp_server_port_fd(grpc_tcp_server* s, unsigned port_index, + unsigned fd_index) { + return -1; +} +static void tcp_server_shutdown_listeners(grpc_tcp_server* s) {} + +grpc_tcp_server_vtable grpc_windows_tcp_server_vtable = { + tcp_server_create, + tcp_server_start, + tcp_server_add_port, + tcp_server_port_fd_count, + tcp_server_port_fd, + tcp_server_ref, + tcp_server_shutdown_starting_add, + tcp_server_unref, + tcp_server_shutdown_listeners}; #endif /* GRPC_WINSOCK_SOCKET */ diff --git a/src/core/lib/iomgr/tcp_uv.cc b/src/core/lib/iomgr/tcp_uv.cc index 6db3217d6e7..5e3166926b6 100644 --- a/src/core/lib/iomgr/tcp_uv.cc +++ b/src/core/lib/iomgr/tcp_uv.cc @@ -21,7 +21,6 @@ #include "src/core/lib/iomgr/port.h" #ifdef GRPC_UV - #include #include @@ -33,393 +32,393 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/error.h" -#include "src/core/lib/iomgr/iomgr_uv.h" +#include "src/core/lib/iomgr/iomgr_custom.h" #include "src/core/lib/iomgr/network_status_tracker.h" +#include "src/core/lib/iomgr/resolve_address_custom.h" #include "src/core/lib/iomgr/resource_quota.h" -#include "src/core/lib/iomgr/tcp_uv.h" +#include "src/core/lib/iomgr/tcp_custom.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" -grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); +#include -typedef struct { - grpc_endpoint base; - gpr_refcount refcount; +#define IGNORE_CONST(addr) ((grpc_sockaddr*)(uintptr_t)(addr)) +typedef struct uv_socket_t { + uv_connect_t connect_req; uv_write_t write_req; uv_shutdown_t shutdown_req; - uv_tcp_t* handle; - - grpc_closure* read_cb; - grpc_closure* write_cb; - - grpc_slice_buffer* read_slices; - grpc_slice_buffer* write_slices; uv_buf_t* write_buffers; - grpc_resource_user* resource_user; - grpc_resource_user_slice_allocator slice_allocator; - - bool shutting_down; + char* read_buf; + size_t read_len; - char* peer_string; - grpc_pollset* pollset; -} grpc_tcp; + bool pending_connection; + grpc_custom_socket* accept_socket; + grpc_error* accept_error; -static grpc_error* tcp_annotate_error(grpc_error* src_error, grpc_tcp* tcp) { - return grpc_error_set_str( - grpc_error_set_int( - src_error, - /* All tcp errors are marked with UNAVAILABLE so that application may - * choose to retry. */ - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE), - GRPC_ERROR_STR_TARGET_ADDRESS, - grpc_slice_from_copied_string(tcp->peer_string)); -} + grpc_custom_connect_callback connect_cb; + grpc_custom_write_callback write_cb; + grpc_custom_read_callback read_cb; + grpc_custom_accept_callback accept_cb; + grpc_custom_close_callback close_cb; -static void tcp_free(grpc_tcp* tcp) { - grpc_resource_user_unref(tcp->resource_user); - gpr_free(tcp->handle); - gpr_free(tcp->peer_string); - gpr_free(tcp); -} - -#ifndef NDEBUG -#define TCP_UNREF(tcp, reason) tcp_unref((tcp), (reason), __FILE__, __LINE__) -#define TCP_REF(tcp, reason) tcp_ref((tcp), (reason), __FILE__, __LINE__) -static void tcp_unref(grpc_tcp* tcp, const char* reason, const char* file, - int line) { - if (grpc_tcp_trace.enabled()) { - gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "TCP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, - val - 1); - } - if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); - } -} +} uv_socket_t; -static void tcp_ref(grpc_tcp* tcp, const char* reason, const char* file, - int line) { - if (grpc_tcp_trace.enabled()) { - gpr_atm val = gpr_atm_no_barrier_load(&tcp->refcount.count); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "TCP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, tcp, reason, val, - val + 1); - } - gpr_ref(&tcp->refcount); -} -#else -#define TCP_UNREF(tcp, reason) tcp_unref((tcp)) -#define TCP_REF(tcp, reason) tcp_ref((tcp)) -static void tcp_unref(grpc_tcp* tcp) { - if (gpr_unref(&tcp->refcount)) { - tcp_free(tcp); +static grpc_error* tcp_error_create(const char* desc, int status) { + if (status == 0) { + return GRPC_ERROR_NONE; } + grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(desc); + /* All tcp errors are marked with UNAVAILABLE so that application may + * choose to retry. */ + error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, + GRPC_STATUS_UNAVAILABLE); + return grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, + grpc_slice_from_static_string(uv_strerror(status))); } -static void tcp_ref(grpc_tcp* tcp) { gpr_ref(&tcp->refcount); } -#endif - -static void uv_close_callback(uv_handle_t* handle) { - grpc_core::ExecCtx exec_ctx; - grpc_tcp* tcp = (grpc_tcp*)handle->data; - TCP_UNREF(tcp, "destroy"); +static void uv_socket_destroy(grpc_custom_socket* socket) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + gpr_free(uv_socket->handle); + gpr_free(uv_socket); } static void alloc_uv_buf(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { - grpc_core::ExecCtx exec_ctx; - grpc_tcp* tcp = (grpc_tcp*)handle->data; + uv_socket_t* uv_socket = + (uv_socket_t*)((grpc_custom_socket*)handle->data)->impl; (void)suggested_size; - /* Before calling uv_read_start, we allocate a buffer with exactly one slice - * to tcp->read_slices and wait for the callback indicating that the - * allocation was successful. So slices[0] should always exist here */ - buf->base = (char*)GRPC_SLICE_START_PTR(tcp->read_slices->slices[0]); - buf->len = GRPC_SLICE_LENGTH(tcp->read_slices->slices[0]); -} - -static void call_read_cb(grpc_tcp* tcp, grpc_error* error) { - grpc_closure* cb = tcp->read_cb; - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "TCP:%p call_cb %p %p:%p", tcp, cb, cb->cb, cb->cb_arg); - size_t i; - const char* str = grpc_error_string(error); - gpr_log(GPR_DEBUG, "read: error=%s", str); - - for (i = 0; i < tcp->read_slices->count; i++) { - char* dump = grpc_dump_slice(tcp->read_slices->slices[i], - GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "READ %p (peer=%s): %s", tcp, tcp->peer_string, dump); - gpr_free(dump); - } - } - tcp->read_slices = NULL; - tcp->read_cb = NULL; - GRPC_CLOSURE_RUN(cb, error); + buf->base = uv_socket->read_buf; + buf->len = uv_socket->read_len; } -static void read_callback(uv_stream_t* stream, ssize_t nread, - const uv_buf_t* buf) { - grpc_error* error; - grpc_core::ExecCtx exec_ctx; - grpc_tcp* tcp = (grpc_tcp*)stream->data; - grpc_slice_buffer garbage; +static void uv_read_callback(uv_stream_t* stream, ssize_t nread, + const uv_buf_t* buf) { + grpc_error* error = GRPC_ERROR_NONE; if (nread == 0) { // Nothing happened. Wait for the next callback return; } - TCP_UNREF(tcp, "read"); // TODO(murgatroid99): figure out what the return value here means uv_read_stop(stream); if (nread == UV_EOF) { - error = - tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"), tcp); - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); - } else if (nread > 0) { - // Successful read - error = GRPC_ERROR_NONE; - if ((size_t)nread < tcp->read_slices->length) { - /* TODO(murgatroid99): Instead of discarding the unused part of the read - * buffer, reuse it as the next read buffer. */ - grpc_slice_buffer_init(&garbage); - grpc_slice_buffer_trim_end( - tcp->read_slices, tcp->read_slices->length - (size_t)nread, &garbage); - grpc_slice_buffer_reset_and_unref_internal(&garbage); - } - } else { - // nread < 0: Error - error = tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed"), tcp); - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("EOF"); + } else if (nread < 0) { + error = tcp_error_create("TCP Read failed", nread); } - call_read_cb(tcp, error); + grpc_custom_socket* socket = (grpc_custom_socket*)stream->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->read_cb(socket, (size_t)nread, error); } -static void tcp_read_allocation_done(void* tcpp, grpc_error* error) { - int status; - grpc_tcp* tcp = (grpc_tcp*)tcpp; - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "TCP:%p read_allocation_done: %s", tcp, - grpc_error_string(error)); - } - if (error == GRPC_ERROR_NONE) { - status = - uv_read_start((uv_stream_t*)tcp->handle, alloc_uv_buf, read_callback); - if (status != 0) { - error = tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Read failed at start"), - tcp); - error = grpc_error_set_str( - error, GRPC_ERROR_STR_OS_ERROR, - grpc_slice_from_static_string(uv_strerror(status))); - } - } - if (error != GRPC_ERROR_NONE) { - grpc_slice_buffer_reset_and_unref_internal(tcp->read_slices); - call_read_cb(tcp, GRPC_ERROR_REF(error)); - TCP_UNREF(tcp, "read"); +static void uv_close_callback(uv_handle_t* handle) { + grpc_custom_socket* socket = (grpc_custom_socket*)handle->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + if (uv_socket->accept_socket) { + uv_socket->accept_cb(socket, uv_socket->accept_socket, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("socket closed")); } - if (grpc_tcp_trace.enabled()) { - const char* str = grpc_error_string(error); - gpr_log(GPR_DEBUG, "Initiating read on %p: error=%s", tcp, str); + uv_socket->close_cb(socket); +} + +static void uv_socket_read(grpc_custom_socket* socket, char* buffer, + size_t length, grpc_custom_read_callback read_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int status; + grpc_error* error; + uv_socket->read_cb = read_cb; + uv_socket->read_buf = buffer; + uv_socket->read_len = length; + // TODO(murgatroid99): figure out what the return value here means + status = + uv_read_start((uv_stream_t*)uv_socket->handle, (uv_alloc_cb)alloc_uv_buf, + (uv_read_cb)uv_read_callback); + if (status != 0) { + error = tcp_error_create("TCP Read failed at start", status); + uv_socket->read_cb(socket, 0, error); } } -static void uv_endpoint_read(grpc_endpoint* ep, grpc_slice_buffer* read_slices, - grpc_closure* cb) { - grpc_tcp* tcp = (grpc_tcp*)ep; - GRPC_UV_ASSERT_SAME_THREAD(); - GPR_ASSERT(tcp->read_cb == NULL); - tcp->read_cb = cb; - tcp->read_slices = read_slices; - grpc_slice_buffer_reset_and_unref_internal(read_slices); - TCP_REF(tcp, "read"); - grpc_resource_user_alloc_slices(&tcp->slice_allocator, - GRPC_TCP_DEFAULT_READ_SLICE_SIZE, 1, - tcp->read_slices); +static void uv_write_callback(uv_write_t* req, int status) { + grpc_custom_socket* socket = (grpc_custom_socket*)req->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + gpr_free(uv_socket->write_buffers); + uv_socket->write_cb(socket, tcp_error_create("TCP Write failed", status)); } -static void write_callback(uv_write_t* req, int status) { - grpc_tcp* tcp = (grpc_tcp*)req->data; - grpc_error* error; - grpc_core::ExecCtx exec_ctx; - grpc_closure* cb = tcp->write_cb; - tcp->write_cb = NULL; - TCP_UNREF(tcp, "write"); - if (status == 0) { - error = GRPC_ERROR_NONE; - } else { - error = tcp_annotate_error( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("TCP Write failed"), tcp); - } - if (grpc_tcp_trace.enabled()) { - const char* str = grpc_error_string(error); - gpr_log(GPR_DEBUG, "write complete on %p: error=%s", tcp, str); +void uv_socket_write(grpc_custom_socket* socket, + grpc_slice_buffer* write_slices, + grpc_custom_write_callback write_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->write_cb = write_cb; + uv_buf_t* uv_buffers; + uv_write_t* write_req; + + uv_buffers = (uv_buf_t*)gpr_malloc(sizeof(uv_buf_t) * write_slices->count); + for (size_t i = 0; i < write_slices->count; i++) { + uv_buffers[i].base = (char*)GRPC_SLICE_START_PTR(write_slices->slices[i]); + uv_buffers[i].len = GRPC_SLICE_LENGTH(write_slices->slices[i]); } - gpr_free(tcp->write_buffers); - GRPC_CLOSURE_SCHED(cb, error); + + uv_socket->write_buffers = uv_buffers; + write_req = &uv_socket->write_req; + write_req->data = socket; + // TODO(murgatroid99): figure out what the return value here means + uv_write(write_req, (uv_stream_t*)uv_socket->handle, uv_buffers, + write_slices->count, uv_write_callback); } -static void uv_endpoint_write(grpc_endpoint* ep, - grpc_slice_buffer* write_slices, - grpc_closure* cb) { - grpc_tcp* tcp = (grpc_tcp*)ep; - uv_buf_t* buffers; - unsigned int buffer_count; - unsigned int i; - grpc_slice* slice; - uv_write_t* write_req; - GRPC_UV_ASSERT_SAME_THREAD(); +static void shutdown_callback(uv_shutdown_t* req, int status) {} - if (grpc_tcp_trace.enabled()) { - size_t j; +static void uv_socket_shutdown(grpc_custom_socket* socket) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_shutdown_t* req = &uv_socket->shutdown_req; + uv_shutdown(req, (uv_stream_t*)uv_socket->handle, shutdown_callback); +} - for (j = 0; j < write_slices->count; j++) { - char* data = grpc_dump_slice(write_slices->slices[j], - GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "WRITE %p (peer=%s): %s", tcp, tcp->peer_string, data); - gpr_free(data); - } +static void uv_socket_close(grpc_custom_socket* socket, + grpc_custom_close_callback close_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->close_cb = close_cb; + uv_close((uv_handle_t*)uv_socket->handle, uv_close_callback); +} + +static grpc_error* uv_socket_init_helper(uv_socket_t* uv_socket, int domain) { + uv_tcp_t* tcp = (uv_tcp_t*)gpr_malloc(sizeof(uv_tcp_t)); + uv_socket->handle = tcp; + int status = uv_tcp_init_ex(uv_default_loop(), tcp, (unsigned int)domain); + if (status != 0) { + return tcp_error_create("Failed to initialize UV tcp handle", status); } + uv_socket->write_buffers = nullptr; + uv_socket->read_len = 0; + uv_tcp_nodelay(uv_socket->handle, 1); + uv_socket->pending_connection = false; + uv_socket->accept_socket = nullptr; + uv_socket->accept_error = GRPC_ERROR_NONE; + return GRPC_ERROR_NONE; +} - if (tcp->shutting_down) { - GRPC_CLOSURE_SCHED(cb, - tcp_annotate_error(GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "TCP socket is shutting down"), - tcp)); - return; +static grpc_error* uv_socket_init(grpc_custom_socket* socket, int domain) { + uv_socket_t* uv_socket = (uv_socket_t*)gpr_malloc(sizeof(uv_socket_t)); + grpc_error* error = uv_socket_init_helper(uv_socket, domain); + if (error != GRPC_ERROR_NONE) { + return error; } + uv_socket->handle->data = socket; + socket->impl = uv_socket; + return GRPC_ERROR_NONE; +} + +static grpc_error* uv_socket_getpeername(grpc_custom_socket* socket, + const grpc_sockaddr* addr, + int* addr_len) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int err = uv_tcp_getpeername(uv_socket->handle, + (struct sockaddr*)IGNORE_CONST(addr), addr_len); + return tcp_error_create("getpeername failed", err); +} + +static grpc_error* uv_socket_getsockname(grpc_custom_socket* socket, + const grpc_sockaddr* addr, + int* addr_len) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int err = uv_tcp_getsockname(uv_socket->handle, + (struct sockaddr*)IGNORE_CONST(addr), addr_len); + return tcp_error_create("getsockname failed", err); +} - GPR_ASSERT(tcp->write_cb == NULL); - tcp->write_slices = write_slices; - GPR_ASSERT(tcp->write_slices->count <= UINT_MAX); - if (tcp->write_slices->count == 0) { - // No slices means we don't have to do anything, - // and libuv doesn't like empty writes - GRPC_CLOSURE_SCHED(cb, GRPC_ERROR_NONE); +static void accept_new_connection(grpc_custom_socket* socket) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + if (!uv_socket->pending_connection || !uv_socket->accept_socket) { return; } + grpc_custom_socket* new_socket = uv_socket->accept_socket; + grpc_error* error = uv_socket->accept_error; + uv_socket->accept_socket = nullptr; + uv_socket->accept_error = GRPC_ERROR_NONE; + uv_socket->pending_connection = false; + if (uv_socket->accept_error != GRPC_ERROR_NONE) { + uv_stream_t dummy_handle; + uv_accept((uv_stream_t*)uv_socket->handle, &dummy_handle); + uv_socket->accept_cb(socket, new_socket, error); + } else { + uv_socket_t* uv_new_socket = (uv_socket_t*)gpr_malloc(sizeof(uv_socket_t)); + uv_socket_init_helper(uv_new_socket, AF_UNSPEC); + // UV documentation says this is guaranteed to succeed + GPR_ASSERT(uv_accept((uv_stream_t*)uv_socket->handle, + (uv_stream_t*)uv_new_socket->handle) == 0); + new_socket->impl = uv_new_socket; + uv_new_socket->handle->data = new_socket; + uv_socket->accept_cb(socket, new_socket, error); + } +} - tcp->write_cb = cb; - buffer_count = (unsigned int)tcp->write_slices->count; - buffers = (uv_buf_t*)gpr_malloc(sizeof(uv_buf_t) * buffer_count); - for (i = 0; i < buffer_count; i++) { - slice = &tcp->write_slices->slices[i]; - buffers[i].base = (char*)GRPC_SLICE_START_PTR(*slice); - buffers[i].len = GRPC_SLICE_LENGTH(*slice); +static void uv_on_connect(uv_stream_t* server, int status) { + grpc_custom_socket* socket = (grpc_custom_socket*)server->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + GPR_ASSERT(!uv_socket->pending_connection); + uv_socket->pending_connection = true; + if (status < 0) { + switch (status) { + case UV_EINTR: + case UV_EAGAIN: + return; + default: + uv_socket->accept_error = tcp_error_create("accept failed", status); + } } - tcp->write_buffers = buffers; - write_req = &tcp->write_req; - write_req->data = tcp; - TCP_REF(tcp, "write"); - // TODO(murgatroid99): figure out what the return value here means - uv_write(write_req, (uv_stream_t*)tcp->handle, buffers, buffer_count, - write_callback); + accept_new_connection(socket); } -static void uv_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { - // No-op. We're ignoring pollsets currently - (void)ep; - (void)pollset; - grpc_tcp* tcp = (grpc_tcp*)ep; - tcp->pollset = pollset; +void uv_socket_accept(grpc_custom_socket* socket, + grpc_custom_socket* new_socket, + grpc_custom_accept_callback accept_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->accept_cb = accept_cb; + GPR_ASSERT(uv_socket->accept_socket == nullptr); + uv_socket->accept_socket = new_socket; + accept_new_connection(socket); } -static void uv_add_to_pollset_set(grpc_endpoint* ep, - grpc_pollset_set* pollset) { - // No-op. We're ignoring pollsets currently - (void)ep; - (void)pollset; +static grpc_error* uv_socket_bind(grpc_custom_socket* socket, + const grpc_sockaddr* addr, size_t len, + int flags) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int status = + uv_tcp_bind((uv_tcp_t*)uv_socket->handle, (struct sockaddr*)addr, 0); + return tcp_error_create("Failed to bind to port", status); } -static void uv_delete_from_pollset_set(grpc_endpoint* ep, - grpc_pollset_set* pollset) { - // No-op. We're ignoring pollsets currently - (void)ep; - (void)pollset; +static grpc_error* uv_socket_listen(grpc_custom_socket* socket) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + int status = + uv_listen((uv_stream_t*)uv_socket->handle, SOMAXCONN, uv_on_connect); + return tcp_error_create("Failed to listen to port", status); } -static void shutdown_callback(uv_shutdown_t* req, int status) {} +static grpc_error* uv_socket_setsockopt(grpc_custom_socket* socket, int level, + int option_name, const void* optval, + socklen_t option_len) { + int fd; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_fileno((uv_handle_t*)uv_socket->handle, &fd); + // TODO Handle error here. Also, does this work on windows?? + setsockopt(fd, level, option_name, &optval, (socklen_t)option_len); + return GRPC_ERROR_NONE; +} -static void uv_endpoint_shutdown(grpc_endpoint* ep, grpc_error* why) { - grpc_tcp* tcp = (grpc_tcp*)ep; - if (!tcp->shutting_down) { - if (grpc_tcp_trace.enabled()) { - const char* str = grpc_error_string(why); - gpr_log(GPR_DEBUG, "TCP %p shutdown why=%s", tcp->handle, str); - } - tcp->shutting_down = true; - uv_shutdown_t* req = &tcp->shutdown_req; - uv_shutdown(req, (uv_stream_t*)tcp->handle, shutdown_callback); - grpc_resource_user_shutdown(tcp->resource_user); +static void uv_tc_on_connect(uv_connect_t* req, int status) { + grpc_custom_socket* socket = (grpc_custom_socket*)req->data; + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + grpc_error* error; + if (status == UV_ECANCELED) { + // This should only happen if the handle is already closed + error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Timeout occurred"); + } else { + error = tcp_error_create("Failed to connect to remote host", status); } - GRPC_ERROR_UNREF(why); + uv_socket->connect_cb(socket, error); } -static void uv_destroy(grpc_endpoint* ep) { - grpc_network_status_unregister_endpoint(ep); - grpc_tcp* tcp = (grpc_tcp*)ep; - uv_close((uv_handle_t*)tcp->handle, uv_close_callback); +static void uv_socket_connect(grpc_custom_socket* socket, + const grpc_sockaddr* addr, size_t len, + grpc_custom_connect_callback connect_cb) { + uv_socket_t* uv_socket = (uv_socket_t*)socket->impl; + uv_socket->connect_cb = connect_cb; + uv_socket->connect_req.data = socket; + int status = uv_tcp_connect(&uv_socket->connect_req, uv_socket->handle, + (struct sockaddr*)addr, uv_tc_on_connect); + if (status != 0) { + // The callback will not be called + uv_socket->connect_cb(socket, tcp_error_create("connect failed", status)); + } +} + +static grpc_resolved_addresses* handle_addrinfo_result( + struct addrinfo* result) { + struct addrinfo* resp; + struct addrinfo* prev; + size_t i; + grpc_resolved_addresses* addresses = + (grpc_resolved_addresses*)gpr_malloc(sizeof(grpc_resolved_addresses)); + addresses->naddrs = 0; + for (resp = result; resp != nullptr; resp = resp->ai_next) { + addresses->naddrs++; + } + addresses->addrs = (grpc_resolved_address*)gpr_malloc( + sizeof(grpc_resolved_address) * addresses->naddrs); + i = 0; + resp = result; + while (resp != nullptr) { + memcpy(&addresses->addrs[i].addr, resp->ai_addr, resp->ai_addrlen); + addresses->addrs[i].len = resp->ai_addrlen; + i++; + prev = resp; + resp = resp->ai_next; + gpr_free(prev); + } + return addresses; } -static char* uv_get_peer(grpc_endpoint* ep) { - grpc_tcp* tcp = (grpc_tcp*)ep; - return gpr_strdup(tcp->peer_string); +static void uv_resolve_callback(uv_getaddrinfo_t* req, int status, + struct addrinfo* res) { + grpc_custom_resolver* r = (grpc_custom_resolver*)req->data; + gpr_free(req); + grpc_resolved_addresses* result = nullptr; + if (status == 0) { + result = handle_addrinfo_result(res); + } + grpc_custom_resolve_callback(r, result, + tcp_error_create("getaddrinfo failed", status)); } -static grpc_resource_user* uv_get_resource_user(grpc_endpoint* ep) { - grpc_tcp* tcp = (grpc_tcp*)ep; - return tcp->resource_user; +static grpc_error* uv_resolve(char* host, char* port, + grpc_resolved_addresses** result) { + int status; + uv_getaddrinfo_t req; + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; /* ipv4 or ipv6 */ + hints.ai_socktype = SOCK_STREAM; /* stream socket */ + hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ + status = uv_getaddrinfo(uv_default_loop(), &req, NULL, host, port, &hints); + if (status != 0) { + *result = nullptr; + } else { + *result = handle_addrinfo_result(req.addrinfo); + } + return tcp_error_create("getaddrinfo failed", status); } -static int uv_get_fd(grpc_endpoint* ep) { return -1; } - -static grpc_endpoint_vtable vtable = {uv_endpoint_read, - uv_endpoint_write, - uv_add_to_pollset, - uv_add_to_pollset_set, - uv_delete_from_pollset_set, - uv_endpoint_shutdown, - uv_destroy, - uv_get_resource_user, - uv_get_peer, - uv_get_fd}; - -grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, - grpc_resource_quota* resource_quota, - char* peer_string) { - grpc_tcp* tcp = (grpc_tcp*)gpr_malloc(sizeof(grpc_tcp)); - grpc_core::ExecCtx exec_ctx; - - if (grpc_tcp_trace.enabled()) { - gpr_log(GPR_DEBUG, "Creating TCP endpoint %p", tcp); +static void uv_resolve_async(grpc_custom_resolver* r, char* host, char* port) { + int status; + uv_getaddrinfo_t* req = + (uv_getaddrinfo_t*)gpr_malloc(sizeof(uv_getaddrinfo_t)); + req->data = r; + struct addrinfo hints; + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = GRPC_AF_UNSPEC; /* ipv4 or ipv6 */ + hints.ai_socktype = GRPC_SOCK_STREAM; /* stream socket */ + hints.ai_flags = GRPC_AI_PASSIVE; /* for wildcard IP address */ + status = uv_getaddrinfo(uv_default_loop(), req, uv_resolve_callback, host, + port, &hints); + if (status != 0) { + gpr_free(req); + grpc_error* error = tcp_error_create("getaddrinfo failed", status); + grpc_custom_resolve_callback(r, NULL, error); } +} - /* Disable Nagle's Algorithm */ - uv_tcp_nodelay(handle, 1); - - memset(tcp, 0, sizeof(grpc_tcp)); - tcp->base.vtable = &vtable; - tcp->handle = handle; - handle->data = tcp; - gpr_ref_init(&tcp->refcount, 1); - tcp->peer_string = gpr_strdup(peer_string); - tcp->shutting_down = false; - tcp->read_slices = NULL; - tcp->resource_user = grpc_resource_user_create(resource_quota, peer_string); - grpc_resource_user_slice_allocator_init( - &tcp->slice_allocator, tcp->resource_user, tcp_read_allocation_done, tcp); - /* Tell network status tracking code about the new endpoint */ - grpc_network_status_register_endpoint(&tcp->base); - -#ifndef GRPC_UV_TCP_HOLD_LOOP - uv_unref((uv_handle_t*)handle); -#endif +grpc_custom_resolver_vtable uv_resolver_vtable = {uv_resolve, uv_resolve_async}; - return &tcp->base; -} +grpc_socket_vtable grpc_uv_socket_vtable = { + uv_socket_init, uv_socket_connect, uv_socket_destroy, + uv_socket_shutdown, uv_socket_close, uv_socket_write, + uv_socket_read, uv_socket_getpeername, uv_socket_getsockname, + uv_socket_setsockopt, uv_socket_bind, uv_socket_listen, + uv_socket_accept}; -#endif /* GRPC_UV */ +#endif diff --git a/src/core/lib/iomgr/tcp_uv.h b/src/core/lib/iomgr/tcp_uv.h deleted file mode 100644 index 6b1a6f77c2c..00000000000 --- a/src/core/lib/iomgr/tcp_uv.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Copyright 2016 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_TCP_UV_H -#define GRPC_CORE_LIB_IOMGR_TCP_UV_H -/* - Low level TCP "bottom half" implementation, for use by transports built on - top of a TCP connection. - - Note that this file does not (yet) include APIs for creating the socket in - the first place. - - All calls passing slice transfer ownership of a slice refcount unless - otherwise specified. -*/ - -#include - -#include "src/core/lib/debug/trace.h" -#include "src/core/lib/iomgr/endpoint.h" - -#include "src/core/lib/iomgr/port.h" - -#ifdef GRPC_UV - -#include - -extern grpc_core::TraceFlag grpc_tcp_trace; - -#define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192 - -grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle, - grpc_resource_quota* resource_quota, - char* peer_string); - -#endif /* GRPC_UV */ - -#endif /* GRPC_CORE_LIB_IOMGR_TCP_UV_H */ diff --git a/src/core/lib/iomgr/tcp_windows.cc b/src/core/lib/iomgr/tcp_windows.cc index aab8edc888e..04e6f11eeeb 100644 --- a/src/core/lib/iomgr/tcp_windows.cc +++ b/src/core/lib/iomgr/tcp_windows.cc @@ -51,7 +51,7 @@ #define GRPC_FIONBIO FIONBIO #endif -grpc_core::TraceFlag grpc_tcp_trace(false, "tcp"); +extern grpc_core::TraceFlag grpc_tcp_trace; static grpc_error* set_non_block(SOCKET sock) { int status; diff --git a/src/core/lib/iomgr/timer.cc b/src/core/lib/iomgr/timer.cc new file mode 100644 index 00000000000..e647cdefa04 --- /dev/null +++ b/src/core/lib/iomgr/timer.cc @@ -0,0 +1,45 @@ +/* + * + * Copyright 2018 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/timer.h" +#include "src/core/lib/iomgr/timer_manager.h" + +grpc_timer_vtable* grpc_timer_impl; + +void grpc_set_timer_impl(grpc_timer_vtable* vtable) { + grpc_timer_impl = vtable; +} + +void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { + grpc_timer_impl->init(timer, deadline, closure); +} + +void grpc_timer_cancel(grpc_timer* timer) { grpc_timer_impl->cancel(timer); } + +grpc_timer_check_result grpc_timer_check(grpc_millis* next) { + return grpc_timer_impl->check(next); +} + +void grpc_timer_list_init() { grpc_timer_impl->list_init(); } + +void grpc_timer_list_shutdown() { grpc_timer_impl->list_shutdown(); } + +void grpc_timer_consume_kick() { grpc_timer_impl->consume_kick(); } diff --git a/src/core/lib/iomgr/timer.h b/src/core/lib/iomgr/timer.h index 67f1b1b3f9d..5ff10d3aee2 100644 --- a/src/core/lib/iomgr/timer.h +++ b/src/core/lib/iomgr/timer.h @@ -23,17 +23,41 @@ #include "src/core/lib/iomgr/port.h" -#ifdef GRPC_UV -#include "src/core/lib/iomgr/timer_uv.h" -#else -#include "src/core/lib/iomgr/timer_generic.h" -#endif /* GRPC_UV */ - #include #include "src/core/lib/iomgr/exec_ctx.h" #include "src/core/lib/iomgr/iomgr.h" -typedef struct grpc_timer grpc_timer; +typedef struct grpc_timer { + gpr_atm deadline; + uint32_t heap_index; /* INVALID_HEAP_INDEX if not in heap */ + bool pending; + struct grpc_timer* next; + struct grpc_timer* prev; + grpc_closure* closure; +#ifndef NDEBUG + struct grpc_timer* hash_table_next; +#endif + + // Optional field used by custom timers + void* custom_timer; +} grpc_timer; + +typedef enum { + GRPC_TIMERS_NOT_CHECKED, + GRPC_TIMERS_CHECKED_AND_EMPTY, + GRPC_TIMERS_FIRED, +} grpc_timer_check_result; + +typedef struct grpc_timer_vtable { + void (*init)(grpc_timer* timer, grpc_millis, grpc_closure* closure); + void (*cancel)(grpc_timer* timer); + + /* Internal API */ + grpc_timer_check_result (*check)(grpc_millis* next); + void (*list_init)(); + void (*list_shutdown)(void); + void (*consume_kick)(void); +} grpc_timer_vtable; /* Initialize *timer. When expired or canceled, closure will be called with error set to indicate if it expired (GRPC_ERROR_NONE) or was canceled @@ -78,12 +102,6 @@ void grpc_timer_cancel(grpc_timer* timer); /* iomgr internal api for dealing with timers */ -typedef enum { - GRPC_TIMERS_NOT_CHECKED, - GRPC_TIMERS_CHECKED_AND_EMPTY, - GRPC_TIMERS_FIRED, -} grpc_timer_check_result; - /* Check for timers to be run, and run them. Return true if timer callbacks were executed. If next is non-null, TRY to update *next with the next running timer @@ -99,7 +117,9 @@ void grpc_timer_list_shutdown(); void grpc_timer_consume_kick(void); /* the following must be implemented by each iomgr implementation */ - void grpc_kick_poller(void); +/* Sets the timer implementation */ +void grpc_set_timer_impl(grpc_timer_vtable* vtable); + #endif /* GRPC_CORE_LIB_IOMGR_TIMER_H */ diff --git a/src/core/lib/iomgr/timer_custom.cc b/src/core/lib/iomgr/timer_custom.cc new file mode 100644 index 00000000000..71d825ff9f5 --- /dev/null +++ b/src/core/lib/iomgr/timer_custom.cc @@ -0,0 +1,93 @@ +/* + * + * 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. + * + */ + +#include + +#include "src/core/lib/iomgr/port.h" + +#include +#include + +#include "src/core/lib/debug/trace.h" +#include "src/core/lib/iomgr/iomgr_custom.h" +#include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/iomgr/timer_custom.h" + +static grpc_custom_timer_vtable* custom_timer_impl; + +void grpc_custom_timer_callback(grpc_custom_timer* t, grpc_error* error) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + grpc_core::ExecCtx exec_ctx; + grpc_timer* timer = t->original; + GPR_ASSERT(timer->pending); + timer->pending = 0; + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); + custom_timer_impl->stop(t); + gpr_free(t); +} + +static void timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { + uint64_t timeout; + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + grpc_millis now = grpc_core::ExecCtx::Get()->Now(); + if (deadline <= grpc_core::ExecCtx::Get()->Now()) { + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_NONE); + timer->pending = false; + return; + } else { + timeout = deadline - now; + } + timer->pending = true; + timer->closure = closure; + grpc_custom_timer* timer_wrapper = + (grpc_custom_timer*)gpr_malloc(sizeof(grpc_custom_timer)); + timer_wrapper->timeout_ms = timeout; + timer->custom_timer = (void*)timer_wrapper; + timer_wrapper->original = timer; + custom_timer_impl->start(timer_wrapper); +} + +static void timer_cancel(grpc_timer* timer) { + GRPC_CUSTOM_IOMGR_ASSERT_SAME_THREAD(); + grpc_custom_timer* tw = (grpc_custom_timer*)timer->custom_timer; + if (timer->pending) { + timer->pending = 0; + GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED); + custom_timer_impl->stop(tw); + gpr_free(tw); + } +} + +static grpc_timer_check_result timer_check(grpc_millis* next) { + return GRPC_TIMERS_NOT_CHECKED; +} + +static void timer_list_init() {} +static void timer_list_shutdown() {} + +static void timer_consume_kick(void) {} + +static grpc_timer_vtable custom_timer_vtable = { + timer_init, timer_cancel, timer_check, + timer_list_init, timer_list_shutdown, timer_consume_kick}; + +void grpc_custom_timer_init(grpc_custom_timer_vtable* impl) { + custom_timer_impl = impl; + grpc_set_timer_impl(&custom_timer_vtable); +} diff --git a/src/core/lib/iomgr/timer_custom.h b/src/core/lib/iomgr/timer_custom.h new file mode 100644 index 00000000000..bfea8bafa69 --- /dev/null +++ b/src/core/lib/iomgr/timer_custom.h @@ -0,0 +1,43 @@ +/* + * + * Copyright 2018 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_TIMER_CUSTOM_H +#define GRPC_CORE_LIB_IOMGR_TIMER_CUSTOM_H + +#include + +#include "src/core/lib/iomgr/timer.h" + +typedef struct grpc_custom_timer { + // Implementation defined + void* timer; + uint64_t timeout_ms; + + grpc_timer* original; +} grpc_custom_timer; + +typedef struct grpc_custom_timer_vtable { + void (*start)(grpc_custom_timer* t); + void (*stop)(grpc_custom_timer* t); +} grpc_custom_timer_vtable; + +void grpc_custom_timer_init(grpc_custom_timer_vtable* impl); + +void grpc_custom_timer_callback(grpc_custom_timer* t, grpc_error* error); + +#endif /* GRPC_CORE_LIB_IOMGR_TIMER_CUSTOM_H */ diff --git a/src/core/lib/iomgr/timer_generic.cc b/src/core/lib/iomgr/timer_generic.cc index 52a571f4255..93e654b7fac 100644 --- a/src/core/lib/iomgr/timer_generic.cc +++ b/src/core/lib/iomgr/timer_generic.cc @@ -22,8 +22,6 @@ #include -#ifdef GRPC_TIMER_USE_GENERIC - #include "src/core/lib/iomgr/timer.h" #include @@ -238,7 +236,7 @@ static gpr_atm compute_min_deadline(timer_shard* shard) { : grpc_timer_heap_top(&shard->heap)->deadline; } -void grpc_timer_list_init() { +static void timer_list_init() { uint32_t i; g_num_shards = GPR_MIN(1, 2 * gpr_cpu_num_cores()); @@ -270,7 +268,7 @@ void grpc_timer_list_init() { INIT_TIMER_HASH_TABLE(); } -void grpc_timer_list_shutdown() { +static void timer_list_shutdown() { size_t i; run_some_expired_timers( GPR_ATM_MAX, nullptr, @@ -326,8 +324,8 @@ static void note_deadline_change(timer_shard* shard) { void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = false; } -void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, - grpc_closure* closure) { +static void timer_init(grpc_timer* timer, grpc_millis deadline, + grpc_closure* closure) { int is_first_timer = 0; timer_shard* shard = &g_shards[GPR_HASH_POINTER(timer, g_num_shards)]; timer->closure = closure; @@ -412,12 +410,12 @@ void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, } } -void grpc_timer_consume_kick(void) { +static void timer_consume_kick(void) { /* force re-evaluation of last seeen min */ gpr_tls_set(&g_last_seen_min_timer, 0); } -void grpc_timer_cancel(grpc_timer* timer) { +static void timer_cancel(grpc_timer* timer) { if (!g_shared_mutables.initialized) { /* must have already been cancelled, also the shard mutex is invalid */ return; @@ -604,7 +602,7 @@ static grpc_timer_check_result run_some_expired_timers(gpr_atm now, return result; } -grpc_timer_check_result grpc_timer_check(grpc_millis* next) { +static grpc_timer_check_result timer_check(grpc_millis* next) { // prelude grpc_millis now = grpc_core::ExecCtx::Get()->Now(); @@ -660,4 +658,6 @@ grpc_timer_check_result grpc_timer_check(grpc_millis* next) { return r; } -#endif /* GRPC_TIMER_USE_GENERIC */ +grpc_timer_vtable grpc_generic_timer_vtable = { + timer_init, timer_cancel, timer_check, + timer_list_init, timer_list_shutdown, timer_consume_kick}; diff --git a/src/core/lib/iomgr/timer_heap.cc b/src/core/lib/iomgr/timer_heap.cc index e5b5abfc971..0c17d607eb5 100644 --- a/src/core/lib/iomgr/timer_heap.cc +++ b/src/core/lib/iomgr/timer_heap.cc @@ -20,8 +20,6 @@ #include "src/core/lib/iomgr/port.h" -#ifdef GRPC_TIMER_USE_GENERIC - #include "src/core/lib/iomgr/timer_heap.h" #include @@ -135,5 +133,3 @@ grpc_timer* grpc_timer_heap_top(grpc_timer_heap* heap) { void grpc_timer_heap_pop(grpc_timer_heap* heap) { grpc_timer_heap_remove(heap, grpc_timer_heap_top(heap)); } - -#endif /* GRPC_TIMER_USE_GENERIC */ diff --git a/src/core/lib/iomgr/timer_uv.cc b/src/core/lib/iomgr/timer_uv.cc index 6f28f553c5f..dadeb960b2b 100644 --- a/src/core/lib/iomgr/timer_uv.cc +++ b/src/core/lib/iomgr/timer_uv.cc @@ -20,20 +20,18 @@ #include "src/core/lib/iomgr/port.h" -#if GRPC_UV +#ifdef GRPC_UV #include #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/iomgr/iomgr_uv.h" +#include "src/core/lib/iomgr/iomgr_custom.h" #include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/iomgr/timer_custom.h" #include -grpc_core::TraceFlag grpc_timer_trace(false, "timer"); -grpc_core::TraceFlag grpc_timer_check_trace(false, "timer_check"); - static void timer_close_callback(uv_handle_t* handle) { gpr_free(handle); } static void stop_uv_timer(uv_timer_t* handle) { @@ -43,57 +41,23 @@ static void stop_uv_timer(uv_timer_t* handle) { } void run_expired_timer(uv_timer_t* handle) { - grpc_timer* timer = (grpc_timer*)handle->data; - grpc_core::ExecCtx exec_ctx; - GRPC_UV_ASSERT_SAME_THREAD(); - GPR_ASSERT(timer->pending); - timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); - stop_uv_timer(handle); + grpc_custom_timer* timer_wrapper = (grpc_custom_timer*)handle->data; + grpc_custom_timer_callback(timer_wrapper, GRPC_ERROR_NONE); } -void grpc_timer_init(grpc_timer* timer, grpc_millis deadline, - grpc_closure* closure) { - uint64_t timeout; +static void timer_start(grpc_custom_timer* t) { uv_timer_t* uv_timer; - GRPC_UV_ASSERT_SAME_THREAD(); - timer->closure = closure; - if (deadline <= grpc_core::ExecCtx::Get()->Now()) { - timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_NONE); - return; - } - timer->pending = 1; - timeout = (uint64_t)(deadline - grpc_core::ExecCtx::Get()->Now()); uv_timer = (uv_timer_t*)gpr_malloc(sizeof(uv_timer_t)); uv_timer_init(uv_default_loop(), uv_timer); - uv_timer->data = timer; - timer->uv_timer = uv_timer; - uv_timer_start(uv_timer, run_expired_timer, timeout, 0); - /* We assume that gRPC timers are only used alongside other active gRPC - objects, and that there will therefore always be something else keeping - the uv loop alive whenever there is a timer */ - uv_unref((uv_handle_t*)uv_timer); + uv_timer->data = t; + t->timer = (void*)uv_timer; + uv_timer_start(uv_timer, run_expired_timer, t->timeout_ms, 0); } -void grpc_timer_init_unset(grpc_timer* timer) { timer->pending = 0; } - -void grpc_timer_cancel(grpc_timer* timer) { - GRPC_UV_ASSERT_SAME_THREAD(); - if (timer->pending) { - timer->pending = 0; - GRPC_CLOSURE_SCHED(timer->closure, GRPC_ERROR_CANCELLED); - stop_uv_timer((uv_timer_t*)timer->uv_timer); - } +static void timer_stop(grpc_custom_timer* t) { + stop_uv_timer((uv_timer_t*)t->timer); } -grpc_timer_check_result grpc_timer_check(grpc_millis* next) { - return GRPC_TIMERS_NOT_CHECKED; -} - -void grpc_timer_list_init() {} -void grpc_timer_list_shutdown() {} - -void grpc_timer_consume_kick(void) {} +grpc_custom_timer_vtable uv_timer_vtable = {timer_start, timer_stop}; -#endif /* GRPC_UV */ +#endif diff --git a/src/core/lib/iomgr/udp_server.cc b/src/core/lib/iomgr/udp_server.cc index e739a5df936..15a242abe22 100644 --- a/src/core/lib/iomgr/udp_server.cc +++ b/src/core/lib/iomgr/udp_server.cc @@ -345,7 +345,7 @@ static int bind_socket(grpc_socket_factory* socket_factory, int sockfd, return (socket_factory != nullptr) ? grpc_socket_factory_bind(socket_factory, sockfd, addr) : bind(sockfd, - reinterpret_cast( + reinterpret_cast( const_cast(addr->addr)), static_cast(addr->len)); } @@ -355,8 +355,8 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd, const grpc_resolved_address* addr, int rcv_buf_size, int snd_buf_size) { grpc_resolved_address sockname_temp; - struct sockaddr* addr_ptr = - reinterpret_cast(const_cast(addr->addr)); + grpc_sockaddr* addr_ptr = + reinterpret_cast(const_cast(addr->addr)); if (fd < 0) { goto error; @@ -392,7 +392,7 @@ static int prepare_socket(grpc_socket_factory* socket_factory, int fd, sockname_temp.len = sizeof(struct sockaddr_storage); - if (getsockname(fd, reinterpret_cast(sockname_temp.addr), + if (getsockname(fd, reinterpret_cast(sockname_temp.addr), reinterpret_cast(&sockname_temp.len)) < 0) { goto error; } @@ -576,10 +576,9 @@ int grpc_udp_server_add_port(grpc_udp_server* s, if (grpc_sockaddr_get_port(addr) == 0) { for (size_t i = 0; i < s->listeners.size(); ++i) { sockname_temp.len = sizeof(struct sockaddr_storage); - if (0 == - getsockname(s->listeners[i].fd(), - reinterpret_cast(sockname_temp.addr), - reinterpret_cast(&sockname_temp.len))) { + if (0 == getsockname(s->listeners[i].fd(), + reinterpret_cast(sockname_temp.addr), + reinterpret_cast(&sockname_temp.len))) { port = grpc_sockaddr_get_port(&sockname_temp); if (port > 0) { allocated_addr = static_cast( diff --git a/src/core/lib/iomgr/unix_sockets_posix.cc b/src/core/lib/iomgr/unix_sockets_posix.cc index 8d252fd3318..5d09b4a9b17 100644 --- a/src/core/lib/iomgr/unix_sockets_posix.cc +++ b/src/core/lib/iomgr/unix_sockets_posix.cc @@ -66,15 +66,15 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name, } int grpc_is_unix_socket(const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); return addr->sa_family == AF_UNIX; } void grpc_unlink_if_unix_domain_socket( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); if (addr->sa_family != AF_UNIX) { return; } @@ -89,8 +89,8 @@ void grpc_unlink_if_unix_domain_socket( char* grpc_sockaddr_to_uri_unix_if_possible( const grpc_resolved_address* resolved_addr) { - const struct sockaddr* addr = - reinterpret_cast(resolved_addr->addr); + const grpc_sockaddr* addr = + reinterpret_cast(resolved_addr->addr); if (addr->sa_family != AF_UNIX) { return nullptr; } diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 994443c651c..d96cbec2922 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -97,6 +97,8 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/gethostname_sysconf.cc', 'src/core/lib/iomgr/iocp_windows.cc', 'src/core/lib/iomgr/iomgr.cc', + 'src/core/lib/iomgr/iomgr_custom.cc', + 'src/core/lib/iomgr/iomgr_internal.cc', 'src/core/lib/iomgr/iomgr_posix.cc', 'src/core/lib/iomgr/iomgr_uv.cc', 'src/core/lib/iomgr/iomgr_windows.cc', @@ -105,12 +107,16 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/lockfree_event.cc', 'src/core/lib/iomgr/network_status_tracker.cc', 'src/core/lib/iomgr/polling_entity.cc', - 'src/core/lib/iomgr/pollset_set_uv.cc', + 'src/core/lib/iomgr/pollset.cc', + 'src/core/lib/iomgr/pollset_custom.cc', + 'src/core/lib/iomgr/pollset_set.cc', + 'src/core/lib/iomgr/pollset_set_custom.cc', 'src/core/lib/iomgr/pollset_set_windows.cc', 'src/core/lib/iomgr/pollset_uv.cc', 'src/core/lib/iomgr/pollset_windows.cc', + 'src/core/lib/iomgr/resolve_address.cc', + 'src/core/lib/iomgr/resolve_address_custom.cc', 'src/core/lib/iomgr/resolve_address_posix.cc', - 'src/core/lib/iomgr/resolve_address_uv.cc', 'src/core/lib/iomgr/resolve_address_windows.cc', 'src/core/lib/iomgr/resource_quota.cc', 'src/core/lib/iomgr/sockaddr_utils.cc', @@ -122,19 +128,24 @@ CORE_SOURCE_FILES = [ 'src/core/lib/iomgr/socket_utils_uv.cc', 'src/core/lib/iomgr/socket_utils_windows.cc', 'src/core/lib/iomgr/socket_windows.cc', + 'src/core/lib/iomgr/tcp_client.cc', + 'src/core/lib/iomgr/tcp_client_custom.cc', 'src/core/lib/iomgr/tcp_client_posix.cc', - 'src/core/lib/iomgr/tcp_client_uv.cc', 'src/core/lib/iomgr/tcp_client_windows.cc', + 'src/core/lib/iomgr/tcp_custom.cc', 'src/core/lib/iomgr/tcp_posix.cc', + 'src/core/lib/iomgr/tcp_server.cc', + 'src/core/lib/iomgr/tcp_server_custom.cc', 'src/core/lib/iomgr/tcp_server_posix.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_common.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc', 'src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc', - 'src/core/lib/iomgr/tcp_server_uv.cc', 'src/core/lib/iomgr/tcp_server_windows.cc', 'src/core/lib/iomgr/tcp_uv.cc', 'src/core/lib/iomgr/tcp_windows.cc', 'src/core/lib/iomgr/time_averaged_stats.cc', + 'src/core/lib/iomgr/timer.cc', + 'src/core/lib/iomgr/timer_custom.cc', 'src/core/lib/iomgr/timer_generic.cc', 'src/core/lib/iomgr/timer_heap.cc', 'src/core/lib/iomgr/timer_manager.cc', diff --git a/test/core/client_channel/parse_address_test.cc b/test/core/client_channel/parse_address_test.cc index 373ed76cbe0..ae157fbb8b8 100644 --- a/test/core/client_channel/parse_address_test.cc +++ b/test/core/client_channel/parse_address_test.cc @@ -18,6 +18,7 @@ #include "src/core/ext/filters/client_channel/parse_address.h" #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #ifdef GRPC_HAVE_UNIX_SOCKET @@ -58,16 +59,15 @@ static void test_grpc_parse_ipv4(const char* uri_text, const char* host, grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; - char ntop_buf[INET_ADDRSTRLEN]; + char ntop_buf[GRPC_INET_ADDRSTRLEN]; GPR_ASSERT(1 == grpc_parse_ipv4(uri, &addr)); - struct sockaddr_in* addr_in = - reinterpret_cast(addr.addr); - GPR_ASSERT(AF_INET == addr_in->sin_family); - GPR_ASSERT(nullptr != grpc_inet_ntop(AF_INET, &addr_in->sin_addr, ntop_buf, - sizeof(ntop_buf))); + grpc_sockaddr_in* addr_in = reinterpret_cast(addr.addr); + GPR_ASSERT(GRPC_AF_INET == addr_in->sin_family); + GPR_ASSERT(nullptr != grpc_inet_ntop(GRPC_AF_INET, &addr_in->sin_addr, + ntop_buf, sizeof(ntop_buf))); GPR_ASSERT(0 == strcmp(ntop_buf, host)); - GPR_ASSERT(ntohs(addr_in->sin_port) == port); + GPR_ASSERT(grpc_ntohs(addr_in->sin_port) == port); grpc_uri_destroy(uri); } @@ -77,16 +77,15 @@ static void test_grpc_parse_ipv6(const char* uri_text, const char* host, grpc_core::ExecCtx exec_ctx; grpc_uri* uri = grpc_uri_parse(uri_text, 0); grpc_resolved_address addr; - char ntop_buf[INET6_ADDRSTRLEN]; + char ntop_buf[GRPC_INET6_ADDRSTRLEN]; GPR_ASSERT(1 == grpc_parse_ipv6(uri, &addr)); - struct sockaddr_in6* addr_in6 = - reinterpret_cast(addr.addr); - GPR_ASSERT(AF_INET6 == addr_in6->sin6_family); - GPR_ASSERT(nullptr != grpc_inet_ntop(AF_INET6, &addr_in6->sin6_addr, ntop_buf, - sizeof(ntop_buf))); + grpc_sockaddr_in6* addr_in6 = reinterpret_cast(addr.addr); + GPR_ASSERT(GRPC_AF_INET6 == addr_in6->sin6_family); + GPR_ASSERT(nullptr != grpc_inet_ntop(GRPC_AF_INET6, &addr_in6->sin6_addr, + ntop_buf, sizeof(ntop_buf))); GPR_ASSERT(0 == strcmp(ntop_buf, host)); - GPR_ASSERT(ntohs(addr_in6->sin6_port) == port); + GPR_ASSERT(grpc_ntohs(addr_in6->sin6_port) == port); GPR_ASSERT(addr_in6->sin6_scope_id == scope_id); grpc_uri_destroy(uri); diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc index 966fb1d14b3..e34aa2e6769 100644 --- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.cc @@ -57,6 +57,9 @@ static void my_resolve_address(const char* addr, const char* default_port, GRPC_CLOSURE_SCHED(on_done, error); } +static grpc_address_resolver_vtable test_resolver = {my_resolve_address, + nullptr}; + static grpc_ares_request* my_dns_lookup_ares( const char* dns_server, const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -143,7 +146,7 @@ int main(int argc, char** argv) { grpc_init(); gpr_mu_init(&g_mu); g_combiner = grpc_combiner_create(); - grpc_resolve_address = my_resolve_address; + grpc_set_resolver_impl(&test_resolver); grpc_dns_lookup_ares = my_dns_lookup_ares; grpc_channel_args* result = (grpc_channel_args*)1; diff --git a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc index 9402a605b38..01c61a9f186 100644 --- a/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_cooldown_test.cc @@ -28,12 +28,10 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "test/core/util/test_config.h" -static grpc_combiner* g_combiner; +extern grpc_address_resolver_vtable* grpc_resolve_address_impl; +static grpc_address_resolver_vtable* default_resolve_address; -static void (*g_default_grpc_resolve_address)( - const char* name, const char* default_port, - grpc_pollset_set* interested_parties, grpc_closure* on_done, - grpc_resolved_addresses** addrs); +static grpc_combiner* g_combiner; grpc_ares_request* (*g_default_dns_lookup_ares)( const char* dns_server, const char* name, const char* default_port, @@ -52,18 +50,28 @@ struct iomgr_args { grpc_pollset_set* pollset_set; } g_iomgr_args; -// Wrapper around g_default_grpc_resolve_address in order to count the number of +// Wrapper around default resolve_address in order to count the number of // times we incur in a system-level name resolution. static void test_resolve_address_impl(const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, grpc_resolved_addresses** addrs) { - g_default_grpc_resolve_address(name, default_port, g_iomgr_args.pollset_set, - on_done, addrs); + default_resolve_address->resolve_address( + name, default_port, g_iomgr_args.pollset_set, on_done, addrs); ++g_resolution_count; } +static grpc_error* test_blocking_resolve_address_impl( + const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + return default_resolve_address->blocking_resolve_address(name, default_port, + addresses); +} + +static grpc_address_resolver_vtable test_resolver = { + test_resolve_address_impl, test_blocking_resolve_address_impl}; + grpc_ares_request* test_dns_lookup_ares( const char* dns_server, const char* name, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -285,11 +293,14 @@ int main(int argc, char** argv) { g_combiner = grpc_combiner_create(); - const bool using_cares = (grpc_resolve_address == grpc_resolve_address_ares); - g_default_grpc_resolve_address = grpc_resolve_address; + bool using_cares = false; +#if GRPC_ARES == 1 + using_cares = true; +#endif g_default_dns_lookup_ares = grpc_dns_lookup_ares; grpc_dns_lookup_ares = test_dns_lookup_ares; - grpc_resolve_address = test_resolve_address_impl; + default_resolve_address = grpc_resolve_address_impl; + grpc_set_resolver_impl(&test_resolver); test_cooldown(using_cares); diff --git a/test/core/end2end/fixtures/http_proxy_fixture.cc b/test/core/end2end/fixtures/http_proxy_fixture.cc index 58353376f3f..f02fa9d9983 100644 --- a/test/core/end2end/fixtures/http_proxy_fixture.cc +++ b/test/core/end2end/fixtures/http_proxy_fixture.cc @@ -535,10 +535,10 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create( GPR_ASSERT(error == GRPC_ERROR_NONE); // Bind to port. grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = - reinterpret_cast(resolved_addr.addr); + grpc_sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); memset(&resolved_addr, 0, sizeof(resolved_addr)); - addr->sin_family = AF_INET; + addr->sin_family = GRPC_AF_INET; grpc_sockaddr_set_port(&resolved_addr, proxy_port); int port; error = grpc_tcp_server_add_port(proxy->server, &resolved_addr, &port); diff --git a/test/core/end2end/fuzzers/api_fuzzer.cc b/test/core/end2end/fuzzers/api_fuzzer.cc index b6347fb1db7..9ace7d04aaf 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.cc +++ b/test/core/end2end/fuzzers/api_fuzzer.cc @@ -426,6 +426,9 @@ void my_resolve_address(const char* addr, const char* default_port, GRPC_CLOSURE_CREATE(finish_resolve, r, grpc_schedule_on_exec_ctx)); } +static grpc_address_resolver_vtable fuzzer_resolver = {my_resolve_address, + nullptr}; + grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, const char* default_port, grpc_pollset_set* interested_parties, @@ -447,12 +450,6 @@ grpc_ares_request* my_dns_lookup_ares(const char* dns_server, const char* addr, //////////////////////////////////////////////////////////////////////////////// // client connection -// defined in tcp_client_posix.c -extern void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, grpc_millis deadline); - static void sched_connect(grpc_closure* closure, grpc_endpoint** ep, gpr_timespec deadline); @@ -513,6 +510,8 @@ static void my_tcp_client_connect(grpc_closure* closure, grpc_endpoint** ep, grpc_millis_to_timespec(deadline, GPR_CLOCK_MONOTONIC)); } +grpc_tcp_client_vtable fuzz_tcp_client_vtable = {my_tcp_client_connect}; + //////////////////////////////////////////////////////////////////////////////// // test driver @@ -753,7 +752,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (squelch && grpc_trace_fuzzer == nullptr) gpr_set_log_function(dont_log); gpr_free(grpc_trace_fuzzer); input_stream inp = {data, data + size}; - grpc_tcp_client_connect_impl = my_tcp_client_connect; + grpc_set_tcp_client_impl(&fuzz_tcp_client_vtable); gpr_now_impl = now_impl; grpc_init(); grpc_timer_manager_set_threading(false); @@ -761,7 +760,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { grpc_core::ExecCtx exec_ctx; grpc_executor_set_threading(false); } - grpc_resolve_address = my_resolve_address; + grpc_set_resolver_impl(&fuzzer_resolver); grpc_dns_lookup_ares = my_dns_lookup_ares; GPR_ASSERT(g_channel == nullptr); diff --git a/test/core/end2end/goaway_server_test.cc b/test/core/end2end/goaway_server_test.cc index 09f0301c448..8ff14e2b855 100644 --- a/test/core/end2end/goaway_server_test.cc +++ b/test/core/end2end/goaway_server_test.cc @@ -21,6 +21,7 @@ including windows.h on Windows, uv.h must be included before other system headers. Therefore, sockaddr.h must always be included first */ #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #include @@ -35,14 +36,13 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" +extern grpc_address_resolver_vtable* grpc_resolve_address_impl; +static grpc_address_resolver_vtable* default_resolver; + static void* tag(intptr_t i) { return (void*)i; } static gpr_mu g_mu; static int g_resolve_port = -1; -static void (*iomgr_resolve_address)(const char* addr, const char* default_port, - grpc_pollset_set* interested_parties, - grpc_closure* on_done, - grpc_resolved_addresses** addresses); static grpc_ares_request* (*iomgr_dns_lookup_ares)( const char* dns_server, const char* addr, const char* default_port, @@ -61,8 +61,8 @@ static void my_resolve_address(const char* addr, const char* default_port, grpc_closure* on_done, grpc_resolved_addresses** addrs) { if (0 != strcmp(addr, "test")) { - iomgr_resolve_address(addr, default_port, interested_parties, on_done, - addrs); + default_resolver->resolve_address(addr, default_port, interested_parties, + on_done, addrs); return; } @@ -77,17 +77,27 @@ static void my_resolve_address(const char* addr, const char* default_port, (*addrs)->addrs = static_cast( gpr_malloc(sizeof(*(*addrs)->addrs))); memset((*addrs)->addrs, 0, sizeof(*(*addrs)->addrs)); - struct sockaddr_in* sa = - reinterpret_cast((*addrs)->addrs[0].addr); - sa->sin_family = AF_INET; - sa->sin_addr.s_addr = htonl(0x7f000001); - sa->sin_port = htons(static_cast(g_resolve_port)); + grpc_sockaddr_in* sa = + reinterpret_cast((*addrs)->addrs[0].addr); + sa->sin_family = GRPC_AF_INET; + sa->sin_addr.s_addr = 0x100007f; + sa->sin_port = grpc_htons(static_cast(g_resolve_port)); (*addrs)->addrs[0].len = sizeof(*sa); gpr_mu_unlock(&g_mu); } GRPC_CLOSURE_SCHED(on_done, error); } +static grpc_error* my_blocking_resolve_address( + const char* name, const char* default_port, + grpc_resolved_addresses** addresses) { + return default_resolver->blocking_resolve_address(name, default_port, + addresses); +} + +static grpc_address_resolver_vtable test_resolver = { + my_resolve_address, my_blocking_resolve_address}; + static grpc_ares_request* my_dns_lookup_ares( const char* dns_server, const char* addr, const char* default_port, grpc_pollset_set* interested_parties, grpc_closure* on_done, @@ -106,11 +116,11 @@ static grpc_ares_request* my_dns_lookup_ares( error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Failure"); } else { *lb_addrs = grpc_lb_addresses_create(1, nullptr); - struct sockaddr_in* sa = static_cast( - gpr_zalloc(sizeof(struct sockaddr_in))); - sa->sin_family = AF_INET; - sa->sin_addr.s_addr = htonl(0x7f000001); - sa->sin_port = htons(static_cast(g_resolve_port)); + grpc_sockaddr_in* sa = + static_cast(gpr_zalloc(sizeof(grpc_sockaddr_in))); + sa->sin_family = GRPC_AF_INET; + sa->sin_addr.s_addr = 0x100007f; + sa->sin_port = grpc_htons(static_cast(g_resolve_port)); grpc_lb_addresses_set_address(*lb_addrs, 0, sa, sizeof(*sa), false, nullptr, nullptr); gpr_free(sa); @@ -130,9 +140,9 @@ int main(int argc, char** argv) { gpr_mu_init(&g_mu); grpc_init(); - iomgr_resolve_address = grpc_resolve_address; + default_resolver = grpc_resolve_address_impl; + grpc_set_resolver_impl(&test_resolver); iomgr_dns_lookup_ares = grpc_dns_lookup_ares; - grpc_resolve_address = my_resolve_address; grpc_dns_lookup_ares = my_dns_lookup_ares; int was_cancelled1; diff --git a/test/core/end2end/tests/request_with_flags.cc b/test/core/end2end/tests/request_with_flags.cc index 4a54318d0fa..c52482470ef 100644 --- a/test/core/end2end/tests/request_with_flags.cc +++ b/test/core/end2end/tests/request_with_flags.cc @@ -48,14 +48,12 @@ static gpr_timespec n_seconds_from_now(int n) { return grpc_timeout_seconds_to_deadline(n); } -static gpr_timespec five_seconds_from_now(void) { - return n_seconds_from_now(5); -} +static gpr_timespec one_second_from_now(void) { return n_seconds_from_now(1); } static void drain_cq(grpc_completion_queue* cq) { grpc_event ev; do { - ev = grpc_completion_queue_next(cq, five_seconds_from_now(), nullptr); + ev = grpc_completion_queue_next(cq, one_second_from_now(), nullptr); } while (ev.type != GRPC_QUEUE_SHUTDOWN); } @@ -109,7 +107,7 @@ static void test_invoke_request_with_flags( grpc_slice details; grpc_call_error expectation; - gpr_timespec deadline = five_seconds_from_now(); + gpr_timespec deadline = one_second_from_now(); c = grpc_channel_create_call( f.client, nullptr, GRPC_PROPAGATE_DEFAULTS, f.cq, grpc_slice_from_static_string("/foo"), diff --git a/test/core/iomgr/sockaddr_utils_test.cc b/test/core/iomgr/sockaddr_utils_test.cc index 32d2a384bd7..aa9ece30815 100644 --- a/test/core/iomgr/sockaddr_utils_test.cc +++ b/test/core/iomgr/sockaddr_utils_test.cc @@ -22,6 +22,7 @@ headers. Therefore, sockaddr.h must always be included first */ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include #include @@ -33,34 +34,33 @@ static grpc_resolved_address make_addr4(const uint8_t* data, size_t data_len) { grpc_resolved_address resolved_addr4; - struct sockaddr_in* addr4 = - reinterpret_cast(resolved_addr4.addr); + grpc_sockaddr_in* addr4 = + reinterpret_cast(resolved_addr4.addr); memset(&resolved_addr4, 0, sizeof(resolved_addr4)); - addr4->sin_family = AF_INET; + addr4->sin_family = GRPC_AF_INET; GPR_ASSERT(data_len == sizeof(addr4->sin_addr.s_addr)); memcpy(&addr4->sin_addr.s_addr, data, data_len); - addr4->sin_port = htons(12345); - resolved_addr4.len = sizeof(struct sockaddr_in); + addr4->sin_port = grpc_htons(12345); + resolved_addr4.len = sizeof(grpc_sockaddr_in); return resolved_addr4; } static grpc_resolved_address make_addr6(const uint8_t* data, size_t data_len) { grpc_resolved_address resolved_addr6; - struct sockaddr_in6* addr6 = - reinterpret_cast(resolved_addr6.addr); + grpc_sockaddr_in6* addr6 = + reinterpret_cast(resolved_addr6.addr); memset(&resolved_addr6, 0, sizeof(resolved_addr6)); - addr6->sin6_family = AF_INET6; + addr6->sin6_family = GRPC_AF_INET6; GPR_ASSERT(data_len == sizeof(addr6->sin6_addr.s6_addr)); memcpy(&addr6->sin6_addr.s6_addr, data, data_len); - addr6->sin6_port = htons(12345); - resolved_addr6.len = sizeof(struct sockaddr_in6); + addr6->sin6_port = grpc_htons(12345); + resolved_addr6.len = sizeof(grpc_sockaddr_in6); return resolved_addr6; } static void set_addr6_scope_id(grpc_resolved_address* addr, uint32_t scope_id) { - struct sockaddr_in6* addr6 = - reinterpret_cast(addr->addr); - GPR_ASSERT(addr6->sin6_family == AF_INET6); + grpc_sockaddr_in6* addr6 = reinterpret_cast(addr->addr); + GPR_ASSERT(addr6->sin6_family == GRPC_AF_INET6); addr6->sin6_scope_id = scope_id; } @@ -131,9 +131,9 @@ static void test_sockaddr_is_wildcard(void) { grpc_resolved_address wild6; grpc_resolved_address wild_mapped; grpc_resolved_address dummy; - struct sockaddr_in* wild4_addr; - struct sockaddr_in6* wild6_addr; - struct sockaddr_in6* wild_mapped_addr; + grpc_sockaddr_in* wild4_addr; + grpc_sockaddr_in6* wild6_addr; + grpc_sockaddr_in6* wild_mapped_addr; int port; gpr_log(GPR_INFO, "%s", "test_sockaddr_is_wildcard"); @@ -146,7 +146,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild4, &port)); GPR_ASSERT(port == 555); - wild4_addr = reinterpret_cast(&wild4.addr); + wild4_addr = reinterpret_cast(&wild4.addr); memset(&wild4_addr->sin_addr.s_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild4, &port)); @@ -154,7 +154,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild6, &port)); GPR_ASSERT(port == 555); - wild6_addr = reinterpret_cast(&wild6.addr); + wild6_addr = reinterpret_cast(&wild6.addr); memset(&wild6_addr->sin6_addr.s6_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild6, &port)); @@ -162,7 +162,7 @@ static void test_sockaddr_is_wildcard(void) { port = -1; GPR_ASSERT(grpc_sockaddr_is_wildcard(&wild_mapped, &port)); GPR_ASSERT(port == 555); - wild_mapped_addr = reinterpret_cast(&wild_mapped.addr); + wild_mapped_addr = reinterpret_cast(&wild_mapped.addr); memset(&wild_mapped_addr->sin6_addr.s6_addr, 0xbd, 1); GPR_ASSERT(!grpc_sockaddr_is_wildcard(&wild_mapped, &port)); @@ -200,7 +200,7 @@ static void test_sockaddr_to_string(void) { grpc_resolved_address input4; grpc_resolved_address input6; grpc_resolved_address dummy; - struct sockaddr* dummy_addr; + grpc_sockaddr* dummy_addr; gpr_log(GPR_INFO, "%s", "test_sockaddr_to_string"); @@ -237,7 +237,7 @@ static void test_sockaddr_to_string(void) { expect_sockaddr_uri("ipv6:[::fffe:c000:263]:12345", &input6); memset(&dummy, 0, sizeof(dummy)); - dummy_addr = reinterpret_cast(dummy.addr); + dummy_addr = reinterpret_cast(dummy.addr); dummy_addr->sa_family = 123; expect_sockaddr_str("(sockaddr family=123)", &dummy, 0); expect_sockaddr_str("(sockaddr family=123)", &dummy, 1); @@ -248,7 +248,7 @@ static void test_sockaddr_set_get_port(void) { grpc_resolved_address input4; grpc_resolved_address input6; grpc_resolved_address dummy; - struct sockaddr* dummy_addr; + grpc_sockaddr* dummy_addr; gpr_log(GPR_DEBUG, "test_sockaddr_set_get_port"); @@ -263,7 +263,7 @@ static void test_sockaddr_set_get_port(void) { GPR_ASSERT(grpc_sockaddr_get_port(&input6) == 54321); memset(&dummy, 0, sizeof(dummy)); - dummy_addr = reinterpret_cast(dummy.addr); + dummy_addr = reinterpret_cast(dummy.addr); dummy_addr->sa_family = 123; GPR_ASSERT(grpc_sockaddr_get_port(&dummy) == 0); GPR_ASSERT(grpc_sockaddr_set_port(&dummy, 1234) == 0); diff --git a/test/core/iomgr/timer_heap_test.cc b/test/core/iomgr/timer_heap_test.cc index 08f5d632e39..ebe5e32f3a5 100644 --- a/test/core/iomgr/timer_heap_test.cc +++ b/test/core/iomgr/timer_heap_test.cc @@ -18,9 +18,6 @@ #include "src/core/lib/iomgr/port.h" -// This test only works with the generic timer implementation -#ifdef GRPC_TIMER_USE_GENERIC - #include "src/core/lib/iomgr/timer_heap.h" #include @@ -299,9 +296,3 @@ int main(int argc, char** argv) { return 0; } - -#else /* GRPC_TIMER_USE_GENERIC */ - -int main(int argc, char** argv) { return 1; } - -#endif /* GRPC_TIMER_USE_GENERIC */ diff --git a/test/core/iomgr/timer_list_test.cc b/test/core/iomgr/timer_list_test.cc index deb8c4d87e9..b1d919b292f 100644 --- a/test/core/iomgr/timer_list_test.cc +++ b/test/core/iomgr/timer_list_test.cc @@ -19,8 +19,9 @@ #include "src/core/lib/iomgr/port.h" // This test only works with the generic timer implementation -#ifdef GRPC_TIMER_USE_GENERIC +#ifndef GRPC_CUSTOM_SOCKET +#include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/timer.h" #include @@ -153,15 +154,19 @@ void destruction_test(void) { int main(int argc, char** argv) { grpc_test_init(argc, argv); grpc_core::ExecCtx::GlobalInit(); + grpc_core::ExecCtx exec_ctx; + grpc_determine_iomgr_platform(); + grpc_iomgr_platform_init(); gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); add_test(); destruction_test(); + grpc_iomgr_platform_shutdown(); grpc_core::ExecCtx::GlobalShutdown(); return 0; } -#else /* GRPC_TIMER_USE_GENERIC */ +#else /* GRPC_CUSTOM_SOCKET */ int main(int argc, char** argv) { return 1; } -#endif /* GRPC_TIMER_USE_GENERIC */ +#endif /* GRPC_CUSTOM_SOCKET */ diff --git a/test/core/iomgr/wakeup_fd_cv_test.cc b/test/core/iomgr/wakeup_fd_cv_test.cc index 9bd7c6e47ec..f297a569d2d 100644 --- a/test/core/iomgr/wakeup_fd_cv_test.cc +++ b/test/core/iomgr/wakeup_fd_cv_test.cc @@ -225,7 +225,7 @@ int main(int argc, char** argv) { grpc_poll_function = &mock_poll; gpr_mu_init(&poll_mu); gpr_cv_init(&poll_cv); - + grpc_determine_iomgr_platform(); grpc_iomgr_platform_init(); test_many_fds(); grpc_iomgr_platform_shutdown(); diff --git a/test/core/surface/concurrent_connectivity_test.cc b/test/core/surface/concurrent_connectivity_test.cc index c1298b66360..fbc5ec4c541 100644 --- a/test/core/surface/concurrent_connectivity_test.cc +++ b/test/core/surface/concurrent_connectivity_test.cc @@ -124,14 +124,13 @@ void bad_server_thread(void* vargs) { grpc_core::ExecCtx exec_ctx; grpc_resolved_address resolved_addr; - struct sockaddr_storage* addr = - reinterpret_cast(resolved_addr.addr); + grpc_sockaddr* addr = reinterpret_cast(resolved_addr.addr); int port; grpc_tcp_server* s; grpc_error* error = grpc_tcp_server_create(nullptr, nullptr, &s); GPR_ASSERT(error == GRPC_ERROR_NONE); memset(&resolved_addr, 0, sizeof(resolved_addr)); - addr->ss_family = AF_INET; + addr->sa_family = GRPC_AF_INET; error = grpc_tcp_server_add_port(s, &resolved_addr, &port); GPR_ASSERT(GRPC_LOG_IF_ERROR("grpc_tcp_server_add_port", error)); GPR_ASSERT(port > 0); diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index cb2bc701fad..610a9918ce6 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -17,6 +17,7 @@ */ #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/iomgr/socket_utils.h" #include "test/core/util/test_tcp_server.h" @@ -54,13 +55,13 @@ void test_tcp_server_init(test_tcp_server* server, void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = - reinterpret_cast(resolved_addr.addr); + grpc_sockaddr_in* addr = + reinterpret_cast(resolved_addr.addr); int port_added; grpc_core::ExecCtx exec_ctx; - addr->sin_family = AF_INET; - addr->sin_port = htons(static_cast(port)); + addr->sin_family = GRPC_AF_INET; + addr->sin_port = grpc_htons(static_cast(port)); memset(&addr->sin_addr, 0, sizeof(addr->sin_addr)); grpc_error* error = grpc_tcp_server_create(&server->shutdown_complete, diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 455eaceb592..a39e443cf0b 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -40,6 +40,7 @@ #include "src/core/lib/gpr/env.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" +#include "src/core/lib/iomgr/tcp_client.h" #include "src/proto/grpc/testing/echo.grpc.pb.h" #include "test/core/util/port.h" @@ -52,13 +53,10 @@ using grpc::testing::EchoRequest; using grpc::testing::EchoResponse; using std::chrono::system_clock; -// defined in tcp_client_posix.c -extern void (*grpc_tcp_client_connect_impl)( - grpc_closure* closure, grpc_endpoint** ep, - grpc_pollset_set* interested_parties, const grpc_channel_args* channel_args, - const grpc_resolved_address* addr, grpc_millis deadline); +// defined in tcp_client.cc +extern grpc_tcp_client_vtable* grpc_tcp_client_impl; -const auto original_tcp_connect_fn = grpc_tcp_client_connect_impl; +static grpc_tcp_client_vtable* default_client_impl; namespace grpc { namespace testing { @@ -75,10 +73,12 @@ void tcp_client_connect_with_delay(grpc_closure* closure, grpc_endpoint** ep, if (delay_ms > 0) { gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(delay_ms)); } - original_tcp_connect_fn(closure, ep, interested_parties, channel_args, addr, - deadline + delay_ms); + default_client_impl->connect(closure, ep, interested_parties, channel_args, + addr, deadline + delay_ms); } +grpc_tcp_client_vtable delayed_connect = {tcp_client_connect_with_delay}; + // Subclass of TestServiceImpl that increments a request counter for // every call to the Echo RPC. class MyTestServiceImpl : public TestServiceImpl { @@ -384,7 +384,8 @@ TEST_F(ClientLbEnd2endTest, PickFirstBackOffMinReconnect) { // Make connection delay a 10% longer than it's willing to in order to make // sure we are hitting the codepath that waits for the min reconnect backoff. gpr_atm_rel_store(&g_connection_delay_ms, kMinReconnectBackOffMs * 1.10); - grpc_tcp_client_connect_impl = tcp_client_connect_with_delay; + default_client_impl = grpc_tcp_client_impl; + grpc_set_tcp_client_impl(&delayed_connect); const gpr_timespec t0 = gpr_now(GPR_CLOCK_MONOTONIC); channel->WaitForConnected( grpc_timeout_milliseconds_to_deadline(kMinReconnectBackOffMs * 2)); diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index ff5abc679d8..c822d9b3cd3 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1070,9 +1070,9 @@ src/core/lib/iomgr/executor.h \ src/core/lib/iomgr/gethostname.h \ src/core/lib/iomgr/iocp_windows.h \ src/core/lib/iomgr/iomgr.h \ +src/core/lib/iomgr/iomgr_custom.h \ src/core/lib/iomgr/iomgr_internal.h \ src/core/lib/iomgr/iomgr_posix.h \ -src/core/lib/iomgr/iomgr_uv.h \ src/core/lib/iomgr/is_epollexclusive_available.h \ src/core/lib/iomgr/load_file.h \ src/core/lib/iomgr/lockfree_event.h \ @@ -1080,14 +1080,17 @@ src/core/lib/iomgr/nameser.h \ src/core/lib/iomgr/network_status_tracker.h \ src/core/lib/iomgr/polling_entity.h \ src/core/lib/iomgr/pollset.h \ +src/core/lib/iomgr/pollset_custom.h \ src/core/lib/iomgr/pollset_set.h \ +src/core/lib/iomgr/pollset_set_custom.h \ src/core/lib/iomgr/pollset_set_windows.h \ -src/core/lib/iomgr/pollset_uv.h \ src/core/lib/iomgr/pollset_windows.h \ src/core/lib/iomgr/port.h \ src/core/lib/iomgr/resolve_address.h \ +src/core/lib/iomgr/resolve_address_custom.h \ src/core/lib/iomgr/resource_quota.h \ src/core/lib/iomgr/sockaddr.h \ +src/core/lib/iomgr/sockaddr_custom.h \ src/core/lib/iomgr/sockaddr_posix.h \ src/core/lib/iomgr/sockaddr_utils.h \ src/core/lib/iomgr/sockaddr_windows.h \ @@ -1099,17 +1102,16 @@ src/core/lib/iomgr/socket_windows.h \ src/core/lib/iomgr/sys_epoll_wrapper.h \ src/core/lib/iomgr/tcp_client.h \ src/core/lib/iomgr/tcp_client_posix.h \ +src/core/lib/iomgr/tcp_custom.h \ src/core/lib/iomgr/tcp_posix.h \ src/core/lib/iomgr/tcp_server.h \ src/core/lib/iomgr/tcp_server_utils_posix.h \ -src/core/lib/iomgr/tcp_uv.h \ src/core/lib/iomgr/tcp_windows.h \ src/core/lib/iomgr/time_averaged_stats.h \ src/core/lib/iomgr/timer.h \ -src/core/lib/iomgr/timer_generic.h \ +src/core/lib/iomgr/timer_custom.h \ src/core/lib/iomgr/timer_heap.h \ src/core/lib/iomgr/timer_manager.h \ -src/core/lib/iomgr/timer_uv.h \ src/core/lib/iomgr/udp_server.h \ src/core/lib/iomgr/unix_sockets_posix.h \ src/core/lib/iomgr/wakeup_fd_cv.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index e7e9e04979e..212e1d53dd8 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1176,11 +1176,13 @@ src/core/lib/iomgr/iocp_windows.cc \ src/core/lib/iomgr/iocp_windows.h \ src/core/lib/iomgr/iomgr.cc \ src/core/lib/iomgr/iomgr.h \ +src/core/lib/iomgr/iomgr_custom.cc \ +src/core/lib/iomgr/iomgr_custom.h \ +src/core/lib/iomgr/iomgr_internal.cc \ src/core/lib/iomgr/iomgr_internal.h \ src/core/lib/iomgr/iomgr_posix.cc \ src/core/lib/iomgr/iomgr_posix.h \ src/core/lib/iomgr/iomgr_uv.cc \ -src/core/lib/iomgr/iomgr_uv.h \ src/core/lib/iomgr/iomgr_windows.cc \ src/core/lib/iomgr/is_epollexclusive_available.cc \ src/core/lib/iomgr/is_epollexclusive_available.h \ @@ -1193,23 +1195,30 @@ src/core/lib/iomgr/network_status_tracker.cc \ src/core/lib/iomgr/network_status_tracker.h \ src/core/lib/iomgr/polling_entity.cc \ src/core/lib/iomgr/polling_entity.h \ +src/core/lib/iomgr/pollset.cc \ src/core/lib/iomgr/pollset.h \ +src/core/lib/iomgr/pollset_custom.cc \ +src/core/lib/iomgr/pollset_custom.h \ +src/core/lib/iomgr/pollset_set.cc \ src/core/lib/iomgr/pollset_set.h \ -src/core/lib/iomgr/pollset_set_uv.cc \ +src/core/lib/iomgr/pollset_set_custom.cc \ +src/core/lib/iomgr/pollset_set_custom.h \ src/core/lib/iomgr/pollset_set_windows.cc \ src/core/lib/iomgr/pollset_set_windows.h \ src/core/lib/iomgr/pollset_uv.cc \ -src/core/lib/iomgr/pollset_uv.h \ src/core/lib/iomgr/pollset_windows.cc \ src/core/lib/iomgr/pollset_windows.h \ src/core/lib/iomgr/port.h \ +src/core/lib/iomgr/resolve_address.cc \ src/core/lib/iomgr/resolve_address.h \ +src/core/lib/iomgr/resolve_address_custom.cc \ +src/core/lib/iomgr/resolve_address_custom.h \ src/core/lib/iomgr/resolve_address_posix.cc \ -src/core/lib/iomgr/resolve_address_uv.cc \ src/core/lib/iomgr/resolve_address_windows.cc \ src/core/lib/iomgr/resource_quota.cc \ src/core/lib/iomgr/resource_quota.h \ src/core/lib/iomgr/sockaddr.h \ +src/core/lib/iomgr/sockaddr_custom.h \ src/core/lib/iomgr/sockaddr_posix.h \ src/core/lib/iomgr/sockaddr_utils.cc \ src/core/lib/iomgr/sockaddr_utils.h \ @@ -1228,36 +1237,40 @@ src/core/lib/iomgr/socket_utils_windows.cc \ src/core/lib/iomgr/socket_windows.cc \ src/core/lib/iomgr/socket_windows.h \ src/core/lib/iomgr/sys_epoll_wrapper.h \ +src/core/lib/iomgr/tcp_client.cc \ src/core/lib/iomgr/tcp_client.h \ +src/core/lib/iomgr/tcp_client_custom.cc \ src/core/lib/iomgr/tcp_client_posix.cc \ src/core/lib/iomgr/tcp_client_posix.h \ -src/core/lib/iomgr/tcp_client_uv.cc \ src/core/lib/iomgr/tcp_client_windows.cc \ +src/core/lib/iomgr/tcp_custom.cc \ +src/core/lib/iomgr/tcp_custom.h \ src/core/lib/iomgr/tcp_posix.cc \ src/core/lib/iomgr/tcp_posix.h \ +src/core/lib/iomgr/tcp_server.cc \ src/core/lib/iomgr/tcp_server.h \ +src/core/lib/iomgr/tcp_server_custom.cc \ src/core/lib/iomgr/tcp_server_posix.cc \ src/core/lib/iomgr/tcp_server_utils_posix.h \ src/core/lib/iomgr/tcp_server_utils_posix_common.cc \ src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc \ src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc \ -src/core/lib/iomgr/tcp_server_uv.cc \ src/core/lib/iomgr/tcp_server_windows.cc \ src/core/lib/iomgr/tcp_uv.cc \ -src/core/lib/iomgr/tcp_uv.h \ src/core/lib/iomgr/tcp_windows.cc \ src/core/lib/iomgr/tcp_windows.h \ src/core/lib/iomgr/time_averaged_stats.cc \ src/core/lib/iomgr/time_averaged_stats.h \ +src/core/lib/iomgr/timer.cc \ src/core/lib/iomgr/timer.h \ +src/core/lib/iomgr/timer_custom.cc \ +src/core/lib/iomgr/timer_custom.h \ src/core/lib/iomgr/timer_generic.cc \ -src/core/lib/iomgr/timer_generic.h \ src/core/lib/iomgr/timer_heap.cc \ src/core/lib/iomgr/timer_heap.h \ src/core/lib/iomgr/timer_manager.cc \ src/core/lib/iomgr/timer_manager.h \ src/core/lib/iomgr/timer_uv.cc \ -src/core/lib/iomgr/timer_uv.h \ src/core/lib/iomgr/udp_server.cc \ src/core/lib/iomgr/udp_server.h \ src/core/lib/iomgr/unix_sockets_posix.cc \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index fb1a4fe0f02..d754c5d6fc1 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9042,6 +9042,8 @@ "src/core/lib/iomgr/gethostname_sysconf.cc", "src/core/lib/iomgr/iocp_windows.cc", "src/core/lib/iomgr/iomgr.cc", + "src/core/lib/iomgr/iomgr_custom.cc", + "src/core/lib/iomgr/iomgr_internal.cc", "src/core/lib/iomgr/iomgr_posix.cc", "src/core/lib/iomgr/iomgr_uv.cc", "src/core/lib/iomgr/iomgr_windows.cc", @@ -9050,12 +9052,16 @@ "src/core/lib/iomgr/lockfree_event.cc", "src/core/lib/iomgr/network_status_tracker.cc", "src/core/lib/iomgr/polling_entity.cc", - "src/core/lib/iomgr/pollset_set_uv.cc", + "src/core/lib/iomgr/pollset.cc", + "src/core/lib/iomgr/pollset_custom.cc", + "src/core/lib/iomgr/pollset_set.cc", + "src/core/lib/iomgr/pollset_set_custom.cc", "src/core/lib/iomgr/pollset_set_windows.cc", "src/core/lib/iomgr/pollset_uv.cc", "src/core/lib/iomgr/pollset_windows.cc", + "src/core/lib/iomgr/resolve_address.cc", + "src/core/lib/iomgr/resolve_address_custom.cc", "src/core/lib/iomgr/resolve_address_posix.cc", - "src/core/lib/iomgr/resolve_address_uv.cc", "src/core/lib/iomgr/resolve_address_windows.cc", "src/core/lib/iomgr/resource_quota.cc", "src/core/lib/iomgr/sockaddr_utils.cc", @@ -9067,19 +9073,24 @@ "src/core/lib/iomgr/socket_utils_uv.cc", "src/core/lib/iomgr/socket_utils_windows.cc", "src/core/lib/iomgr/socket_windows.cc", + "src/core/lib/iomgr/tcp_client.cc", + "src/core/lib/iomgr/tcp_client_custom.cc", "src/core/lib/iomgr/tcp_client_posix.cc", - "src/core/lib/iomgr/tcp_client_uv.cc", "src/core/lib/iomgr/tcp_client_windows.cc", + "src/core/lib/iomgr/tcp_custom.cc", "src/core/lib/iomgr/tcp_posix.cc", + "src/core/lib/iomgr/tcp_server.cc", + "src/core/lib/iomgr/tcp_server_custom.cc", "src/core/lib/iomgr/tcp_server_posix.cc", "src/core/lib/iomgr/tcp_server_utils_posix_common.cc", "src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc", "src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc", - "src/core/lib/iomgr/tcp_server_uv.cc", "src/core/lib/iomgr/tcp_server_windows.cc", "src/core/lib/iomgr/tcp_uv.cc", "src/core/lib/iomgr/tcp_windows.cc", "src/core/lib/iomgr/time_averaged_stats.cc", + "src/core/lib/iomgr/timer.cc", + "src/core/lib/iomgr/timer_custom.cc", "src/core/lib/iomgr/timer_generic.cc", "src/core/lib/iomgr/timer_heap.cc", "src/core/lib/iomgr/timer_manager.cc", @@ -9201,9 +9212,9 @@ "src/core/lib/iomgr/gethostname.h", "src/core/lib/iomgr/iocp_windows.h", "src/core/lib/iomgr/iomgr.h", + "src/core/lib/iomgr/iomgr_custom.h", "src/core/lib/iomgr/iomgr_internal.h", "src/core/lib/iomgr/iomgr_posix.h", - "src/core/lib/iomgr/iomgr_uv.h", "src/core/lib/iomgr/is_epollexclusive_available.h", "src/core/lib/iomgr/load_file.h", "src/core/lib/iomgr/lockfree_event.h", @@ -9211,14 +9222,17 @@ "src/core/lib/iomgr/network_status_tracker.h", "src/core/lib/iomgr/polling_entity.h", "src/core/lib/iomgr/pollset.h", + "src/core/lib/iomgr/pollset_custom.h", "src/core/lib/iomgr/pollset_set.h", + "src/core/lib/iomgr/pollset_set_custom.h", "src/core/lib/iomgr/pollset_set_windows.h", - "src/core/lib/iomgr/pollset_uv.h", "src/core/lib/iomgr/pollset_windows.h", "src/core/lib/iomgr/port.h", "src/core/lib/iomgr/resolve_address.h", + "src/core/lib/iomgr/resolve_address_custom.h", "src/core/lib/iomgr/resource_quota.h", "src/core/lib/iomgr/sockaddr.h", + "src/core/lib/iomgr/sockaddr_custom.h", "src/core/lib/iomgr/sockaddr_posix.h", "src/core/lib/iomgr/sockaddr_utils.h", "src/core/lib/iomgr/sockaddr_windows.h", @@ -9230,17 +9244,16 @@ "src/core/lib/iomgr/sys_epoll_wrapper.h", "src/core/lib/iomgr/tcp_client.h", "src/core/lib/iomgr/tcp_client_posix.h", + "src/core/lib/iomgr/tcp_custom.h", "src/core/lib/iomgr/tcp_posix.h", "src/core/lib/iomgr/tcp_server.h", "src/core/lib/iomgr/tcp_server_utils_posix.h", - "src/core/lib/iomgr/tcp_uv.h", "src/core/lib/iomgr/tcp_windows.h", "src/core/lib/iomgr/time_averaged_stats.h", "src/core/lib/iomgr/timer.h", - "src/core/lib/iomgr/timer_generic.h", + "src/core/lib/iomgr/timer_custom.h", "src/core/lib/iomgr/timer_heap.h", "src/core/lib/iomgr/timer_manager.h", - "src/core/lib/iomgr/timer_uv.h", "src/core/lib/iomgr/udp_server.h", "src/core/lib/iomgr/unix_sockets_posix.h", "src/core/lib/iomgr/wakeup_fd_cv.h", @@ -9345,9 +9358,9 @@ "src/core/lib/iomgr/gethostname.h", "src/core/lib/iomgr/iocp_windows.h", "src/core/lib/iomgr/iomgr.h", + "src/core/lib/iomgr/iomgr_custom.h", "src/core/lib/iomgr/iomgr_internal.h", "src/core/lib/iomgr/iomgr_posix.h", - "src/core/lib/iomgr/iomgr_uv.h", "src/core/lib/iomgr/is_epollexclusive_available.h", "src/core/lib/iomgr/load_file.h", "src/core/lib/iomgr/lockfree_event.h", @@ -9355,14 +9368,17 @@ "src/core/lib/iomgr/network_status_tracker.h", "src/core/lib/iomgr/polling_entity.h", "src/core/lib/iomgr/pollset.h", + "src/core/lib/iomgr/pollset_custom.h", "src/core/lib/iomgr/pollset_set.h", + "src/core/lib/iomgr/pollset_set_custom.h", "src/core/lib/iomgr/pollset_set_windows.h", - "src/core/lib/iomgr/pollset_uv.h", "src/core/lib/iomgr/pollset_windows.h", "src/core/lib/iomgr/port.h", "src/core/lib/iomgr/resolve_address.h", + "src/core/lib/iomgr/resolve_address_custom.h", "src/core/lib/iomgr/resource_quota.h", "src/core/lib/iomgr/sockaddr.h", + "src/core/lib/iomgr/sockaddr_custom.h", "src/core/lib/iomgr/sockaddr_posix.h", "src/core/lib/iomgr/sockaddr_utils.h", "src/core/lib/iomgr/sockaddr_windows.h", @@ -9374,17 +9390,16 @@ "src/core/lib/iomgr/sys_epoll_wrapper.h", "src/core/lib/iomgr/tcp_client.h", "src/core/lib/iomgr/tcp_client_posix.h", + "src/core/lib/iomgr/tcp_custom.h", "src/core/lib/iomgr/tcp_posix.h", "src/core/lib/iomgr/tcp_server.h", "src/core/lib/iomgr/tcp_server_utils_posix.h", - "src/core/lib/iomgr/tcp_uv.h", "src/core/lib/iomgr/tcp_windows.h", "src/core/lib/iomgr/time_averaged_stats.h", "src/core/lib/iomgr/timer.h", - "src/core/lib/iomgr/timer_generic.h", + "src/core/lib/iomgr/timer_custom.h", "src/core/lib/iomgr/timer_heap.h", "src/core/lib/iomgr/timer_manager.h", - "src/core/lib/iomgr/timer_uv.h", "src/core/lib/iomgr/udp_server.h", "src/core/lib/iomgr/unix_sockets_posix.h", "src/core/lib/iomgr/wakeup_fd_cv.h", diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index b751bf97140..85c7f5c4dc0 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -281,7 +281,7 @@ class CLanguage(object): self._docker_distro, self._make_options = self._compiler_options( self.args.use_docker, self.args.compiler) if args.iomgr_platform == "uv": - cflags = '-DGRPC_UV -DGRPC_UV_THREAD_CHECK' + cflags = '-DGRPC_UV -DGRPC_CUSTOM_IOMGR_THREAD_CHECK ' try: cflags += subprocess.check_output( ['pkg-config', '--cflags', 'libuv']).strip() + ' ' diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj new file mode 100644 index 00000000000..8f357d35e99 --- /dev/null +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -0,0 +1,646 @@ + + + + + Debug-DLL + Win32 + + + Debug-DLL + x64 + + + Release-DLL + Win32 + + + Release-DLL + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {C187A093-A0FE-489D-A40A-6E33DE0F9FEB} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + grpc++ + + + grpc++ + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {29D16885-7228-4C31-81ED-5F9187C7F2A9} + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters new file mode 100644 index 00000000000..c5c1eba5938 --- /dev/null +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -0,0 +1,1096 @@ + + + + + src\cpp\client + + + src\cpp\client + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\thread_manager + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\codegen + + + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\ext + + + include\grpc++\generic + + + include\grpc++\generic + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl\codegen + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++ + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc\support + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen\security + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + + + include\grpc++\impl\codegen + + + src\cpp\client + + + src\cpp\common + + + src\cpp\server + + + src\cpp\client + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server + + + src\cpp\thread_manager + + + src\core\lib\profiling + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\debug + + + src\core\ext\transport\inproc + + + third_party\nanopb + + + third_party\nanopb + + + third_party\nanopb + + + third_party\nanopb + + + + + + {82445414-24cd-8198-1fe1-4267c3f3df00} + + + {16946104-53ac-ac76-68b9-f9ec77ea6fae} + + + {784a0281-f547-aeb0-9f55-b26b7de9c769} + + + {25501d8e-5fae-2fe4-14a6-d69a07acefdd} + + + {51dae921-3aa2-1976-2ee4-c5615de1af54} + + + {0da8cd95-314f-da1b-5ce7-7791a5be1f1a} + + + {a3e7f28b-a7c7-7364-d402-edb1bfa414a4} + + + {20cbcf00-994a-300a-5184-bda96c6f45e4} + + + {a80eb32b-1be9-1187-5f40-30d92accecc8} + + + {a5c10dae-f715-2a30-1066-d22f8bc94cb2} + + + {48c3b0ae-c00f-fa20-6965-b73da65d71cb} + + + {dc8bfccd-341f-26f0-8ee4-47dde62a6dd1} + + + {5ec10a44-9a09-9220-cf3b-b18ce6e4f70f} + + + {328ff211-2886-406e-56f9-18ba1686f363} + + + {d02f1155-7e7e-3736-3c69-dc9146dc523d} + + + {96d09c4a-59f9-3486-6c2f-cbf695b285d8} + + + {202b1172-189f-afc4-f16c-4ca12677b480} + + + {635a93a8-e23a-a664-c9cb-0963736dd9ce} + + + {80567a8f-622f-a3ce-c12d-aebb63984b07} + + + {e769265c-8abd-cd64-2cc2-a52da484fe7b} + + + {701b2d46-11c6-3640-b189-45287f00bee3} + + + {ada68fd5-8e51-98cb-71a7-baf7989d8ffa} + + + {e770844e-61d4-555e-59be-81288e21a35f} + + + {04dfa1c8-7ffe-4f06-4a7c-37441dc75764} + + + {a5d5bddf-6f19-b655-a03a-f30ff5c253a5} + + + {836e78ab-aaae-9dce-dd1e-06f03c436a13} + + + {afe126ba-52c9-1daa-d174-8ee8aade08c2} + + + {83b45914-6f97-b4ad-f2d0-cc56a10ea1bb} + + + {fb2276d7-5a11-f1d9-82c3-e7c7f1155523} + + + {4bd7971a-68f7-0d5a-f502-6dea3099caaa} + + + {2420a905-e4f1-a5aa-a364-6a112878a39e} + + + {7febf32a-d7a6-76fa-9e17-f189f591c062} + + + {3c3e27f4-d3d9-3c42-5204-08b5e839f2de} + + + {2336e396-7e0b-8bf9-3b09-adc6ad1f0e5b} + + + {321b0980-74ad-e8ca-f23b-deffa5d6bb8f} + + + {5bc9ef4e-78c1-159e-4e4e-30ddfce3e140} + + + {23f9df56-8604-52a0-e6a2-f01b8e68d0e7} + + + {f842537a-2bf1-1ec3-b495-7d62c64a1c06} + + + {0cfc99f5-c633-356e-6810-754c93b15658} + + + {abc9bbec-57f7-141f-8616-e2d3aa8b2e6d} + + + + diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj new file mode 100644 index 00000000000..3d8bf82b6a7 --- /dev/null +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -0,0 +1,630 @@ + + + + + Debug-DLL + Win32 + + + Debug-DLL + x64 + + + Release-DLL + Win32 + + + Release-DLL + x64 + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {6EE56155-DF7C-4F6E-BFC4-F6F776BEB211} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + grpc++_unsecure + + + grpc++_unsecure + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters new file mode 100644 index 00000000000..2c4230f4fe8 --- /dev/null +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -0,0 +1,1063 @@ + + + + + src\cpp\client + + + src\cpp\common + + + src\cpp\server + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\client + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\server + + + src\cpp\thread_manager + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\util + + + src\cpp\codegen + + + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\ext + + + include\grpc++\generic + + + include\grpc++\generic + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl\codegen + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++\impl + + + include\grpc++ + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++\security + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++ + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc++\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\support + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc + + + include\grpc\support + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen\security + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + include\grpc++\impl\codegen + + + + + src\cpp\client + + + src\cpp\common + + + src\cpp\server + + + src\cpp\server\health + + + src\cpp\server\health + + + src\cpp\server + + + src\cpp\thread_manager + + + src\core\lib\profiling + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\support + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\debug + + + src\core\ext\transport\inproc + + + third_party\nanopb + + + third_party\nanopb + + + third_party\nanopb + + + third_party\nanopb + + + + + + {5c4eb19f-d511-e8fd-e1d6-c377cdc7d3b1} + + + {f3dd91a8-058b-becf-9e41-eb42c7bc6e55} + + + {eceb50c0-bb49-3812-b6bd-b0af6df81da7} + + + {e6643be2-2b2f-953d-ab14-27d89c835c8a} + + + {83717d3c-57d9-2bfa-ed9c-2b08f86da12b} + + + {dadc0002-f2ac-451b-a9b8-33b8de10b5fc} + + + {ccc364e2-3f28-8bfc-c26e-800dd6f9a9af} + + + {87cae06e-f40c-8fb6-73d6-26c7482ed9da} + + + {64bf60ff-9192-bb59-dcc8-8a0021e1d016} + + + {0ebf8008-80b9-d6da-e1dc-854bf1ec2195} + + + {c1049250-64f6-f900-d2e5-1718e148f1f0} + + + {adf6b8e3-4a4b-cb35-bb3d-568af97b58d1} + + + {9d6d36f2-26e7-a66b-c19d-a958b80878d6} + + + {cce6a85d-1111-3834-6825-31e170d93cff} + + + {595f2ea0-aafb-87e5-c938-db3ff0b0c69a} + + + {52eca76b-9502-3d96-9064-6415226a860f} + + + {8e70201f-3b54-d3cb-8b30-ebe0d96a9b2a} + + + {ecf09c42-c470-1883-35d7-442453ea8370} + + + {cf8fd5d8-ff54-331d-2d20-36d6cae0e14b} + + + {7e0225af-000b-4873-1c16-caffffbfd084} + + + {0bbdbf56-83ad-bb4b-c4e2-a6d38c342179} + + + {3875f7d7-ff11-c91d-0f98-810260cb554b} + + + {4bd405b9-af65-f0a6-d67a-433f75900668} + + + {f4b146e4-8fba-83a6-1cc1-1262ebb785e8} + + + {b83c8e70-e491-f6f9-a08c-85f632bb61d2} + + + {c3b582f8-079a-5936-7694-54cd75a7e61e} + + + {0d6d88e2-8549-5118-8b78-06e8283dadcb} + + + {a5139298-498a-41d4-59fd-c38d8f0380c1} + + + {1d59dcef-3358-d0ab-fa42-64da74065785} + + + {ba865739-5dd9-6731-6772-48c25d45134f} + + + {1e5fd68c-bd87-e803-42b0-75a7fa19b91d} + + + {ff72923a-6499-8d2a-e0fb-6d574b85d77e} + + + {18e9c249-37f0-7f2c-f026-502d48ed8c92} + + + {ed8e4daa-825f-fbe5-2a45-846ad9165d3d} + + + {8a54a279-d14b-4237-0df3-1ffe1ef5a7af} + + + {a003cb5c-7249-106c-8ee5-de5e11a6692c} + + + {e5b55f25-d99f-b8e5-9981-7da7fa7ba628} + + + {fb5d9a64-20ca-5119-ed38-04a3cf94923d} + + + {e911fd76-1313-5d02-3983-cdd0bafe1c6a} + + + {1ff41e28-caf4-c4b9-0170-53d36c7dac29} + + + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index fbb9fde7538..73cb0c243ab 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -334,9 +334,9 @@ + - @@ -362,6 +362,7 @@ + @@ -369,10 +370,9 @@ - + - @@ -595,9 +595,11 @@ - + + + - + @@ -611,7 +613,13 @@ - + + + + + + + @@ -619,9 +627,11 @@ - + - + + + @@ -645,14 +655,22 @@ - + - + + + + + + + + + @@ -661,8 +679,6 @@ - - @@ -671,6 +687,10 @@ + + + + @@ -885,6 +905,8 @@ + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 5332066df63..043671cd148 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -106,10 +106,13 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr - + src\core\lib\iomgr @@ -130,7 +133,16 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -142,10 +154,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -181,18 +196,30 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -205,9 +232,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -220,6 +244,12 @@ src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -541,6 +571,9 @@ src\core\lib\surface + + src\python\grpcio\grpc\_cython + src\core\tsi @@ -965,13 +998,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + src\core\lib\iomgr - + src\core\lib\iomgr @@ -1049,6 +1082,9 @@ src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr @@ -1070,7 +1106,7 @@ src\core\lib\iomgr - + src\core\lib\iomgr @@ -1079,9 +1115,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -1748,6 +1781,18 @@ {0b0f9ab1-efa4-7f03-e446-6fb9b5227e84} + + {50d054e3-a413-b871-9049-e8612ef56281} + + + {92bc7bec-9183-0f2b-47d9-31f68a980f1e} + + + {a75d942e-8d7a-306e-372f-0c6260f439d4} + + + {89423fb6-ab96-95e8-d197-239e91b777ca} + {aaab30a4-2a15-732e-c141-3fbc0f0f5a7a} diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 3fd0fb5f9fd..cd7bbe2081f 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -420,9 +420,11 @@ - + + + - + @@ -436,7 +438,13 @@ - + + + + + + + @@ -444,9 +452,11 @@ - + - + + + @@ -470,14 +480,22 @@ - + + + - + + + + + + + @@ -486,8 +504,6 @@ - - @@ -496,6 +512,10 @@ + + + + diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters index d51623834f4..6fd8b127e1c 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -163,10 +163,13 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr - + src\core\lib\iomgr @@ -187,7 +190,16 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -199,10 +211,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -238,18 +253,30 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -262,9 +289,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -277,6 +301,12 @@ src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr diff --git a/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj b/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj new file mode 100644 index 00000000000..972828fa315 --- /dev/null +++ b/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj @@ -0,0 +1,649 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {0A7E7F92-FDEA-40F1-A9EC-3BA484F98BBF} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + grpc_test_util_unsecure + + + grpc_test_util_unsecure + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + true + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + true + None + false + + + Windows + true + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + + + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + + + {46CEDFFF-9692-456A-AA24-38B5D6BCF4C5} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj.filters new file mode 100644 index 00000000000..b92079c7a07 --- /dev/null +++ b/vsprojects/vcxproj/grpc_test_util_unsecure/grpc_test_util_unsecure.vcxproj.filters @@ -0,0 +1,946 @@ + + + + + src\core\ext\filters\client_channel\resolver\fake + + + test\core\end2end + + + test\core\end2end\fixtures + + + test\core\end2end\fixtures + + + test\core\iomgr + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\channel + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\compression + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\http + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\json + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\slice + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\surface + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\transport + + + src\core\lib\debug + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\deadline + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\alpn + + + src\core\ext\filters\http\client + + + src\core\ext\filters\http + + + src\core\ext\filters\http\message_compress + + + src\core\ext\filters\http\server + + + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + include\grpc\impl\codegen + + + + + src\core\ext\filters\client_channel\resolver\fake + + + test\core\end2end + + + test\core\end2end\fixtures + + + test\core\end2end\fixtures + + + test\core\iomgr + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + test\core\util + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\client_channel + + + src\core\ext\filters\deadline + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\transport + + + src\core\ext\transport\chttp2\alpn + + + src\core\ext\filters\http\client + + + src\core\ext\filters\http\message_compress + + + src\core\ext\filters\http\server + + + + + + {9793fab6-15ae-1f61-712d-c3d673654d72} + + + {c2447106-a6bf-6b88-9ad0-a42b7ac1573c} + + + {dba70812-267b-656c-9f8c-636338d3f5c0} + + + {b9e2ddac-f042-3042-ba4b-79ba4445e68c} + + + {65483377-42fd-137e-3847-00dfd4675db3} + + + {51a516dc-93e3-4dd5-d114-2d06f5df4ad7} + + + {a927155d-bcf6-0dd8-6d63-be48bcaf617f} + + + {df16e935-149b-79bf-ecb3-dc3a6b628082} + + + {0fb7c1f0-5e3a-d1df-4c9d-96a677a7f3ee} + + + {f47477d5-cb4e-e726-04dd-182151e81c71} + + + {2d280bd0-f4ee-d1f2-4d70-174147ac0dbc} + + + {6820a68f-2aa3-8b45-ddea-294656d531f6} + + + {b7df4d88-fa6b-6bd3-579e-b5f086ba6299} + + + {37d93a32-6a75-3b9e-35a4-c47f0a2d274a} + + + {a4bd6a23-c8e1-4e35-f9eb-6434a86f38f0} + + + {2dd536f5-341a-771f-4853-a95522e59224} + + + {fb32254e-a807-768a-3686-4e87f3bf1e8e} + + + {87c61e56-5090-5e1a-22af-02e3c8bf4a2a} + + + {e50ce1d1-6b17-dad2-9ef3-46f68d4bee1b} + + + {67007111-23fe-296f-1808-91f2b96a31aa} + + + {e3d002a7-9318-1ac5-4259-e177f58ccc9a} + + + {ac14fd16-a4af-6b22-4226-2d7dabf25409} + + + {24268e45-f6c3-6024-b49a-d01bb9c12d96} + + + {0be401bd-3e26-dead-fdf4-2ce27a1ac3a3} + + + {ac2f12e3-ac77-f0a7-d15d-92899e61ed25} + + + {9015222c-df04-298f-3f2c-d19babffc180} + + + {c3ff117a-aae9-dedd-2f5a-888f0383cbb8} + + + {588ffbfc-2f94-a99f-85b0-4c47ec9f8d13} + + + {732318c6-bb34-9a99-611b-9928db3d4e2a} + + + {2c0ca4a1-38df-329d-eeba-5c5b61dc81a5} + + + {037c7645-1698-cf2d-4163-525240323101} + + + {85f90d4a-70b4-1b30-8cef-4eadb2a3a04b} + + + {6387fc42-48d5-0134-a9d4-4477151722bf} + + + {204e56b4-4315-b3bd-4a71-7e1c3ebef3ce} + + + {53745d42-f5b1-2381-6b64-146f1234e513} + + + {31b30beb-baf0-3979-2a54-560a16814cf9} + + + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 08c1e78e8f9..0575d47622e 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -324,9 +324,9 @@ + - @@ -352,6 +352,7 @@ + @@ -359,10 +360,9 @@ - + - @@ -561,9 +561,11 @@ - + + + - + @@ -577,7 +579,13 @@ - + + + + + + + @@ -585,9 +593,11 @@ - + - + + + @@ -611,14 +621,22 @@ - + + + - + + + + + + + @@ -627,8 +645,6 @@ - - @@ -637,6 +653,10 @@ + + + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index d9a5914e653..4c25674b1e1 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -109,10 +109,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -133,7 +136,16 @@ src\core\lib\iomgr - + + src\core\lib\iomgr + + + src\core\lib\iomgr + + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -145,10 +157,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr @@ -184,18 +199,30 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + + src\core\lib\iomgr + + src\core\lib\iomgr src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -208,9 +235,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -223,6 +247,12 @@ src\core\lib\iomgr + + src\core\lib\iomgr + + + src\core\lib\iomgr + src\core\lib\iomgr @@ -872,13 +902,13 @@ src\core\lib\iomgr - + src\core\lib\iomgr - + src\core\lib\iomgr - + src\core\lib\iomgr @@ -956,6 +986,9 @@ src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr @@ -977,7 +1010,7 @@ src\core\lib\iomgr - + src\core\lib\iomgr @@ -986,9 +1019,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr