grpc 1.74.1 → 1.75.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +83 -41
- data/include/grpc/credentials.h +7 -1
- data/src/core/call/client_call.cc +4 -4
- data/src/core/call/filter_fusion.h +1230 -0
- data/src/core/call/metadata.cc +22 -0
- data/src/core/call/metadata.h +24 -2
- data/src/core/channelz/channelz.cc +10 -17
- data/src/core/channelz/channelz.h +58 -19
- data/src/core/channelz/channelz_registry.cc +0 -162
- data/src/core/channelz/channelz_registry.h +14 -7
- data/src/core/channelz/property_list.cc +19 -23
- data/src/core/channelz/property_list.h +3 -1
- data/src/core/channelz/v2tov1/convert.cc +683 -0
- data/src/core/channelz/v2tov1/convert.h +58 -0
- data/src/core/channelz/v2tov1/legacy_api.cc +425 -0
- data/src/core/channelz/v2tov1/legacy_api.h +32 -0
- data/src/core/channelz/v2tov1/property_list.cc +118 -0
- data/src/core/channelz/v2tov1/property_list.h +52 -0
- data/src/core/client_channel/client_channel_filter.cc +5 -4
- data/src/core/client_channel/client_channel_filter.h +2 -2
- data/src/core/client_channel/client_channel_internal.h +2 -1
- data/src/core/client_channel/load_balanced_call_destination.cc +6 -5
- data/src/core/client_channel/subchannel.cc +14 -6
- data/src/core/client_channel/subchannel.h +2 -0
- data/src/core/config/core_configuration.cc +3 -1
- data/src/core/config/core_configuration.h +12 -0
- data/src/core/credentials/transport/alts/alts_credentials.cc +5 -0
- data/src/core/credentials/transport/alts/check_gcp_environment_windows.cc +2 -0
- data/src/core/credentials/transport/channel_creds_registry_init.cc +3 -1
- data/src/core/credentials/transport/ssl/ssl_credentials.cc +1 -1
- data/src/core/credentials/transport/ssl/ssl_security_connector.cc +8 -3
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -24
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +19 -8
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +96 -54
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +15 -2
- data/src/core/credentials/transport/tls/spiffe_utils.cc +371 -0
- data/src/core/credentials/transport/tls/spiffe_utils.h +171 -0
- data/src/core/credentials/transport/tls/ssl_utils.cc +11 -10
- data/src/core/credentials/transport/tls/ssl_utils.h +4 -2
- data/src/core/credentials/transport/tls/tls_credentials.cc +2 -0
- data/src/core/credentials/transport/tls/tls_security_connector.cc +11 -26
- data/src/core/credentials/transport/tls/tls_security_connector.h +12 -12
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -2
- data/src/core/ext/filters/http/client/http_client_filter.cc +3 -6
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -2
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
- data/src/core/ext/filters/http/server/http_server_filter.cc +3 -6
- data/src/core/ext/filters/message_size/message_size_filter.cc +4 -4
- data/src/core/ext/filters/rbac/rbac_filter.cc +1 -1
- data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +3 -5
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +3 -2
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -0
- data/src/core/ext/transport/chttp2/transport/frame.cc +89 -6
- data/src/core/ext/transport/chttp2/transport/frame.h +38 -0
- data/src/core/ext/transport/chttp2/transport/header_assembler.h +5 -14
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -1
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +294 -78
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +128 -9
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +11 -38
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +52 -35
- data/src/core/ext/transport/chttp2/transport/http2_settings_manager.cc +61 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings_manager.h +142 -0
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +81 -3
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +12 -1
- data/src/core/ext/transport/chttp2/transport/message_assembler.h +2 -2
- data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +22 -5
- data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +607 -0
- data/src/core/ext/transport/chttp2/transport/writable_streams.h +254 -0
- data/src/core/ext/transport/chttp2/transport/writing.cc +6 -4
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb.h +4959 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.c +1111 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.h +108 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb.h +142 -54
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.c +18 -14
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.h +2 -2
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +716 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.h +227 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.c +86 -88
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.h +2 -2
- data/src/core/filter/auth/auth_filters.h +2 -2
- data/src/core/filter/fused_filters.cc +154 -0
- data/src/core/handshaker/security/legacy_secure_endpoint.cc +1 -1
- data/src/core/handshaker/security/pipelined_secure_endpoint.cc +965 -0
- data/src/core/handshaker/security/secure_endpoint.cc +28 -13
- data/src/core/handshaker/security/secure_endpoint.h +8 -0
- data/src/core/lib/channel/promise_based_filter.cc +15 -25
- data/src/core/lib/channel/promise_based_filter.h +6 -5
- data/src/core/lib/event_engine/ares_resolver.h +3 -1
- data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -5
- data/src/core/lib/event_engine/cf_engine/cf_engine.h +2 -1
- data/src/core/lib/event_engine/cf_engine/cfsocket_listener.cc +263 -0
- data/src/core/lib/event_engine/cf_engine/cfsocket_listener.h +107 -0
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +31 -3
- data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +12 -0
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +12 -10
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +6 -4
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +15 -14
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +7 -5
- data/src/core/lib/event_engine/posix_engine/event_poller.h +0 -8
- data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.cc +11 -5
- data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.h +3 -2
- data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +1 -0
- data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +4 -4
- data/src/core/lib/event_engine/posix_engine/lockfree_event.h +3 -4
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +2 -2
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +188 -199
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +30 -45
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -1
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +1 -1
- data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +2 -1
- data/src/core/lib/experiments/experiments.cc +120 -6
- data/src/core/lib/experiments/experiments.h +46 -3
- data/src/core/lib/iomgr/combiner.cc +1 -1
- data/src/core/lib/iomgr/exec_ctx.h +3 -9
- data/src/core/lib/iomgr/socket_mutator.cc +1 -1
- data/src/core/lib/iomgr/socket_utils_posix.cc +1 -1
- data/src/core/lib/iomgr/socket_utils_posix.h +1 -1
- data/src/core/lib/iomgr/tcp_client_posix.cc +1 -1
- data/src/core/lib/iomgr/tcp_posix.cc +3 -3
- data/src/core/lib/promise/activity.h +2 -2
- data/src/core/lib/promise/mpsc.cc +8 -8
- data/src/core/lib/promise/party.cc +7 -7
- data/src/core/lib/promise/party.h +4 -4
- data/src/core/lib/promise/poll.h +10 -0
- data/src/core/lib/resource_quota/memory_quota.cc +90 -3
- data/src/core/lib/resource_quota/memory_quota.h +20 -9
- data/src/core/lib/resource_quota/periodic_update.cc +14 -0
- data/src/core/lib/resource_quota/periodic_update.h +8 -0
- data/src/core/lib/resource_quota/resource_quota.cc +15 -4
- data/src/core/lib/resource_quota/resource_quota.h +3 -0
- data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +1 -2
- data/src/core/lib/surface/call.cc +5 -5
- data/src/core/lib/surface/call.h +6 -5
- data/src/core/lib/surface/completion_queue.cc +2 -4
- data/src/core/lib/surface/filter_stack_call.cc +1 -1
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/promise_endpoint.cc +2 -2
- data/src/core/lib/transport/promise_endpoint.h +3 -3
- data/src/core/load_balancing/endpoint_list.cc +29 -2
- data/src/core/load_balancing/grpclb/client_load_reporting_filter.cc +3 -3
- data/src/core/load_balancing/grpclb/client_load_reporting_filter.h +1 -1
- data/src/core/load_balancing/pick_first/pick_first.cc +12 -5
- data/src/core/load_balancing/xds/xds_cluster_impl.cc +5 -3
- data/src/core/net/socket_mutator.cc +19 -0
- data/src/core/net/socket_mutator.h +25 -0
- data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +6 -1
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +2 -1
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +8 -5
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
- data/src/core/resolver/xds/xds_dependency_manager.cc +1 -1
- data/src/core/server/server.cc +1 -1
- data/src/core/server/server_call_tracer_filter.cc +0 -66
- data/src/core/server/server_call_tracer_filter.h +64 -0
- data/src/core/server/server_config_selector_filter.cc +1 -1
- data/src/core/service_config/service_config_channel_arg_filter.cc +3 -60
- data/src/core/service_config/service_config_channel_arg_filter.h +82 -0
- data/src/core/telemetry/call_tracer.cc +20 -14
- data/src/core/telemetry/call_tracer.h +22 -17
- data/src/core/telemetry/metrics.h +8 -8
- data/src/core/telemetry/stats_data.cc +151 -151
- data/src/core/telemetry/stats_data.h +87 -87
- data/src/core/transport/auth_context.cc +20 -0
- data/src/core/transport/auth_context.h +4 -0
- data/src/core/transport/auth_context_comparator_registry.h +69 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +2 -3
- data/src/core/tsi/ssl_transport_security.cc +202 -32
- data/src/core/tsi/ssl_transport_security.h +19 -10
- data/src/core/tsi/ssl_transport_security_utils.cc +21 -0
- data/src/core/tsi/ssl_transport_security_utils.h +4 -0
- data/src/core/util/http_client/httpcli_security_connector.cc +3 -1
- data/src/core/util/latent_see.cc +178 -146
- data/src/core/util/latent_see.h +245 -188
- data/src/core/util/single_set_ptr.h +5 -2
- data/src/core/util/useful.h +91 -0
- data/src/core/util/windows/directory_reader.cc +1 -0
- data/src/core/util/windows/thd.cc +1 -3
- data/src/core/util/work_serializer.cc +1 -1
- data/src/core/xds/grpc/file_watcher_certificate_provider_factory.cc +32 -5
- data/src/core/xds/grpc/file_watcher_certificate_provider_factory.h +5 -0
- data/src/core/xds/grpc/xds_certificate_provider.cc +5 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/cares/cares/include/ares.h +925 -460
- data/third_party/cares/cares/include/ares_dns.h +86 -71
- data/third_party/cares/cares/include/ares_dns_record.h +1118 -0
- data/third_party/cares/cares/include/ares_nameser.h +215 -189
- data/third_party/cares/cares/include/ares_version.h +37 -14
- data/third_party/cares/cares/src/lib/ares_addrinfo2hostent.c +305 -0
- data/third_party/cares/cares/src/lib/ares_addrinfo_localhost.c +245 -0
- data/third_party/cares/cares/src/lib/ares_android.c +216 -164
- data/third_party/cares/cares/src/lib/ares_android.h +25 -14
- data/third_party/cares/cares/src/lib/ares_cancel.c +68 -44
- data/third_party/cares/cares/src/lib/ares_close_sockets.c +137 -0
- data/third_party/cares/cares/src/lib/ares_conn.c +511 -0
- data/third_party/cares/cares/src/lib/ares_conn.h +196 -0
- data/third_party/cares/cares/src/lib/ares_cookie.c +461 -0
- data/third_party/cares/cares/src/lib/ares_data.c +93 -181
- data/third_party/cares/cares/src/lib/ares_data.h +50 -39
- data/third_party/cares/cares/src/lib/ares_destroy.c +127 -89
- data/third_party/cares/cares/src/lib/ares_free_hostent.c +35 -24
- data/third_party/cares/cares/src/lib/ares_free_string.c +24 -16
- data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +45 -38
- data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +549 -663
- data/third_party/cares/cares/src/lib/ares_getenv.c +25 -15
- data/third_party/cares/cares/src/lib/ares_getenv.h +26 -18
- data/third_party/cares/cares/src/lib/ares_gethostbyaddr.c +163 -221
- data/third_party/cares/cares/src/lib/ares_gethostbyname.c +222 -223
- data/third_party/cares/cares/src/lib/ares_getnameinfo.c +328 -338
- data/third_party/cares/cares/src/lib/ares_hosts_file.c +952 -0
- data/third_party/cares/cares/src/lib/ares_inet_net_pton.h +25 -19
- data/third_party/cares/cares/src/lib/ares_init.c +425 -2091
- data/third_party/cares/cares/src/lib/ares_ipv6.h +63 -33
- data/third_party/cares/cares/src/lib/ares_library_init.c +110 -54
- data/third_party/cares/cares/src/lib/ares_metrics.c +261 -0
- data/third_party/cares/cares/src/lib/ares_options.c +418 -332
- data/third_party/cares/cares/src/lib/ares_parse_into_addrinfo.c +179 -0
- data/third_party/cares/cares/src/lib/ares_private.h +558 -356
- data/third_party/cares/cares/src/lib/ares_process.c +1224 -1369
- data/third_party/cares/cares/src/lib/ares_qcache.c +430 -0
- data/third_party/cares/cares/src/lib/ares_query.c +126 -121
- data/third_party/cares/cares/src/lib/ares_search.c +564 -262
- data/third_party/cares/cares/src/lib/ares_send.c +264 -93
- data/third_party/cares/cares/src/lib/ares_set_socket_functions.c +588 -0
- data/third_party/cares/cares/src/lib/ares_setup.h +115 -111
- data/third_party/cares/cares/src/lib/ares_socket.c +425 -0
- data/third_party/cares/cares/src/lib/ares_socket.h +163 -0
- data/third_party/cares/cares/src/lib/ares_sortaddrinfo.c +447 -0
- data/third_party/cares/cares/src/lib/ares_strerror.c +83 -48
- data/third_party/cares/cares/src/lib/ares_sysconfig.c +639 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_files.c +839 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_mac.c +373 -0
- data/third_party/cares/cares/src/lib/ares_sysconfig_win.c +621 -0
- data/third_party/cares/cares/src/lib/ares_timeout.c +136 -73
- data/third_party/cares/cares/src/lib/ares_update_servers.c +1362 -0
- data/third_party/cares/cares/src/lib/ares_version.c +29 -4
- data/third_party/cares/cares/src/lib/config-dos.h +88 -89
- data/third_party/cares/cares/src/lib/config-win32.h +122 -77
- data/third_party/cares/cares/src/lib/dsa/ares_array.c +394 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable.c +447 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable.h +174 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_asvp.c +224 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_dict.c +228 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_strvp.c +210 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_szvp.c +188 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_vpstr.c +186 -0
- data/third_party/cares/cares/src/lib/dsa/ares_htable_vpvp.c +194 -0
- data/third_party/cares/cares/src/lib/dsa/ares_llist.c +382 -0
- data/third_party/cares/cares/src/lib/dsa/ares_slist.c +479 -0
- data/third_party/cares/cares/src/lib/dsa/ares_slist.h +207 -0
- data/third_party/cares/cares/src/lib/event/ares_event.h +191 -0
- data/third_party/cares/cares/src/lib/event/ares_event_configchg.c +743 -0
- data/third_party/cares/cares/src/lib/event/ares_event_epoll.c +192 -0
- data/third_party/cares/cares/src/lib/event/ares_event_kqueue.c +248 -0
- data/third_party/cares/cares/src/lib/event/ares_event_poll.c +140 -0
- data/third_party/cares/cares/src/lib/event/ares_event_select.c +159 -0
- data/third_party/cares/cares/src/lib/event/ares_event_thread.c +567 -0
- data/third_party/cares/cares/src/lib/event/ares_event_wake_pipe.c +166 -0
- data/third_party/cares/cares/src/lib/event/ares_event_win32.c +978 -0
- data/third_party/cares/cares/src/lib/event/ares_event_win32.h +161 -0
- data/third_party/cares/cares/src/lib/include/ares_array.h +276 -0
- data/third_party/cares/cares/src/lib/include/ares_buf.h +732 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_asvp.h +130 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_dict.h +123 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_strvp.h +130 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_szvp.h +118 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_vpstr.h +111 -0
- data/third_party/cares/cares/src/lib/include/ares_htable_vpvp.h +128 -0
- data/third_party/cares/cares/src/lib/include/ares_llist.h +239 -0
- data/third_party/cares/cares/src/lib/include/ares_mem.h +38 -0
- data/third_party/cares/cares/src/lib/include/ares_str.h +244 -0
- data/third_party/cares/cares/src/lib/inet_net_pton.c +202 -157
- data/third_party/cares/cares/src/lib/inet_ntop.c +87 -69
- data/third_party/cares/cares/src/lib/legacy/ares_create_query.c +78 -0
- data/third_party/cares/cares/src/lib/legacy/ares_expand_name.c +99 -0
- data/third_party/cares/cares/src/lib/legacy/ares_expand_string.c +107 -0
- data/third_party/cares/cares/src/lib/legacy/ares_fds.c +80 -0
- data/third_party/cares/cares/src/lib/legacy/ares_getsock.c +85 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_a_reply.c +107 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
- data/third_party/cares/cares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_mapping.c +982 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_multistring.c +307 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_multistring.h +72 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_name.c +673 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_parse.c +1329 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_private.h +273 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_record.c +1661 -0
- data/third_party/cares/cares/src/lib/record/ares_dns_write.c +1229 -0
- data/third_party/cares/cares/src/lib/str/ares_buf.c +1498 -0
- data/third_party/cares/cares/src/lib/str/ares_str.c +508 -0
- data/third_party/cares/cares/src/lib/str/ares_strsplit.c +90 -0
- data/third_party/cares/cares/src/lib/str/ares_strsplit.h +51 -0
- data/third_party/cares/cares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
- data/third_party/cares/cares/src/lib/util/ares_iface_ips.c +628 -0
- data/third_party/cares/cares/src/lib/util/ares_iface_ips.h +139 -0
- data/third_party/cares/cares/src/lib/util/ares_math.c +158 -0
- data/third_party/cares/cares/src/lib/util/ares_math.h +45 -0
- data/third_party/cares/cares/src/lib/util/ares_rand.c +389 -0
- data/third_party/cares/cares/src/lib/util/ares_rand.h +36 -0
- data/third_party/cares/cares/src/lib/util/ares_threads.c +614 -0
- data/third_party/cares/cares/src/lib/util/ares_threads.h +60 -0
- data/third_party/cares/cares/src/lib/util/ares_time.h +48 -0
- data/third_party/cares/cares/src/lib/util/ares_timeval.c +95 -0
- data/third_party/cares/cares/src/lib/util/ares_uri.c +1626 -0
- data/third_party/cares/cares/src/lib/util/ares_uri.h +252 -0
- data/third_party/cares/cares/src/lib/windows_port.c +16 -9
- metadata +121 -49
- data/src/core/util/ring_buffer.h +0 -122
- data/third_party/cares/cares/include/ares_rules.h +0 -125
- data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +0 -266
- data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +0 -240
- data/third_party/cares/cares/src/lib/ares__close_sockets.c +0 -61
- data/third_party/cares/cares/src/lib/ares__get_hostent.c +0 -260
- data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +0 -229
- data/third_party/cares/cares/src/lib/ares__read_line.c +0 -73
- data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +0 -258
- data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +0 -507
- data/third_party/cares/cares/src/lib/ares__timeval.c +0 -111
- data/third_party/cares/cares/src/lib/ares_create_query.c +0 -197
- data/third_party/cares/cares/src/lib/ares_expand_name.c +0 -311
- data/third_party/cares/cares/src/lib/ares_expand_string.c +0 -67
- data/third_party/cares/cares/src/lib/ares_fds.c +0 -59
- data/third_party/cares/cares/src/lib/ares_getsock.c +0 -66
- data/third_party/cares/cares/src/lib/ares_iphlpapi.h +0 -221
- data/third_party/cares/cares/src/lib/ares_llist.c +0 -63
- data/third_party/cares/cares/src/lib/ares_llist.h +0 -39
- data/third_party/cares/cares/src/lib/ares_mkquery.c +0 -24
- data/third_party/cares/cares/src/lib/ares_nowarn.c +0 -260
- data/third_party/cares/cares/src/lib/ares_nowarn.h +0 -61
- data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +0 -90
- data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +0 -92
- data/third_party/cares/cares/src/lib/ares_parse_caa_reply.c +0 -199
- data/third_party/cares/cares/src/lib/ares_parse_mx_reply.c +0 -164
- data/third_party/cares/cares/src/lib/ares_parse_naptr_reply.c +0 -183
- data/third_party/cares/cares/src/lib/ares_parse_ns_reply.c +0 -177
- data/third_party/cares/cares/src/lib/ares_parse_ptr_reply.c +0 -228
- data/third_party/cares/cares/src/lib/ares_parse_soa_reply.c +0 -179
- data/third_party/cares/cares/src/lib/ares_parse_srv_reply.c +0 -168
- data/third_party/cares/cares/src/lib/ares_parse_txt_reply.c +0 -214
- data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +0 -184
- data/third_party/cares/cares/src/lib/ares_platform.c +0 -11042
- data/third_party/cares/cares/src/lib/ares_platform.h +0 -43
- data/third_party/cares/cares/src/lib/ares_rand.c +0 -279
- data/third_party/cares/cares/src/lib/ares_strcasecmp.c +0 -66
- data/third_party/cares/cares/src/lib/ares_strcasecmp.h +0 -30
- data/third_party/cares/cares/src/lib/ares_strdup.c +0 -42
- data/third_party/cares/cares/src/lib/ares_strdup.h +0 -24
- data/third_party/cares/cares/src/lib/ares_strsplit.c +0 -94
- data/third_party/cares/cares/src/lib/ares_strsplit.h +0 -42
- data/third_party/cares/cares/src/lib/ares_writev.c +0 -79
- data/third_party/cares/cares/src/lib/ares_writev.h +0 -36
- data/third_party/cares/cares/src/lib/bitncmp.c +0 -59
- data/third_party/cares/cares/src/lib/bitncmp.h +0 -26
- data/third_party/cares/cares/src/lib/setup_once.h +0 -554
- data/third_party/cares/cares/src/tools/ares_getopt.h +0 -53
@@ -0,0 +1,159 @@
|
|
1
|
+
/* MIT License
|
2
|
+
*
|
3
|
+
* Copyright (c) 2024 Brad House
|
4
|
+
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
10
|
+
* furnished to do so, subject to the following conditions:
|
11
|
+
*
|
12
|
+
* The above copyright notice and this permission notice (including the next
|
13
|
+
* paragraph) shall be included in all copies or substantial portions of the
|
14
|
+
* Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
* SOFTWARE.
|
23
|
+
*
|
24
|
+
* SPDX-License-Identifier: MIT
|
25
|
+
*/
|
26
|
+
|
27
|
+
/* Some systems might default to something low like 256 (NetBSD), lets define
|
28
|
+
* this to assist. Really, no one should be using select, but lets be safe
|
29
|
+
* anyhow */
|
30
|
+
#define FD_SETSIZE 4096
|
31
|
+
|
32
|
+
#include "ares_private.h"
|
33
|
+
#include "ares_event.h"
|
34
|
+
|
35
|
+
/* All systems have select(), but not all have a way to wake, so we require
|
36
|
+
* pipe() to wake the select() */
|
37
|
+
#if defined(HAVE_PIPE) && defined(CARES_THREADS)
|
38
|
+
|
39
|
+
#ifdef HAVE_SYS_SELECT_H
|
40
|
+
# include <sys/select.h>
|
41
|
+
#endif
|
42
|
+
|
43
|
+
static ares_bool_t ares_evsys_select_init(ares_event_thread_t *e)
|
44
|
+
{
|
45
|
+
e->ev_signal = ares_pipeevent_create(e);
|
46
|
+
if (e->ev_signal == NULL) {
|
47
|
+
return ARES_FALSE; /* LCOV_EXCL_LINE: UntestablePath */
|
48
|
+
}
|
49
|
+
return ARES_TRUE;
|
50
|
+
}
|
51
|
+
|
52
|
+
static void ares_evsys_select_destroy(ares_event_thread_t *e)
|
53
|
+
{
|
54
|
+
(void)e;
|
55
|
+
}
|
56
|
+
|
57
|
+
static ares_bool_t ares_evsys_select_event_add(ares_event_t *event)
|
58
|
+
{
|
59
|
+
(void)event;
|
60
|
+
return ARES_TRUE;
|
61
|
+
}
|
62
|
+
|
63
|
+
static void ares_evsys_select_event_del(ares_event_t *event)
|
64
|
+
{
|
65
|
+
(void)event;
|
66
|
+
}
|
67
|
+
|
68
|
+
static void ares_evsys_select_event_mod(ares_event_t *event,
|
69
|
+
ares_event_flags_t new_flags)
|
70
|
+
{
|
71
|
+
(void)event;
|
72
|
+
(void)new_flags;
|
73
|
+
}
|
74
|
+
|
75
|
+
static size_t ares_evsys_select_wait(ares_event_thread_t *e,
|
76
|
+
unsigned long timeout_ms)
|
77
|
+
{
|
78
|
+
size_t num_fds = 0;
|
79
|
+
ares_socket_t *fdlist = ares_htable_asvp_keys(e->ev_sock_handles, &num_fds);
|
80
|
+
int rv;
|
81
|
+
size_t cnt = 0;
|
82
|
+
size_t i;
|
83
|
+
fd_set read_fds;
|
84
|
+
fd_set write_fds;
|
85
|
+
fd_set except_fds;
|
86
|
+
int nfds = 0;
|
87
|
+
struct timeval tv;
|
88
|
+
struct timeval *tout = NULL;
|
89
|
+
|
90
|
+
FD_ZERO(&read_fds);
|
91
|
+
FD_ZERO(&write_fds);
|
92
|
+
FD_ZERO(&except_fds);
|
93
|
+
|
94
|
+
for (i = 0; i < num_fds; i++) {
|
95
|
+
const ares_event_t *ev =
|
96
|
+
ares_htable_asvp_get_direct(e->ev_sock_handles, fdlist[i]);
|
97
|
+
if (ev->flags & ARES_EVENT_FLAG_READ) {
|
98
|
+
FD_SET(ev->fd, &read_fds);
|
99
|
+
}
|
100
|
+
if (ev->flags & ARES_EVENT_FLAG_WRITE) {
|
101
|
+
FD_SET(ev->fd, &write_fds);
|
102
|
+
}
|
103
|
+
FD_SET(ev->fd, &except_fds);
|
104
|
+
if (ev->fd + 1 > nfds) {
|
105
|
+
nfds = ev->fd + 1;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
if (timeout_ms) {
|
110
|
+
tv.tv_sec = (int)(timeout_ms / 1000);
|
111
|
+
tv.tv_usec = (int)((timeout_ms % 1000) * 1000);
|
112
|
+
tout = &tv;
|
113
|
+
}
|
114
|
+
|
115
|
+
rv = select(nfds, &read_fds, &write_fds, &except_fds, tout);
|
116
|
+
if (rv > 0) {
|
117
|
+
for (i = 0; i < num_fds; i++) {
|
118
|
+
ares_event_t *ev;
|
119
|
+
ares_event_flags_t flags = 0;
|
120
|
+
|
121
|
+
ev = ares_htable_asvp_get_direct(e->ev_sock_handles, fdlist[i]);
|
122
|
+
if (ev == NULL || ev->cb == NULL) {
|
123
|
+
continue; /* LCOV_EXCL_LINE: DefensiveCoding */
|
124
|
+
}
|
125
|
+
|
126
|
+
if (FD_ISSET(fdlist[i], &read_fds) || FD_ISSET(fdlist[i], &except_fds)) {
|
127
|
+
flags |= ARES_EVENT_FLAG_READ;
|
128
|
+
}
|
129
|
+
|
130
|
+
if (FD_ISSET(fdlist[i], &write_fds)) {
|
131
|
+
flags |= ARES_EVENT_FLAG_WRITE;
|
132
|
+
}
|
133
|
+
|
134
|
+
if (flags == 0) {
|
135
|
+
continue;
|
136
|
+
}
|
137
|
+
|
138
|
+
cnt++;
|
139
|
+
|
140
|
+
ev->cb(e, fdlist[i], ev->data, flags);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
ares_free(fdlist);
|
145
|
+
|
146
|
+
return cnt;
|
147
|
+
}
|
148
|
+
|
149
|
+
const ares_event_sys_t ares_evsys_select = {
|
150
|
+
"select",
|
151
|
+
ares_evsys_select_init,
|
152
|
+
ares_evsys_select_destroy, /* NoOp */
|
153
|
+
ares_evsys_select_event_add, /* NoOp */
|
154
|
+
ares_evsys_select_event_del, /* NoOp */
|
155
|
+
ares_evsys_select_event_mod, /* NoOp */
|
156
|
+
ares_evsys_select_wait
|
157
|
+
};
|
158
|
+
|
159
|
+
#endif
|
@@ -0,0 +1,567 @@
|
|
1
|
+
/* MIT License
|
2
|
+
*
|
3
|
+
* Copyright (c) 2024 Brad House
|
4
|
+
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
10
|
+
* furnished to do so, subject to the following conditions:
|
11
|
+
*
|
12
|
+
* The above copyright notice and this permission notice (including the next
|
13
|
+
* paragraph) shall be included in all copies or substantial portions of the
|
14
|
+
* Software.
|
15
|
+
*
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
* SOFTWARE.
|
23
|
+
*
|
24
|
+
* SPDX-License-Identifier: MIT
|
25
|
+
*/
|
26
|
+
#include "ares_private.h"
|
27
|
+
#include "ares_event.h"
|
28
|
+
|
29
|
+
#ifdef CARES_THREADS
|
30
|
+
static void ares_event_destroy_cb(void *arg)
|
31
|
+
{
|
32
|
+
ares_event_t *event = arg;
|
33
|
+
if (event == NULL) {
|
34
|
+
return; /* LCOV_EXCL_LINE: DefensiveCoding */
|
35
|
+
}
|
36
|
+
|
37
|
+
/* Unregister from the event thread if it was registered with one */
|
38
|
+
if (event->e) {
|
39
|
+
const ares_event_thread_t *e = event->e;
|
40
|
+
e->ev_sys->event_del(event);
|
41
|
+
event->e = NULL;
|
42
|
+
}
|
43
|
+
|
44
|
+
if (event->free_data_cb && event->data) {
|
45
|
+
event->free_data_cb(event->data);
|
46
|
+
}
|
47
|
+
|
48
|
+
ares_free(event);
|
49
|
+
}
|
50
|
+
|
51
|
+
static void ares_event_signal(const ares_event_t *event)
|
52
|
+
{
|
53
|
+
if (event == NULL || event->signal_cb == NULL) {
|
54
|
+
return; /* LCOV_EXCL_LINE: DefensiveCoding */
|
55
|
+
}
|
56
|
+
event->signal_cb(event);
|
57
|
+
}
|
58
|
+
|
59
|
+
static void ares_event_thread_wake(const ares_event_thread_t *e)
|
60
|
+
{
|
61
|
+
if (e == NULL) {
|
62
|
+
return; /* LCOV_EXCL_LINE: DefensiveCoding */
|
63
|
+
}
|
64
|
+
|
65
|
+
ares_event_signal(e->ev_signal);
|
66
|
+
}
|
67
|
+
|
68
|
+
/* See if a pending update already exists. We don't want to enqueue multiple
|
69
|
+
* updates for the same event handle. Right now this is O(n) based on number
|
70
|
+
* of updates already enqueued. In the future, it might make sense to make
|
71
|
+
* this O(1) with a hashtable.
|
72
|
+
* NOTE: in some cases a delete then re-add of the same fd, but really pointing
|
73
|
+
* to a different destination can happen due to a quick close of a
|
74
|
+
* connection then creation of a new one. So we need to look at the
|
75
|
+
* flags and ignore any delete events when finding a match since we
|
76
|
+
* need to process the delete always, it can't be combined with other
|
77
|
+
* updates. */
|
78
|
+
static ares_event_t *ares_event_update_find(ares_event_thread_t *e,
|
79
|
+
ares_socket_t fd, const void *data)
|
80
|
+
{
|
81
|
+
ares_llist_node_t *node;
|
82
|
+
|
83
|
+
for (node = ares_llist_node_first(e->ev_updates); node != NULL;
|
84
|
+
node = ares_llist_node_next(node)) {
|
85
|
+
ares_event_t *ev = ares_llist_node_val(node);
|
86
|
+
|
87
|
+
if (fd != ARES_SOCKET_BAD && fd == ev->fd && ev->flags != 0) {
|
88
|
+
return ev;
|
89
|
+
}
|
90
|
+
|
91
|
+
if (fd == ARES_SOCKET_BAD && ev->fd == ARES_SOCKET_BAD &&
|
92
|
+
data == ev->data && ev->flags != 0) {
|
93
|
+
return ev;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
return NULL;
|
98
|
+
}
|
99
|
+
|
100
|
+
ares_status_t ares_event_update(ares_event_t **event, ares_event_thread_t *e,
|
101
|
+
ares_event_flags_t flags, ares_event_cb_t cb,
|
102
|
+
ares_socket_t fd, void *data,
|
103
|
+
ares_event_free_data_t free_data_cb,
|
104
|
+
ares_event_signal_cb_t signal_cb)
|
105
|
+
{
|
106
|
+
ares_event_t *ev = NULL;
|
107
|
+
ares_status_t status;
|
108
|
+
|
109
|
+
if (e == NULL) {
|
110
|
+
return ARES_EFORMERR; /* LCOV_EXCL_LINE: DefensiveCoding */
|
111
|
+
}
|
112
|
+
|
113
|
+
/* Callback must be specified if not a removal event. */
|
114
|
+
if (flags != ARES_EVENT_FLAG_NONE && cb == NULL) {
|
115
|
+
return ARES_EFORMERR;
|
116
|
+
}
|
117
|
+
|
118
|
+
if (event != NULL) {
|
119
|
+
*event = NULL;
|
120
|
+
}
|
121
|
+
|
122
|
+
/* Validate flags */
|
123
|
+
if (fd == ARES_SOCKET_BAD) {
|
124
|
+
if (flags & (ARES_EVENT_FLAG_READ | ARES_EVENT_FLAG_WRITE)) {
|
125
|
+
return ARES_EFORMERR;
|
126
|
+
}
|
127
|
+
if (!(flags & ARES_EVENT_FLAG_OTHER)) {
|
128
|
+
return ARES_EFORMERR;
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
if (flags & ARES_EVENT_FLAG_OTHER) {
|
132
|
+
return ARES_EFORMERR;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
/* That's all the validation we can really do */
|
137
|
+
|
138
|
+
ares_thread_mutex_lock(e->mutex);
|
139
|
+
|
140
|
+
/* See if we have a queued update already */
|
141
|
+
ev = ares_event_update_find(e, fd, data);
|
142
|
+
if (ev == NULL) {
|
143
|
+
/* Allocate a new one */
|
144
|
+
ev = ares_malloc_zero(sizeof(*ev));
|
145
|
+
if (ev == NULL) {
|
146
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
147
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
148
|
+
}
|
149
|
+
|
150
|
+
if (ares_llist_insert_last(e->ev_updates, ev) == NULL) {
|
151
|
+
ares_free(ev); /* LCOV_EXCL_LINE: OutOfMemory */
|
152
|
+
status = ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
153
|
+
goto done; /* LCOV_EXCL_LINE: OutOfMemory */
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
ev->flags = flags;
|
158
|
+
ev->fd = fd;
|
159
|
+
if (ev->cb == NULL) {
|
160
|
+
ev->cb = cb;
|
161
|
+
}
|
162
|
+
if (ev->data == NULL) {
|
163
|
+
ev->data = data;
|
164
|
+
}
|
165
|
+
if (ev->free_data_cb == NULL) {
|
166
|
+
ev->free_data_cb = free_data_cb;
|
167
|
+
}
|
168
|
+
if (ev->signal_cb == NULL) {
|
169
|
+
ev->signal_cb = signal_cb;
|
170
|
+
}
|
171
|
+
|
172
|
+
if (event != NULL) {
|
173
|
+
*event = ev;
|
174
|
+
}
|
175
|
+
|
176
|
+
status = ARES_SUCCESS;
|
177
|
+
|
178
|
+
done:
|
179
|
+
if (status == ARES_SUCCESS) {
|
180
|
+
/* Wake event thread if successful so it can pull the updates */
|
181
|
+
ares_event_thread_wake(e);
|
182
|
+
}
|
183
|
+
|
184
|
+
ares_thread_mutex_unlock(e->mutex);
|
185
|
+
|
186
|
+
return status;
|
187
|
+
}
|
188
|
+
|
189
|
+
static void ares_event_thread_process_fd(ares_event_thread_t *e,
|
190
|
+
ares_socket_t fd, void *data,
|
191
|
+
ares_event_flags_t flags)
|
192
|
+
{
|
193
|
+
ares_fd_events_t event;
|
194
|
+
(void)data;
|
195
|
+
|
196
|
+
event.fd = fd;
|
197
|
+
event.events = 0;
|
198
|
+
if (flags & ARES_EVENT_FLAG_READ) {
|
199
|
+
event.events |= ARES_FD_EVENT_READ;
|
200
|
+
}
|
201
|
+
if (flags & ARES_EVENT_FLAG_WRITE) {
|
202
|
+
event.events |= ARES_FD_EVENT_WRITE;
|
203
|
+
}
|
204
|
+
ares_process_fds(e->channel, &event, 1, ARES_PROCESS_FLAG_SKIP_NON_FD);
|
205
|
+
}
|
206
|
+
|
207
|
+
static void ares_event_thread_sockstate_cb(void *data, ares_socket_t socket_fd,
|
208
|
+
int readable, int writable)
|
209
|
+
{
|
210
|
+
ares_event_thread_t *e = data;
|
211
|
+
ares_event_flags_t flags = ARES_EVENT_FLAG_NONE;
|
212
|
+
|
213
|
+
if (readable) {
|
214
|
+
flags |= ARES_EVENT_FLAG_READ;
|
215
|
+
}
|
216
|
+
|
217
|
+
if (writable) {
|
218
|
+
flags |= ARES_EVENT_FLAG_WRITE;
|
219
|
+
}
|
220
|
+
|
221
|
+
/* Update channel fd. This function will lock e->mutex and also wake the
|
222
|
+
* event thread to process the update */
|
223
|
+
ares_event_update(NULL, e, flags, ares_event_thread_process_fd, socket_fd,
|
224
|
+
NULL, NULL, NULL);
|
225
|
+
}
|
226
|
+
|
227
|
+
static void notifywrite_cb(void *data)
|
228
|
+
{
|
229
|
+
ares_event_thread_t *e = data;
|
230
|
+
|
231
|
+
ares_thread_mutex_lock(e->mutex);
|
232
|
+
e->process_pending_write = ARES_TRUE;
|
233
|
+
ares_thread_mutex_unlock(e->mutex);
|
234
|
+
|
235
|
+
ares_event_thread_wake(e);
|
236
|
+
}
|
237
|
+
|
238
|
+
static void ares_event_process_updates(ares_event_thread_t *e)
|
239
|
+
{
|
240
|
+
ares_llist_node_t *node;
|
241
|
+
|
242
|
+
/* Iterate across all updates and apply to internal list, removing from update
|
243
|
+
* list */
|
244
|
+
while ((node = ares_llist_node_first(e->ev_updates)) != NULL) {
|
245
|
+
ares_event_t *newev = ares_llist_node_claim(node);
|
246
|
+
ares_event_t *oldev;
|
247
|
+
|
248
|
+
if (newev->fd == ARES_SOCKET_BAD) {
|
249
|
+
oldev = ares_htable_vpvp_get_direct(e->ev_cust_handles, newev->data);
|
250
|
+
} else {
|
251
|
+
oldev = ares_htable_asvp_get_direct(e->ev_sock_handles, newev->fd);
|
252
|
+
}
|
253
|
+
|
254
|
+
/* Adding new */
|
255
|
+
if (oldev == NULL) {
|
256
|
+
newev->e = e;
|
257
|
+
/* Don't try to add a new event if all flags are cleared, that's basically
|
258
|
+
* someone trying to delete something already deleted. Also if it fails
|
259
|
+
* to add, cleanup. */
|
260
|
+
if (newev->flags == ARES_EVENT_FLAG_NONE ||
|
261
|
+
!e->ev_sys->event_add(newev)) {
|
262
|
+
newev->e = NULL;
|
263
|
+
ares_event_destroy_cb(newev);
|
264
|
+
} else {
|
265
|
+
if (newev->fd == ARES_SOCKET_BAD) {
|
266
|
+
ares_htable_vpvp_insert(e->ev_cust_handles, newev->data, newev);
|
267
|
+
} else {
|
268
|
+
ares_htable_asvp_insert(e->ev_sock_handles, newev->fd, newev);
|
269
|
+
}
|
270
|
+
}
|
271
|
+
continue;
|
272
|
+
}
|
273
|
+
|
274
|
+
/* Removal request */
|
275
|
+
if (newev->flags == ARES_EVENT_FLAG_NONE) {
|
276
|
+
/* the callback for the removal will call e->ev_sys->event_del(e, event)
|
277
|
+
*/
|
278
|
+
if (newev->fd == ARES_SOCKET_BAD) {
|
279
|
+
ares_htable_vpvp_remove(e->ev_cust_handles, newev->data);
|
280
|
+
} else {
|
281
|
+
ares_htable_asvp_remove(e->ev_sock_handles, newev->fd);
|
282
|
+
}
|
283
|
+
ares_free(newev);
|
284
|
+
continue;
|
285
|
+
}
|
286
|
+
|
287
|
+
/* Modify request -- only flags can be changed */
|
288
|
+
e->ev_sys->event_mod(oldev, newev->flags);
|
289
|
+
oldev->flags = newev->flags;
|
290
|
+
ares_free(newev);
|
291
|
+
}
|
292
|
+
}
|
293
|
+
|
294
|
+
static void ares_event_thread_cleanup(ares_event_thread_t *e)
|
295
|
+
{
|
296
|
+
/* Manually free any updates that weren't processed */
|
297
|
+
if (e->ev_updates != NULL) {
|
298
|
+
ares_llist_node_t *node;
|
299
|
+
|
300
|
+
while ((node = ares_llist_node_first(e->ev_updates)) != NULL) {
|
301
|
+
ares_event_destroy_cb(ares_llist_node_claim(node));
|
302
|
+
}
|
303
|
+
ares_llist_destroy(e->ev_updates);
|
304
|
+
e->ev_updates = NULL;
|
305
|
+
}
|
306
|
+
|
307
|
+
if (e->ev_sock_handles != NULL) {
|
308
|
+
ares_htable_asvp_destroy(e->ev_sock_handles);
|
309
|
+
e->ev_sock_handles = NULL;
|
310
|
+
}
|
311
|
+
|
312
|
+
if (e->ev_cust_handles != NULL) {
|
313
|
+
ares_htable_vpvp_destroy(e->ev_cust_handles);
|
314
|
+
e->ev_cust_handles = NULL;
|
315
|
+
}
|
316
|
+
|
317
|
+
if (e->ev_sys != NULL && e->ev_sys->destroy != NULL) {
|
318
|
+
e->ev_sys->destroy(e);
|
319
|
+
e->ev_sys = NULL;
|
320
|
+
}
|
321
|
+
}
|
322
|
+
|
323
|
+
static void *ares_event_thread(void *arg)
|
324
|
+
{
|
325
|
+
ares_event_thread_t *e = arg;
|
326
|
+
ares_thread_mutex_lock(e->mutex);
|
327
|
+
|
328
|
+
while (e->isup) {
|
329
|
+
struct timeval tv;
|
330
|
+
const struct timeval *tvout;
|
331
|
+
unsigned long timeout_ms = 0; /* 0 = unlimited */
|
332
|
+
ares_bool_t process_pending_write;
|
333
|
+
|
334
|
+
ares_event_process_updates(e);
|
335
|
+
|
336
|
+
/* Don't hold a mutex while waiting on events or calling into anything
|
337
|
+
* that might require a c-ares channel lock since a callback could be
|
338
|
+
* triggered cross-thread */
|
339
|
+
ares_thread_mutex_unlock(e->mutex);
|
340
|
+
|
341
|
+
tvout = ares_timeout(e->channel, NULL, &tv);
|
342
|
+
if (tvout != NULL) {
|
343
|
+
timeout_ms =
|
344
|
+
(unsigned long)((tvout->tv_sec * 1000) + (tvout->tv_usec / 1000) + 1);
|
345
|
+
}
|
346
|
+
|
347
|
+
e->ev_sys->wait(e, timeout_ms);
|
348
|
+
|
349
|
+
/* Process pending write operation */
|
350
|
+
ares_thread_mutex_lock(e->mutex);
|
351
|
+
process_pending_write = e->process_pending_write;
|
352
|
+
e->process_pending_write = ARES_FALSE;
|
353
|
+
ares_thread_mutex_unlock(e->mutex);
|
354
|
+
if (process_pending_write) {
|
355
|
+
ares_process_pending_write(e->channel);
|
356
|
+
}
|
357
|
+
|
358
|
+
/* Relock before we loop again */
|
359
|
+
ares_thread_mutex_lock(e->mutex);
|
360
|
+
|
361
|
+
/* Each iteration should do timeout processing and any other cleanup
|
362
|
+
* that may not have been performed */
|
363
|
+
if (e->isup) {
|
364
|
+
ares_thread_mutex_unlock(e->mutex);
|
365
|
+
ares_process_fds(e->channel, NULL, 0, ARES_PROCESS_FLAG_NONE);
|
366
|
+
ares_thread_mutex_lock(e->mutex);
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
/* Lets cleanup while we're in the thread itself */
|
371
|
+
ares_event_thread_cleanup(e);
|
372
|
+
|
373
|
+
ares_thread_mutex_unlock(e->mutex);
|
374
|
+
|
375
|
+
return NULL;
|
376
|
+
}
|
377
|
+
|
378
|
+
static void ares_event_thread_destroy_int(ares_event_thread_t *e)
|
379
|
+
{
|
380
|
+
/* Wake thread and tell it to shutdown if it exists */
|
381
|
+
ares_thread_mutex_lock(e->mutex);
|
382
|
+
if (e->isup) {
|
383
|
+
e->isup = ARES_FALSE;
|
384
|
+
ares_event_thread_wake(e);
|
385
|
+
}
|
386
|
+
ares_thread_mutex_unlock(e->mutex);
|
387
|
+
|
388
|
+
/* Wait for thread to shutdown */
|
389
|
+
if (e->thread) {
|
390
|
+
void *rv = NULL;
|
391
|
+
ares_thread_join(e->thread, &rv);
|
392
|
+
e->thread = NULL;
|
393
|
+
}
|
394
|
+
|
395
|
+
/* If the event thread ever got to the point of starting, this is a no-op
|
396
|
+
* as it runs this same cleanup when it shuts down */
|
397
|
+
ares_event_thread_cleanup(e);
|
398
|
+
|
399
|
+
ares_thread_mutex_destroy(e->mutex);
|
400
|
+
e->mutex = NULL;
|
401
|
+
|
402
|
+
ares_free(e);
|
403
|
+
}
|
404
|
+
|
405
|
+
void ares_event_thread_destroy(ares_channel_t *channel)
|
406
|
+
{
|
407
|
+
ares_event_thread_t *e = channel->sock_state_cb_data;
|
408
|
+
|
409
|
+
if (e == NULL) {
|
410
|
+
return; /* LCOV_EXCL_LINE: DefensiveCoding */
|
411
|
+
}
|
412
|
+
|
413
|
+
ares_event_thread_destroy_int(e);
|
414
|
+
channel->sock_state_cb_data = NULL;
|
415
|
+
channel->sock_state_cb = NULL;
|
416
|
+
channel->notify_pending_write_cb = NULL;
|
417
|
+
channel->notify_pending_write_cb_data = NULL;
|
418
|
+
}
|
419
|
+
|
420
|
+
static const ares_event_sys_t *ares_event_fetch_sys(ares_evsys_t evsys)
|
421
|
+
{
|
422
|
+
switch (evsys) {
|
423
|
+
case ARES_EVSYS_WIN32:
|
424
|
+
#if defined(USE_WINSOCK)
|
425
|
+
return &ares_evsys_win32;
|
426
|
+
#else
|
427
|
+
return NULL;
|
428
|
+
#endif
|
429
|
+
|
430
|
+
case ARES_EVSYS_EPOLL:
|
431
|
+
#if defined(HAVE_EPOLL)
|
432
|
+
return &ares_evsys_epoll;
|
433
|
+
#else
|
434
|
+
return NULL;
|
435
|
+
#endif
|
436
|
+
|
437
|
+
case ARES_EVSYS_KQUEUE:
|
438
|
+
#if defined(HAVE_KQUEUE)
|
439
|
+
return &ares_evsys_kqueue;
|
440
|
+
#else
|
441
|
+
return NULL;
|
442
|
+
#endif
|
443
|
+
|
444
|
+
case ARES_EVSYS_POLL:
|
445
|
+
#if defined(HAVE_POLL)
|
446
|
+
return &ares_evsys_poll;
|
447
|
+
#else
|
448
|
+
return NULL;
|
449
|
+
#endif
|
450
|
+
|
451
|
+
case ARES_EVSYS_SELECT:
|
452
|
+
#if defined(HAVE_PIPE)
|
453
|
+
return &ares_evsys_select;
|
454
|
+
#else
|
455
|
+
return NULL;
|
456
|
+
#endif
|
457
|
+
|
458
|
+
/* case ARES_EVSYS_DEFAULT: */
|
459
|
+
default:
|
460
|
+
break;
|
461
|
+
}
|
462
|
+
|
463
|
+
/* default */
|
464
|
+
#if defined(USE_WINSOCK)
|
465
|
+
return &ares_evsys_win32;
|
466
|
+
#elif defined(HAVE_KQUEUE)
|
467
|
+
return &ares_evsys_kqueue;
|
468
|
+
#elif defined(HAVE_EPOLL)
|
469
|
+
return &ares_evsys_epoll;
|
470
|
+
#elif defined(HAVE_POLL)
|
471
|
+
return &ares_evsys_poll;
|
472
|
+
#elif defined(HAVE_PIPE)
|
473
|
+
return &ares_evsys_select;
|
474
|
+
#else
|
475
|
+
return NULL;
|
476
|
+
#endif
|
477
|
+
}
|
478
|
+
|
479
|
+
ares_status_t ares_event_thread_init(ares_channel_t *channel)
|
480
|
+
{
|
481
|
+
ares_event_thread_t *e;
|
482
|
+
|
483
|
+
e = ares_malloc_zero(sizeof(*e));
|
484
|
+
if (e == NULL) {
|
485
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
486
|
+
}
|
487
|
+
|
488
|
+
e->mutex = ares_thread_mutex_create();
|
489
|
+
if (e->mutex == NULL) {
|
490
|
+
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */
|
491
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
492
|
+
}
|
493
|
+
|
494
|
+
e->ev_updates = ares_llist_create(NULL);
|
495
|
+
if (e->ev_updates == NULL) {
|
496
|
+
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */
|
497
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
498
|
+
}
|
499
|
+
|
500
|
+
e->ev_sock_handles = ares_htable_asvp_create(ares_event_destroy_cb);
|
501
|
+
if (e->ev_sock_handles == NULL) {
|
502
|
+
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */
|
503
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
504
|
+
}
|
505
|
+
|
506
|
+
e->ev_cust_handles = ares_htable_vpvp_create(NULL, ares_event_destroy_cb);
|
507
|
+
if (e->ev_cust_handles == NULL) {
|
508
|
+
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: OutOfMemory */
|
509
|
+
return ARES_ENOMEM; /* LCOV_EXCL_LINE: OutOfMemory */
|
510
|
+
}
|
511
|
+
|
512
|
+
e->channel = channel;
|
513
|
+
e->isup = ARES_TRUE;
|
514
|
+
e->ev_sys = ares_event_fetch_sys(channel->evsys);
|
515
|
+
if (e->ev_sys == NULL) {
|
516
|
+
ares_event_thread_destroy_int(e); /* LCOV_EXCL_LINE: UntestablePath */
|
517
|
+
return ARES_ENOTIMP; /* LCOV_EXCL_LINE: UntestablePath */
|
518
|
+
}
|
519
|
+
|
520
|
+
channel->sock_state_cb = ares_event_thread_sockstate_cb;
|
521
|
+
channel->sock_state_cb_data = e;
|
522
|
+
channel->notify_pending_write_cb = notifywrite_cb;
|
523
|
+
channel->notify_pending_write_cb_data = e;
|
524
|
+
|
525
|
+
if (!e->ev_sys->init(e)) {
|
526
|
+
/* LCOV_EXCL_START: UntestablePath */
|
527
|
+
ares_event_thread_destroy_int(e);
|
528
|
+
channel->sock_state_cb = NULL;
|
529
|
+
channel->sock_state_cb_data = NULL;
|
530
|
+
return ARES_ESERVFAIL;
|
531
|
+
/* LCOV_EXCL_STOP */
|
532
|
+
}
|
533
|
+
|
534
|
+
/* Before starting the thread, process any possible events the initialization
|
535
|
+
* might have enqueued as we may actually depend on these being valid
|
536
|
+
* immediately upon return, which may mean before the thread is fully spawned
|
537
|
+
* and processed the list itself. We don't want any sort of race conditions
|
538
|
+
* (like the event system wake handle itself). */
|
539
|
+
ares_event_process_updates(e);
|
540
|
+
|
541
|
+
/* Start thread */
|
542
|
+
if (ares_thread_create(&e->thread, ares_event_thread, e) != ARES_SUCCESS) {
|
543
|
+
/* LCOV_EXCL_START: UntestablePath */
|
544
|
+
ares_event_thread_destroy_int(e);
|
545
|
+
channel->sock_state_cb = NULL;
|
546
|
+
channel->sock_state_cb_data = NULL;
|
547
|
+
return ARES_ESERVFAIL;
|
548
|
+
/* LCOV_EXCL_STOP */
|
549
|
+
}
|
550
|
+
|
551
|
+
return ARES_SUCCESS;
|
552
|
+
}
|
553
|
+
|
554
|
+
#else
|
555
|
+
|
556
|
+
ares_status_t ares_event_thread_init(ares_channel_t *channel)
|
557
|
+
{
|
558
|
+
(void)channel;
|
559
|
+
return ARES_ENOTIMP;
|
560
|
+
}
|
561
|
+
|
562
|
+
void ares_event_thread_destroy(ares_channel_t *channel)
|
563
|
+
{
|
564
|
+
(void)channel;
|
565
|
+
}
|
566
|
+
|
567
|
+
#endif
|