Merge branch 'threadpool'

pull/19701/head
Yunjia Wang 6 years ago
commit ccd75156e4
  1. 10
      BUILD
  2. 11
      BUILD.gn
  3. 155
      CMakeLists.txt
  4. 97
      Makefile
  5. 32
      build.yaml
  6. 3
      config.m4
  7. 3
      config.w32
  8. 8
      gRPC-C++.podspec
  9. 11
      gRPC-Core.podspec
  10. 7
      grpc.gemspec
  11. 6
      grpc.gyp
  12. 7
      package.xml
  13. 19
      src/core/ext/filters/client_channel/http_proxy.cc
  14. 1
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  15. 1
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc
  16. 55
      src/core/ext/filters/client_channel/parse_address.cc
  17. 1
      src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
  18. 95
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc
  19. 1
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc
  20. 1
      src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc
  21. 1
      src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc
  22. 1
      src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc
  23. 1
      src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc
  24. 1
      src/core/ext/transport/chttp2/server/chttp2_server.cc
  25. 8
      src/core/ext/transport/chttp2/transport/frame_data.cc
  26. 22
      src/core/ext/transport/chttp2/transport/hpack_encoder.cc
  27. 96
      src/core/ext/transport/chttp2/transport/hpack_parser.cc
  28. 1
      src/core/ext/transport/cronet/transport/cronet_transport.cc
  29. 15
      src/core/lib/channel/channelz.cc
  30. 98
      src/core/lib/gpr/host_port.cc
  31. 9
      src/core/lib/gpr/string.cc
  32. 1
      src/core/lib/gpr/string.h
  33. 105
      src/core/lib/gprpp/host_port.cc
  34. 38
      src/core/lib/gprpp/host_port.h
  35. 143
      src/core/lib/gprpp/string_view.h
  36. 4
      src/core/lib/http/httpcli_security_connector.cc
  37. 18
      src/core/lib/iomgr/executor/mpmcqueue.cc
  38. 5
      src/core/lib/iomgr/executor/mpmcqueue.h
  39. 136
      src/core/lib/iomgr/executor/threadpool.cc
  40. 153
      src/core/lib/iomgr/executor/threadpool.h
  41. 10
      src/core/lib/iomgr/iomgr_posix_cfstream.cc
  42. 35
      src/core/lib/iomgr/resolve_address_custom.cc
  43. 18
      src/core/lib/iomgr/resolve_address_posix.cc
  44. 14
      src/core/lib/iomgr/resolve_address_windows.cc
  45. 8
      src/core/lib/iomgr/sockaddr_utils.cc
  46. 1
      src/core/lib/iomgr/socket_utils_common_posix.cc
  47. 13
      src/core/lib/iomgr/tcp_client_cfstream.cc
  48. 5
      src/core/lib/security/security_connector/alts/alts_security_connector.cc
  49. 46
      src/core/lib/security/security_connector/fake/fake_security_connector.cc
  50. 5
      src/core/lib/security/security_connector/local/local_security_connector.cc
  51. 2
      src/core/lib/security/security_connector/security_connector.cc
  52. 2
      src/core/lib/security/security_connector/security_connector.h
  53. 38
      src/core/lib/security/security_connector/ssl/ssl_security_connector.cc
  54. 57
      src/core/lib/security/security_connector/ssl_utils.cc
  55. 19
      src/core/lib/security/security_connector/ssl_utils.h
  56. 36
      src/core/lib/security/security_connector/tls/spiffe_security_connector.cc
  57. 7
      src/core/lib/security/security_connector/tls/spiffe_security_connector.h
  58. 3
      src/core/lib/security/transport/client_auth_filter.cc
  59. 6
      src/core/lib/transport/metadata.h
  60. 172
      src/core/lib/transport/static_metadata.cc
  61. 1
      src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc
  62. 78
      src/core/tsi/ssl_transport_security.cc
  63. 3
      src/core/tsi/ssl_transport_security.h
  64. 5
      src/objective-c/GRPCClient/GRPCCall.m
  65. 2
      src/objective-c/manual_tests/main.m
  66. 21
      src/objective-c/tests/CronetTests/CoreCronetEnd2EndTests.mm
  67. 14
      src/objective-c/tests/CronetTests/CronetUnitTests.mm
  68. 3
      src/python/grpcio/grpc_core_dependencies.py
  69. 9
      templates/CMakeLists.txt.template
  70. 1
      templates/Makefile.template
  71. 8
      test/core/bad_ssl/bad_ssl_test.cc
  72. 17
      test/core/client_channel/parse_address_with_named_scope_id_test.cc
  73. 11
      test/core/end2end/bad_server_response_test.cc
  74. 12
      test/core/end2end/connection_refused_test.cc
  75. 25
      test/core/end2end/dualstack_socket_test.cc
  76. 22
      test/core/end2end/fixtures/h2_census.cc
  77. 33
      test/core/end2end/fixtures/h2_compress.cc
  78. 23
      test/core/end2end/fixtures/h2_fakesec.cc
  79. 21
      test/core/end2end/fixtures/h2_full+pipe.cc
  80. 21
      test/core/end2end/fixtures/h2_full+trace.cc
  81. 24
      test/core/end2end/fixtures/h2_full+workarounds.cc
  82. 21
      test/core/end2end/fixtures/h2_full.cc
  83. 27
      test/core/end2end/fixtures/h2_http_proxy.cc
  84. 4
      test/core/end2end/fixtures/h2_local_ipv4.cc
  85. 4
      test/core/end2end/fixtures/h2_local_ipv6.cc
  86. 8
      test/core/end2end/fixtures/h2_local_uds.cc
  87. 25
      test/core/end2end/fixtures/h2_oauth2.cc
  88. 1
      test/core/end2end/fixtures/h2_proxy.cc
  89. 25
      test/core/end2end/fixtures/h2_spiffe.cc
  90. 22
      test/core/end2end/fixtures/h2_ssl.cc
  91. 24
      test/core/end2end/fixtures/h2_ssl_cred_reload.cc
  92. 1
      test/core/end2end/fixtures/h2_ssl_proxy.cc
  93. 1
      test/core/end2end/fixtures/h2_uds.cc
  94. 14
      test/core/end2end/fixtures/http_proxy_fixture.cc
  95. 1
      test/core/end2end/fixtures/inproc.cc
  96. 15
      test/core/end2end/fixtures/local_util.cc
  97. 6
      test/core/end2end/fixtures/local_util.h
  98. 29
      test/core/end2end/fixtures/proxy.cc
  99. 22
      test/core/end2end/h2_ssl_cert_test.cc
  100. 15
      test/core/end2end/h2_ssl_session_reuse_test.cc
  101. Some files were not shown because too many files have changed in this diff Show More

10
BUILD

@ -559,7 +559,6 @@ grpc_cc_library(
"src/core/lib/gpr/env_linux.cc",
"src/core/lib/gpr/env_posix.cc",
"src/core/lib/gpr/env_windows.cc",
"src/core/lib/gpr/host_port.cc",
"src/core/lib/gpr/log.cc",
"src/core/lib/gpr/log_android.cc",
"src/core/lib/gpr/log_linux.cc",
@ -586,6 +585,7 @@ grpc_cc_library(
"src/core/lib/gprpp/arena.cc",
"src/core/lib/gprpp/fork.cc",
"src/core/lib/gprpp/global_config_env.cc",
"src/core/lib/gprpp/host_port.cc",
"src/core/lib/gprpp/thd_posix.cc",
"src/core/lib/gprpp/thd_windows.cc",
"src/core/lib/profiling/basic_timers.cc",
@ -595,7 +595,6 @@ grpc_cc_library(
"src/core/lib/gpr/alloc.h",
"src/core/lib/gpr/arena.h",
"src/core/lib/gpr/env.h",
"src/core/lib/gpr/host_port.h",
"src/core/lib/gpr/mpscq.h",
"src/core/lib/gpr/murmur_hash.h",
"src/core/lib/gpr/spinlock.h",
@ -612,14 +611,16 @@ grpc_cc_library(
"src/core/lib/gprpp/arena.h",
"src/core/lib/gprpp/atomic.h",
"src/core/lib/gprpp/fork.h",
"src/core/lib/gprpp/global_config.h",
"src/core/lib/gprpp/global_config_custom.h",
"src/core/lib/gprpp/global_config_env.h",
"src/core/lib/gprpp/global_config_generic.h",
"src/core/lib/gprpp/global_config.h",
"src/core/lib/gprpp/host_port.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/map.h",
"src/core/lib/gprpp/memory.h",
"src/core/lib/gprpp/pair.h",
"src/core/lib/gprpp/string_view.h",
"src/core/lib/gprpp/sync.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/profiling/timers.h",
@ -628,6 +629,7 @@ grpc_cc_library(
public_hdrs = GPR_PUBLIC_HDRS,
deps = [
"gpr_codegen",
"grpc_codegen",
],
)
@ -784,6 +786,7 @@ grpc_cc_library(
"src/core/lib/iomgr/exec_ctx.cc",
"src/core/lib/iomgr/executor.cc",
"src/core/lib/iomgr/executor/mpmcqueue.cc",
"src/core/lib/iomgr/executor/threadpool.cc",
"src/core/lib/iomgr/fork_posix.cc",
"src/core/lib/iomgr/fork_windows.cc",
"src/core/lib/iomgr/gethostname_fallback.cc",
@ -942,6 +945,7 @@ grpc_cc_library(
"src/core/lib/iomgr/exec_ctx.h",
"src/core/lib/iomgr/executor.h",
"src/core/lib/iomgr/executor/mpmcqueue.h",
"src/core/lib/iomgr/executor/threadpool.h",
"src/core/lib/iomgr/gethostname.h",
"src/core/lib/iomgr/gevent_util.h",
"src/core/lib/iomgr/grpc_if_nametoindex.h",

@ -141,8 +141,6 @@ config("grpc_config") {
"src/core/lib/gpr/env_linux.cc",
"src/core/lib/gpr/env_posix.cc",
"src/core/lib/gpr/env_windows.cc",
"src/core/lib/gpr/host_port.cc",
"src/core/lib/gpr/host_port.h",
"src/core/lib/gpr/log.cc",
"src/core/lib/gpr/log_android.cc",
"src/core/lib/gpr/log_linux.cc",
@ -189,6 +187,8 @@ config("grpc_config") {
"src/core/lib/gprpp/global_config_env.cc",
"src/core/lib/gprpp/global_config_env.h",
"src/core/lib/gprpp/global_config_generic.h",
"src/core/lib/gprpp/host_port.cc",
"src/core/lib/gprpp/host_port.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/map.h",
"src/core/lib/gprpp/memory.h",
@ -480,6 +480,7 @@ config("grpc_config") {
"src/core/lib/gprpp/orphanable.h",
"src/core/lib/gprpp/ref_counted.h",
"src/core/lib/gprpp/ref_counted_ptr.h",
"src/core/lib/gprpp/string_view.h",
"src/core/lib/http/format_request.cc",
"src/core/lib/http/format_request.h",
"src/core/lib/http/httpcli.cc",
@ -526,6 +527,8 @@ config("grpc_config") {
"src/core/lib/iomgr/executor.h",
"src/core/lib/iomgr/executor/mpmcqueue.cc",
"src/core/lib/iomgr/executor/mpmcqueue.h",
"src/core/lib/iomgr/executor/threadpool.cc",
"src/core/lib/iomgr/executor/threadpool.h",
"src/core/lib/iomgr/fork_posix.cc",
"src/core/lib/iomgr/fork_windows.cc",
"src/core/lib/iomgr/gethostname.h",
@ -1174,7 +1177,6 @@ config("grpc_config") {
"src/core/lib/gpr/alloc.h",
"src/core/lib/gpr/arena.h",
"src/core/lib/gpr/env.h",
"src/core/lib/gpr/host_port.h",
"src/core/lib/gpr/mpscq.h",
"src/core/lib/gpr/murmur_hash.h",
"src/core/lib/gpr/spinlock.h",
@ -1196,6 +1198,7 @@ config("grpc_config") {
"src/core/lib/gprpp/global_config_custom.h",
"src/core/lib/gprpp/global_config_env.h",
"src/core/lib/gprpp/global_config_generic.h",
"src/core/lib/gprpp/host_port.h",
"src/core/lib/gprpp/inlined_vector.h",
"src/core/lib/gprpp/manual_constructor.h",
"src/core/lib/gprpp/map.h",
@ -1205,6 +1208,7 @@ config("grpc_config") {
"src/core/lib/gprpp/pair.h",
"src/core/lib/gprpp/ref_counted.h",
"src/core/lib/gprpp/ref_counted_ptr.h",
"src/core/lib/gprpp/string_view.h",
"src/core/lib/gprpp/sync.h",
"src/core/lib/gprpp/thd.h",
"src/core/lib/http/format_request.h",
@ -1230,6 +1234,7 @@ config("grpc_config") {
"src/core/lib/iomgr/exec_ctx.h",
"src/core/lib/iomgr/executor.h",
"src/core/lib/iomgr/executor/mpmcqueue.h",
"src/core/lib/iomgr/executor/threadpool.h",
"src/core/lib/iomgr/gethostname.h",
"src/core/lib/iomgr/grpc_if_nametoindex.h",
"src/core/lib/iomgr/internal_errqueue.h",

@ -428,6 +428,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_c tcp_server_posix_test)
endif()
add_dependencies(buildtests_c tcp_server_uv_test)
add_dependencies(buildtests_c threadpool_test)
add_dependencies(buildtests_c time_averaged_stats_test)
add_dependencies(buildtests_c timeout_encoding_test)
add_dependencies(buildtests_c timer_heap_test)
@ -715,6 +716,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
add_dependencies(buildtests_cxx streaming_throughput_test)
endif()
add_dependencies(buildtests_cxx stress_test)
add_dependencies(buildtests_cxx string_view_test)
add_dependencies(buildtests_cxx thread_manager_test)
add_dependencies(buildtests_cxx thread_stress_test)
if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX)
@ -863,7 +865,6 @@ add_library(gpr
src/core/lib/gpr/env_linux.cc
src/core/lib/gpr/env_posix.cc
src/core/lib/gpr/env_windows.cc
src/core/lib/gpr/host_port.cc
src/core/lib/gpr/log.cc
src/core/lib/gpr/log_android.cc
src/core/lib/gpr/log_linux.cc
@ -890,6 +891,7 @@ add_library(gpr
src/core/lib/gprpp/arena.cc
src/core/lib/gprpp/fork.cc
src/core/lib/gprpp/global_config_env.cc
src/core/lib/gprpp/host_port.cc
src/core/lib/gprpp/thd_posix.cc
src/core/lib/gprpp/thd_windows.cc
src/core/lib/profiling/basic_timers.cc
@ -1031,6 +1033,7 @@ add_library(grpc
src/core/lib/iomgr/exec_ctx.cc
src/core/lib/iomgr/executor.cc
src/core/lib/iomgr/executor/mpmcqueue.cc
src/core/lib/iomgr/executor/threadpool.cc
src/core/lib/iomgr/fork_posix.cc
src/core/lib/iomgr/fork_windows.cc
src/core/lib/iomgr/gethostname_fallback.cc
@ -1366,6 +1369,9 @@ target_link_libraries(grpc
${_gRPC_ALLTARGETS_LIBRARIES}
gpr
)
if (_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc "-framework CoreFoundation")
endif()
foreach(_hdr
include/grpc/impl/codegen/byte_buffer.h
@ -1467,6 +1473,7 @@ add_library(grpc_cronet
src/core/lib/iomgr/exec_ctx.cc
src/core/lib/iomgr/executor.cc
src/core/lib/iomgr/executor/mpmcqueue.cc
src/core/lib/iomgr/executor/threadpool.cc
src/core/lib/iomgr/fork_posix.cc
src/core/lib/iomgr/fork_windows.cc
src/core/lib/iomgr/gethostname_fallback.cc
@ -1765,6 +1772,9 @@ target_link_libraries(grpc_cronet
${_gRPC_ALLTARGETS_LIBRARIES}
gpr
)
if (_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc_cronet "-framework CoreFoundation")
endif()
foreach(_hdr
include/grpc/impl/codegen/byte_buffer.h
@ -1885,6 +1895,7 @@ add_library(grpc_test_util
src/core/lib/iomgr/exec_ctx.cc
src/core/lib/iomgr/executor.cc
src/core/lib/iomgr/executor/mpmcqueue.cc
src/core/lib/iomgr/executor/threadpool.cc
src/core/lib/iomgr/fork_posix.cc
src/core/lib/iomgr/fork_windows.cc
src/core/lib/iomgr/gethostname_fallback.cc
@ -2095,6 +2106,9 @@ target_link_libraries(grpc_test_util
gpr
grpc
)
if (_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc_test_util "-framework CoreFoundation")
endif()
foreach(_hdr
include/grpc/support/alloc.h
@ -2216,6 +2230,7 @@ add_library(grpc_test_util_unsecure
src/core/lib/iomgr/exec_ctx.cc
src/core/lib/iomgr/executor.cc
src/core/lib/iomgr/executor/mpmcqueue.cc
src/core/lib/iomgr/executor/threadpool.cc
src/core/lib/iomgr/fork_posix.cc
src/core/lib/iomgr/fork_windows.cc
src/core/lib/iomgr/gethostname_fallback.cc
@ -2426,6 +2441,9 @@ target_link_libraries(grpc_test_util_unsecure
gpr
grpc_unsecure
)
if (_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc_test_util_unsecure "-framework CoreFoundation")
endif()
foreach(_hdr
include/grpc/support/alloc.h
@ -2523,6 +2541,7 @@ add_library(grpc_unsecure
src/core/lib/iomgr/exec_ctx.cc
src/core/lib/iomgr/executor.cc
src/core/lib/iomgr/executor/mpmcqueue.cc
src/core/lib/iomgr/executor/threadpool.cc
src/core/lib/iomgr/fork_posix.cc
src/core/lib/iomgr/fork_windows.cc
src/core/lib/iomgr/gethostname_fallback.cc
@ -2780,6 +2799,9 @@ target_link_libraries(grpc_unsecure
${_gRPC_ALLTARGETS_LIBRARIES}
gpr
)
if (_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc_unsecure "-framework CoreFoundation")
endif()
foreach(_hdr
include/grpc/impl/codegen/byte_buffer.h
@ -3551,6 +3573,7 @@ add_library(grpc++_cronet
src/core/lib/iomgr/exec_ctx.cc
src/core/lib/iomgr/executor.cc
src/core/lib/iomgr/executor/mpmcqueue.cc
src/core/lib/iomgr/executor/threadpool.cc
src/core/lib/iomgr/fork_posix.cc
src/core/lib/iomgr/fork_windows.cc
src/core/lib/iomgr/gethostname_fallback.cc
@ -3737,6 +3760,9 @@ target_link_libraries(grpc++_cronet
grpc_cronet
grpc
)
if (_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(grpc++_cronet "-framework CoreFoundation")
endif()
foreach(_hdr
include/grpc++/alarm.h
@ -5779,58 +5805,6 @@ endif()
endif (gRPC_BUILD_CSHARP_EXT)
if (gRPC_BUILD_TESTS)
add_library(upb
third_party/upb/google/protobuf/descriptor.upb.c
third_party/upb/upb/decode.c
third_party/upb/upb/def.c
third_party/upb/upb/encode.c
third_party/upb/upb/handlers.c
third_party/upb/upb/msg.c
third_party/upb/upb/msgfactory.c
third_party/upb/upb/sink.c
third_party/upb/upb/table.c
third_party/upb/upb/upb.c
)
if(WIN32 AND MSVC)
set_target_properties(upb PROPERTIES COMPILE_PDB_NAME "upb"
COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
if (gRPC_INSTALL)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/upb.pdb
DESTINATION ${gRPC_INSTALL_LIBDIR} OPTIONAL
)
endif()
endif()
target_include_directories(upb
PUBLIC $<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
)
# avoid dependency on libstdc++
if (_gRPC_CORE_NOSTDCXX_FLAGS)
set_target_properties(upb PROPERTIES LINKER_LANGUAGE C)
# only use the flags for C++ source files
target_compile_options(upb PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${_gRPC_CORE_NOSTDCXX_FLAGS}>)
endif()
target_link_libraries(upb
${_gRPC_SSL_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_library(bad_client_test
test/core/bad_client/bad_client.cc
)
@ -7551,7 +7525,7 @@ endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(gpr_host_port_test
test/core/gpr/host_port_test.cc
test/core/gprpp/host_port_test.cc
)
@ -10541,6 +10515,40 @@ target_link_libraries(tcp_server_uv_test
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(threadpool_test
test/core/iomgr/threadpool_test.cc
)
target_include_directories(threadpool_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
)
target_link_libraries(threadpool_test
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
grpc
gpr
)
# avoid dependency on libstdc++
if (_gRPC_CORE_NOSTDCXX_FLAGS)
set_target_properties(threadpool_test PROPERTIES LINKER_LANGUAGE C)
target_compile_options(threadpool_test PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${_gRPC_CORE_NOSTDCXX_FLAGS}>)
endif()
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(time_averaged_stats_test
test/core/iomgr/time_averaged_stats_test.cc
)
@ -16718,6 +16726,45 @@ target_link_libraries(stress_test
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)
add_executable(string_view_test
test/core/gprpp/string_view_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(string_view_test
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${_gRPC_SSL_INCLUDE_DIR}
PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR}
PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR}
PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR}
PRIVATE ${_gRPC_CARES_INCLUDE_DIR}
PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR}
PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR}
PRIVATE third_party/googletest/googletest/include
PRIVATE third_party/googletest/googletest
PRIVATE third_party/googletest/googlemock/include
PRIVATE third_party/googletest/googlemock
PRIVATE ${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(string_view_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc_test_util
grpc++
grpc
gpr
${_gRPC_GFLAGS_LIBRARIES}
)
endif (gRPC_BUILD_TESTS)
if (gRPC_BUILD_TESTS)

@ -351,6 +351,7 @@ CFLAGS += -std=c99 -Wsign-conversion -Wconversion $(W_SHADOW) $(W_EXTRA_SEMI)
CXXFLAGS += -std=c++11
ifeq ($(SYSTEM),Darwin)
CXXFLAGS += -stdlib=libc++
LDFLAGS += -framework CoreFoundation
endif
CXXFLAGS += -Wnon-virtual-dtor
CPPFLAGS += -g -Wall -Wextra -Werror -Wno-long-long -Wno-unused-parameter -DOSATOMIC_USE_INLINED=1 -Wno-deprecated-declarations -Ithird_party/nanopb -DPB_FIELD_32BIT
@ -1132,6 +1133,7 @@ tcp_client_uv_test: $(BINDIR)/$(CONFIG)/tcp_client_uv_test
tcp_posix_test: $(BINDIR)/$(CONFIG)/tcp_posix_test
tcp_server_posix_test: $(BINDIR)/$(CONFIG)/tcp_server_posix_test
tcp_server_uv_test: $(BINDIR)/$(CONFIG)/tcp_server_uv_test
threadpool_test: $(BINDIR)/$(CONFIG)/threadpool_test
time_averaged_stats_test: $(BINDIR)/$(CONFIG)/time_averaged_stats_test
timeout_encoding_test: $(BINDIR)/$(CONFIG)/timeout_encoding_test
timer_heap_test: $(BINDIR)/$(CONFIG)/timer_heap_test
@ -1280,6 +1282,7 @@ status_metadata_test: $(BINDIR)/$(CONFIG)/status_metadata_test
status_util_test: $(BINDIR)/$(CONFIG)/status_util_test
streaming_throughput_test: $(BINDIR)/$(CONFIG)/streaming_throughput_test
stress_test: $(BINDIR)/$(CONFIG)/stress_test
string_view_test: $(BINDIR)/$(CONFIG)/string_view_test
thread_manager_test: $(BINDIR)/$(CONFIG)/thread_manager_test
thread_stress_test: $(BINDIR)/$(CONFIG)/thread_stress_test
time_change_test: $(BINDIR)/$(CONFIG)/time_change_test
@ -1551,6 +1554,7 @@ buildtests_c: privatelibs_c \
$(BINDIR)/$(CONFIG)/tcp_posix_test \
$(BINDIR)/$(CONFIG)/tcp_server_posix_test \
$(BINDIR)/$(CONFIG)/tcp_server_uv_test \
$(BINDIR)/$(CONFIG)/threadpool_test \
$(BINDIR)/$(CONFIG)/time_averaged_stats_test \
$(BINDIR)/$(CONFIG)/timeout_encoding_test \
$(BINDIR)/$(CONFIG)/timer_heap_test \
@ -1748,6 +1752,7 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/status_util_test \
$(BINDIR)/$(CONFIG)/streaming_throughput_test \
$(BINDIR)/$(CONFIG)/stress_test \
$(BINDIR)/$(CONFIG)/string_view_test \
$(BINDIR)/$(CONFIG)/thread_manager_test \
$(BINDIR)/$(CONFIG)/thread_stress_test \
$(BINDIR)/$(CONFIG)/time_change_test \
@ -1911,6 +1916,7 @@ buildtests_cxx: privatelibs_cxx \
$(BINDIR)/$(CONFIG)/status_util_test \
$(BINDIR)/$(CONFIG)/streaming_throughput_test \
$(BINDIR)/$(CONFIG)/stress_test \
$(BINDIR)/$(CONFIG)/string_view_test \
$(BINDIR)/$(CONFIG)/thread_manager_test \
$(BINDIR)/$(CONFIG)/thread_stress_test \
$(BINDIR)/$(CONFIG)/time_change_test \
@ -2181,6 +2187,8 @@ test_c: buildtests_c
$(Q) $(BINDIR)/$(CONFIG)/tcp_server_posix_test || ( echo test tcp_server_posix_test failed ; exit 1 )
$(E) "[RUN] Testing tcp_server_uv_test"
$(Q) $(BINDIR)/$(CONFIG)/tcp_server_uv_test || ( echo test tcp_server_uv_test failed ; exit 1 )
$(E) "[RUN] Testing threadpool_test"
$(Q) $(BINDIR)/$(CONFIG)/threadpool_test || ( echo test threadpool_test failed ; exit 1 )
$(E) "[RUN] Testing time_averaged_stats_test"
$(Q) $(BINDIR)/$(CONFIG)/time_averaged_stats_test || ( echo test time_averaged_stats_test failed ; exit 1 )
$(E) "[RUN] Testing timeout_encoding_test"
@ -2441,6 +2449,8 @@ test_cxx: buildtests_cxx
$(Q) $(BINDIR)/$(CONFIG)/status_util_test || ( echo test status_util_test failed ; exit 1 )
$(E) "[RUN] Testing streaming_throughput_test"
$(Q) $(BINDIR)/$(CONFIG)/streaming_throughput_test || ( echo test streaming_throughput_test failed ; exit 1 )
$(E) "[RUN] Testing string_view_test"
$(Q) $(BINDIR)/$(CONFIG)/string_view_test || ( echo test string_view_test failed ; exit 1 )
$(E) "[RUN] Testing thread_manager_test"
$(Q) $(BINDIR)/$(CONFIG)/thread_manager_test || ( echo test thread_manager_test failed ; exit 1 )
$(E) "[RUN] Testing thread_stress_test"
@ -3387,7 +3397,6 @@ LIBGPR_SRC = \
src/core/lib/gpr/env_linux.cc \
src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/host_port.cc \
src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.cc \
@ -3414,6 +3423,7 @@ LIBGPR_SRC = \
src/core/lib/gprpp/arena.cc \
src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/global_config_env.cc \
src/core/lib/gprpp/host_port.cc \
src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \
src/core/lib/profiling/basic_timers.cc \
@ -3534,6 +3544,7 @@ LIBGRPC_SRC = \
src/core/lib/iomgr/exec_ctx.cc \
src/core/lib/iomgr/executor.cc \
src/core/lib/iomgr/executor/mpmcqueue.cc \
src/core/lib/iomgr/executor/threadpool.cc \
src/core/lib/iomgr/fork_posix.cc \
src/core/lib/iomgr/fork_windows.cc \
src/core/lib/iomgr/gethostname_fallback.cc \
@ -3964,6 +3975,7 @@ LIBGRPC_CRONET_SRC = \
src/core/lib/iomgr/exec_ctx.cc \
src/core/lib/iomgr/executor.cc \
src/core/lib/iomgr/executor/mpmcqueue.cc \
src/core/lib/iomgr/executor/threadpool.cc \
src/core/lib/iomgr/fork_posix.cc \
src/core/lib/iomgr/fork_windows.cc \
src/core/lib/iomgr/gethostname_fallback.cc \
@ -4375,6 +4387,7 @@ LIBGRPC_TEST_UTIL_SRC = \
src/core/lib/iomgr/exec_ctx.cc \
src/core/lib/iomgr/executor.cc \
src/core/lib/iomgr/executor/mpmcqueue.cc \
src/core/lib/iomgr/executor/threadpool.cc \
src/core/lib/iomgr/fork_posix.cc \
src/core/lib/iomgr/fork_windows.cc \
src/core/lib/iomgr/gethostname_fallback.cc \
@ -4693,6 +4706,7 @@ LIBGRPC_TEST_UTIL_UNSECURE_SRC = \
src/core/lib/iomgr/exec_ctx.cc \
src/core/lib/iomgr/executor.cc \
src/core/lib/iomgr/executor/mpmcqueue.cc \
src/core/lib/iomgr/executor/threadpool.cc \
src/core/lib/iomgr/fork_posix.cc \
src/core/lib/iomgr/fork_windows.cc \
src/core/lib/iomgr/gethostname_fallback.cc \
@ -4974,6 +4988,7 @@ LIBGRPC_UNSECURE_SRC = \
src/core/lib/iomgr/exec_ctx.cc \
src/core/lib/iomgr/executor.cc \
src/core/lib/iomgr/executor/mpmcqueue.cc \
src/core/lib/iomgr/executor/threadpool.cc \
src/core/lib/iomgr/fork_posix.cc \
src/core/lib/iomgr/fork_windows.cc \
src/core/lib/iomgr/gethostname_fallback.cc \
@ -5975,6 +5990,7 @@ LIBGRPC++_CRONET_SRC = \
src/core/lib/iomgr/exec_ctx.cc \
src/core/lib/iomgr/executor.cc \
src/core/lib/iomgr/executor/mpmcqueue.cc \
src/core/lib/iomgr/executor/threadpool.cc \
src/core/lib/iomgr/fork_posix.cc \
src/core/lib/iomgr/fork_windows.cc \
src/core/lib/iomgr/gethostname_fallback.cc \
@ -10267,7 +10283,7 @@ endif
GPR_HOST_PORT_TEST_SRC = \
test/core/gpr/host_port_test.cc \
test/core/gprpp/host_port_test.cc \
GPR_HOST_PORT_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GPR_HOST_PORT_TEST_SRC))))
ifeq ($(NO_SECURE),true)
@ -10287,7 +10303,7 @@ $(BINDIR)/$(CONFIG)/gpr_host_port_test: $(GPR_HOST_PORT_TEST_OBJS) $(LIBDIR)/$(C
endif
$(OBJDIR)/$(CONFIG)/test/core/gpr/host_port_test.o: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a
$(OBJDIR)/$(CONFIG)/test/core/gprpp/host_port_test.o: $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a
deps_gpr_host_port_test: $(GPR_HOST_PORT_TEST_OBJS:.o=.dep)
@ -13420,6 +13436,38 @@ endif
endif
THREADPOOL_TEST_SRC = \
test/core/iomgr/threadpool_test.cc \
THREADPOOL_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(THREADPOOL_TEST_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/threadpool_test: openssl_dep_error
else
$(BINDIR)/$(CONFIG)/threadpool_test: $(THREADPOOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LD) $(LDFLAGS) $(THREADPOOL_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/threadpool_test
endif
$(OBJDIR)/$(CONFIG)/test/core/iomgr/threadpool_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_threadpool_test: $(THREADPOOL_TEST_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(THREADPOOL_TEST_OBJS:.o=.dep)
endif
endif
TIME_AVERAGED_STATS_TEST_SRC = \
test/core/iomgr/time_averaged_stats_test.cc \
@ -19747,6 +19795,49 @@ $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_test.o: $(GENDIR)/src/proto/grpc/tes
$(OBJDIR)/$(CONFIG)/test/cpp/util/metrics_server.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc
STRING_VIEW_TEST_SRC = \
test/core/gprpp/string_view_test.cc \
STRING_VIEW_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STRING_VIEW_TEST_SRC))))
ifeq ($(NO_SECURE),true)
# You can't build secure targets if you don't have OpenSSL.
$(BINDIR)/$(CONFIG)/string_view_test: openssl_dep_error
else
ifeq ($(NO_PROTOBUF),true)
# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+.
$(BINDIR)/$(CONFIG)/string_view_test: protobuf_dep_error
else
$(BINDIR)/$(CONFIG)/string_view_test: $(PROTOBUF_DEP) $(STRING_VIEW_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(STRING_VIEW_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/string_view_test
endif
endif
$(OBJDIR)/$(CONFIG)/test/core/gprpp/string_view_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_string_view_test: $(STRING_VIEW_TEST_OBJS:.o=.dep)
ifneq ($(NO_SECURE),true)
ifneq ($(NO_DEPS),true)
-include $(STRING_VIEW_TEST_OBJS:.o=.dep)
endif
endif
THREAD_MANAGER_TEST_SRC = \
test/cpp/thread_manager/thread_manager_test.cc \

@ -122,7 +122,6 @@ filegroups:
- src/core/lib/gpr/env_linux.cc
- src/core/lib/gpr/env_posix.cc
- src/core/lib/gpr/env_windows.cc
- src/core/lib/gpr/host_port.cc
- src/core/lib/gpr/log.cc
- src/core/lib/gpr/log_android.cc
- src/core/lib/gpr/log_linux.cc
@ -149,6 +148,7 @@ filegroups:
- src/core/lib/gprpp/arena.cc
- src/core/lib/gprpp/fork.cc
- src/core/lib/gprpp/global_config_env.cc
- src/core/lib/gprpp/host_port.cc
- src/core/lib/gprpp/thd_posix.cc
- src/core/lib/gprpp/thd_windows.cc
- src/core/lib/profiling/basic_timers.cc
@ -178,7 +178,6 @@ filegroups:
- src/core/lib/gpr/alloc.h
- src/core/lib/gpr/arena.h
- src/core/lib/gpr/env.h
- src/core/lib/gpr/host_port.h
- src/core/lib/gpr/mpscq.h
- src/core/lib/gpr/murmur_hash.h
- src/core/lib/gpr/spinlock.h
@ -199,6 +198,7 @@ filegroups:
- src/core/lib/gprpp/global_config_custom.h
- src/core/lib/gprpp/global_config_env.h
- src/core/lib/gprpp/global_config_generic.h
- src/core/lib/gprpp/host_port.h
- src/core/lib/gprpp/manual_constructor.h
- src/core/lib/gprpp/map.h
- src/core/lib/gprpp/memory.h
@ -281,6 +281,7 @@ filegroups:
- src/core/lib/iomgr/exec_ctx.cc
- src/core/lib/iomgr/executor.cc
- src/core/lib/iomgr/executor/mpmcqueue.cc
- src/core/lib/iomgr/executor/threadpool.cc
- src/core/lib/iomgr/fork_posix.cc
- src/core/lib/iomgr/fork_windows.cc
- src/core/lib/iomgr/gethostname_fallback.cc
@ -445,6 +446,7 @@ filegroups:
- src/core/lib/gprpp/orphanable.h
- src/core/lib/gprpp/ref_counted.h
- src/core/lib/gprpp/ref_counted_ptr.h
- src/core/lib/gprpp/string_view.h
- src/core/lib/http/format_request.h
- src/core/lib/http/httpcli.h
- src/core/lib/http/parser.h
@ -468,6 +470,7 @@ filegroups:
- src/core/lib/iomgr/exec_ctx.h
- src/core/lib/iomgr/executor.h
- src/core/lib/iomgr/executor/mpmcqueue.h
- src/core/lib/iomgr/executor/threadpool.h
- src/core/lib/iomgr/gethostname.h
- src/core/lib/iomgr/grpc_if_nametoindex.h
- src/core/lib/iomgr/internal_errqueue.h
@ -2641,7 +2644,7 @@ targets:
build: test
language: c
src:
- test/core/gpr/host_port_test.cc
- test/core/gprpp/host_port_test.cc
deps:
- gpr
- grpc_test_util_unsecure
@ -3732,6 +3735,16 @@ targets:
- gpr
exclude_iomgrs:
- native
- name: threadpool_test
build: test
language: c
src:
- test/core/iomgr/threadpool_test.cc
deps:
- grpc_test_util
- grpc
- gpr
uses_polling: false
- name: time_averaged_stats_test
build: test
language: c
@ -5786,6 +5799,19 @@ targets:
- grpc
- gpr
- grpc++_test_config
- name: string_view_test
gtest: true
build: test
language: c++
src:
- test/core/gprpp/string_view_test.cc
deps:
- grpc_test_util
- grpc++
- grpc
- gpr
uses:
- grpc++_test
- name: thread_manager_test
build: test
language: c++

@ -53,7 +53,6 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gpr/env_linux.cc \
src/core/lib/gpr/env_posix.cc \
src/core/lib/gpr/env_windows.cc \
src/core/lib/gpr/host_port.cc \
src/core/lib/gpr/log.cc \
src/core/lib/gpr/log_android.cc \
src/core/lib/gpr/log_linux.cc \
@ -80,6 +79,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/gprpp/arena.cc \
src/core/lib/gprpp/fork.cc \
src/core/lib/gprpp/global_config_env.cc \
src/core/lib/gprpp/host_port.cc \
src/core/lib/gprpp/thd_posix.cc \
src/core/lib/gprpp/thd_windows.cc \
src/core/lib/profiling/basic_timers.cc \
@ -128,6 +128,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/iomgr/exec_ctx.cc \
src/core/lib/iomgr/executor.cc \
src/core/lib/iomgr/executor/mpmcqueue.cc \
src/core/lib/iomgr/executor/threadpool.cc \
src/core/lib/iomgr/fork_posix.cc \
src/core/lib/iomgr/fork_windows.cc \
src/core/lib/iomgr/gethostname_fallback.cc \

@ -28,7 +28,6 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gpr\\env_linux.cc " +
"src\\core\\lib\\gpr\\env_posix.cc " +
"src\\core\\lib\\gpr\\env_windows.cc " +
"src\\core\\lib\\gpr\\host_port.cc " +
"src\\core\\lib\\gpr\\log.cc " +
"src\\core\\lib\\gpr\\log_android.cc " +
"src\\core\\lib\\gpr\\log_linux.cc " +
@ -55,6 +54,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\gprpp\\arena.cc " +
"src\\core\\lib\\gprpp\\fork.cc " +
"src\\core\\lib\\gprpp\\global_config_env.cc " +
"src\\core\\lib\\gprpp\\host_port.cc " +
"src\\core\\lib\\gprpp\\thd_posix.cc " +
"src\\core\\lib\\gprpp\\thd_windows.cc " +
"src\\core\\lib\\profiling\\basic_timers.cc " +
@ -103,6 +103,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\iomgr\\exec_ctx.cc " +
"src\\core\\lib\\iomgr\\executor.cc " +
"src\\core\\lib\\iomgr\\executor\\mpmcqueue.cc " +
"src\\core\\lib\\iomgr\\executor\\threadpool.cc " +
"src\\core\\lib\\iomgr\\fork_posix.cc " +
"src\\core\\lib\\iomgr\\fork_windows.cc " +
"src\\core\\lib\\iomgr\\gethostname_fallback.cc " +

@ -262,7 +262,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/arena.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/host_port.h',
'src/core/lib/gpr/mpscq.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
@ -283,6 +282,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/global_config_custom.h',
'src/core/lib/gprpp/global_config_env.h',
'src/core/lib/gprpp/global_config_generic.h',
'src/core/lib/gprpp/host_port.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
@ -445,6 +445,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/orphanable.h',
'src/core/lib/gprpp/ref_counted.h',
'src/core/lib/gprpp/ref_counted_ptr.h',
'src/core/lib/gprpp/string_view.h',
'src/core/lib/http/format_request.h',
'src/core/lib/http/httpcli.h',
'src/core/lib/http/parser.h',
@ -468,6 +469,7 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/exec_ctx.h',
'src/core/lib/iomgr/executor.h',
'src/core/lib/iomgr/executor/mpmcqueue.h',
'src/core/lib/iomgr/executor/threadpool.h',
'src/core/lib/iomgr/gethostname.h',
'src/core/lib/iomgr/grpc_if_nametoindex.h',
'src/core/lib/iomgr/internal_errqueue.h',
@ -593,7 +595,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/arena.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/host_port.h',
'src/core/lib/gpr/mpscq.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
@ -614,6 +615,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/global_config_custom.h',
'src/core/lib/gprpp/global_config_env.h',
'src/core/lib/gprpp/global_config_generic.h',
'src/core/lib/gprpp/host_port.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
@ -650,6 +652,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/orphanable.h',
'src/core/lib/gprpp/ref_counted.h',
'src/core/lib/gprpp/ref_counted_ptr.h',
'src/core/lib/gprpp/string_view.h',
'src/core/lib/http/format_request.h',
'src/core/lib/http/httpcli.h',
'src/core/lib/http/parser.h',
@ -673,6 +676,7 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/exec_ctx.h',
'src/core/lib/iomgr/executor.h',
'src/core/lib/iomgr/executor/mpmcqueue.h',
'src/core/lib/iomgr/executor/threadpool.h',
'src/core/lib/iomgr/gethostname.h',
'src/core/lib/iomgr/grpc_if_nametoindex.h',
'src/core/lib/iomgr/internal_errqueue.h',

@ -191,7 +191,6 @@ Pod::Spec.new do |s|
ss.source_files = 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/arena.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/host_port.h',
'src/core/lib/gpr/mpscq.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
@ -212,6 +211,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/global_config_custom.h',
'src/core/lib/gprpp/global_config_env.h',
'src/core/lib/gprpp/global_config_generic.h',
'src/core/lib/gprpp/host_port.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
@ -228,7 +228,6 @@ Pod::Spec.new do |s|
'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/host_port.cc',
'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.cc',
@ -255,6 +254,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/arena.cc',
'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc',
'src/core/lib/gprpp/host_port.cc',
'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc',
@ -414,6 +414,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/orphanable.h',
'src/core/lib/gprpp/ref_counted.h',
'src/core/lib/gprpp/ref_counted_ptr.h',
'src/core/lib/gprpp/string_view.h',
'src/core/lib/http/format_request.h',
'src/core/lib/http/httpcli.h',
'src/core/lib/http/parser.h',
@ -437,6 +438,7 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/exec_ctx.h',
'src/core/lib/iomgr/executor.h',
'src/core/lib/iomgr/executor/mpmcqueue.h',
'src/core/lib/iomgr/executor/threadpool.h',
'src/core/lib/iomgr/gethostname.h',
'src/core/lib/iomgr/grpc_if_nametoindex.h',
'src/core/lib/iomgr/internal_errqueue.h',
@ -591,6 +593,7 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/exec_ctx.cc',
'src/core/lib/iomgr/executor.cc',
'src/core/lib/iomgr/executor/mpmcqueue.cc',
'src/core/lib/iomgr/executor/threadpool.cc',
'src/core/lib/iomgr/fork_posix.cc',
'src/core/lib/iomgr/fork_windows.cc',
'src/core/lib/iomgr/gethostname_fallback.cc',
@ -886,7 +889,6 @@ Pod::Spec.new do |s|
ss.private_header_files = 'src/core/lib/gpr/alloc.h',
'src/core/lib/gpr/arena.h',
'src/core/lib/gpr/env.h',
'src/core/lib/gpr/host_port.h',
'src/core/lib/gpr/mpscq.h',
'src/core/lib/gpr/murmur_hash.h',
'src/core/lib/gpr/spinlock.h',
@ -907,6 +909,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/global_config_custom.h',
'src/core/lib/gprpp/global_config_env.h',
'src/core/lib/gprpp/global_config_generic.h',
'src/core/lib/gprpp/host_port.h',
'src/core/lib/gprpp/manual_constructor.h',
'src/core/lib/gprpp/map.h',
'src/core/lib/gprpp/memory.h',
@ -1069,6 +1072,7 @@ Pod::Spec.new do |s|
'src/core/lib/gprpp/orphanable.h',
'src/core/lib/gprpp/ref_counted.h',
'src/core/lib/gprpp/ref_counted_ptr.h',
'src/core/lib/gprpp/string_view.h',
'src/core/lib/http/format_request.h',
'src/core/lib/http/httpcli.h',
'src/core/lib/http/parser.h',
@ -1092,6 +1096,7 @@ Pod::Spec.new do |s|
'src/core/lib/iomgr/exec_ctx.h',
'src/core/lib/iomgr/executor.h',
'src/core/lib/iomgr/executor/mpmcqueue.h',
'src/core/lib/iomgr/executor/threadpool.h',
'src/core/lib/iomgr/gethostname.h',
'src/core/lib/iomgr/grpc_if_nametoindex.h',
'src/core/lib/iomgr/internal_errqueue.h',

@ -85,7 +85,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/alloc.h )
s.files += %w( src/core/lib/gpr/arena.h )
s.files += %w( src/core/lib/gpr/env.h )
s.files += %w( src/core/lib/gpr/host_port.h )
s.files += %w( src/core/lib/gpr/mpscq.h )
s.files += %w( src/core/lib/gpr/murmur_hash.h )
s.files += %w( src/core/lib/gpr/spinlock.h )
@ -106,6 +105,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/global_config_custom.h )
s.files += %w( src/core/lib/gprpp/global_config_env.h )
s.files += %w( src/core/lib/gprpp/global_config_generic.h )
s.files += %w( src/core/lib/gprpp/host_port.h )
s.files += %w( src/core/lib/gprpp/manual_constructor.h )
s.files += %w( src/core/lib/gprpp/map.h )
s.files += %w( src/core/lib/gprpp/memory.h )
@ -122,7 +122,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gpr/env_linux.cc )
s.files += %w( src/core/lib/gpr/env_posix.cc )
s.files += %w( src/core/lib/gpr/env_windows.cc )
s.files += %w( src/core/lib/gpr/host_port.cc )
s.files += %w( src/core/lib/gpr/log.cc )
s.files += %w( src/core/lib/gpr/log_android.cc )
s.files += %w( src/core/lib/gpr/log_linux.cc )
@ -149,6 +148,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/arena.cc )
s.files += %w( src/core/lib/gprpp/fork.cc )
s.files += %w( src/core/lib/gprpp/global_config_env.cc )
s.files += %w( src/core/lib/gprpp/host_port.cc )
s.files += %w( src/core/lib/gprpp/thd_posix.cc )
s.files += %w( src/core/lib/gprpp/thd_windows.cc )
s.files += %w( src/core/lib/profiling/basic_timers.cc )
@ -348,6 +348,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/gprpp/orphanable.h )
s.files += %w( src/core/lib/gprpp/ref_counted.h )
s.files += %w( src/core/lib/gprpp/ref_counted_ptr.h )
s.files += %w( src/core/lib/gprpp/string_view.h )
s.files += %w( src/core/lib/http/format_request.h )
s.files += %w( src/core/lib/http/httpcli.h )
s.files += %w( src/core/lib/http/parser.h )
@ -371,6 +372,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/iomgr/exec_ctx.h )
s.files += %w( src/core/lib/iomgr/executor.h )
s.files += %w( src/core/lib/iomgr/executor/mpmcqueue.h )
s.files += %w( src/core/lib/iomgr/executor/threadpool.h )
s.files += %w( src/core/lib/iomgr/gethostname.h )
s.files += %w( src/core/lib/iomgr/grpc_if_nametoindex.h )
s.files += %w( src/core/lib/iomgr/internal_errqueue.h )
@ -525,6 +527,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/iomgr/exec_ctx.cc )
s.files += %w( src/core/lib/iomgr/executor.cc )
s.files += %w( src/core/lib/iomgr/executor/mpmcqueue.cc )
s.files += %w( src/core/lib/iomgr/executor/threadpool.cc )
s.files += %w( src/core/lib/iomgr/fork_posix.cc )
s.files += %w( src/core/lib/iomgr/fork_windows.cc )
s.files += %w( src/core/lib/iomgr/gethostname_fallback.cc )

@ -226,7 +226,6 @@
'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/host_port.cc',
'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.cc',
@ -253,6 +252,7 @@
'src/core/lib/gprpp/arena.cc',
'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc',
'src/core/lib/gprpp/host_port.cc',
'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc',
@ -310,6 +310,7 @@
'src/core/lib/iomgr/exec_ctx.cc',
'src/core/lib/iomgr/executor.cc',
'src/core/lib/iomgr/executor/mpmcqueue.cc',
'src/core/lib/iomgr/executor/threadpool.cc',
'src/core/lib/iomgr/fork_posix.cc',
'src/core/lib/iomgr/fork_windows.cc',
'src/core/lib/iomgr/gethostname_fallback.cc',
@ -687,6 +688,7 @@
'src/core/lib/iomgr/exec_ctx.cc',
'src/core/lib/iomgr/executor.cc',
'src/core/lib/iomgr/executor/mpmcqueue.cc',
'src/core/lib/iomgr/executor/threadpool.cc',
'src/core/lib/iomgr/fork_posix.cc',
'src/core/lib/iomgr/fork_windows.cc',
'src/core/lib/iomgr/gethostname_fallback.cc',
@ -938,6 +940,7 @@
'src/core/lib/iomgr/exec_ctx.cc',
'src/core/lib/iomgr/executor.cc',
'src/core/lib/iomgr/executor/mpmcqueue.cc',
'src/core/lib/iomgr/executor/threadpool.cc',
'src/core/lib/iomgr/fork_posix.cc',
'src/core/lib/iomgr/fork_windows.cc',
'src/core/lib/iomgr/gethostname_fallback.cc',
@ -1165,6 +1168,7 @@
'src/core/lib/iomgr/exec_ctx.cc',
'src/core/lib/iomgr/executor.cc',
'src/core/lib/iomgr/executor/mpmcqueue.cc',
'src/core/lib/iomgr/executor/threadpool.cc',
'src/core/lib/iomgr/fork_posix.cc',
'src/core/lib/iomgr/fork_windows.cc',
'src/core/lib/iomgr/gethostname_fallback.cc',

@ -90,7 +90,6 @@
<file baseinstalldir="/" name="src/core/lib/gpr/alloc.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/arena.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/host_port.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/mpscq.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/murmur_hash.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/spinlock.h" role="src" />
@ -111,6 +110,7 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config_custom.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config_env.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config_generic.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/host_port.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/manual_constructor.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/map.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/memory.h" role="src" />
@ -127,7 +127,6 @@
<file baseinstalldir="/" name="src/core/lib/gpr/env_linux.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/env_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/host_port.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_android.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gpr/log_linux.cc" role="src" />
@ -154,6 +153,7 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/arena.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/fork.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/global_config_env.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/host_port.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/thd_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/thd_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/profiling/basic_timers.cc" role="src" />
@ -353,6 +353,7 @@
<file baseinstalldir="/" name="src/core/lib/gprpp/orphanable.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/ref_counted.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/ref_counted_ptr.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/gprpp/string_view.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/http/format_request.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/http/httpcli.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/http/parser.h" role="src" />
@ -376,6 +377,7 @@
<file baseinstalldir="/" name="src/core/lib/iomgr/exec_ctx.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/executor.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/executor/mpmcqueue.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/executor/threadpool.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/gethostname.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/grpc_if_nametoindex.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/internal_errqueue.h" role="src" />
@ -530,6 +532,7 @@
<file baseinstalldir="/" name="src/core/lib/iomgr/exec_ctx.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/executor.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/executor/mpmcqueue.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/executor/threadpool.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/fork_posix.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/fork_windows.cc" role="src" />
<file baseinstalldir="/" name="src/core/lib/iomgr/gethostname_fallback.cc" role="src" />

@ -31,8 +31,8 @@
#include "src/core/ext/filters/client_channel/proxy_mapper_registry.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/slice/b64.h"
#include "src/core/lib/uri/uri_parser.h"
@ -126,17 +126,18 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,
if (no_proxy_str != nullptr) {
static const char* NO_PROXY_SEPARATOR = ",";
bool use_proxy = true;
char* server_host;
char* server_port;
if (!gpr_split_host_port(uri->path[0] == '/' ? uri->path + 1 : uri->path,
&server_host, &server_port)) {
grpc_core::UniquePtr<char> server_host;
grpc_core::UniquePtr<char> server_port;
if (!grpc_core::SplitHostPort(
uri->path[0] == '/' ? uri->path + 1 : uri->path, &server_host,
&server_port)) {
gpr_log(GPR_INFO,
"unable to split host and port, not checking no_proxy list for "
"host '%s'",
server_uri);
gpr_free(no_proxy_str);
} else {
size_t uri_len = strlen(server_host);
size_t uri_len = strlen(server_host.get());
char** no_proxy_hosts;
size_t num_no_proxy_hosts;
gpr_string_split(no_proxy_str, NO_PROXY_SEPARATOR, &no_proxy_hosts,
@ -145,8 +146,8 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,
char* no_proxy_entry = no_proxy_hosts[i];
size_t no_proxy_len = strlen(no_proxy_entry);
if (no_proxy_len <= uri_len &&
gpr_stricmp(no_proxy_entry, &server_host[uri_len - no_proxy_len]) ==
0) {
gpr_stricmp(no_proxy_entry,
&(server_host.get()[uri_len - no_proxy_len])) == 0) {
gpr_log(GPR_INFO, "not using proxy for host in no_proxy list '%s'",
server_uri);
use_proxy = false;
@ -157,8 +158,6 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,
gpr_free(no_proxy_hosts[i]);
}
gpr_free(no_proxy_hosts);
gpr_free(server_host);
gpr_free(server_port);
gpr_free(no_proxy_str);
if (!use_proxy) goto no_use_proxy;
}

@ -84,7 +84,6 @@
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/memory.h"

@ -84,7 +84,6 @@
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channel_stack.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/gprpp/map.h"

@ -33,8 +33,8 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#ifdef GRPC_POSIX_SOCKET
#include <errno.h>
@ -73,9 +73,9 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
bool log_errors) {
bool success = false;
// Split host and port.
char* host;
char* port;
if (!gpr_split_host_port(hostport, &host, &port)) {
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
if (!grpc_core::SplitHostPort(hostport, &host, &port)) {
if (log_errors) {
gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
}
@ -86,8 +86,10 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in));
grpc_sockaddr_in* in = reinterpret_cast<grpc_sockaddr_in*>(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);
if (grpc_inet_pton(GRPC_AF_INET, host.get(), &in->sin_addr) == 0) {
if (log_errors) {
gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host.get());
}
goto done;
}
// Parse port.
@ -96,15 +98,14 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
goto done;
}
int port_num;
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) {
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port);
if (sscanf(port.get(), "%d", &port_num) != 1 || port_num < 0 ||
port_num > 65535) {
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port.get());
goto done;
}
in->sin_port = grpc_htons(static_cast<uint16_t>(port_num));
success = true;
done:
gpr_free(host);
gpr_free(port);
return success;
}
@ -124,9 +125,9 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
bool log_errors) {
bool success = false;
// Split host and port.
char* host;
char* port;
if (!gpr_split_host_port(hostport, &host, &port)) {
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
if (!grpc_core::SplitHostPort(hostport, &host, &port)) {
if (log_errors) {
gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
}
@ -138,11 +139,12 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
grpc_sockaddr_in6* in6 = reinterpret_cast<grpc_sockaddr_in6*>(addr->addr);
in6->sin6_family = GRPC_AF_INET6;
// Handle the RFC6874 syntax for IPv6 zone identifiers.
char* host_end = static_cast<char*>(gpr_memrchr(host, '%', strlen(host)));
char* host_end =
static_cast<char*>(gpr_memrchr(host.get(), '%', strlen(host.get())));
if (host_end != nullptr) {
GPR_ASSERT(host_end >= host);
GPR_ASSERT(host_end >= host.get());
char host_without_scope[GRPC_INET6_ADDRSTRLEN + 1];
size_t host_without_scope_len = static_cast<size_t>(host_end - host);
size_t host_without_scope_len = static_cast<size_t>(host_end - host.get());
uint32_t sin6_scope_id = 0;
if (host_without_scope_len > GRPC_INET6_ADDRSTRLEN) {
if (log_errors) {
@ -154,7 +156,7 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
}
goto done;
}
strncpy(host_without_scope, host, host_without_scope_len);
strncpy(host_without_scope, host.get(), host_without_scope_len);
host_without_scope[host_without_scope_len] = '\0';
if (grpc_inet_pton(GRPC_AF_INET6, host_without_scope, &in6->sin6_addr) ==
0) {
@ -163,9 +165,9 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
}
goto done;
}
if (gpr_parse_bytes_to_uint32(host_end + 1,
strlen(host) - host_without_scope_len - 1,
&sin6_scope_id) == 0) {
if (gpr_parse_bytes_to_uint32(
host_end + 1, strlen(host.get()) - host_without_scope_len - 1,
&sin6_scope_id) == 0) {
if ((sin6_scope_id = grpc_if_nametoindex(host_end + 1)) == 0) {
gpr_log(GPR_ERROR,
"Invalid interface name: '%s'. "
@ -177,8 +179,10 @@ 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 (grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) == 0) {
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
if (grpc_inet_pton(GRPC_AF_INET6, host.get(), &in6->sin6_addr) == 0) {
if (log_errors) {
gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host.get());
}
goto done;
}
}
@ -188,15 +192,14 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
goto done;
}
int port_num;
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) {
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port);
if (sscanf(port.get(), "%d", &port_num) != 1 || port_num < 0 ||
port_num > 65535) {
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port.get());
goto done;
}
in6->sin6_port = grpc_htons(static_cast<uint16_t>(port_num));
success = true;
done:
gpr_free(host);
gpr_free(port);
return success;
}

@ -38,7 +38,6 @@
#include "src/core/ext/filters/client_channel/service_config.h"
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/iomgr/combiner.h"

@ -35,8 +35,8 @@
#include <address_sorting/address_sorting.h>
#include "src/core/ext/filters/client_channel/parse_address.h"
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/executor.h"
@ -355,9 +355,9 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
grpc_ares_hostbyname_request* hr = nullptr;
ares_channel* channel = nullptr;
/* parse name, splitting it into host and port parts */
char* host;
char* port;
gpr_split_host_port(name, &host, &port);
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
grpc_core::SplitHostPort(name, &host, &port);
if (host == nullptr) {
error = grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"),
@ -370,7 +370,7 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
goto error_cleanup;
}
port = gpr_strdup(default_port);
port.reset(gpr_strdup(default_port));
}
error = grpc_ares_ev_driver_create_locked(&r->ev_driver, interested_parties,
query_timeout_ms, combiner, r);
@ -414,20 +414,22 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
}
r->pending_queries = 1;
if (grpc_ares_query_ipv6()) {
hr = create_hostbyname_request_locked(r, host, grpc_strhtons(port),
false /* is_balancer */);
hr = create_hostbyname_request_locked(r, host.get(),
grpc_strhtons(port.get()),
/*is_balancer=*/false);
ares_gethostbyname(*channel, hr->host, AF_INET6, on_hostbyname_done_locked,
hr);
}
hr = create_hostbyname_request_locked(r, host, grpc_strhtons(port),
false /* is_balancer */);
hr =
create_hostbyname_request_locked(r, host.get(), grpc_strhtons(port.get()),
/*is_balancer=*/false);
ares_gethostbyname(*channel, hr->host, AF_INET, on_hostbyname_done_locked,
hr);
if (check_grpclb) {
/* Query the SRV record */
grpc_ares_request_ref_locked(r);
char* service_name;
gpr_asprintf(&service_name, "_grpclb._tcp.%s", host);
gpr_asprintf(&service_name, "_grpclb._tcp.%s", host.get());
ares_query(*channel, service_name, ns_c_in, ns_t_srv,
on_srv_query_done_locked, r);
gpr_free(service_name);
@ -435,28 +437,25 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
if (r->service_config_json_out != nullptr) {
grpc_ares_request_ref_locked(r);
char* config_name;
gpr_asprintf(&config_name, "_grpc_config.%s", host);
gpr_asprintf(&config_name, "_grpc_config.%s", host.get());
ares_search(*channel, config_name, ns_c_in, ns_t_txt, on_txt_done_locked,
r);
gpr_free(config_name);
}
grpc_ares_ev_driver_start_locked(r->ev_driver);
grpc_ares_request_unref_locked(r);
gpr_free(host);
gpr_free(port);
return;
error_cleanup:
GRPC_CLOSURE_SCHED(r->on_done, error);
gpr_free(host);
gpr_free(port);
}
static bool inner_resolve_as_ip_literal_locked(
const char* name, const char* default_port,
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host,
char** port, char** hostport) {
gpr_split_host_port(name, host, port);
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs,
grpc_core::UniquePtr<char>* host, grpc_core::UniquePtr<char>* port,
grpc_core::UniquePtr<char>* hostport) {
grpc_core::SplitHostPort(name, host, port);
if (*host == nullptr) {
gpr_log(GPR_ERROR,
"Failed to parse %s to host:port while attempting to resolve as ip "
@ -472,12 +471,14 @@ static bool inner_resolve_as_ip_literal_locked(
name);
return false;
}
*port = gpr_strdup(default_port);
port->reset(gpr_strdup(default_port));
}
grpc_resolved_address addr;
GPR_ASSERT(gpr_join_host_port(hostport, *host, atoi(*port)));
if (grpc_parse_ipv4_hostport(*hostport, &addr, false /* log errors */) ||
grpc_parse_ipv6_hostport(*hostport, &addr, false /* log errors */)) {
GPR_ASSERT(grpc_core::JoinHostPort(hostport, host->get(), atoi(port->get())));
if (grpc_parse_ipv4_hostport(hostport->get(), &addr,
false /* log errors */) ||
grpc_parse_ipv6_hostport(hostport->get(), &addr,
false /* log errors */)) {
GPR_ASSERT(*addrs == nullptr);
*addrs = grpc_core::MakeUnique<ServerAddressList>();
(*addrs)->emplace_back(addr.addr, addr.len, nullptr /* args */);
@ -489,24 +490,22 @@ static bool inner_resolve_as_ip_literal_locked(
static bool resolve_as_ip_literal_locked(
const char* name, const char* default_port,
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
char* host = nullptr;
char* port = nullptr;
char* hostport = nullptr;
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
grpc_core::UniquePtr<char> hostport;
bool out = inner_resolve_as_ip_literal_locked(name, default_port, addrs,
&host, &port, &hostport);
gpr_free(host);
gpr_free(port);
gpr_free(hostport);
return out;
}
static bool target_matches_localhost_inner(const char* name, char** host,
char** port) {
if (!gpr_split_host_port(name, host, port)) {
static bool target_matches_localhost_inner(const char* name,
grpc_core::UniquePtr<char>* host,
grpc_core::UniquePtr<char>* port) {
if (!grpc_core::SplitHostPort(name, host, port)) {
gpr_log(GPR_ERROR, "Unable to split host and port for name: %s", name);
return false;
}
if (gpr_stricmp(*host, "localhost") == 0) {
if (gpr_stricmp(host->get(), "localhost") == 0) {
return true;
} else {
return false;
@ -514,20 +513,17 @@ static bool target_matches_localhost_inner(const char* name, char** host,
}
static bool target_matches_localhost(const char* name) {
char* host = nullptr;
char* port = nullptr;
bool out = target_matches_localhost_inner(name, &host, &port);
gpr_free(host);
gpr_free(port);
return out;
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
return target_matches_localhost_inner(name, &host, &port);
}
#ifdef GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY
static bool inner_maybe_resolve_localhost_manually_locked(
const char* name, const char* default_port,
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host,
char** port) {
gpr_split_host_port(name, host, port);
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs,
grpc_core::UniquePtr<char>* host, grpc_core::UniquePtr<char>* port) {
grpc_core::SplitHostPort(name, host, port);
if (*host == nullptr) {
gpr_log(GPR_ERROR,
"Failed to parse %s into host:port during manual localhost "
@ -543,12 +539,12 @@ static bool inner_maybe_resolve_localhost_manually_locked(
name);
return false;
}
*port = gpr_strdup(default_port);
port->reset(gpr_strdup(default_port));
}
if (gpr_stricmp(*host, "localhost") == 0) {
if (gpr_stricmp(host->get(), "localhost") == 0) {
GPR_ASSERT(*addrs == nullptr);
*addrs = grpc_core::MakeUnique<grpc_core::ServerAddressList>();
uint16_t numeric_port = grpc_strhtons(*port);
uint16_t numeric_port = grpc_strhtons(port->get());
// Append the ipv6 loopback address.
struct sockaddr_in6 ipv6_loopback_addr;
memset(&ipv6_loopback_addr, 0, sizeof(ipv6_loopback_addr));
@ -576,13 +572,10 @@ static bool inner_maybe_resolve_localhost_manually_locked(
static bool grpc_ares_maybe_resolve_localhost_manually_locked(
const char* name, const char* default_port,
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
char* host = nullptr;
char* port = nullptr;
bool out = inner_maybe_resolve_localhost_manually_locked(name, default_port,
addrs, &host, &port);
gpr_free(host);
gpr_free(port);
return out;
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
return inner_maybe_resolve_localhost_manually_locked(name, default_port,
addrs, &host, &port);
}
#else /* GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY */
static bool grpc_ares_maybe_resolve_localhost_manually_locked(

@ -26,7 +26,6 @@
#include "src/core/ext/filters/client_channel/parse_address.h"
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
bool grpc_ares_query_ipv6() {

@ -26,7 +26,6 @@
#include "src/core/ext/filters/client_channel/parse_address.h"
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/iomgr/socket_windows.h"

@ -31,7 +31,6 @@
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/backoff/backoff.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/iomgr/combiner.h"

@ -32,7 +32,6 @@
#include "src/core/ext/filters/client_channel/resolver_registry.h"
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/channel/channel_args.h"
#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/closure.h"

@ -30,7 +30,6 @@
#include "src/core/ext/filters/client_channel/resolver_registry.h"
#include "src/core/ext/filters/client_channel/server_address.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/iomgr/combiner.h"
#include "src/core/lib/iomgr/resolve_address.h"

@ -37,7 +37,6 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/channel/handshaker_registry.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/resource_quota.h"

@ -137,10 +137,10 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_STREAM_ID,
static_cast<intptr_t>(s->id));
gpr_free(msg);
p->error =
grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES,
grpc_dump_slice_to_slice(
*slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
p->error = grpc_error_set_str(
p->error, GRPC_ERROR_STR_RAW_BYTES,
grpc_slice_from_moved_string(grpc_core::UniquePtr<char>(
grpc_dump_slice(*slice, GPR_DUMP_HEX | GPR_DUMP_ASCII))));
p->error =
grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg);
p->state = GRPC_CHTTP2_DATA_ERROR;

@ -712,18 +712,28 @@ void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c,
}
for (size_t i = 0; i < extra_headers_size; ++i) {
grpc_mdelem md = *extra_headers[i];
uintptr_t static_index = grpc_chttp2_get_static_hpack_table_index(md);
if (static_index) {
emit_indexed(c, static_cast<uint32_t>(static_index), &st);
const bool is_static =
GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC;
uintptr_t static_index;
if (is_static &&
(static_index =
reinterpret_cast<grpc_core::StaticMetadata*>(GRPC_MDELEM_DATA(md))
->StaticIndex()) < GRPC_CHTTP2_LAST_STATIC_ENTRY) {
emit_indexed(c, static_cast<uint32_t>(static_index + 1), &st);
} else {
hpack_enc(c, md, &st);
}
}
grpc_metadata_batch_assert_ok(metadata);
for (grpc_linked_mdelem* l = metadata->list.head; l; l = l->next) {
uintptr_t static_index = grpc_chttp2_get_static_hpack_table_index(l->md);
if (static_index) {
emit_indexed(c, static_cast<uint32_t>(static_index), &st);
const bool is_static =
GRPC_MDELEM_STORAGE(l->md) == GRPC_MDELEM_STORAGE_STATIC;
uintptr_t static_index;
if (is_static &&
(static_index = reinterpret_cast<grpc_core::StaticMetadata*>(
GRPC_MDELEM_DATA(l->md))
->StaticIndex()) < GRPC_CHTTP2_LAST_STATIC_ENTRY) {
emit_indexed(c, static_cast<uint32_t>(static_index + 1), &st);
} else {
hpack_enc(c, l->md, &st);
}

@ -622,33 +622,37 @@ static const uint8_t inverse_base64[256] = {
255,
};
static void GPR_ATTRIBUTE_NOINLINE on_hdr_log(grpc_mdelem md) {
char* k = grpc_slice_to_c_string(GRPC_MDKEY(md));
char* v = nullptr;
if (grpc_is_binary_header_internal(GRPC_MDKEY(md))) {
v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX);
} else {
v = grpc_slice_to_c_string(GRPC_MDVALUE(md));
}
gpr_log(
GPR_INFO,
"Decode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d",
k, v, GRPC_MDELEM_IS_INTERNED(md), GRPC_MDELEM_STORAGE(md),
grpc_slice_is_interned(GRPC_MDKEY(md)),
grpc_slice_is_interned(GRPC_MDVALUE(md)));
gpr_free(k);
gpr_free(v);
}
/* emission helpers */
static grpc_error* on_hdr(grpc_chttp2_hpack_parser* p, grpc_mdelem md,
int add_to_table) {
template <bool do_add>
static grpc_error* on_hdr(grpc_chttp2_hpack_parser* p, grpc_mdelem md) {
if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
char* k = grpc_slice_to_c_string(GRPC_MDKEY(md));
char* v = nullptr;
if (grpc_is_binary_header_internal(GRPC_MDKEY(md))) {
v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX);
} else {
v = grpc_slice_to_c_string(GRPC_MDVALUE(md));
}
gpr_log(
GPR_INFO,
"Decode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d",
k, v, GRPC_MDELEM_IS_INTERNED(md), GRPC_MDELEM_STORAGE(md),
grpc_slice_is_interned(GRPC_MDKEY(md)),
grpc_slice_is_interned(GRPC_MDVALUE(md)));
gpr_free(k);
gpr_free(v);
on_hdr_log(md);
}
if (add_to_table) {
GPR_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED ||
GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC);
if (do_add) {
GPR_DEBUG_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED ||
GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC);
grpc_error* err = grpc_chttp2_hptbl_add(&p->table, md);
if (err != GRPC_ERROR_NONE) return err;
if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) return err;
}
if (p->on_header == nullptr) {
if (GPR_UNLIKELY(p->on_header == nullptr)) {
GRPC_MDELEM_UNREF(md);
return GRPC_ERROR_CREATE_FROM_STATIC_STRING("on_header callback not set");
}
@ -765,7 +769,7 @@ static grpc_error* finish_indexed_field(grpc_chttp2_hpack_parser* p,
}
GRPC_MDELEM_REF(md);
GRPC_STATS_INC_HPACK_RECV_INDEXED();
grpc_error* err = on_hdr(p, md, 0);
grpc_error* err = on_hdr<false>(p, md);
if (err != GRPC_ERROR_NONE) return err;
return parse_begin(p, cur, end);
}
@ -798,11 +802,9 @@ static grpc_error* finish_lithdr_incidx(grpc_chttp2_hpack_parser* p,
grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */
GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX();
grpc_error* err =
on_hdr(p,
grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)),
take_string(p, &p->value, true)),
1);
grpc_error* err = on_hdr<true>(
p, grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)),
take_string(p, &p->value, true)));
if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
return parse_begin(p, cur, end);
}
@ -813,10 +815,8 @@ static grpc_error* finish_lithdr_incidx_v(grpc_chttp2_hpack_parser* p,
const uint8_t* end) {
GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V();
grpc_error* err =
on_hdr(p,
grpc_mdelem_from_slices(take_string(p, &p->key, true),
take_string(p, &p->value, true)),
1);
on_hdr<true>(p, grpc_mdelem_from_slices(take_string(p, &p->key, true),
take_string(p, &p->value, true)));
if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
return parse_begin(p, cur, end);
}
@ -865,11 +865,9 @@ static grpc_error* finish_lithdr_notidx(grpc_chttp2_hpack_parser* p,
grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */
GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX();
grpc_error* err =
on_hdr(p,
grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)),
take_string(p, &p->value, false)),
0);
grpc_error* err = on_hdr<false>(
p, grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)),
take_string(p, &p->value, false)));
if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
return parse_begin(p, cur, end);
}
@ -879,11 +877,9 @@ static grpc_error* finish_lithdr_notidx_v(grpc_chttp2_hpack_parser* p,
const uint8_t* cur,
const uint8_t* end) {
GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V();
grpc_error* err =
on_hdr(p,
grpc_mdelem_from_slices(take_string(p, &p->key, true),
take_string(p, &p->value, false)),
0);
grpc_error* err = on_hdr<false>(
p, grpc_mdelem_from_slices(take_string(p, &p->key, true),
take_string(p, &p->value, false)));
if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
return parse_begin(p, cur, end);
}
@ -932,11 +928,9 @@ static grpc_error* finish_lithdr_nvridx(grpc_chttp2_hpack_parser* p,
grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index);
GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */
GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX();
grpc_error* err =
on_hdr(p,
grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)),
take_string(p, &p->value, false)),
0);
grpc_error* err = on_hdr<false>(
p, grpc_mdelem_from_slices(grpc_slice_ref_internal(GRPC_MDKEY(md)),
take_string(p, &p->value, false)));
if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
return parse_begin(p, cur, end);
}
@ -946,11 +940,9 @@ static grpc_error* finish_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p,
const uint8_t* cur,
const uint8_t* end) {
GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V();
grpc_error* err =
on_hdr(p,
grpc_mdelem_from_slices(take_string(p, &p->key, true),
take_string(p, &p->value, false)),
0);
grpc_error* err = on_hdr<false>(
p, grpc_mdelem_from_slices(take_string(p, &p->key, true),
take_string(p, &p->value, false)));
if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
return parse_begin(p, cur, end);
}

@ -30,7 +30,6 @@
#include "src/core/ext/transport/chttp2/transport/incoming_metadata.h"
#include "src/core/ext/transport/cronet/transport/cronet_transport.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/manual_constructor.h"
#include "src/core/lib/iomgr/endpoint.h"

@ -30,9 +30,9 @@
#include "src/core/lib/channel/channelz_registry.h"
#include "src/core/lib/channel/status_util.h"
#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/gprpp/host_port.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/exec_ctx.h"
@ -406,14 +406,15 @@ void PopulateSocketAddressJson(grpc_json* json, const char* name,
(strcmp(uri->scheme, "ipv6") == 0))) {
const char* host_port = uri->path;
if (*host_port == '/') ++host_port;
char* host = nullptr;
char* port = nullptr;
GPR_ASSERT(gpr_split_host_port(host_port, &host, &port));
UniquePtr<char> host;
UniquePtr<char> port;
GPR_ASSERT(SplitHostPort(host_port, &host, &port));
int port_num = -1;
if (port != nullptr) {
port_num = atoi(port);
port_num = atoi(port.get());
}
char* b64_host = grpc_base64_encode(host, strlen(host), false, false);
char* b64_host =
grpc_base64_encode(host.get(), strlen(host.get()), false, false);
json_iterator = grpc_json_create_child(json_iterator, json, "tcpip_address",
nullptr, GRPC_JSON_OBJECT, false);
json = json_iterator;
@ -422,8 +423,6 @@ void PopulateSocketAddressJson(grpc_json* json, const char* name,
"port", port_num);
json_iterator = grpc_json_create_child(json_iterator, json, "ip_address",
b64_host, GRPC_JSON_STRING, true);
gpr_free(host);
gpr_free(port);
} else if (uri != nullptr && strcmp(uri->scheme, "unix") == 0) {
json_iterator = grpc_json_create_child(json_iterator, json, "uds_address",
nullptr, GRPC_JSON_OBJECT, false);

@ -1,98 +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 <grpc/support/port_platform.h>
#include "src/core/lib/gpr/host_port.h"
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/string.h"
int gpr_join_host_port(char** out, const char* host, int port) {
if (host[0] != '[' && strchr(host, ':') != nullptr) {
/* IPv6 literals must be enclosed in brackets. */
return gpr_asprintf(out, "[%s]:%d", host, port);
} else {
/* Ordinary non-bracketed host:port. */
return gpr_asprintf(out, "%s:%d", host, port);
}
}
int gpr_split_host_port(const char* name, char** host, char** port) {
const char* host_start;
size_t host_len;
const char* port_start;
*host = nullptr;
*port = nullptr;
if (name[0] == '[') {
/* Parse a bracketed host, typically an IPv6 literal. */
const char* rbracket = strchr(name, ']');
if (rbracket == nullptr) {
/* Unmatched [ */
return 0;
}
if (rbracket[1] == '\0') {
/* ]<end> */
port_start = nullptr;
} else if (rbracket[1] == ':') {
/* ]:<port?> */
port_start = rbracket + 2;
} else {
/* ]<invalid> */
return 0;
}
host_start = name + 1;
host_len = static_cast<size_t>(rbracket - host_start);
if (memchr(host_start, ':', host_len) == nullptr) {
/* Require all bracketed hosts to contain a colon, because a hostname or
IPv4 address should never use brackets. */
return 0;
}
} else {
const char* colon = strchr(name, ':');
if (colon != nullptr && strchr(colon + 1, ':') == nullptr) {
/* Exactly 1 colon. Split into host:port. */
host_start = name;
host_len = static_cast<size_t>(colon - name);
port_start = colon + 1;
} else {
/* 0 or 2+ colons. Bare hostname or IPv6 litearal. */
host_start = name;
host_len = strlen(name);
port_start = nullptr;
}
}
/* Allocate return values. */
*host = static_cast<char*>(gpr_malloc(host_len + 1));
memcpy(*host, host_start, host_len);
(*host)[host_len] = '\0';
if (port_start != nullptr) {
*port = gpr_strdup(port_start);
}
return 1;
}

@ -289,17 +289,22 @@ char* gpr_strvec_flatten(gpr_strvec* sv, size_t* final_length) {
return gpr_strjoin((const char**)sv->strs, sv->count, final_length);
}
int gpr_stricmp(const char* a, const char* b) {
int gpr_strincmp(const char* a, const char* b, size_t n) {
int ca, cb;
do {
ca = tolower(*a);
cb = tolower(*b);
++a;
++b;
} while (ca == cb && ca && cb);
--n;
} while (ca == cb && ca != 0 && cb != 0 && n != 0);
return ca - cb;
}
int gpr_stricmp(const char* a, const char* b) {
return gpr_strincmp(a, b, SIZE_MAX);
}
static void add_string_to_split(const char* beg, const char* end, char*** strs,
size_t* nstrs, size_t* capstrs) {
char* out =

@ -115,6 +115,7 @@ char* gpr_strvec_flatten(gpr_strvec* strs, size_t* total_length);
/** Case insensitive string comparison... return <0 if lower(a)<lower(b), ==0 if
lower(a)==lower(b), >0 if lower(a)>lower(b) */
int gpr_stricmp(const char* a, const char* b);
int gpr_strincmp(const char* a, const char* b, size_t n);
void* gpr_memrchr(const void* s, int c, size_t n);

@ -0,0 +1,105 @@
/*
*
* 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 <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/host_port.h"
#include <string.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/string_view.h"
namespace grpc_core {
int JoinHostPort(UniquePtr<char>* out, const char* host, int port) {
char* tmp;
int ret;
if (host[0] != '[' && strchr(host, ':') != nullptr) {
/* IPv6 literals must be enclosed in brackets. */
ret = gpr_asprintf(&tmp, "[%s]:%d", host, port);
} else {
/* Ordinary non-bracketed host:port. */
ret = gpr_asprintf(&tmp, "%s:%d", host, port);
}
out->reset(tmp);
return ret;
}
bool SplitHostPort(StringView name, StringView* host, StringView* port) {
if (name[0] == '[') {
/* Parse a bracketed host, typically an IPv6 literal. */
const size_t rbracket = name.find(']', 1);
if (rbracket == grpc_core::StringView::npos) {
/* Unmatched [ */
return false;
}
if (rbracket == name.size() - 1) {
/* ]<end> */
port->clear();
} else if (name[rbracket + 1] == ':') {
/* ]:<port?> */
*port = name.substr(rbracket + 2, name.size() - rbracket - 2);
} else {
/* ]<invalid> */
return false;
}
*host = name.substr(1, rbracket - 1);
if (host->find(':') == grpc_core::StringView::npos) {
/* Require all bracketed hosts to contain a colon, because a hostname or
IPv4 address should never use brackets. */
host->clear();
return false;
}
} else {
size_t colon = name.find(':');
if (colon != grpc_core::StringView::npos &&
name.find(':', colon + 1) == grpc_core::StringView::npos) {
/* Exactly 1 colon. Split into host:port. */
*host = name.substr(0, colon);
*port = name.substr(colon + 1, name.size() - colon - 1);
} else {
/* 0 or 2+ colons. Bare hostname or IPv6 litearal. */
*host = name;
port->clear();
}
}
return true;
}
bool SplitHostPort(StringView name, UniquePtr<char>* host,
UniquePtr<char>* port) {
GPR_DEBUG_ASSERT(host != nullptr && *host == nullptr);
GPR_DEBUG_ASSERT(port != nullptr && *port == nullptr);
StringView host_view;
StringView port_view;
const bool ret = SplitHostPort(name, &host_view, &port_view);
if (ret) {
// We always set the host, but port is set only when it's non-empty,
// to remain backward compatible with the old split_host_port API.
*host = host_view.dup();
if (!port_view.empty()) {
*port = port_view.dup();
}
}
return ret;
}
} // namespace grpc_core

@ -16,28 +16,44 @@
*
*/
#ifndef GRPC_CORE_LIB_GPR_HOST_PORT_H
#define GRPC_CORE_LIB_GPR_HOST_PORT_H
#ifndef GRPC_CORE_LIB_GPRPP_HOST_PORT_H
#define GRPC_CORE_LIB_GPRPP_HOST_PORT_H
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/string_view.h"
namespace grpc_core {
/** Given a host and port, creates a newly-allocated string of the form
"host:port" or "[ho:st]:port", depending on whether the host contains colons
like an IPv6 literal. If the host is already bracketed, then additional
brackets will not be added.
Usage is similar to gpr_asprintf: returns the number of bytes written
(excluding the final '\0'), and *out points to a string which must later be
destroyed using gpr_free().
(excluding the final '\0'), and *out points to a string.
In the unlikely event of an error, returns -1 and sets *out to NULL. */
int gpr_join_host_port(char** out, const char* host, int port);
int JoinHostPort(UniquePtr<char>* out, const char* host, int port);
/** Given a name in the form "host:port" or "[ho:st]:port", split into hostname
and port number, into newly allocated strings, which must later be
destroyed using gpr_free().
Return 1 on success, 0 on failure. Guarantees *host and *port == NULL on
failure. */
int gpr_split_host_port(const char* name, char** host, char** port);
and port number.
There are two variants of this method:
1) StringView output: port and host are returned as views on name.
2) char* output: port and host are copied into newly allocated strings.
Prefer variant (1) over (2), because no allocation or copy is performed in
variant (1). Use (2) only when interacting with C API that mandate
null-terminated strings.
Return true on success, false on failure. Guarantees *host and *port are
cleared on failure. */
bool SplitHostPort(StringView name, StringView* host, StringView* port);
bool SplitHostPort(StringView name, UniquePtr<char>* host,
UniquePtr<char>* port);
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPR_HOST_PORT_H */
#endif /* GRPC_CORE_LIB_GPRPP_HOST_PORT_H */

@ -0,0 +1,143 @@
/*
*
* Copyright 2019 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_GPRPP_STRING_VIEW_H
#define GRPC_CORE_LIB_GPRPP_STRING_VIEW_H
#include <grpc/support/port_platform.h>
#include <grpc/impl/codegen/slice.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include <algorithm>
#include <cstdint>
#include <cstring>
#include <limits>
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
namespace grpc_core {
// Provides a light-weight view over a char array or a slice, similar but not
// identical to absl::string_view.
//
// Any method that has the same name as absl::string_view MUST HAVE identical
// semantics to what absl::string_view provides.
//
// Methods that are not part of absl::string_view API, must be clearly
// annotated.
//
// StringView does not own the buffers that back the view. Callers must ensure
// the buffer stays around while the StringView is accessible.
//
// Pass StringView by value in functions, since it is exactly two pointers in
// size.
//
// The interface used here is not identical to absl::string_view. Notably, we
// need to support slices while we cannot support std::string, and gpr string
// style functions such as strdup() and cmp(). Once we switch to
// absl::string_view this class will inherit from absl::string_view and add the
// gRPC-specific APIs.
class StringView final {
public:
static constexpr size_t npos = std::numeric_limits<size_t>::max();
constexpr StringView(const char* ptr, size_t size) : ptr_(ptr), size_(size) {}
constexpr StringView(const char* ptr)
: StringView(ptr, ptr == nullptr ? 0 : strlen(ptr)) {}
// Not part of absl::string_view API.
StringView(const grpc_slice& slice)
: StringView(reinterpret_cast<const char*>(GRPC_SLICE_START_PTR(slice)),
GRPC_SLICE_LENGTH(slice)) {}
constexpr StringView() : StringView(nullptr, 0) {}
constexpr const char* data() const { return ptr_; }
constexpr size_t size() const { return size_; }
constexpr bool empty() const { return size_ == 0; }
StringView substr(size_t start, size_t size = npos) {
GPR_DEBUG_ASSERT(start + size <= size_);
return StringView(ptr_ + start, std::min(size, size_ - start));
}
constexpr const char& operator[](size_t i) const { return ptr_[i]; }
const char& front() const { return ptr_[0]; }
const char& back() const { return ptr_[size_ - 1]; }
void remove_prefix(size_t n) {
GPR_DEBUG_ASSERT(n <= size_);
ptr_ += n;
size_ -= n;
}
void remove_suffix(size_t n) {
GPR_DEBUG_ASSERT(n <= size_);
size_ -= n;
}
size_t find(char c, size_t pos = 0) const {
if (empty() || pos >= size_) return npos;
const char* result =
static_cast<const char*>(memchr(ptr_ + pos, c, size_ - pos));
return result != nullptr ? result - ptr_ : npos;
}
void clear() {
ptr_ = nullptr;
size_ = 0;
}
// Creates a dup of the string viewed by this class.
// Return value is null-terminated and never nullptr.
//
// Not part of absl::string_view API.
grpc_core::UniquePtr<char> dup() const {
char* str = static_cast<char*>(gpr_malloc(size_ + 1));
if (size_ > 0) memcpy(str, ptr_, size_);
str[size_] = '\0';
return grpc_core::UniquePtr<char>(str);
}
// Not part of absl::string_view API.
int cmp(StringView other) const {
const size_t len = GPR_MIN(size(), other.size());
const int ret = strncmp(data(), other.data(), len);
if (ret != 0) return ret;
if (size() == other.size()) return 0;
if (size() < other.size()) return -1;
return 1;
}
private:
const char* ptr_;
size_t size_;
};
inline bool operator==(StringView lhs, StringView rhs) {
return lhs.size() == rhs.size() &&
strncmp(lhs.data(), rhs.data(), lhs.size()) == 0;
}
inline bool operator!=(StringView lhs, StringView rhs) { return !(lhs == rhs); }
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_STRING_VIEW_H */

@ -30,6 +30,7 @@
#include "src/core/lib/channel/handshaker_registry.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/string_view.h"
#include "src/core/lib/iomgr/pollset.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
@ -108,7 +109,8 @@ class grpc_httpcli_ssl_channel_security_connector final
return strcmp(secure_peer_name_, other->secure_peer_name_);
}
bool check_call_host(const char* host, grpc_auth_context* auth_context,
bool check_call_host(grpc_core::StringView host,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) override {
*error = GRPC_ERROR_NONE;

@ -111,4 +111,22 @@ void* InfLenFIFOQueue::Get() {
return PopFront();
}
void* InfLenFIFOQueue::Get(gpr_timespec* wait_time) {
MutexLock l(&mu_);
if (count_.Load(MemoryOrder::RELAXED) == 0) {
gpr_timespec start_time;
start_time = gpr_now(GPR_CLOCK_MONOTONIC);
num_waiters_++;
do {
wait_nonempty_.Wait(&mu_);
} while (count_.Load(MemoryOrder::RELAXED) == 0);
num_waiters_--;
*wait_time = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), start_time);
}
GPR_DEBUG_ASSERT(count_.Load(MemoryOrder::RELAXED) > 0);
return PopFront();
}
} // namespace grpc_core

@ -67,6 +67,11 @@ class InfLenFIFOQueue : public MPMCQueueInterface {
// This routine will cause the thread to block if queue is currently empty.
void* Get();
// Same as Get(), but will record how long waited when getting.
// This routine should be only called when debug trace is on and wants to
// collect stats data.
void* Get(gpr_timespec* wait_time);
// Returns number of elements in queue currently.
// There might be concurrently add/remove on queue, so count might change
// quickly.

@ -0,0 +1,136 @@
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <grpc/support/port_platform.h>
#include "src/core/lib/iomgr/executor/threadpool.h"
namespace grpc_core {
void ThreadPoolWorker::Run() {
while (true) {
void* elem;
if (GRPC_TRACE_FLAG_ENABLED(grpc_thread_pool_trace)) {
// Updates stats and print
gpr_timespec wait_time = gpr_time_0(GPR_TIMESPAN);
elem = static_cast<InfLenFIFOQueue*>(queue_)->Get(&wait_time);
stats_.sleep_cycles = gpr_time_add(stats_.sleep_cycles, wait_time);
gpr_log(GPR_INFO,
"ThreadPool Worker [%s %d] Stats: sleep_cycles %f",
thd_name_, index_, gpr_timespec_to_micros(stats_.sleep_cycles));
} else {
elem = static_cast<InfLenFIFOQueue*>(queue_)->Get();
}
if (elem == nullptr) {
break;
}
// Runs closure
grpc_experimental_completion_queue_functor* closure =
static_cast<grpc_experimental_completion_queue_functor*>(elem);
closure->functor_run(closure->internal_next, closure->internal_success);
}
}
void ThreadPool::SharedThreadPoolConstructor() {
// All worker threads in thread pool must be joinable.
thread_options_.set_joinable(true);
queue_ = New<InfLenFIFOQueue>();
threads_ = static_cast<ThreadPoolWorker**>(
gpr_zalloc(num_threads_ * sizeof(ThreadPoolWorker*)));
for (int i = 0; i < num_threads_; ++i) {
threads_[i] =
New<ThreadPoolWorker>(thd_name_, this, queue_, thread_options_, i);
threads_[i]->Start();
}
}
size_t ThreadPool::DefaultStackSize() {
#if defined(__ANDROID__) || defined(__APPLE__)
return 1952 * 1024;
#else
return 64 * 1024;
#endif
}
bool ThreadPool::HasBeenShutDown() {
return shut_down_.Load(MemoryOrder::ACQUIRE);
}
ThreadPool::ThreadPool(int num_threads) : num_threads_(num_threads) {
thd_name_ = "ThreadPoolWorker";
thread_options_ = Thread::Options();
thread_options_.set_stack_size(DefaultStackSize());
SharedThreadPoolConstructor();
}
ThreadPool::ThreadPool(int num_threads, const char* thd_name)
: num_threads_(num_threads), thd_name_(thd_name) {
thread_options_ = Thread::Options();
thread_options_.set_stack_size(DefaultStackSize());
SharedThreadPoolConstructor();
}
ThreadPool::ThreadPool(int num_threads, const char* thd_name,
const Thread::Options& thread_options)
: num_threads_(num_threads),
thd_name_(thd_name),
thread_options_(thread_options) {
if (thread_options_.stack_size() == 0) {
thread_options_.set_stack_size(DefaultStackSize());
}
SharedThreadPoolConstructor();
}
ThreadPool::~ThreadPool() {
shut_down_.Store(false, MemoryOrder::RELEASE);
for (int i = 0; i < num_threads_; ++i) {
queue_->Put(nullptr);
}
for (int i = 0; i < num_threads_; ++i) {
threads_[i]->Join();
}
for (int i = 0; i < num_threads_; ++i) {
Delete(threads_[i]);
}
gpr_free(threads_);
Delete(queue_);
}
void ThreadPool::Add(grpc_experimental_completion_queue_functor* closure) {
if (HasBeenShutDown()) {
gpr_log(GPR_ERROR, "ThreadPool Has Already Been Shut Down.");
} else {
queue_->Put(static_cast<void*>(closure));
}
}
int ThreadPool::num_pending_closures() const { return queue_->count(); }
int ThreadPool::pool_capacity() const { return num_threads_; }
const Thread::Options& ThreadPool::thread_options() const {
return thread_options_;
}
const char* ThreadPool::thread_name() const { return thd_name_; }
} // namespace grpc_core

@ -0,0 +1,153 @@
/*
*
* Copyright 2019 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_EXECUTOR_THREADPOOL_H
#define GRPC_CORE_LIB_IOMGR_EXECUTOR_THREADPOOL_H
#include <grpc/support/port_platform.h>
#include <grpc/grpc.h>
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/executor/mpmcqueue.h"
namespace grpc_core {
// A base abstract base class for threadpool.
// Threadpool is an executor that maintains a pool of threads sitting around
// and waiting for closures. A threadpool also maintains a queue of pending
// closures, when closures appearing in the queue, the threads in pool will
// pull them out and execute them.
class ThreadPoolInterface {
public:
// Waits for all pending closures to complete, then shuts down thread pool.
virtual ~ThreadPoolInterface() {}
// Schedules a given closure for execution later.
// Depending on specific subclass implementation, this routine might cause
// current thread to be blocked (in case of unable to schedule).
// Closure should contain a function pointer and arguments it will take, more
// details for closure struct at /grpc/include/grpc/impl/codegen/grpc_types.h
virtual void Add(grpc_experimental_completion_queue_functor* closure)
GRPC_ABSTRACT;
// Returns the current number of pending closures
virtual int num_pending_closures() const GRPC_ABSTRACT;
// Returns the capacity of pool (number of worker threads in pool)
virtual int pool_capacity() const GRPC_ABSTRACT;
// Thread option accessor
virtual const Thread::Options& thread_options() const GRPC_ABSTRACT;
// Returns the thread name for threads in this ThreadPool.
virtual const char* thread_name() const GRPC_ABSTRACT;
GRPC_ABSTRACT_BASE_CLASS
};
// Worker thread for threadpool. Executes closures in the queue, until getting a
// NULL closure.
class ThreadPoolWorker {
public:
ThreadPoolWorker(const char* thd_name, ThreadPoolInterface* pool,
MPMCQueueInterface* queue, Thread::Options& options,
int index)
: queue_(queue), thd_name_(thd_name), index_(index) {
thd_ = Thread(thd_name,
[](void* th) { static_cast<ThreadPoolWorker*>(th)->Run(); },
this, nullptr, options);
}
~ThreadPoolWorker() {}
void Start() { thd_.Start(); }
void Join() { thd_.Join(); }
GRPC_ABSTRACT_BASE_CLASS
private:
// struct for tracking stats of thread
struct Stats {
gpr_timespec sleep_cycles;
Stats() { sleep_cycles = gpr_time_0(GPR_TIMESPAN); }
};
void Run(); // Pulls closures from queue and executes them
MPMCQueueInterface* queue_; // Queue in thread pool to pull closures from
Thread thd_; // Thread wrapped in
Stats stats_; // Stats to be collected in run time
const char* thd_name_; // Name of thread
int index_; // Index in thread pool
};
// A fixed size thread pool implementation of abstract thread pool interface.
// In this implementation, the number of threads in pool is fixed, but the
// capacity of closure queue is unlimited.
class ThreadPool : public ThreadPoolInterface {
public:
// Creates a thread pool with size of "num_threads", with default thread name
// "ThreadPoolWorker" and all thread options set to default.
ThreadPool(int num_threads);
// Same as ThreadPool(int num_threads) constructor, except
// that it also sets "thd_name" as the name of all threads in the thread pool.
ThreadPool(int num_threads, const char* thd_name);
// Same as ThreadPool(const char *thd_name, int num_threads) constructor,
// except that is also set thread_options for threads.
// Notes for stack size:
// If the stack size field of the passed in Thread::Options is set to default
// value 0, default ThreadPool stack size will be used. The current default
// stack size of this implementation is 1952K for mobile platform and 64K for
// all others.
ThreadPool(int num_threads, const char* thd_name,
const Thread::Options& thread_options);
// Waits for all pending closures to complete, then shuts down thread pool.
~ThreadPool() override;
// Adds given closure into pending queue immediately. Since closure queue has
// infinite length, this routine will not block.
void Add(grpc_experimental_completion_queue_functor* closure) override;
int num_pending_closures() const override;
int pool_capacity() const override;
const Thread::Options& thread_options() const override;
const char* thread_name() const override;
private:
int num_threads_ = 0;
const char* thd_name_ = nullptr;
Thread::Options thread_options_;
ThreadPoolWorker** threads_ = nullptr; // Array of worker threads
MPMCQueueInterface* queue_ = nullptr;
Atomic<bool> shut_down_{false}; // Destructor has been called if set to true
void SharedThreadPoolConstructor();
// For ThreadPool, default stack size for mobile platform is 1952K. for other
// platforms is 64K.
size_t DefaultStackSize();
bool HasBeenShutDown();
};
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_IOMGR_EXECUTOR_THREADPOOL_H */

@ -78,9 +78,19 @@ static grpc_iomgr_platform_vtable vtable = {
void grpc_set_default_iomgr_platform() {
char* enable_cfstream = getenv(grpc_cfstream_env_var);
grpc_tcp_client_vtable* client_vtable = &grpc_posix_tcp_client_vtable;
// CFStream is enabled by default on iOS, and disabled by default on other
// platforms. Defaults can be overriden by setting the grpc_cfstream
// environment variable.
#if TARGET_OS_IPHONE
if (enable_cfstream == nullptr || enable_cfstream[0] == '1') {
client_vtable = &grpc_cfstream_client_vtable;
}
#else
if (enable_cfstream != nullptr && enable_cfstream[0] == '1') {
client_vtable = &grpc_cfstream_client_vtable;
}
#endif
grpc_set_tcp_client_impl(client_vtable);
grpc_set_tcp_server_impl(&grpc_posix_tcp_server_vtable);
grpc_set_timer_impl(&grpc_generic_timer_vtable);

@ -24,9 +24,9 @@
#include <grpc/support/string_util.h>
#include <grpc/support/log.h>
#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/gprpp/host_port.h"
#include "src/core/lib/iomgr/iomgr_custom.h"
#include "src/core/lib/iomgr/resolve_address_custom.h"
@ -86,11 +86,12 @@ void grpc_custom_resolve_callback(grpc_custom_resolver* r,
}
static grpc_error* try_split_host_port(const char* name,
const char* default_port, char** host,
char** port) {
const char* default_port,
grpc_core::UniquePtr<char>* host,
grpc_core::UniquePtr<char>* port) {
/* parse name, splitting it into host and port parts */
grpc_error* error;
gpr_split_host_port(name, host, port);
SplitHostPort(name, host, port);
if (*host == nullptr) {
char* msg;
gpr_asprintf(&msg, "unparseable host:port: '%s'", name);
@ -107,7 +108,7 @@ static grpc_error* try_split_host_port(const char* name,
gpr_free(msg);
return error;
}
*port = gpr_strdup(default_port);
port->reset(gpr_strdup(default_port));
}
return GRPC_ERROR_NONE;
}
@ -115,28 +116,26 @@ static grpc_error* try_split_host_port(const char* name,
static grpc_error* blocking_resolve_address_impl(
const char* name, const char* default_port,
grpc_resolved_addresses** addresses) {
char* host;
char* port;
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<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;
resolver.host = host.get();
resolver.port = port.get();
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);
err = resolve_address_vtable->resolve(host.get(), port.get(), &addrs);
if (err != GRPC_ERROR_NONE) {
if (retry_named_port_failure(&resolver, &addrs)) {
GRPC_ERROR_UNREF(err);
@ -147,8 +146,6 @@ static grpc_error* blocking_resolve_address_impl(
if (err == GRPC_ERROR_NONE) {
*addresses = addrs;
}
gpr_free(resolver.host);
gpr_free(resolver.port);
return err;
}
@ -157,22 +154,20 @@ static void resolve_address_impl(const char* name, const char* default_port,
grpc_closure* on_done,
grpc_resolved_addresses** addrs) {
grpc_custom_resolver* r = nullptr;
char* host = nullptr;
char* port = nullptr;
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<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) {
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;
r->host = host.release();
r->port = port.release();
/* Call getaddrinfo */
resolve_address_vtable->resolve_async(r, r->host, r->port);

@ -33,9 +33,9 @@
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
#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/gprpp/host_port.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/block_annotate.h"
#include "src/core/lib/iomgr/executor.h"
@ -48,8 +48,6 @@ static grpc_error* posix_blocking_resolve_address(
grpc_core::ExecCtx exec_ctx;
struct addrinfo hints;
struct addrinfo *result = nullptr, *resp;
char* host;
char* port;
int s;
size_t i;
grpc_error* err;
@ -59,8 +57,10 @@ static grpc_error* posix_blocking_resolve_address(
return grpc_resolve_unix_domain_address(name + 5, addresses);
}
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
/* parse name, splitting it into host and port parts */
gpr_split_host_port(name, &host, &port);
grpc_core::SplitHostPort(name, &host, &port);
if (host == nullptr) {
err = grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"),
@ -74,7 +74,7 @@ static grpc_error* posix_blocking_resolve_address(
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
goto done;
}
port = gpr_strdup(default_port);
port.reset(gpr_strdup(default_port));
}
/* Call getaddrinfo */
@ -84,16 +84,16 @@ static grpc_error* posix_blocking_resolve_address(
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
GRPC_SCHEDULING_START_BLOCKING_REGION;
s = getaddrinfo(host, port, &hints, &result);
s = getaddrinfo(host.get(), port.get(), &hints, &result);
GRPC_SCHEDULING_END_BLOCKING_REGION;
if (s != 0) {
/* Retry if well-known service name is recognized */
const char* svc[][2] = {{"http", "80"}, {"https", "443"}};
for (i = 0; i < GPR_ARRAY_SIZE(svc); i++) {
if (strcmp(port, svc[i][0]) == 0) {
if (strcmp(port.get(), svc[i][0]) == 0) {
GRPC_SCHEDULING_START_BLOCKING_REGION;
s = getaddrinfo(host, svc[i][1], &hints, &result);
s = getaddrinfo(host.get(), svc[i][1], &hints, &result);
GRPC_SCHEDULING_END_BLOCKING_REGION;
break;
}
@ -133,8 +133,6 @@ static grpc_error* posix_blocking_resolve_address(
err = GRPC_ERROR_NONE;
done:
gpr_free(host);
gpr_free(port);
if (result) {
freeaddrinfo(result);
}

@ -35,8 +35,8 @@
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/block_annotate.h"
#include "src/core/lib/iomgr/executor.h"
@ -57,14 +57,14 @@ static grpc_error* windows_blocking_resolve_address(
grpc_core::ExecCtx exec_ctx;
struct addrinfo hints;
struct addrinfo *result = NULL, *resp;
char* host;
char* port;
int s;
size_t i;
grpc_error* error = GRPC_ERROR_NONE;
/* parse name, splitting it into host and port parts */
gpr_split_host_port(name, &host, &port);
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
grpc_core::SplitHostPort(name, &host, &port);
if (host == NULL) {
char* msg;
gpr_asprintf(&msg, "unparseable host:port: '%s'", name);
@ -80,7 +80,7 @@ static grpc_error* windows_blocking_resolve_address(
gpr_free(msg);
goto done;
}
port = gpr_strdup(default_port);
port.reset(gpr_strdup(default_port));
}
/* Call getaddrinfo */
@ -90,7 +90,7 @@ static grpc_error* windows_blocking_resolve_address(
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */
GRPC_SCHEDULING_START_BLOCKING_REGION;
s = getaddrinfo(host, port, &hints, &result);
s = getaddrinfo(host.get(), port.get(), &hints, &result);
GRPC_SCHEDULING_END_BLOCKING_REGION;
if (s != 0) {
error = GRPC_WSA_ERROR(WSAGetLastError(), "getaddrinfo");
@ -122,8 +122,6 @@ static grpc_error* windows_blocking_resolve_address(
}
done:
gpr_free(host);
gpr_free(port);
if (result) {
freeaddrinfo(result);
}

@ -28,8 +28,8 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/sockaddr.h"
#include "src/core/lib/iomgr/socket_utils.h"
#include "src/core/lib/iomgr/unix_sockets_posix.h"
@ -181,15 +181,17 @@ int grpc_sockaddr_to_string(char** out,
}
if (ip != nullptr && grpc_inet_ntop(addr->sa_family, ip, ntop_buf,
sizeof(ntop_buf)) != nullptr) {
grpc_core::UniquePtr<char> tmp_out;
if (sin6_scope_id != 0) {
char* host_with_scope;
/* Enclose sin6_scope_id with the format defined in RFC 6784 section 2. */
gpr_asprintf(&host_with_scope, "%s%%25%" PRIu32, ntop_buf, sin6_scope_id);
ret = gpr_join_host_port(out, host_with_scope, port);
ret = grpc_core::JoinHostPort(&tmp_out, host_with_scope, port);
gpr_free(host_with_scope);
} else {
ret = gpr_join_host_port(out, ntop_buf, port);
ret = grpc_core::JoinHostPort(&tmp_out, ntop_buf, port);
}
*out = tmp_out.release();
} else {
ret = gpr_asprintf(out, "(sockaddr family=%d)", addr->sa_family);
}

@ -46,7 +46,6 @@
#include <grpc/support/sync.h>
#include "src/core/lib/channel/channel_args.h"
#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"

@ -34,7 +34,7 @@
#include <netinet/in.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/cfstream_handle.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint_cfstream.h"
@ -143,12 +143,13 @@ static void OnOpen(void* arg, grpc_error* error) {
static void ParseResolvedAddress(const grpc_resolved_address* addr,
CFStringRef* host, int* port) {
char *host_port, *host_string, *port_string;
char* host_port;
grpc_sockaddr_to_string(&host_port, addr, 1);
gpr_split_host_port(host_port, &host_string, &port_string);
*host = CFStringCreateWithCString(NULL, host_string, kCFStringEncodingUTF8);
gpr_free(host_string);
gpr_free(port_string);
grpc_core::UniquePtr<char> host_string;
grpc_core::UniquePtr<char> port_string;
grpc_core::SplitHostPort(host_port, &host_string, &port_string);
*host =
CFStringCreateWithCString(NULL, host_string.get(), kCFStringEncodingUTF8);
gpr_free(host_port);
*port = grpc_sockaddr_get_port(addr);
}

@ -108,10 +108,11 @@ class grpc_alts_channel_security_connector final
return strcmp(target_name_, other->target_name_);
}
bool check_call_host(const char* host, grpc_auth_context* auth_context,
bool check_call_host(grpc_core::StringView host,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) override {
if (host == nullptr || strcmp(host, target_name_) != 0) {
if (host.empty() || host != target_name_) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"ALTS call host does not match target name");
}

@ -31,8 +31,8 @@
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/credentials/credentials.h"
@ -102,39 +102,35 @@ class grpc_fake_channel_security_connector final
tsi_create_fake_handshaker(/*is_client=*/true), this));
}
bool check_call_host(const char* host, grpc_auth_context* auth_context,
bool check_call_host(grpc_core::StringView host,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) override {
char* authority_hostname = nullptr;
char* authority_ignored_port = nullptr;
char* target_hostname = nullptr;
char* target_ignored_port = nullptr;
gpr_split_host_port(host, &authority_hostname, &authority_ignored_port);
gpr_split_host_port(target_, &target_hostname, &target_ignored_port);
grpc_core::StringView authority_hostname;
grpc_core::StringView authority_ignored_port;
grpc_core::StringView target_hostname;
grpc_core::StringView target_ignored_port;
grpc_core::SplitHostPort(host, &authority_hostname,
&authority_ignored_port);
grpc_core::SplitHostPort(target_, &target_hostname, &target_ignored_port);
if (target_name_override_ != nullptr) {
char* fake_security_target_name_override_hostname = nullptr;
char* fake_security_target_name_override_ignored_port = nullptr;
gpr_split_host_port(target_name_override_,
&fake_security_target_name_override_hostname,
&fake_security_target_name_override_ignored_port);
if (strcmp(authority_hostname,
fake_security_target_name_override_hostname) != 0) {
grpc_core::StringView fake_security_target_name_override_hostname;
grpc_core::StringView fake_security_target_name_override_ignored_port;
grpc_core::SplitHostPort(
target_name_override_, &fake_security_target_name_override_hostname,
&fake_security_target_name_override_ignored_port);
if (authority_hostname != fake_security_target_name_override_hostname) {
gpr_log(GPR_ERROR,
"Authority (host) '%s' != Fake Security Target override '%s'",
host, fake_security_target_name_override_hostname);
host.data(),
fake_security_target_name_override_hostname.data());
abort();
}
gpr_free(fake_security_target_name_override_hostname);
gpr_free(fake_security_target_name_override_ignored_port);
} else if (strcmp(authority_hostname, target_hostname) != 0) {
gpr_log(GPR_ERROR, "Authority (host) '%s' != Target '%s'",
authority_hostname, target_hostname);
} else if (authority_hostname != target_hostname) {
gpr_log(GPR_ERROR, "Authority (host) '%s' != Target '%s'", host.data(),
target_);
abort();
}
gpr_free(authority_hostname);
gpr_free(authority_ignored_port);
gpr_free(target_hostname);
gpr_free(target_ignored_port);
return true;
}

@ -156,10 +156,11 @@ class grpc_local_channel_security_connector final
creds->connect_type());
}
bool check_call_host(const char* host, grpc_auth_context* auth_context,
bool check_call_host(grpc_core::StringView host,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) override {
if (host == nullptr || strcmp(host, target_name_) != 0) {
if (host.empty() || host != target_name_) {
*error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"local call host does not match target name");
}

@ -28,8 +28,8 @@
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/credentials/credentials.h"

@ -98,7 +98,7 @@ class grpc_channel_security_connector : public grpc_security_connector {
/// Returns true if completed synchronously, in which case \a error will
/// be set to indicate the result. Otherwise, \a on_call_host_checked
/// will be invoked when complete.
virtual bool check_call_host(const char* host,
virtual bool check_call_host(grpc_core::StringView host,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) GRPC_ABSTRACT;

@ -28,8 +28,8 @@
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/security/context/security_context.h"
#include "src/core/lib/security/credentials/credentials.h"
@ -75,15 +75,14 @@ class grpc_ssl_channel_security_connector final
? nullptr
: gpr_strdup(overridden_target_name)),
verify_options_(&config->verify_options) {
char* port;
gpr_split_host_port(target_name, &target_name_, &port);
gpr_free(port);
grpc_core::StringView host;
grpc_core::StringView port;
grpc_core::SplitHostPort(target_name, &host, &port);
target_name_ = host.dup();
}
~grpc_ssl_channel_security_connector() override {
tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory_);
if (target_name_ != nullptr) gpr_free(target_name_);
if (overridden_target_name_ != nullptr) gpr_free(overridden_target_name_);
}
grpc_security_status InitializeHandshakerFactory(
@ -123,8 +122,8 @@ class grpc_ssl_channel_security_connector final
tsi_handshaker* tsi_hs = nullptr;
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
client_handshaker_factory_,
overridden_target_name_ != nullptr ? overridden_target_name_
: target_name_,
overridden_target_name_ != nullptr ? overridden_target_name_.get()
: target_name_.get(),
&tsi_hs);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
@ -139,8 +138,8 @@ class grpc_ssl_channel_security_connector final
grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
grpc_closure* on_peer_checked) override {
const char* target_name = overridden_target_name_ != nullptr
? overridden_target_name_
: target_name_;
? overridden_target_name_.get()
: target_name_.get();
grpc_error* error = ssl_check_peer(target_name, &peer, auth_context);
if (error == GRPC_ERROR_NONE &&
verify_options_->verify_peer_callback != nullptr) {
@ -175,17 +174,18 @@ class grpc_ssl_channel_security_connector final
reinterpret_cast<const grpc_ssl_channel_security_connector*>(other_sc);
int c = channel_security_connector_cmp(other);
if (c != 0) return c;
c = strcmp(target_name_, other->target_name_);
c = strcmp(target_name_.get(), other->target_name_.get());
if (c != 0) return c;
return (overridden_target_name_ == nullptr ||
other->overridden_target_name_ == nullptr)
? GPR_ICMP(overridden_target_name_,
other->overridden_target_name_)
: strcmp(overridden_target_name_,
other->overridden_target_name_);
? GPR_ICMP(overridden_target_name_.get(),
other->overridden_target_name_.get())
: strcmp(overridden_target_name_.get(),
other->overridden_target_name_.get());
}
bool check_call_host(const char* host, grpc_auth_context* auth_context,
bool check_call_host(grpc_core::StringView host,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) override {
grpc_security_status status = GRPC_SECURITY_ERROR;
@ -194,7 +194,7 @@ class grpc_ssl_channel_security_connector final
/* If the target name was overridden, then the original target_name was
'checked' transitively during the previous peer check at the end of the
handshake. */
if (overridden_target_name_ != nullptr && strcmp(host, target_name_) == 0) {
if (overridden_target_name_ != nullptr && host == target_name_.get()) {
status = GRPC_SECURITY_OK;
}
if (status != GRPC_SECURITY_OK) {
@ -212,8 +212,8 @@ class grpc_ssl_channel_security_connector final
private:
tsi_ssl_client_handshaker_factory* client_handshaker_factory_;
char* target_name_;
char* overridden_target_name_;
grpc_core::UniquePtr<char> target_name_;
grpc_core::UniquePtr<char> overridden_target_name_;
const verify_peer_options* verify_options_;
};

@ -27,9 +27,9 @@
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/global_config.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/iomgr/load_file.h"
#include "src/core/lib/security/context/security_context.h"
@ -136,12 +136,13 @@ grpc_error* grpc_ssl_check_alpn(const tsi_peer* peer) {
return GRPC_ERROR_NONE;
}
grpc_error* grpc_ssl_check_peer_name(const char* peer_name,
grpc_error* grpc_ssl_check_peer_name(grpc_core::StringView peer_name,
const tsi_peer* peer) {
/* Check the peer name if specified. */
if (peer_name != nullptr && !grpc_ssl_host_matches_name(peer, peer_name)) {
if (!peer_name.empty() && !grpc_ssl_host_matches_name(peer, peer_name)) {
char* msg;
gpr_asprintf(&msg, "Peer name %s is not in peer certificate", peer_name);
gpr_asprintf(&msg, "Peer name %s is not in peer certificate",
peer_name.data());
grpc_error* error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
gpr_free(msg);
return error;
@ -149,15 +150,16 @@ grpc_error* grpc_ssl_check_peer_name(const char* peer_name,
return GRPC_ERROR_NONE;
}
bool grpc_ssl_check_call_host(const char* host, const char* target_name,
const char* overridden_target_name,
bool grpc_ssl_check_call_host(grpc_core::StringView host,
grpc_core::StringView target_name,
grpc_core::StringView overridden_target_name,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) {
grpc_security_status status = GRPC_SECURITY_ERROR;
tsi_peer peer = grpc_shallow_peer_from_ssl_auth_context(auth_context);
if (grpc_ssl_host_matches_name(&peer, host)) status = GRPC_SECURITY_OK;
if (overridden_target_name != nullptr && strcmp(host, target_name) == 0) {
if (!overridden_target_name.empty() && host == target_name) {
status = GRPC_SECURITY_OK;
}
if (status != GRPC_SECURITY_OK) {
@ -179,35 +181,28 @@ const char** grpc_fill_alpn_protocol_strings(size_t* num_alpn_protocols) {
return alpn_protocol_strings;
}
int grpc_ssl_host_matches_name(const tsi_peer* peer, const char* peer_name) {
char* allocated_name = nullptr;
int r;
char* ignored_port;
gpr_split_host_port(peer_name, &allocated_name, &ignored_port);
gpr_free(ignored_port);
peer_name = allocated_name;
if (!peer_name) return 0;
int grpc_ssl_host_matches_name(const tsi_peer* peer,
grpc_core::StringView peer_name) {
grpc_core::StringView allocated_name;
grpc_core::StringView ignored_port;
grpc_core::SplitHostPort(peer_name, &allocated_name, &ignored_port);
if (allocated_name.empty()) return 0;
// IPv6 zone-id should not be included in comparisons.
char* const zone_id = strchr(allocated_name, '%');
if (zone_id != nullptr) *zone_id = '\0';
r = tsi_ssl_peer_matches_name(peer, peer_name);
gpr_free(allocated_name);
return r;
const size_t zone_id = allocated_name.find('%');
if (zone_id != grpc_core::StringView::npos) {
allocated_name.remove_suffix(allocated_name.size() - zone_id);
}
return tsi_ssl_peer_matches_name(peer, allocated_name);
}
bool grpc_ssl_cmp_target_name(const char* target_name,
const char* other_target_name,
const char* overridden_target_name,
const char* other_overridden_target_name) {
int c = strcmp(target_name, other_target_name);
int grpc_ssl_cmp_target_name(
grpc_core::StringView target_name, grpc_core::StringView other_target_name,
grpc_core::StringView overridden_target_name,
grpc_core::StringView other_overridden_target_name) {
int c = target_name.cmp(other_target_name);
if (c != 0) return c;
return (overridden_target_name == nullptr ||
other_overridden_target_name == nullptr)
? GPR_ICMP(overridden_target_name, other_overridden_target_name)
: strcmp(overridden_target_name, other_overridden_target_name);
return overridden_target_name.cmp(other_overridden_target_name);
}
grpc_core::RefCountedPtr<grpc_auth_context> grpc_ssl_peer_to_auth_context(

@ -28,6 +28,7 @@
#include "src/core/lib/gprpp/global_config.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/string_view.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/security/security_connector/security_connector.h"
#include "src/core/tsi/ssl_transport_security.h"
@ -46,16 +47,17 @@ GPR_GLOBAL_CONFIG_DECLARE_BOOL(grpc_not_use_system_ssl_roots);
grpc_error* grpc_ssl_check_alpn(const tsi_peer* peer);
/* Check peer name information returned from SSL handshakes. */
grpc_error* grpc_ssl_check_peer_name(const char* peer_name,
grpc_error* grpc_ssl_check_peer_name(grpc_core::StringView peer_name,
const tsi_peer* peer);
/* Compare targer_name information extracted from SSL security connectors. */
bool grpc_ssl_cmp_target_name(const char* target_name,
const char* other_target_name,
const char* overridden_target_name,
const char* other_overridden_target_name);
int grpc_ssl_cmp_target_name(
grpc_core::StringView target_name, grpc_core::StringView other_target_name,
grpc_core::StringView overridden_target_name,
grpc_core::StringView other_overridden_target_name);
/* Check the host that will be set for a call is acceptable.*/
bool grpc_ssl_check_call_host(const char* host, const char* target_name,
const char* overridden_target_name,
bool grpc_ssl_check_call_host(grpc_core::StringView host,
grpc_core::StringView target_name,
grpc_core::StringView overridden_target_name,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error);
@ -89,7 +91,8 @@ grpc_core::RefCountedPtr<grpc_auth_context> grpc_ssl_peer_to_auth_context(
tsi_peer grpc_shallow_peer_from_ssl_auth_context(
const grpc_auth_context* auth_context);
void grpc_shallow_peer_destruct(tsi_peer* peer);
int grpc_ssl_host_matches_name(const tsi_peer* peer, const char* peer_name);
int grpc_ssl_host_matches_name(const tsi_peer* peer,
grpc_core::StringView peer_name);
/* --- Default SSL Root Store. --- */
namespace grpc_core {

@ -28,7 +28,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/credentials/ssl/ssl_credentials.h"
#include "src/core/lib/security/credentials/tls/spiffe_credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
@ -105,18 +105,13 @@ SpiffeChannelSecurityConnector::SpiffeChannelSecurityConnector(
? nullptr
: gpr_strdup(overridden_target_name)) {
check_arg_ = ServerAuthorizationCheckArgCreate(this);
char* port;
gpr_split_host_port(target_name, &target_name_, &port);
gpr_free(port);
grpc_core::StringView host;
grpc_core::StringView port;
grpc_core::SplitHostPort(target_name, &host, &port);
target_name_ = host.dup();
}
SpiffeChannelSecurityConnector::~SpiffeChannelSecurityConnector() {
if (target_name_ != nullptr) {
gpr_free(target_name_);
}
if (overridden_target_name_ != nullptr) {
gpr_free(overridden_target_name_);
}
if (client_handshaker_factory_ != nullptr) {
tsi_ssl_client_handshaker_factory_unref(client_handshaker_factory_);
}
@ -130,8 +125,8 @@ void SpiffeChannelSecurityConnector::add_handshakers(
tsi_handshaker* tsi_hs = nullptr;
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
client_handshaker_factory_,
overridden_target_name_ != nullptr ? overridden_target_name_
: target_name_,
overridden_target_name_ != nullptr ? overridden_target_name_.get()
: target_name_.get(),
&tsi_hs);
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
@ -147,8 +142,8 @@ void SpiffeChannelSecurityConnector::check_peer(
grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
grpc_closure* on_peer_checked) {
const char* target_name = overridden_target_name_ != nullptr
? overridden_target_name_
: target_name_;
? overridden_target_name_.get()
: target_name_.get();
grpc_error* error = grpc_ssl_check_alpn(&peer);
if (error != GRPC_ERROR_NONE) {
GRPC_CLOSURE_SCHED(on_peer_checked, error);
@ -203,16 +198,17 @@ int SpiffeChannelSecurityConnector::cmp(
if (c != 0) {
return c;
}
return grpc_ssl_cmp_target_name(target_name_, other->target_name_,
overridden_target_name_,
other->overridden_target_name_);
return grpc_ssl_cmp_target_name(target_name_.get(), other->target_name_.get(),
overridden_target_name_.get(),
other->overridden_target_name_.get());
}
bool SpiffeChannelSecurityConnector::check_call_host(
const char* host, grpc_auth_context* auth_context,
grpc_core::StringView host, grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked, grpc_error** error) {
return grpc_ssl_check_call_host(host, target_name_, overridden_target_name_,
auth_context, on_call_host_checked, error);
return grpc_ssl_check_call_host(host, target_name_.get(),
overridden_target_name_.get(), auth_context,
on_call_host_checked, error);
}
void SpiffeChannelSecurityConnector::cancel_check_call_host(

@ -53,7 +53,8 @@ class SpiffeChannelSecurityConnector final
int cmp(const grpc_security_connector* other_sc) const override;
bool check_call_host(const char* host, grpc_auth_context* auth_context,
bool check_call_host(grpc_core::StringView host,
grpc_auth_context* auth_context,
grpc_closure* on_call_host_checked,
grpc_error** error) override;
@ -83,8 +84,8 @@ class SpiffeChannelSecurityConnector final
grpc_tls_server_authorization_check_arg* arg);
grpc_closure* on_peer_checked_;
char* target_name_;
char* overridden_target_name_;
grpc_core::UniquePtr<char> target_name_;
grpc_core::UniquePtr<char> overridden_target_name_;
tsi_ssl_client_handshaker_factory* client_handshaker_factory_ = nullptr;
grpc_tls_server_authorization_check_arg* check_arg_;
};

@ -346,7 +346,7 @@ static void auth_start_transport_stream_op_batch(
GRPC_CALL_STACK_REF(calld->owning_call, "check_call_host");
GRPC_CLOSURE_INIT(&calld->async_result_closure, on_host_checked, batch,
grpc_schedule_on_exec_ctx);
char* call_host = grpc_slice_to_c_string(calld->host);
grpc_core::StringView call_host(calld->host);
grpc_error* error = GRPC_ERROR_NONE;
if (chand->security_connector->check_call_host(
call_host, chand->auth_context.get(),
@ -360,7 +360,6 @@ static void auth_start_transport_stream_op_batch(
&calld->check_call_host_cancel_closure, cancel_check_call_host,
elem, grpc_schedule_on_exec_ctx));
}
gpr_free(call_host);
return; /* early exit */
}
}

@ -186,19 +186,21 @@ struct UserData {
class StaticMetadata {
public:
StaticMetadata(const grpc_slice& key, const grpc_slice& value)
: kv_({key, value}), hash_(0) {}
StaticMetadata(const grpc_slice& key, const grpc_slice& value, uintptr_t idx)
: kv_({key, value}), hash_(0), static_idx_(idx) {}
const grpc_mdelem_data& data() const { return kv_; }
void HashInit();
uint32_t hash() { return hash_; }
uintptr_t StaticIndex() { return static_idx_; }
private:
grpc_mdelem_data kv_;
/* private only data */
uint32_t hash_;
uintptr_t static_idx_;
};
class RefcountedMdBase {

@ -398,262 +398,262 @@ grpc_mdelem grpc_static_mdelem_for_static_strings(intptr_t a, intptr_t b) {
grpc_core::StaticMetadata grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[3], {{10, g_bytes + 19}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 0),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[1], {{7, g_bytes + 5}}},
{&grpc_static_metadata_refcounts[40], {{3, g_bytes + 612}}}),
{&grpc_static_metadata_refcounts[40], {{3, g_bytes + 612}}}, 1),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[1], {{7, g_bytes + 5}}},
{&grpc_static_metadata_refcounts[41], {{4, g_bytes + 615}}}),
{&grpc_static_metadata_refcounts[41], {{4, g_bytes + 615}}}, 2),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[0], {{5, g_bytes + 0}}},
{&grpc_static_metadata_refcounts[42], {{1, g_bytes + 619}}}),
{&grpc_static_metadata_refcounts[42], {{1, g_bytes + 619}}}, 3),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[0], {{5, g_bytes + 0}}},
{&grpc_static_metadata_refcounts[43], {{11, g_bytes + 620}}}),
{&grpc_static_metadata_refcounts[43], {{11, g_bytes + 620}}}, 4),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[4], {{7, g_bytes + 29}}},
{&grpc_static_metadata_refcounts[44], {{4, g_bytes + 631}}}),
{&grpc_static_metadata_refcounts[44], {{4, g_bytes + 631}}}, 5),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[4], {{7, g_bytes + 29}}},
{&grpc_static_metadata_refcounts[45], {{5, g_bytes + 635}}}),
{&grpc_static_metadata_refcounts[45], {{5, g_bytes + 635}}}, 6),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[2], {{7, g_bytes + 12}}},
{&grpc_static_metadata_refcounts[46], {{3, g_bytes + 640}}}),
{&grpc_static_metadata_refcounts[46], {{3, g_bytes + 640}}}, 7),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[2], {{7, g_bytes + 12}}},
{&grpc_static_metadata_refcounts[47], {{3, g_bytes + 643}}}),
{&grpc_static_metadata_refcounts[47], {{3, g_bytes + 643}}}, 8),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[2], {{7, g_bytes + 12}}},
{&grpc_static_metadata_refcounts[48], {{3, g_bytes + 646}}}),
{&grpc_static_metadata_refcounts[48], {{3, g_bytes + 646}}}, 9),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[2], {{7, g_bytes + 12}}},
{&grpc_static_metadata_refcounts[49], {{3, g_bytes + 649}}}),
{&grpc_static_metadata_refcounts[49], {{3, g_bytes + 649}}}, 10),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[2], {{7, g_bytes + 12}}},
{&grpc_static_metadata_refcounts[50], {{3, g_bytes + 652}}}),
{&grpc_static_metadata_refcounts[50], {{3, g_bytes + 652}}}, 11),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[2], {{7, g_bytes + 12}}},
{&grpc_static_metadata_refcounts[51], {{3, g_bytes + 655}}}),
{&grpc_static_metadata_refcounts[51], {{3, g_bytes + 655}}}, 12),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[2], {{7, g_bytes + 12}}},
{&grpc_static_metadata_refcounts[52], {{3, g_bytes + 658}}}),
{&grpc_static_metadata_refcounts[52], {{3, g_bytes + 658}}}, 13),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[53], {{14, g_bytes + 661}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 14),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[16], {{15, g_bytes + 186}}},
{&grpc_static_metadata_refcounts[54], {{13, g_bytes + 675}}}),
{&grpc_static_metadata_refcounts[54], {{13, g_bytes + 675}}}, 15),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[55], {{15, g_bytes + 688}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 16),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[56], {{13, g_bytes + 703}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 17),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[57], {{6, g_bytes + 716}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 18),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[58], {{27, g_bytes + 722}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 19),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[59], {{3, g_bytes + 749}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 20),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[60], {{5, g_bytes + 752}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 21),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[61], {{13, g_bytes + 757}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 22),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[62], {{13, g_bytes + 770}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 23),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[63], {{19, g_bytes + 783}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 24),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[15], {{16, g_bytes + 170}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 25),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[64], {{16, g_bytes + 802}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 26),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[65], {{14, g_bytes + 818}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 27),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[66], {{16, g_bytes + 832}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 28),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[67], {{13, g_bytes + 848}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 29),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[14], {{12, g_bytes + 158}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 30),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[68], {{6, g_bytes + 861}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 31),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[69], {{4, g_bytes + 867}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 32),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[70], {{4, g_bytes + 871}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 33),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[71], {{6, g_bytes + 875}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 34),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[72], {{7, g_bytes + 881}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 35),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[73], {{4, g_bytes + 888}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 36),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[20], {{4, g_bytes + 278}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 37),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[74], {{8, g_bytes + 892}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 38),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[75], {{17, g_bytes + 900}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 39),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[76], {{13, g_bytes + 917}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 40),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[77], {{8, g_bytes + 930}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 41),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[78], {{19, g_bytes + 938}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 42),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[79], {{13, g_bytes + 957}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 43),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[80], {{4, g_bytes + 970}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 44),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[81], {{8, g_bytes + 974}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 45),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[82], {{12, g_bytes + 982}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 46),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[83], {{18, g_bytes + 994}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 47),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[84], {{19, g_bytes + 1012}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 48),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[85], {{5, g_bytes + 1031}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 49),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[86], {{7, g_bytes + 1036}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 50),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[87], {{7, g_bytes + 1043}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 51),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[88], {{11, g_bytes + 1050}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 52),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[89], {{6, g_bytes + 1061}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 53),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[90], {{10, g_bytes + 1067}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 54),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[91], {{25, g_bytes + 1077}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 55),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[92], {{17, g_bytes + 1102}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 56),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[19], {{10, g_bytes + 268}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 57),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[93], {{4, g_bytes + 1119}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 58),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[94], {{3, g_bytes + 1123}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 59),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[95], {{16, g_bytes + 1126}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 60),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[7], {{11, g_bytes + 50}}},
{&grpc_static_metadata_refcounts[96], {{1, g_bytes + 1142}}}),
{&grpc_static_metadata_refcounts[96], {{1, g_bytes + 1142}}}, 61),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[7], {{11, g_bytes + 50}}},
{&grpc_static_metadata_refcounts[25], {{1, g_bytes + 350}}}),
{&grpc_static_metadata_refcounts[25], {{1, g_bytes + 350}}}, 62),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[7], {{11, g_bytes + 50}}},
{&grpc_static_metadata_refcounts[26], {{1, g_bytes + 351}}}),
{&grpc_static_metadata_refcounts[26], {{1, g_bytes + 351}}}, 63),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[9], {{13, g_bytes + 77}}},
{&grpc_static_metadata_refcounts[97], {{8, g_bytes + 1143}}}),
{&grpc_static_metadata_refcounts[97], {{8, g_bytes + 1143}}}, 64),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[9], {{13, g_bytes + 77}}},
{&grpc_static_metadata_refcounts[38], {{4, g_bytes + 597}}}),
{&grpc_static_metadata_refcounts[38], {{4, g_bytes + 597}}}, 65),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[9], {{13, g_bytes + 77}}},
{&grpc_static_metadata_refcounts[37], {{7, g_bytes + 590}}}),
{&grpc_static_metadata_refcounts[37], {{7, g_bytes + 590}}}, 66),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[5], {{2, g_bytes + 36}}},
{&grpc_static_metadata_refcounts[98], {{8, g_bytes + 1151}}}),
{&grpc_static_metadata_refcounts[98], {{8, g_bytes + 1151}}}, 67),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[14], {{12, g_bytes + 158}}},
{&grpc_static_metadata_refcounts[99], {{16, g_bytes + 1159}}}),
{&grpc_static_metadata_refcounts[99], {{16, g_bytes + 1159}}}, 68),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[4], {{7, g_bytes + 29}}},
{&grpc_static_metadata_refcounts[100], {{4, g_bytes + 1175}}}),
{&grpc_static_metadata_refcounts[100], {{4, g_bytes + 1175}}}, 69),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[1], {{7, g_bytes + 5}}},
{&grpc_static_metadata_refcounts[101], {{3, g_bytes + 1179}}}),
{&grpc_static_metadata_refcounts[101], {{3, g_bytes + 1179}}}, 70),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[16], {{15, g_bytes + 186}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 71),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[15], {{16, g_bytes + 170}}},
{&grpc_static_metadata_refcounts[97], {{8, g_bytes + 1143}}}),
{&grpc_static_metadata_refcounts[97], {{8, g_bytes + 1143}}}, 72),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[15], {{16, g_bytes + 170}}},
{&grpc_static_metadata_refcounts[38], {{4, g_bytes + 597}}}),
{&grpc_static_metadata_refcounts[38], {{4, g_bytes + 597}}}, 73),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[21], {{8, g_bytes + 282}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 74),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[102], {{11, g_bytes + 1182}}},
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}),
{&grpc_static_metadata_refcounts[29], {{0, g_bytes + 354}}}, 75),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[10], {{20, g_bytes + 90}}},
{&grpc_static_metadata_refcounts[97], {{8, g_bytes + 1143}}}),
{&grpc_static_metadata_refcounts[97], {{8, g_bytes + 1143}}}, 76),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[10], {{20, g_bytes + 90}}},
{&grpc_static_metadata_refcounts[37], {{7, g_bytes + 590}}}),
{&grpc_static_metadata_refcounts[37], {{7, g_bytes + 590}}}, 77),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[10], {{20, g_bytes + 90}}},
{&grpc_static_metadata_refcounts[103], {{16, g_bytes + 1193}}}),
{&grpc_static_metadata_refcounts[103], {{16, g_bytes + 1193}}}, 78),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[10], {{20, g_bytes + 90}}},
{&grpc_static_metadata_refcounts[38], {{4, g_bytes + 597}}}),
{&grpc_static_metadata_refcounts[38], {{4, g_bytes + 597}}}, 79),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[10], {{20, g_bytes + 90}}},
{&grpc_static_metadata_refcounts[104], {{13, g_bytes + 1209}}}),
{&grpc_static_metadata_refcounts[104], {{13, g_bytes + 1209}}}, 80),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[10], {{20, g_bytes + 90}}},
{&grpc_static_metadata_refcounts[105], {{12, g_bytes + 1222}}}),
{&grpc_static_metadata_refcounts[105], {{12, g_bytes + 1222}}}, 81),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[10], {{20, g_bytes + 90}}},
{&grpc_static_metadata_refcounts[106], {{21, g_bytes + 1234}}}),
{&grpc_static_metadata_refcounts[106], {{21, g_bytes + 1234}}}, 82),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[16], {{15, g_bytes + 186}}},
{&grpc_static_metadata_refcounts[97], {{8, g_bytes + 1143}}}),
{&grpc_static_metadata_refcounts[97], {{8, g_bytes + 1143}}}, 83),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[16], {{15, g_bytes + 186}}},
{&grpc_static_metadata_refcounts[38], {{4, g_bytes + 597}}}),
{&grpc_static_metadata_refcounts[38], {{4, g_bytes + 597}}}, 84),
grpc_core::StaticMetadata(
{&grpc_static_metadata_refcounts[16], {{15, g_bytes + 186}}},
{&grpc_static_metadata_refcounts[104], {{13, g_bytes + 1209}}}),
{&grpc_static_metadata_refcounts[104], {{13, g_bytes + 1209}}}, 85),
};
const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 76, 77, 78,
79, 80, 81, 82};

@ -30,7 +30,6 @@
#include <grpc/support/sync.h>
#include <grpc/support/thd_id.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/slice/slice_internal.h"

@ -233,11 +233,10 @@ static void ssl_info_callback(const SSL* ssl, int where, int ret) {
/* Returns 1 if name looks like an IP address, 0 otherwise.
This is a very rough heuristic, and only handles IPv6 in hexadecimal form. */
static int looks_like_ip_address(const char* name) {
size_t i;
static int looks_like_ip_address(grpc_core::StringView name) {
size_t dot_count = 0;
size_t num_size = 0;
for (i = 0; i < strlen(name); i++) {
for (size_t i = 0; i < name.size(); ++i) {
if (name[i] == ':') {
/* IPv6 Address in hexadecimal form, : is not allowed in DNS names. */
return 1;
@ -1506,52 +1505,46 @@ static void tsi_ssl_server_handshaker_factory_destroy(
gpr_free(self);
}
static int does_entry_match_name(const char* entry, size_t entry_length,
const char* name) {
const char* dot;
const char* name_subdomain = nullptr;
size_t name_length = strlen(name);
size_t name_subdomain_length;
if (entry_length == 0) return 0;
static int does_entry_match_name(grpc_core::StringView entry,
grpc_core::StringView name) {
if (entry.empty()) return 0;
/* Take care of '.' terminations. */
if (name[name_length - 1] == '.') {
name_length--;
if (name.back() == '.') {
name.remove_suffix(1);
}
if (entry[entry_length - 1] == '.') {
entry_length--;
if (entry_length == 0) return 0;
if (entry.back() == '.') {
entry.remove_suffix(1);
if (entry.empty()) return 0;
}
if ((name_length == entry_length) &&
strncmp(name, entry, entry_length) == 0) {
if (name == entry) {
return 1; /* Perfect match. */
}
if (entry[0] != '*') return 0;
if (entry.front() != '*') return 0;
/* Wildchar subdomain matching. */
if (entry_length < 3 || entry[1] != '.') { /* At least *.x */
if (entry.size() < 3 || entry[1] != '.') { /* At least *.x */
gpr_log(GPR_ERROR, "Invalid wildchar entry.");
return 0;
}
name_subdomain = strchr(name, '.');
if (name_subdomain == nullptr) return 0;
name_subdomain_length = strlen(name_subdomain);
if (name_subdomain_length < 2) return 0;
name_subdomain++; /* Starts after the dot. */
name_subdomain_length--;
entry += 2; /* Remove *. */
entry_length -= 2;
dot = strchr(name_subdomain, '.');
if ((dot == nullptr) || (dot == &name_subdomain[name_subdomain_length - 1])) {
gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s", name_subdomain);
size_t name_subdomain_pos = name.find('.');
if (name_subdomain_pos == grpc_core::StringView::npos) return 0;
if (name_subdomain_pos >= name.size() - 2) return 0;
grpc_core::StringView name_subdomain =
name.substr(name_subdomain_pos + 1); /* Starts after the dot. */
entry.remove_prefix(2); /* Remove *. */
size_t dot = name_subdomain.find('.');
if (dot == grpc_core::StringView::npos || dot == name_subdomain.size() - 1) {
grpc_core::UniquePtr<char> name_subdomain_cstr(name_subdomain.dup());
gpr_log(GPR_ERROR, "Invalid toplevel subdomain: %s",
name_subdomain_cstr.get());
return 0;
}
if (name_subdomain[name_subdomain_length - 1] == '.') {
name_subdomain_length--;
if (name_subdomain.back() == '.') {
name_subdomain.remove_suffix(1);
}
return ((entry_length > 0) && (name_subdomain_length == entry_length) &&
strncmp(entry, name_subdomain, entry_length) == 0);
return !entry.empty() && name_subdomain == entry;
}
static int ssl_server_handshaker_factory_servername_callback(SSL* ssl, int* ap,
@ -1919,7 +1912,8 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
/* --- tsi_ssl utils. --- */
int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) {
int tsi_ssl_peer_matches_name(const tsi_peer* peer,
grpc_core::StringView name) {
size_t i = 0;
size_t san_count = 0;
const tsi_peer_property* cn_property = nullptr;
@ -1933,13 +1927,10 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) {
TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY) == 0) {
san_count++;
if (!like_ip && does_entry_match_name(property->value.data,
property->value.length, name)) {
grpc_core::StringView entry(property->value.data, property->value.length);
if (!like_ip && does_entry_match_name(entry, name)) {
return 1;
} else if (like_ip &&
strncmp(name, property->value.data, property->value.length) ==
0 &&
strlen(name) == property->value.length) {
} else if (like_ip && name == entry) {
/* IP Addresses are exact matches only. */
return 1;
}
@ -1951,8 +1942,9 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name) {
/* If there's no SAN, try the CN, but only if its not like an IP Address */
if (san_count == 0 && cn_property != nullptr && !like_ip) {
if (does_entry_match_name(cn_property->value.data,
cn_property->value.length, name)) {
if (does_entry_match_name(grpc_core::StringView(cn_property->value.data,
cn_property->value.length),
name)) {
return 1;
}
}

@ -21,6 +21,7 @@
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/string_view.h"
#include "src/core/tsi/transport_security_interface.h"
/* Value for the TSI_CERTIFICATE_TYPE_PEER_PROPERTY property for X509 certs. */
@ -306,7 +307,7 @@ void tsi_ssl_server_handshaker_factory_unref(
- handle mixed case.
- handle %encoded chars.
- handle public suffix wildchar more strictly (e.g. *.co.uk) */
int tsi_ssl_peer_matches_name(const tsi_peer* peer, const char* name);
int tsi_ssl_peer_matches_name(const tsi_peer* peer, grpc_core::StringView name);
/* --- Testing support. ---

@ -322,9 +322,6 @@ const char *kCFStreamVarName = "grpc_cfstream";
// Guarantees the code in {} block is invoked only once. See ref at:
// https://developer.apple.com/documentation/objectivec/nsobject/1418639-initialize?language=objc
if (self == [GRPCCall self]) {
// Enable CFStream by default by do not overwrite if the user explicitly disables CFStream with
// environment variable "grpc_cfstream=0"
setenv(kCFStreamVarName, "1", 0);
grpc_init();
callFlags = [NSMutableDictionary dictionary];
}
@ -780,7 +777,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
// Connectivity monitor is not required for CFStream
char *enableCFStream = getenv(kCFStreamVarName);
if (enableCFStream == nil || enableCFStream[0] != '1') {
if (enableCFStream != nil && enableCFStream[0] != '1') {
[GRPCConnectivityMonitor registerObserver:self selector:@selector(connectivityChanged:)];
}
}

@ -21,8 +21,6 @@
int main(int argc, char* argv[]) {
@autoreleasepool {
// enable CFStream API
setenv("grpc_cfstream", "1", 1);
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

@ -37,9 +37,9 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
#include "test/core/end2end/data/ssl_test_data.h"
@ -51,19 +51,18 @@
#import "../ConfigureCronet.h"
typedef struct fullstack_secure_fixture_data {
char *localaddr;
} fullstack_secure_fixture_data;
struct fullstack_secure_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_channel_args *client_args, grpc_channel_args *server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data *ffd =
(fullstack_secure_fixture_data *)gpr_malloc(sizeof(fullstack_secure_fixture_data));
fullstack_secure_fixture_data *ffd = grpc_core::New<fullstack_secure_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "127.0.0.1", port);
grpc_core::JoinHostPort(&ffd->localaddr, "127.0.0.1", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(NULL);
@ -83,7 +82,8 @@ static void cronet_init_client_secure_fullstack(grpc_end2end_test_fixture *f,
grpc_channel_args *client_args,
stream_engine *cronetEngine) {
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
f->client = grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr, client_args, NULL);
f->client =
grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr.get(), client_args, NULL);
GPR_ASSERT(f->client != NULL);
}
@ -96,15 +96,14 @@ static void chttp2_init_server_secure_fullstack(grpc_end2end_test_fixture *f,
}
f->server = grpc_server_create(server_args, NULL);
grpc_server_register_completion_queue(f->server, f->cq, NULL);
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, server_creds));
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(), server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
}
static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) {
fullstack_secure_fixture_data *ffd = (fullstack_secure_fixture_data *)f->fixture_data;
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
static void cronet_init_client_simple_ssl_secure_fullstack(grpc_end2end_test_fixture *f,

@ -33,9 +33,9 @@
#import "src/core/lib/channel/channel_args.h"
#import "src/core/lib/gpr/env.h"
#import "src/core/lib/gpr/host_port.h"
#import "src/core/lib/gpr/string.h"
#import "src/core/lib/gpr/tmpfile.h"
#import "src/core/lib/gprpp/host_port.h"
#import "test/core/end2end/data/ssl_test_data.h"
#import "test/core/util/test_config.h"
@ -133,11 +133,11 @@ unsigned int parse_h2_length(const char *field) {
{{NULL, NULL, NULL, NULL}}}};
int port = grpc_pick_unused_port_or_die();
char *addr;
gpr_join_host_port(&addr, "127.0.0.1", port);
grpc_core::UniquePtr<char> addr;
grpc_core::JoinHostPort(&addr, "127.0.0.1", port);
grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
stream_engine *cronetEngine = [Cronet getGlobalEngine];
grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr, NULL, NULL);
grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr.get(), NULL, NULL);
cq_verifier *cqv = cq_verifier_create(cq);
grpc_op ops[6];
@ -264,11 +264,11 @@ unsigned int parse_h2_length(const char *field) {
{{NULL, NULL, NULL, NULL}}}};
int port = grpc_pick_unused_port_or_die();
char *addr;
gpr_join_host_port(&addr, "127.0.0.1", port);
grpc_core::UniquePtr<char> addr;
grpc_core::JoinHostPort(&addr, "127.0.0.1", port);
grpc_completion_queue *cq = grpc_completion_queue_create_for_next(NULL);
stream_engine *cronetEngine = [Cronet getGlobalEngine];
grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr, args, NULL);
grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr.get(), args, NULL);
cq_verifier *cqv = cq_verifier_create(cq);
grpc_op ops[6];

@ -27,7 +27,6 @@ CORE_SOURCE_FILES = [
'src/core/lib/gpr/env_linux.cc',
'src/core/lib/gpr/env_posix.cc',
'src/core/lib/gpr/env_windows.cc',
'src/core/lib/gpr/host_port.cc',
'src/core/lib/gpr/log.cc',
'src/core/lib/gpr/log_android.cc',
'src/core/lib/gpr/log_linux.cc',
@ -54,6 +53,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/gprpp/arena.cc',
'src/core/lib/gprpp/fork.cc',
'src/core/lib/gprpp/global_config_env.cc',
'src/core/lib/gprpp/host_port.cc',
'src/core/lib/gprpp/thd_posix.cc',
'src/core/lib/gprpp/thd_windows.cc',
'src/core/lib/profiling/basic_timers.cc',
@ -102,6 +102,7 @@ CORE_SOURCE_FILES = [
'src/core/lib/iomgr/exec_ctx.cc',
'src/core/lib/iomgr/executor.cc',
'src/core/lib/iomgr/executor/mpmcqueue.cc',
'src/core/lib/iomgr/executor/threadpool.cc',
'src/core/lib/iomgr/fork_posix.cc',
'src/core/lib/iomgr/fork_windows.cc',
'src/core/lib/iomgr/gethostname_fallback.cc',

@ -325,7 +325,7 @@
% for lib in libs:
% if lib.build in ["all", "protoc", "tool", "test", "private"] and not lib.boringssl:
% if not lib.get('build_system', []) or 'cmake' in lib.get('build_system', []):
% if not lib.name in ['ares', 'benchmark', 'z']: # we build these using CMake instead
% if not lib.name in ['ares', 'benchmark', 'upb', 'z']: # we build these using CMake instead
% if lib.build in ["test", "private"]:
if (gRPC_BUILD_TESTS)
${cc_library(lib)}
@ -467,6 +467,13 @@
)
endif (_gRPC_PLATFORM_ANDROID)
% endif
% if lib.name in ["grpc", "grpc_cronet", "grpc_test_util", \
"grpc_test_util_unsecure", "grpc_unsecure", \
"grpc++_cronet"]:
if (_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
target_link_libraries(${lib.name} "-framework CoreFoundation")
endif()
%endif
% if len(lib.get('public_headers', [])) > 0:
foreach(_hdr

@ -220,6 +220,7 @@
CXXFLAGS += -std=c++11
ifeq ($(SYSTEM),Darwin)
CXXFLAGS += -stdlib=libc++
LDFLAGS += -framework CoreFoundation
endif
% for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'COREFLAGS', 'LDFLAGS', 'DEFINES']:
% if defaults.get('global', []).get(arg, None) is not None:

@ -25,8 +25,9 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/port.h"
@ -144,7 +145,9 @@ int main(int argc, char** argv) {
gpr_asprintf(&args[0], "%s/bad_ssl_%s_server%s", root, test,
gpr_subprocess_binary_extension());
args[1] = const_cast<char*>("--bind");
gpr_join_host_port(&args[2], "::", port);
grpc_core::UniquePtr<char> joined;
grpc_core::JoinHostPort(&joined, "::", port);
args[2] = joined.get();
svr = gpr_subprocess_create(4, (const char**)args);
gpr_free(args[0]);
@ -153,7 +156,6 @@ int main(int argc, char** argv) {
run_test(args[2], i);
grpc_shutdown();
}
gpr_free(args[2]);
gpr_subprocess_interrupt(svr);
status = gpr_subprocess_join(svr);

@ -30,7 +30,8 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/socket_utils.h"
#include "test/core/util/test_config.h"
@ -60,20 +61,20 @@ static void test_grpc_parse_ipv6_parity_with_getaddrinfo(
struct sockaddr_in6 resolve_with_gettaddrinfo(const char* uri_text) {
grpc_uri* uri = grpc_uri_parse(uri_text, 0);
char* host = nullptr;
char* port = nullptr;
gpr_split_host_port(uri->path, &host, &port);
grpc_core::UniquePtr<char> host;
grpc_core::UniquePtr<char> port;
grpc_core::SplitHostPort(uri->path, &host, &port);
struct addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_NUMERICHOST;
struct addrinfo* result;
int res = getaddrinfo(host, port, &hints, &result);
int res = getaddrinfo(host.get(), port.get(), &hints, &result);
if (res != 0) {
gpr_log(GPR_ERROR,
"getaddrinfo failed to resolve host:%s port:%s. Error: %d.", host,
port, res);
"getaddrinfo failed to resolve host:%s port:%s. Error: %d.",
host.get(), port.get(), res);
abort();
}
size_t num_addrs_from_getaddrinfo = 0;
@ -86,8 +87,6 @@ struct sockaddr_in6 resolve_with_gettaddrinfo(const char* uri_text) {
*reinterpret_cast<struct sockaddr_in6*>(result->ai_addr);
// Cleanup
freeaddrinfo(result);
gpr_free(host);
gpr_free(port);
grpc_uri_destroy(uri);
return out;
}

@ -29,8 +29,8 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/sockaddr.h"
@ -71,7 +71,7 @@
#define SERVER_INCOMING_DATA_LENGTH_LOWER_THRESHOLD (size_t)200
struct rpc_state {
char* target;
grpc_core::UniquePtr<char> target;
grpc_completion_queue* cq;
grpc_channel* channel;
grpc_call* call;
@ -165,8 +165,9 @@ static void start_rpc(int target_port, grpc_status_code expected_status,
state.cq = grpc_completion_queue_create_for_next(nullptr);
cqv = cq_verifier_create(state.cq);
gpr_join_host_port(&state.target, "127.0.0.1", target_port);
state.channel = grpc_insecure_channel_create(state.target, nullptr, nullptr);
grpc_core::JoinHostPort(&state.target, "127.0.0.1", target_port);
state.channel =
grpc_insecure_channel_create(state.target.get(), nullptr, nullptr);
grpc_slice host = grpc_slice_from_static_string("localhost");
state.call = grpc_channel_create_call(
state.channel, nullptr, GRPC_PROPAGATE_DEFAULTS, state.cq,
@ -230,7 +231,7 @@ static void cleanup_rpc() {
} while (ev.type != GRPC_QUEUE_SHUTDOWN);
grpc_completion_queue_destroy(state.cq);
grpc_channel_destroy(state.channel);
gpr_free(state.target);
state.target.reset();
}
typedef struct {

@ -24,7 +24,7 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/transport/metadata.h"
@ -77,10 +77,10 @@ static void run_test(bool wait_for_ready, bool use_service_config) {
/* create a call, channel to a port which will refuse connection */
int port = grpc_pick_unused_port_or_die();
char* addr;
gpr_join_host_port(&addr, "127.0.0.1", port);
gpr_log(GPR_INFO, "server: %s", addr);
chan = grpc_insecure_channel_create(addr, args, nullptr);
grpc_core::UniquePtr<char> addr;
grpc_core::JoinHostPort(&addr, "127.0.0.1", port);
gpr_log(GPR_INFO, "server: %s", addr.get());
chan = grpc_insecure_channel_create(addr.get(), args, nullptr);
grpc_slice host = grpc_slice_from_static_string("nonexistant");
gpr_timespec deadline = grpc_timeout_seconds_to_deadline(2);
call =
@ -88,8 +88,6 @@ static void run_test(bool wait_for_ready, bool use_service_config) {
grpc_slice_from_static_string("/service/method"),
&host, deadline, nullptr);
gpr_free(addr);
memset(ops, 0, sizeof(ops));
op = ops;
op->op = GRPC_OP_SEND_INITIAL_METADATA;

@ -28,8 +28,8 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/iomgr/resolve_address.h"
#include "src/core/lib/iomgr/sockaddr_utils.h"
@ -70,8 +70,6 @@ static void log_resolved_addrs(const char* label, const char* hostname) {
void test_connect(const char* server_host, const char* client_host, int port,
int expect_ok) {
char* client_hostport;
char* server_hostport;
grpc_channel* client;
grpc_server* server;
grpc_completion_queue* cq;
@ -99,7 +97,8 @@ void test_connect(const char* server_host, const char* client_host, int port,
picked_port = 1;
}
gpr_join_host_port(&server_hostport, server_host, port);
grpc_core::UniquePtr<char> server_hostport;
grpc_core::JoinHostPort(&server_hostport, server_host, port);
grpc_metadata_array_init(&initial_metadata_recv);
grpc_metadata_array_init(&trailing_metadata_recv);
@ -111,7 +110,7 @@ void test_connect(const char* server_host, const char* client_host, int port,
server = grpc_server_create(nullptr, nullptr);
grpc_server_register_completion_queue(server, cq, nullptr);
GPR_ASSERT((got_port = grpc_server_add_insecure_http2_port(
server, server_hostport)) > 0);
server, server_hostport.get())) > 0);
if (port == 0) {
port = got_port;
} else {
@ -121,6 +120,7 @@ void test_connect(const char* server_host, const char* client_host, int port,
cqv = cq_verifier_create(cq);
/* Create client. */
grpc_core::UniquePtr<char> client_hostport;
if (client_host[0] == 'i') {
/* for ipv4:/ipv6: addresses, concatenate the port to each of the parts */
size_t i;
@ -139,8 +139,8 @@ void test_connect(const char* server_host, const char* client_host, int port,
gpr_asprintf(&hosts_with_port[i], "%s:%d", uri_part_str, port);
gpr_free(uri_part_str);
}
client_hostport = gpr_strjoin_sep((const char**)hosts_with_port,
uri_parts.count, ",", nullptr);
client_hostport.reset(gpr_strjoin_sep((const char**)hosts_with_port,
uri_parts.count, ",", nullptr));
for (i = 0; i < uri_parts.count; i++) {
gpr_free(hosts_with_port[i]);
}
@ -148,18 +148,17 @@ void test_connect(const char* server_host, const char* client_host, int port,
grpc_slice_buffer_destroy(&uri_parts);
grpc_slice_unref(uri_slice);
} else {
gpr_join_host_port(&client_hostport, client_host, port);
grpc_core::JoinHostPort(&client_hostport, client_host, port);
}
client = grpc_insecure_channel_create(client_hostport, nullptr, nullptr);
client =
grpc_insecure_channel_create(client_hostport.get(), nullptr, nullptr);
gpr_log(GPR_INFO, "Testing with server=%s client=%s (expecting %s)",
server_hostport, client_hostport, expect_ok ? "success" : "failure");
server_hostport.get(), client_hostport.get(),
expect_ok ? "success" : "failure");
log_resolved_addrs("server resolved addr", server_host);
log_resolved_addrs("client resolved addr", client_host);
gpr_free(client_hostport);
gpr_free(server_hostport);
if (expect_ok) {
/* Normal deadline, shouldn't be reached. */
deadline = grpc_timeout_milliseconds_to_deadline(60000);

@ -29,25 +29,23 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_fixture_data {
char* localaddr;
} fullstack_fixture_data;
struct fullstack_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
gpr_malloc(sizeof(fullstack_fixture_data)));
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -71,7 +69,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
grpc_arg arg = make_census_enable_arg();
client_args = grpc_channel_args_copy_and_add(client_args, &arg, 1);
f->client =
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
GPR_ASSERT(f->client);
{
grpc_core::ExecCtx exec_ctx;
@ -94,15 +92,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
grpc_channel_args_destroy(server_args);
}
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
GPR_ASSERT(
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
/* All test configurations */

@ -30,28 +30,29 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/compression/compression_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_compression_fixture_data {
char* localaddr;
grpc_channel_args* client_args_compression;
grpc_channel_args* server_args_compression;
} fullstack_compression_fixture_data;
struct fullstack_compression_fixture_data {
~fullstack_compression_fixture_data() {
grpc_channel_args_destroy(client_args_compression);
grpc_channel_args_destroy(server_args_compression);
}
grpc_core::UniquePtr<char> localaddr;
grpc_channel_args* client_args_compression = nullptr;
grpc_channel_args* server_args_compression = nullptr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_compression(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_compression_fixture_data* ffd =
static_cast<fullstack_compression_fixture_data*>(
gpr_malloc(sizeof(fullstack_compression_fixture_data)));
memset(ffd, 0, sizeof(fullstack_compression_fixture_data));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::New<fullstack_compression_fixture_data>();
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
memset(&f, 0, sizeof(f));
f.fixture_data = ffd;
@ -73,7 +74,7 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f,
grpc_channel_args_set_channel_default_compression_algorithm(
client_args, GRPC_COMPRESS_GZIP);
f->client = grpc_insecure_channel_create(
ffd->localaddr, ffd->client_args_compression, nullptr);
ffd->localaddr.get(), ffd->client_args_compression, nullptr);
}
void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f,
@ -92,7 +93,8 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f,
}
f->server = grpc_server_create(ffd->server_args_compression, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
GPR_ASSERT(
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
grpc_server_start(f->server);
}
@ -100,10 +102,7 @@ void chttp2_tear_down_fullstack_compression(grpc_end2end_test_fixture* f) {
grpc_core::ExecCtx exec_ctx;
fullstack_compression_fixture_data* ffd =
static_cast<fullstack_compression_fixture_data*>(f->fixture_data);
grpc_channel_args_destroy(ffd->client_args_compression);
grpc_channel_args_destroy(ffd->server_args_compression);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
/* All test configurations */

@ -25,26 +25,24 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/credentials/fake/fake_credentials.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_secure_fixture_data {
char* localaddr;
} fullstack_secure_fixture_data;
struct fullstack_secure_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
grpc_core::New<fullstack_secure_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -66,8 +64,8 @@ static void chttp2_init_client_secure_fullstack(
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client =
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
client_args, nullptr);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
@ -82,7 +80,7 @@ static void chttp2_init_server_secure_fullstack(
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
@ -91,8 +89,7 @@ static void chttp2_init_server_secure_fullstack(
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
static void chttp2_init_client_fake_secure_fullstack(

@ -33,26 +33,25 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/wakeup_fd_posix.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_fixture_data {
char* localaddr;
} fullstack_fixture_data;
struct fullstack_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
gpr_malloc(sizeof(fullstack_fixture_data)));
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -66,7 +65,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
f->client =
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
GPR_ASSERT(f->client);
}
@ -79,15 +78,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
GPR_ASSERT(
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
/* All test configurations */

@ -34,25 +34,24 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_fixture_data {
char* localaddr;
} fullstack_fixture_data;
struct fullstack_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
gpr_malloc(sizeof(fullstack_fixture_data)));
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -66,7 +65,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
f->client =
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
GPR_ASSERT(f->client);
}
@ -79,15 +78,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
GPR_ASSERT(
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
/* All test configurations */

@ -30,7 +30,7 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
@ -39,24 +39,20 @@
static char* workarounds_arg[GRPC_MAX_WORKAROUND_ID] = {
const_cast<char*>(GRPC_ARG_WORKAROUND_CRONET_COMPRESSION)};
typedef struct fullstack_fixture_data {
char* localaddr;
} fullstack_fixture_data;
struct fullstack_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
gpr_malloc(sizeof(fullstack_fixture_data)));
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
return f;
}
@ -65,7 +61,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
f->client =
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
GPR_ASSERT(f->client);
}
@ -88,7 +84,8 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
}
f->server = grpc_server_create(server_args_new, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
GPR_ASSERT(
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
grpc_server_start(f->server);
grpc_channel_args_destroy(server_args_new);
}
@ -96,8 +93,7 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
/* All test configurations */

@ -28,25 +28,24 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_fixture_data {
char* localaddr;
} fullstack_fixture_data;
struct fullstack_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
gpr_malloc(sizeof(fullstack_fixture_data)));
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -60,7 +59,7 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
f->client =
grpc_insecure_channel_create(ffd->localaddr, client_args, nullptr);
grpc_insecure_channel_create(ffd->localaddr.get(), client_args, nullptr);
GPR_ASSERT(f->client);
}
@ -73,15 +72,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->localaddr));
GPR_ASSERT(
grpc_server_add_insecure_http2_port(f->server, ffd->localaddr.get()));
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
/* All test configurations */

@ -30,26 +30,26 @@
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/end2end/fixtures/http_proxy_fixture.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_fixture_data {
char* server_addr;
grpc_end2end_http_proxy* proxy;
} fullstack_fixture_data;
struct fullstack_fixture_data {
~fullstack_fixture_data() { grpc_end2end_http_proxy_destroy(proxy); }
grpc_core::UniquePtr<char> server_addr;
grpc_end2end_http_proxy* proxy = nullptr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
memset(&f, 0, sizeof(f));
fullstack_fixture_data* ffd = static_cast<fullstack_fixture_data*>(
gpr_malloc(sizeof(fullstack_fixture_data)));
fullstack_fixture_data* ffd = grpc_core::New<fullstack_fixture_data>();
const int server_port = grpc_pick_unused_port_or_die();
gpr_join_host_port(&ffd->server_addr, "localhost", server_port);
grpc_core::JoinHostPort(&ffd->server_addr, "localhost", server_port);
/* Passing client_args to proxy_create for the case of checking for proxy auth
*/
@ -81,8 +81,8 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
}
gpr_setenv("http_proxy", proxy_uri);
gpr_free(proxy_uri);
f->client =
grpc_insecure_channel_create(ffd->server_addr, client_args, nullptr);
f->client = grpc_insecure_channel_create(ffd->server_addr.get(), client_args,
nullptr);
GPR_ASSERT(f->client);
}
@ -95,16 +95,15 @@ void chttp2_init_server_fullstack(grpc_end2end_test_fixture* f,
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_insecure_http2_port(f->server, ffd->server_addr));
GPR_ASSERT(
grpc_server_add_insecure_http2_port(f->server, ffd->server_addr.get()));
grpc_server_start(f->server);
}
void chttp2_tear_down_fullstack(grpc_end2end_test_fixture* f) {
fullstack_fixture_data* ffd =
static_cast<fullstack_fixture_data*>(f->fixture_data);
gpr_free(ffd->server_addr);
grpc_end2end_http_proxy_destroy(ffd->proxy);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
/* All test configurations */

@ -20,7 +20,7 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/local_util.h"
#include "test/core/util/port.h"
@ -31,7 +31,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_ipv4(
grpc_end2end_test_fixture f =
grpc_end2end_local_chttp2_create_fixture_fullstack();
int port = grpc_pick_unused_port_or_die();
gpr_join_host_port(
grpc_core::JoinHostPort(
&static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr,
"127.0.0.1", port);

@ -20,7 +20,7 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "test/core/end2end/end2end_tests.h"
#include "test/core/end2end/fixtures/local_util.h"
#include "test/core/util/port.h"
@ -31,7 +31,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_ipv6(
grpc_end2end_test_fixture f =
grpc_end2end_local_chttp2_create_fixture_fullstack();
int port = grpc_pick_unused_port_or_die();
gpr_join_host_port(
grpc_core::JoinHostPort(
&static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr,
"[::1]", port);

@ -30,10 +30,10 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack_uds(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f =
grpc_end2end_local_chttp2_create_fixture_fullstack();
gpr_asprintf(
&static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr,
"unix:/tmp/grpc_fullstack_test.%d.%d", getpid(), unique++);
char* out = nullptr;
gpr_asprintf(&out, "unix:/tmp/grpc_fullstack_test.%d.%d", getpid(), unique++);
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f.fixture_data)
->localaddr.reset(out);
return f;
}

@ -25,7 +25,7 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/iomgr/iomgr.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "test/core/end2end/data/ssl_test_data.h"
@ -36,9 +36,9 @@ static const char oauth2_md[] = "Bearer aaslkfjs424535asdf";
static const char* client_identity_property_name = "smurf_name";
static const char* client_identity = "Brainy Smurf";
typedef struct fullstack_secure_fixture_data {
char* localaddr;
} fullstack_secure_fixture_data;
struct fullstack_secure_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static const grpc_metadata* find_metadata(const grpc_metadata* md,
size_t md_count, const char* key,
@ -95,16 +95,12 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
grpc_core::New<fullstack_secure_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
return f;
}
@ -113,8 +109,8 @@ static void chttp2_init_client_secure_fullstack(
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client =
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
client_args, nullptr);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
@ -129,7 +125,7 @@ static void chttp2_init_server_secure_fullstack(
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
@ -138,8 +134,7 @@ static void chttp2_init_server_secure_fullstack(
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack(

@ -28,7 +28,6 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/end2end/fixtures/proxy.h"

@ -28,9 +28,9 @@
#include <grpc/support/string_util.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/env.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/inlined_vector.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/security/credentials/credentials.h"
@ -42,10 +42,15 @@
typedef grpc_core::InlinedVector<grpc_core::Thread, 1> ThreadList;
typedef struct fullstack_secure_fixture_data {
char* localaddr;
struct fullstack_secure_fixture_data {
~fullstack_secure_fixture_data() {
for (size_t ind = 0; ind < thd_list.size(); ind++) {
thd_list[ind].Join();
}
}
grpc_core::UniquePtr<char> localaddr;
ThreadList thd_list;
} fullstack_secure_fixture_data;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
@ -54,7 +59,7 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
fullstack_secure_fixture_data* ffd =
grpc_core::New<fullstack_secure_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
f.shutdown_cq = grpc_completion_queue_create_for_pluck(nullptr);
@ -74,8 +79,8 @@ static void chttp2_init_client_secure_fullstack(
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client =
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
client_args, nullptr);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
@ -90,7 +95,7 @@ static void chttp2_init_server_secure_fullstack(
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
@ -99,10 +104,6 @@ static void chttp2_init_server_secure_fullstack(
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
for (size_t ind = 0; ind < ffd->thd_list.size(); ind++) {
ffd->thd_list[ind].Join();
}
gpr_free(ffd->localaddr);
grpc_core::Delete(ffd);
}

@ -25,29 +25,28 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_secure_fixture_data {
char* localaddr;
} fullstack_secure_fixture_data;
struct fullstack_secure_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
grpc_core::New<fullstack_secure_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -69,8 +68,8 @@ static void chttp2_init_client_secure_fullstack(
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client =
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
client_args, nullptr);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
@ -85,7 +84,7 @@ static void chttp2_init_server_secure_fullstack(
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
@ -94,8 +93,7 @@ static void chttp2_init_server_secure_fullstack(
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
static void chttp2_init_client_simple_ssl_secure_fullstack(

@ -25,19 +25,19 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
#include "test/core/util/test_config.h"
typedef struct fullstack_secure_fixture_data {
char* localaddr;
bool server_credential_reloaded;
} fullstack_secure_fixture_data;
struct fullstack_secure_fixture_data {
grpc_core::UniquePtr<char> localaddr;
bool server_credential_reloaded = false;
};
static grpc_ssl_certificate_config_reload_status
ssl_server_certificate_config_callback(
@ -64,10 +64,9 @@ static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
grpc_core::New<fullstack_secure_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -89,8 +88,8 @@ static void chttp2_init_client_secure_fullstack(
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client =
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
client_args, nullptr);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
@ -106,7 +105,7 @@ static void chttp2_init_server_secure_fullstack(
ffd->server_credential_reloaded = false;
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
@ -115,8 +114,7 @@ static void chttp2_init_server_secure_fullstack(
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
static void chttp2_init_client_simple_ssl_secure_fullstack(

@ -25,7 +25,6 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/security/credentials/credentials.h"

@ -31,7 +31,6 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"

@ -31,8 +31,8 @@
#include <grpc/support/sync.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/http/parser.h"
#include "src/core/lib/iomgr/closure.h"
@ -53,8 +53,7 @@
struct grpc_end2end_http_proxy {
grpc_end2end_http_proxy()
: proxy_name(nullptr),
server(nullptr),
: server(nullptr),
channel_args(nullptr),
mu(nullptr),
pollset(nullptr),
@ -62,7 +61,7 @@ struct grpc_end2end_http_proxy {
gpr_ref_init(&users, 1);
combiner = grpc_combiner_create();
}
char* proxy_name;
grpc_core::UniquePtr<char> proxy_name;
grpc_core::Thread thd;
grpc_tcp_server* server;
grpc_channel_args* channel_args;
@ -532,8 +531,8 @@ grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(
grpc_end2end_http_proxy* proxy = grpc_core::New<grpc_end2end_http_proxy>();
// Construct proxy address.
const int proxy_port = grpc_pick_unused_port_or_die();
gpr_join_host_port(&proxy->proxy_name, "localhost", proxy_port);
gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name);
grpc_core::JoinHostPort(&proxy->proxy_name, "localhost", proxy_port);
gpr_log(GPR_INFO, "Proxy address: %s", proxy->proxy_name.get());
// Create TCP server.
proxy->channel_args = grpc_channel_args_copy(args);
grpc_error* error =
@ -573,7 +572,6 @@ void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) {
proxy->thd.Join();
grpc_tcp_server_shutdown_listeners(proxy->server);
grpc_tcp_server_unref(proxy->server);
gpr_free(proxy->proxy_name);
grpc_channel_args_destroy(proxy->channel_args);
grpc_pollset_shutdown(proxy->pollset,
GRPC_CLOSURE_CREATE(destroy_pollset, proxy->pollset,
@ -584,5 +582,5 @@ void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) {
const char* grpc_end2end_http_proxy_get_proxy_name(
grpc_end2end_http_proxy* proxy) {
return proxy->proxy_name;
return proxy->proxy_name.get();
}

@ -28,7 +28,6 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/inproc/inproc_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/lib/surface/server.h"
#include "test/core/util/port.h"

@ -27,7 +27,6 @@
#include "src/core/ext/filters/http/server/http_server_filter.h"
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
#include "src/core/lib/channel/connected_channel.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/surface/server.h"
@ -37,8 +36,7 @@
grpc_end2end_test_fixture grpc_end2end_local_chttp2_create_fixture_fullstack() {
grpc_end2end_test_fixture f;
grpc_end2end_local_fullstack_fixture_data* ffd =
static_cast<grpc_end2end_local_fullstack_fixture_data*>(
gpr_malloc(sizeof(grpc_end2end_local_fullstack_fixture_data)));
grpc_core::New<grpc_end2end_local_fullstack_fixture_data>();
memset(&f, 0, sizeof(f));
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -52,8 +50,8 @@ void grpc_end2end_local_chttp2_init_client_fullstack(
grpc_channel_credentials* creds = grpc_local_credentials_create(type);
grpc_end2end_local_fullstack_fixture_data* ffd =
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f->fixture_data);
f->client =
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
client_args, nullptr);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
@ -99,8 +97,8 @@ void grpc_end2end_local_chttp2_init_server_fullstack(
nullptr};
grpc_server_credentials_set_auth_metadata_processor(creds, processor);
}
GPR_ASSERT(
grpc_server_add_secure_http2_port(f->server, ffd->localaddr, creds));
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
creds));
grpc_server_credentials_release(creds);
grpc_server_start(f->server);
}
@ -109,6 +107,5 @@ void grpc_end2end_local_chttp2_tear_down_fullstack(
grpc_end2end_test_fixture* f) {
grpc_end2end_local_fullstack_fixture_data* ffd =
static_cast<grpc_end2end_local_fullstack_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}

@ -22,9 +22,9 @@
#include "src/core/lib/surface/channel.h"
typedef struct grpc_end2end_local_fullstack_fixture_data {
char* localaddr;
} grpc_end2end_local_fullstack_fixture_data;
struct grpc_end2end_local_fullstack_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
/* Utility functions shared by h2_local tests. */
grpc_end2end_test_fixture grpc_end2end_local_chttp2_create_fixture_fullstack();

@ -24,16 +24,15 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/thd.h"
#include "test/core/util/port.h"
struct grpc_end2end_proxy {
grpc_end2end_proxy()
: proxy_port(nullptr),
server_port(nullptr),
cq(nullptr),
: cq(nullptr),
server(nullptr),
client(nullptr),
shutdown(false),
@ -42,8 +41,8 @@ struct grpc_end2end_proxy {
memset(&new_call_metadata, 0, sizeof(new_call_metadata));
}
grpc_core::Thread thd;
char* proxy_port;
char* server_port;
grpc_core::UniquePtr<char> proxy_port;
grpc_core::UniquePtr<char> server_port;
grpc_completion_queue* cq;
grpc_server* server;
grpc_channel* client;
@ -92,15 +91,15 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def,
grpc_end2end_proxy* proxy = grpc_core::New<grpc_end2end_proxy>();
gpr_join_host_port(&proxy->proxy_port, "localhost", proxy_port);
gpr_join_host_port(&proxy->server_port, "localhost", server_port);
grpc_core::JoinHostPort(&proxy->proxy_port, "localhost", proxy_port);
grpc_core::JoinHostPort(&proxy->server_port, "localhost", server_port);
gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port,
proxy->server_port);
gpr_log(GPR_DEBUG, "PROXY ADDR:%s BACKEND:%s", proxy->proxy_port.get(),
proxy->server_port.get());
proxy->cq = grpc_completion_queue_create_for_next(nullptr);
proxy->server = def->create_server(proxy->proxy_port, server_args);
proxy->client = def->create_client(proxy->server_port, client_args);
proxy->server = def->create_server(proxy->proxy_port.get(), server_args);
proxy->client = def->create_client(proxy->server_port.get(), client_args);
grpc_server_register_completion_queue(proxy->server, proxy->cq, nullptr);
grpc_server_start(proxy->server);
@ -131,8 +130,6 @@ void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy) {
grpc_server_shutdown_and_notify(proxy->server, proxy->cq,
new_closure(shutdown_complete, proxy));
proxy->thd.Join();
gpr_free(proxy->proxy_port);
gpr_free(proxy->server_port);
grpc_server_destroy(proxy->server);
grpc_channel_destroy(proxy->client);
grpc_completion_queue_destroy(proxy->cq);
@ -441,9 +438,9 @@ static void thread_main(void* arg) {
}
const char* grpc_end2end_proxy_get_client_target(grpc_end2end_proxy* proxy) {
return proxy->proxy_port;
return proxy->proxy_port.get();
}
const char* grpc_end2end_proxy_get_server_port(grpc_end2end_proxy* proxy) {
return proxy->server_port;
return proxy->server_port.get();
}

@ -25,9 +25,9 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
#include "test/core/end2end/cq_verifier.h"
@ -40,20 +40,19 @@
namespace grpc {
namespace testing {
typedef struct fullstack_secure_fixture_data {
char* localaddr;
} fullstack_secure_fixture_data;
struct fullstack_secure_fixture_data {
grpc_core::UniquePtr<char> localaddr;
};
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack(
grpc_channel_args* client_args, grpc_channel_args* server_args) {
grpc_end2end_test_fixture f;
int port = grpc_pick_unused_port_or_die();
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(
gpr_malloc(sizeof(fullstack_secure_fixture_data)));
grpc_core::New<fullstack_secure_fixture_data>();
memset(&f, 0, sizeof(f));
gpr_join_host_port(&ffd->localaddr, "localhost", port);
grpc_core::JoinHostPort(&ffd->localaddr, "localhost", port);
f.fixture_data = ffd;
f.cq = grpc_completion_queue_create_for_next(nullptr);
@ -73,8 +72,8 @@ static void chttp2_init_client_secure_fullstack(
grpc_channel_credentials* creds) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
f->client =
grpc_secure_channel_create(creds, ffd->localaddr, client_args, nullptr);
f->client = grpc_secure_channel_create(creds, ffd->localaddr.get(),
client_args, nullptr);
GPR_ASSERT(f->client != nullptr);
grpc_channel_credentials_release(creds);
}
@ -89,7 +88,7 @@ static void chttp2_init_server_secure_fullstack(
}
f->server = grpc_server_create(server_args, nullptr);
grpc_server_register_completion_queue(f->server, f->cq, nullptr);
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr,
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr.get(),
server_creds));
grpc_server_credentials_release(server_creds);
grpc_server_start(f->server);
@ -98,8 +97,7 @@ static void chttp2_init_server_secure_fullstack(
void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture* f) {
fullstack_secure_fixture_data* ffd =
static_cast<fullstack_secure_fixture_data*>(f->fixture_data);
gpr_free(ffd->localaddr);
gpr_free(ffd);
grpc_core::Delete(ffd);
}
static int fail_server_auth_check(grpc_channel_args* server_args) {

@ -25,9 +25,9 @@
#include <grpc/support/log.h>
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/gpr/host_port.h"
#include "src/core/lib/gpr/string.h"
#include "src/core/lib/gpr/tmpfile.h"
#include "src/core/lib/gprpp/host_port.h"
#include "src/core/lib/security/credentials/credentials.h"
#include "src/core/lib/security/security_connector/ssl_utils.h"
#include "test/core/end2end/cq_verifier.h"
@ -215,19 +215,18 @@ void drain_cq(grpc_completion_queue* cq) {
TEST(H2SessionReuseTest, SingleReuse) {
int port = grpc_pick_unused_port_or_die();
char* server_addr;
gpr_join_host_port(&server_addr, "localhost", port);
grpc_core::UniquePtr<char> server_addr;
grpc_core::JoinHostPort(&server_addr, "localhost", port);
grpc_completion_queue* cq = grpc_completion_queue_create_for_next(nullptr);
grpc_ssl_session_cache* cache = grpc_ssl_session_cache_create_lru(16);
grpc_server* server = server_create(cq, server_addr);
grpc_server* server = server_create(cq, server_addr.get());
do_round_trip(cq, server, server_addr, cache, false);
do_round_trip(cq, server, server_addr, cache, true);
do_round_trip(cq, server, server_addr, cache, true);
do_round_trip(cq, server, server_addr.get(), cache, false);
do_round_trip(cq, server, server_addr.get(), cache, true);
do_round_trip(cq, server, server_addr.get(), cache, true);
gpr_free(server_addr);
grpc_ssl_session_cache_destroy(cache);
GPR_ASSERT(grpc_completion_queue_next(

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save