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.
Files changed (368) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +83 -41
  3. data/include/grpc/credentials.h +7 -1
  4. data/src/core/call/client_call.cc +4 -4
  5. data/src/core/call/filter_fusion.h +1230 -0
  6. data/src/core/call/metadata.cc +22 -0
  7. data/src/core/call/metadata.h +24 -2
  8. data/src/core/channelz/channelz.cc +10 -17
  9. data/src/core/channelz/channelz.h +58 -19
  10. data/src/core/channelz/channelz_registry.cc +0 -162
  11. data/src/core/channelz/channelz_registry.h +14 -7
  12. data/src/core/channelz/property_list.cc +19 -23
  13. data/src/core/channelz/property_list.h +3 -1
  14. data/src/core/channelz/v2tov1/convert.cc +683 -0
  15. data/src/core/channelz/v2tov1/convert.h +58 -0
  16. data/src/core/channelz/v2tov1/legacy_api.cc +425 -0
  17. data/src/core/channelz/v2tov1/legacy_api.h +32 -0
  18. data/src/core/channelz/v2tov1/property_list.cc +118 -0
  19. data/src/core/channelz/v2tov1/property_list.h +52 -0
  20. data/src/core/client_channel/client_channel_filter.cc +5 -4
  21. data/src/core/client_channel/client_channel_filter.h +2 -2
  22. data/src/core/client_channel/client_channel_internal.h +2 -1
  23. data/src/core/client_channel/load_balanced_call_destination.cc +6 -5
  24. data/src/core/client_channel/subchannel.cc +14 -6
  25. data/src/core/client_channel/subchannel.h +2 -0
  26. data/src/core/config/core_configuration.cc +3 -1
  27. data/src/core/config/core_configuration.h +12 -0
  28. data/src/core/credentials/transport/alts/alts_credentials.cc +5 -0
  29. data/src/core/credentials/transport/alts/check_gcp_environment_windows.cc +2 -0
  30. data/src/core/credentials/transport/channel_creds_registry_init.cc +3 -1
  31. data/src/core/credentials/transport/ssl/ssl_credentials.cc +1 -1
  32. data/src/core/credentials/transport/ssl/ssl_security_connector.cc +8 -3
  33. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -24
  34. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +19 -8
  35. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +96 -54
  36. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +15 -2
  37. data/src/core/credentials/transport/tls/spiffe_utils.cc +371 -0
  38. data/src/core/credentials/transport/tls/spiffe_utils.h +171 -0
  39. data/src/core/credentials/transport/tls/ssl_utils.cc +11 -10
  40. data/src/core/credentials/transport/tls/ssl_utils.h +4 -2
  41. data/src/core/credentials/transport/tls/tls_credentials.cc +2 -0
  42. data/src/core/credentials/transport/tls/tls_security_connector.cc +11 -26
  43. data/src/core/credentials/transport/tls/tls_security_connector.h +12 -12
  44. data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -2
  45. data/src/core/ext/filters/http/client/http_client_filter.cc +3 -6
  46. data/src/core/ext/filters/http/client_authority_filter.cc +1 -2
  47. data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
  48. data/src/core/ext/filters/http/server/http_server_filter.cc +3 -6
  49. data/src/core/ext/filters/message_size/message_size_filter.cc +4 -4
  50. data/src/core/ext/filters/rbac/rbac_filter.cc +1 -1
  51. data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +3 -5
  52. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +3 -2
  53. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -0
  55. data/src/core/ext/transport/chttp2/transport/frame.cc +89 -6
  56. data/src/core/ext/transport/chttp2/transport/frame.h +38 -0
  57. data/src/core/ext/transport/chttp2/transport/header_assembler.h +5 -14
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -1
  59. data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +294 -78
  60. data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +128 -9
  61. data/src/core/ext/transport/chttp2/transport/http2_settings.cc +11 -38
  62. data/src/core/ext/transport/chttp2/transport/http2_settings.h +52 -35
  63. data/src/core/ext/transport/chttp2/transport/http2_settings_manager.cc +61 -0
  64. data/src/core/ext/transport/chttp2/transport/http2_settings_manager.h +142 -0
  65. data/src/core/ext/transport/chttp2/transport/http2_transport.cc +81 -3
  66. data/src/core/ext/transport/chttp2/transport/http2_transport.h +12 -1
  67. data/src/core/ext/transport/chttp2/transport/message_assembler.h +2 -2
  68. data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
  69. data/src/core/ext/transport/chttp2/transport/ping_promise.cc +2 -1
  70. data/src/core/ext/transport/chttp2/transport/ping_promise.h +22 -5
  71. data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +607 -0
  72. data/src/core/ext/transport/chttp2/transport/writable_streams.h +254 -0
  73. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -4
  74. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb.h +4959 -0
  75. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.c +1111 -0
  76. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.h +108 -0
  77. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb.h +142 -54
  78. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.c +18 -14
  79. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.h +2 -2
  80. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +716 -0
  81. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.h +227 -0
  82. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.c +86 -88
  83. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.h +2 -2
  84. data/src/core/filter/auth/auth_filters.h +2 -2
  85. data/src/core/filter/fused_filters.cc +154 -0
  86. data/src/core/handshaker/security/legacy_secure_endpoint.cc +1 -1
  87. data/src/core/handshaker/security/pipelined_secure_endpoint.cc +965 -0
  88. data/src/core/handshaker/security/secure_endpoint.cc +28 -13
  89. data/src/core/handshaker/security/secure_endpoint.h +8 -0
  90. data/src/core/lib/channel/promise_based_filter.cc +15 -25
  91. data/src/core/lib/channel/promise_based_filter.h +6 -5
  92. data/src/core/lib/event_engine/ares_resolver.h +3 -1
  93. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -5
  94. data/src/core/lib/event_engine/cf_engine/cf_engine.h +2 -1
  95. data/src/core/lib/event_engine/cf_engine/cfsocket_listener.cc +263 -0
  96. data/src/core/lib/event_engine/cf_engine/cfsocket_listener.h +107 -0
  97. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +31 -3
  98. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +12 -0
  99. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +12 -10
  100. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +6 -4
  101. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +15 -14
  102. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +7 -5
  103. data/src/core/lib/event_engine/posix_engine/event_poller.h +0 -8
  104. data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.cc +11 -5
  105. data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.h +3 -2
  106. data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +1 -0
  107. data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +4 -4
  108. data/src/core/lib/event_engine/posix_engine/lockfree_event.h +3 -4
  109. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +2 -2
  110. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +188 -199
  111. data/src/core/lib/event_engine/posix_engine/posix_engine.h +30 -45
  112. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -1
  113. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +1 -1
  114. data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +2 -1
  115. data/src/core/lib/experiments/experiments.cc +120 -6
  116. data/src/core/lib/experiments/experiments.h +46 -3
  117. data/src/core/lib/iomgr/combiner.cc +1 -1
  118. data/src/core/lib/iomgr/exec_ctx.h +3 -9
  119. data/src/core/lib/iomgr/socket_mutator.cc +1 -1
  120. data/src/core/lib/iomgr/socket_utils_posix.cc +1 -1
  121. data/src/core/lib/iomgr/socket_utils_posix.h +1 -1
  122. data/src/core/lib/iomgr/tcp_client_posix.cc +1 -1
  123. data/src/core/lib/iomgr/tcp_posix.cc +3 -3
  124. data/src/core/lib/promise/activity.h +2 -2
  125. data/src/core/lib/promise/mpsc.cc +8 -8
  126. data/src/core/lib/promise/party.cc +7 -7
  127. data/src/core/lib/promise/party.h +4 -4
  128. data/src/core/lib/promise/poll.h +10 -0
  129. data/src/core/lib/resource_quota/memory_quota.cc +90 -3
  130. data/src/core/lib/resource_quota/memory_quota.h +20 -9
  131. data/src/core/lib/resource_quota/periodic_update.cc +14 -0
  132. data/src/core/lib/resource_quota/periodic_update.h +8 -0
  133. data/src/core/lib/resource_quota/resource_quota.cc +15 -4
  134. data/src/core/lib/resource_quota/resource_quota.h +3 -0
  135. data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +1 -2
  136. data/src/core/lib/surface/call.cc +5 -5
  137. data/src/core/lib/surface/call.h +6 -5
  138. data/src/core/lib/surface/completion_queue.cc +2 -4
  139. data/src/core/lib/surface/filter_stack_call.cc +1 -1
  140. data/src/core/lib/surface/version.cc +2 -2
  141. data/src/core/lib/transport/promise_endpoint.cc +2 -2
  142. data/src/core/lib/transport/promise_endpoint.h +3 -3
  143. data/src/core/load_balancing/endpoint_list.cc +29 -2
  144. data/src/core/load_balancing/grpclb/client_load_reporting_filter.cc +3 -3
  145. data/src/core/load_balancing/grpclb/client_load_reporting_filter.h +1 -1
  146. data/src/core/load_balancing/pick_first/pick_first.cc +12 -5
  147. data/src/core/load_balancing/xds/xds_cluster_impl.cc +5 -3
  148. data/src/core/net/socket_mutator.cc +19 -0
  149. data/src/core/net/socket_mutator.h +25 -0
  150. data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
  151. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +6 -1
  152. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +2 -1
  153. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +8 -5
  154. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  155. data/src/core/resolver/xds/xds_dependency_manager.cc +1 -1
  156. data/src/core/server/server.cc +1 -1
  157. data/src/core/server/server_call_tracer_filter.cc +0 -66
  158. data/src/core/server/server_call_tracer_filter.h +64 -0
  159. data/src/core/server/server_config_selector_filter.cc +1 -1
  160. data/src/core/service_config/service_config_channel_arg_filter.cc +3 -60
  161. data/src/core/service_config/service_config_channel_arg_filter.h +82 -0
  162. data/src/core/telemetry/call_tracer.cc +20 -14
  163. data/src/core/telemetry/call_tracer.h +22 -17
  164. data/src/core/telemetry/metrics.h +8 -8
  165. data/src/core/telemetry/stats_data.cc +151 -151
  166. data/src/core/telemetry/stats_data.h +87 -87
  167. data/src/core/transport/auth_context.cc +20 -0
  168. data/src/core/transport/auth_context.h +4 -0
  169. data/src/core/transport/auth_context_comparator_registry.h +69 -0
  170. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +2 -3
  171. data/src/core/tsi/ssl_transport_security.cc +202 -32
  172. data/src/core/tsi/ssl_transport_security.h +19 -10
  173. data/src/core/tsi/ssl_transport_security_utils.cc +21 -0
  174. data/src/core/tsi/ssl_transport_security_utils.h +4 -0
  175. data/src/core/util/http_client/httpcli_security_connector.cc +3 -1
  176. data/src/core/util/latent_see.cc +178 -146
  177. data/src/core/util/latent_see.h +245 -188
  178. data/src/core/util/single_set_ptr.h +5 -2
  179. data/src/core/util/useful.h +91 -0
  180. data/src/core/util/windows/directory_reader.cc +1 -0
  181. data/src/core/util/windows/thd.cc +1 -3
  182. data/src/core/util/work_serializer.cc +1 -1
  183. data/src/core/xds/grpc/file_watcher_certificate_provider_factory.cc +32 -5
  184. data/src/core/xds/grpc/file_watcher_certificate_provider_factory.h +5 -0
  185. data/src/core/xds/grpc/xds_certificate_provider.cc +5 -6
  186. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  187. data/src/ruby/lib/grpc/version.rb +1 -1
  188. data/third_party/cares/cares/include/ares.h +925 -460
  189. data/third_party/cares/cares/include/ares_dns.h +86 -71
  190. data/third_party/cares/cares/include/ares_dns_record.h +1118 -0
  191. data/third_party/cares/cares/include/ares_nameser.h +215 -189
  192. data/third_party/cares/cares/include/ares_version.h +37 -14
  193. data/third_party/cares/cares/src/lib/ares_addrinfo2hostent.c +305 -0
  194. data/third_party/cares/cares/src/lib/ares_addrinfo_localhost.c +245 -0
  195. data/third_party/cares/cares/src/lib/ares_android.c +216 -164
  196. data/third_party/cares/cares/src/lib/ares_android.h +25 -14
  197. data/third_party/cares/cares/src/lib/ares_cancel.c +68 -44
  198. data/third_party/cares/cares/src/lib/ares_close_sockets.c +137 -0
  199. data/third_party/cares/cares/src/lib/ares_conn.c +511 -0
  200. data/third_party/cares/cares/src/lib/ares_conn.h +196 -0
  201. data/third_party/cares/cares/src/lib/ares_cookie.c +461 -0
  202. data/third_party/cares/cares/src/lib/ares_data.c +93 -181
  203. data/third_party/cares/cares/src/lib/ares_data.h +50 -39
  204. data/third_party/cares/cares/src/lib/ares_destroy.c +127 -89
  205. data/third_party/cares/cares/src/lib/ares_free_hostent.c +35 -24
  206. data/third_party/cares/cares/src/lib/ares_free_string.c +24 -16
  207. data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +45 -38
  208. data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +549 -663
  209. data/third_party/cares/cares/src/lib/ares_getenv.c +25 -15
  210. data/third_party/cares/cares/src/lib/ares_getenv.h +26 -18
  211. data/third_party/cares/cares/src/lib/ares_gethostbyaddr.c +163 -221
  212. data/third_party/cares/cares/src/lib/ares_gethostbyname.c +222 -223
  213. data/third_party/cares/cares/src/lib/ares_getnameinfo.c +328 -338
  214. data/third_party/cares/cares/src/lib/ares_hosts_file.c +952 -0
  215. data/third_party/cares/cares/src/lib/ares_inet_net_pton.h +25 -19
  216. data/third_party/cares/cares/src/lib/ares_init.c +425 -2091
  217. data/third_party/cares/cares/src/lib/ares_ipv6.h +63 -33
  218. data/third_party/cares/cares/src/lib/ares_library_init.c +110 -54
  219. data/third_party/cares/cares/src/lib/ares_metrics.c +261 -0
  220. data/third_party/cares/cares/src/lib/ares_options.c +418 -332
  221. data/third_party/cares/cares/src/lib/ares_parse_into_addrinfo.c +179 -0
  222. data/third_party/cares/cares/src/lib/ares_private.h +558 -356
  223. data/third_party/cares/cares/src/lib/ares_process.c +1224 -1369
  224. data/third_party/cares/cares/src/lib/ares_qcache.c +430 -0
  225. data/third_party/cares/cares/src/lib/ares_query.c +126 -121
  226. data/third_party/cares/cares/src/lib/ares_search.c +564 -262
  227. data/third_party/cares/cares/src/lib/ares_send.c +264 -93
  228. data/third_party/cares/cares/src/lib/ares_set_socket_functions.c +588 -0
  229. data/third_party/cares/cares/src/lib/ares_setup.h +115 -111
  230. data/third_party/cares/cares/src/lib/ares_socket.c +425 -0
  231. data/third_party/cares/cares/src/lib/ares_socket.h +163 -0
  232. data/third_party/cares/cares/src/lib/ares_sortaddrinfo.c +447 -0
  233. data/third_party/cares/cares/src/lib/ares_strerror.c +83 -48
  234. data/third_party/cares/cares/src/lib/ares_sysconfig.c +639 -0
  235. data/third_party/cares/cares/src/lib/ares_sysconfig_files.c +839 -0
  236. data/third_party/cares/cares/src/lib/ares_sysconfig_mac.c +373 -0
  237. data/third_party/cares/cares/src/lib/ares_sysconfig_win.c +621 -0
  238. data/third_party/cares/cares/src/lib/ares_timeout.c +136 -73
  239. data/third_party/cares/cares/src/lib/ares_update_servers.c +1362 -0
  240. data/third_party/cares/cares/src/lib/ares_version.c +29 -4
  241. data/third_party/cares/cares/src/lib/config-dos.h +88 -89
  242. data/third_party/cares/cares/src/lib/config-win32.h +122 -77
  243. data/third_party/cares/cares/src/lib/dsa/ares_array.c +394 -0
  244. data/third_party/cares/cares/src/lib/dsa/ares_htable.c +447 -0
  245. data/third_party/cares/cares/src/lib/dsa/ares_htable.h +174 -0
  246. data/third_party/cares/cares/src/lib/dsa/ares_htable_asvp.c +224 -0
  247. data/third_party/cares/cares/src/lib/dsa/ares_htable_dict.c +228 -0
  248. data/third_party/cares/cares/src/lib/dsa/ares_htable_strvp.c +210 -0
  249. data/third_party/cares/cares/src/lib/dsa/ares_htable_szvp.c +188 -0
  250. data/third_party/cares/cares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  251. data/third_party/cares/cares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  252. data/third_party/cares/cares/src/lib/dsa/ares_llist.c +382 -0
  253. data/third_party/cares/cares/src/lib/dsa/ares_slist.c +479 -0
  254. data/third_party/cares/cares/src/lib/dsa/ares_slist.h +207 -0
  255. data/third_party/cares/cares/src/lib/event/ares_event.h +191 -0
  256. data/third_party/cares/cares/src/lib/event/ares_event_configchg.c +743 -0
  257. data/third_party/cares/cares/src/lib/event/ares_event_epoll.c +192 -0
  258. data/third_party/cares/cares/src/lib/event/ares_event_kqueue.c +248 -0
  259. data/third_party/cares/cares/src/lib/event/ares_event_poll.c +140 -0
  260. data/third_party/cares/cares/src/lib/event/ares_event_select.c +159 -0
  261. data/third_party/cares/cares/src/lib/event/ares_event_thread.c +567 -0
  262. data/third_party/cares/cares/src/lib/event/ares_event_wake_pipe.c +166 -0
  263. data/third_party/cares/cares/src/lib/event/ares_event_win32.c +978 -0
  264. data/third_party/cares/cares/src/lib/event/ares_event_win32.h +161 -0
  265. data/third_party/cares/cares/src/lib/include/ares_array.h +276 -0
  266. data/third_party/cares/cares/src/lib/include/ares_buf.h +732 -0
  267. data/third_party/cares/cares/src/lib/include/ares_htable_asvp.h +130 -0
  268. data/third_party/cares/cares/src/lib/include/ares_htable_dict.h +123 -0
  269. data/third_party/cares/cares/src/lib/include/ares_htable_strvp.h +130 -0
  270. data/third_party/cares/cares/src/lib/include/ares_htable_szvp.h +118 -0
  271. data/third_party/cares/cares/src/lib/include/ares_htable_vpstr.h +111 -0
  272. data/third_party/cares/cares/src/lib/include/ares_htable_vpvp.h +128 -0
  273. data/third_party/cares/cares/src/lib/include/ares_llist.h +239 -0
  274. data/third_party/cares/cares/src/lib/include/ares_mem.h +38 -0
  275. data/third_party/cares/cares/src/lib/include/ares_str.h +244 -0
  276. data/third_party/cares/cares/src/lib/inet_net_pton.c +202 -157
  277. data/third_party/cares/cares/src/lib/inet_ntop.c +87 -69
  278. data/third_party/cares/cares/src/lib/legacy/ares_create_query.c +78 -0
  279. data/third_party/cares/cares/src/lib/legacy/ares_expand_name.c +99 -0
  280. data/third_party/cares/cares/src/lib/legacy/ares_expand_string.c +107 -0
  281. data/third_party/cares/cares/src/lib/legacy/ares_fds.c +80 -0
  282. data/third_party/cares/cares/src/lib/legacy/ares_getsock.c +85 -0
  283. data/third_party/cares/cares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  284. data/third_party/cares/cares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  285. data/third_party/cares/cares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  286. data/third_party/cares/cares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  287. data/third_party/cares/cares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  288. data/third_party/cares/cares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  289. data/third_party/cares/cares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  290. data/third_party/cares/cares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  291. data/third_party/cares/cares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  292. data/third_party/cares/cares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  293. data/third_party/cares/cares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  294. data/third_party/cares/cares/src/lib/record/ares_dns_mapping.c +982 -0
  295. data/third_party/cares/cares/src/lib/record/ares_dns_multistring.c +307 -0
  296. data/third_party/cares/cares/src/lib/record/ares_dns_multistring.h +72 -0
  297. data/third_party/cares/cares/src/lib/record/ares_dns_name.c +673 -0
  298. data/third_party/cares/cares/src/lib/record/ares_dns_parse.c +1329 -0
  299. data/third_party/cares/cares/src/lib/record/ares_dns_private.h +273 -0
  300. data/third_party/cares/cares/src/lib/record/ares_dns_record.c +1661 -0
  301. data/third_party/cares/cares/src/lib/record/ares_dns_write.c +1229 -0
  302. data/third_party/cares/cares/src/lib/str/ares_buf.c +1498 -0
  303. data/third_party/cares/cares/src/lib/str/ares_str.c +508 -0
  304. data/third_party/cares/cares/src/lib/str/ares_strsplit.c +90 -0
  305. data/third_party/cares/cares/src/lib/str/ares_strsplit.h +51 -0
  306. data/third_party/cares/cares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  307. data/third_party/cares/cares/src/lib/util/ares_iface_ips.c +628 -0
  308. data/third_party/cares/cares/src/lib/util/ares_iface_ips.h +139 -0
  309. data/third_party/cares/cares/src/lib/util/ares_math.c +158 -0
  310. data/third_party/cares/cares/src/lib/util/ares_math.h +45 -0
  311. data/third_party/cares/cares/src/lib/util/ares_rand.c +389 -0
  312. data/third_party/cares/cares/src/lib/util/ares_rand.h +36 -0
  313. data/third_party/cares/cares/src/lib/util/ares_threads.c +614 -0
  314. data/third_party/cares/cares/src/lib/util/ares_threads.h +60 -0
  315. data/third_party/cares/cares/src/lib/util/ares_time.h +48 -0
  316. data/third_party/cares/cares/src/lib/util/ares_timeval.c +95 -0
  317. data/third_party/cares/cares/src/lib/util/ares_uri.c +1626 -0
  318. data/third_party/cares/cares/src/lib/util/ares_uri.h +252 -0
  319. data/third_party/cares/cares/src/lib/windows_port.c +16 -9
  320. metadata +121 -49
  321. data/src/core/util/ring_buffer.h +0 -122
  322. data/third_party/cares/cares/include/ares_rules.h +0 -125
  323. data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +0 -266
  324. data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +0 -240
  325. data/third_party/cares/cares/src/lib/ares__close_sockets.c +0 -61
  326. data/third_party/cares/cares/src/lib/ares__get_hostent.c +0 -260
  327. data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +0 -229
  328. data/third_party/cares/cares/src/lib/ares__read_line.c +0 -73
  329. data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +0 -258
  330. data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +0 -507
  331. data/third_party/cares/cares/src/lib/ares__timeval.c +0 -111
  332. data/third_party/cares/cares/src/lib/ares_create_query.c +0 -197
  333. data/third_party/cares/cares/src/lib/ares_expand_name.c +0 -311
  334. data/third_party/cares/cares/src/lib/ares_expand_string.c +0 -67
  335. data/third_party/cares/cares/src/lib/ares_fds.c +0 -59
  336. data/third_party/cares/cares/src/lib/ares_getsock.c +0 -66
  337. data/third_party/cares/cares/src/lib/ares_iphlpapi.h +0 -221
  338. data/third_party/cares/cares/src/lib/ares_llist.c +0 -63
  339. data/third_party/cares/cares/src/lib/ares_llist.h +0 -39
  340. data/third_party/cares/cares/src/lib/ares_mkquery.c +0 -24
  341. data/third_party/cares/cares/src/lib/ares_nowarn.c +0 -260
  342. data/third_party/cares/cares/src/lib/ares_nowarn.h +0 -61
  343. data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +0 -90
  344. data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +0 -92
  345. data/third_party/cares/cares/src/lib/ares_parse_caa_reply.c +0 -199
  346. data/third_party/cares/cares/src/lib/ares_parse_mx_reply.c +0 -164
  347. data/third_party/cares/cares/src/lib/ares_parse_naptr_reply.c +0 -183
  348. data/third_party/cares/cares/src/lib/ares_parse_ns_reply.c +0 -177
  349. data/third_party/cares/cares/src/lib/ares_parse_ptr_reply.c +0 -228
  350. data/third_party/cares/cares/src/lib/ares_parse_soa_reply.c +0 -179
  351. data/third_party/cares/cares/src/lib/ares_parse_srv_reply.c +0 -168
  352. data/third_party/cares/cares/src/lib/ares_parse_txt_reply.c +0 -214
  353. data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +0 -184
  354. data/third_party/cares/cares/src/lib/ares_platform.c +0 -11042
  355. data/third_party/cares/cares/src/lib/ares_platform.h +0 -43
  356. data/third_party/cares/cares/src/lib/ares_rand.c +0 -279
  357. data/third_party/cares/cares/src/lib/ares_strcasecmp.c +0 -66
  358. data/third_party/cares/cares/src/lib/ares_strcasecmp.h +0 -30
  359. data/third_party/cares/cares/src/lib/ares_strdup.c +0 -42
  360. data/third_party/cares/cares/src/lib/ares_strdup.h +0 -24
  361. data/third_party/cares/cares/src/lib/ares_strsplit.c +0 -94
  362. data/third_party/cares/cares/src/lib/ares_strsplit.h +0 -42
  363. data/third_party/cares/cares/src/lib/ares_writev.c +0 -79
  364. data/third_party/cares/cares/src/lib/ares_writev.h +0 -36
  365. data/third_party/cares/cares/src/lib/bitncmp.c +0 -59
  366. data/third_party/cares/cares/src/lib/bitncmp.h +0 -26
  367. data/third_party/cares/cares/src/lib/setup_once.h +0 -554
  368. data/third_party/cares/cares/src/tools/ares_getopt.h +0 -53
@@ -0,0 +1,978 @@
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
+ /* Uses an anonymous union */
28
+ #if defined(__clang__) || defined(__GNUC__)
29
+ # pragma GCC diagnostic push
30
+ # if defined(__clang__)
31
+ # pragma GCC diagnostic ignored "-Wc11-extensions"
32
+ # else
33
+ # pragma GCC diagnostic ignored "-Wpedantic"
34
+ # endif
35
+ #endif
36
+
37
+ #include "ares_private.h"
38
+ #include "ares_event.h"
39
+ #include "ares_event_win32.h"
40
+
41
+
42
+ #if defined(USE_WINSOCK) && defined(CARES_THREADS)
43
+
44
+ #ifdef HAVE_LIMITS_H
45
+ # include <limits.h>
46
+ #endif
47
+
48
+ /* IMPLEMENTATION NOTES
49
+ * ====================
50
+ *
51
+ * This implementation uses some undocumented functionality within Windows for
52
+ * monitoring sockets. The Ancillary Function Driver (AFD) is the low level
53
+ * implementation that Winsock2 sits on top of. Winsock2 unfortunately does
54
+ * not expose the equivalent of epoll() or kqueue(), but it is possible to
55
+ * access AFD directly and use along with IOCP to simulate the functionality.
56
+ * We want to use IOCP if possible as it gives us the ability to monitor more
57
+ * than just sockets (WSAPoll is not an option), and perform arbitrary callbacks
58
+ * which means we can hook in non-socket related events.
59
+ *
60
+ * The information for this implementation was gathered from "wepoll" and
61
+ * "libuv" which both use slight variants on this. We originally went with
62
+ * an implementation methodology more similar to "libuv", but we had a few
63
+ * user reports of crashes during shutdown and memory leaks due to some
64
+ * events not being delivered for cleanup of closed sockets.
65
+ *
66
+ * Initialization:
67
+ * 1. Dynamically load the NtDeviceIoControlFile, NtCreateFile, and
68
+ * NtCancelIoFileEx internal symbols from ntdll.dll. (Don't believe
69
+ * Microsoft's documentation for NtCancelIoFileEx as it documents an
70
+ * invalid prototype). These functions are to open a reference to the
71
+ * Ancillary Function Driver (AFD), and to submit and cancel POLL
72
+ * requests.
73
+ * 2. Create an IO Completion Port base handle via CreateIoCompletionPort()
74
+ * that all socket events will be delivered through.
75
+ * 3. Create a list of AFD Handles and track the number of poll requests
76
+ * per AFD handle. When we exceed a pre-determined limit of poll requests
77
+ * for a handle (128), we will automatically create a new handle. The
78
+ * reason behind this is NtCancelIoFileEx uses a horrible algorithm for
79
+ * issuing cancellations. See:
80
+ * https://github.com/python-trio/trio/issues/52#issuecomment-548215128
81
+ * 4. Create a callback to be used to be able to interrupt waiting for IOCP
82
+ * events, this may be called for allowing enqueuing of additional socket
83
+ * events or removing socket events. PostQueuedCompletionStatus() is the
84
+ * obvious choice. We can use the same container format, the event
85
+ * delivered won't have an OVERLAPPED pointer so we can differentiate from
86
+ * socket events. Use the container as the completion key.
87
+ *
88
+ * Socket Add:
89
+ * 1. Create/Allocate a container for holding metadata about a socket
90
+ * including:
91
+ * - SOCKET base_socket;
92
+ * - IO_STATUS_BLOCK iosb; -- Used by AFD POLL, returned as OVERLAPPED
93
+ * - AFD_POLL_INFO afd_poll_info; -- Used by AFD POLL
94
+ * - afd list node -- for tracking which AFD handle a POLL request was
95
+ * submitted to.
96
+ * 2. Call WSAIoctl(..., SIO_BASE_HANDLE, ...) to unwrap the SOCKET and get
97
+ * the "base socket" we can use for polling. It appears this may fail so
98
+ * we should call WSAIoctl(..., SIO_BSP_HANDLE_POLL, ...) as a fallback.
99
+ * 3. Submit AFD POLL request (see "AFD POLL Request" section)
100
+ * 4. Record a mapping between the "IO Status Block" and the socket container
101
+ * so when events are delivered we can dereference.
102
+ *
103
+ * Socket Delete:
104
+ * 1. Call
105
+ * NtCancelIoFileEx(afd, iosb, &temp_iosb);
106
+ * to cancel any pending operations.
107
+ * 2. Tag the socket container as being queued for deletion
108
+ * 3. Wait for an event to be delivered for the socket (cancel isn't
109
+ * immediate, it delivers an event to know its complete). Delete only once
110
+ * that event has been delivered. If we don't do this we could try to
111
+ * access free()'d memory at a later point.
112
+ *
113
+ * Socket Modify:
114
+ * 1. Call
115
+ * NtCancelIoFileEx(afd, iosb, &temp_iosb)
116
+ * to cancel any pending operation.
117
+ * 2. When the event comes through that the cancel is complete, enqueue
118
+ * another "AFD Poll Request" for the desired events.
119
+ *
120
+ * Event Wait:
121
+ * 1. Call GetQueuedCompletionStatusEx() with the base IOCP handle, a
122
+ * stack allocated array of OVERLAPPED_ENTRY's, and an appropriate
123
+ * timeout.
124
+ * 2. Iterate across returned events, if the lpOverlapped is NULL, then the
125
+ * the CompletionKey is a pointer to the container registered via
126
+ * PostQueuedCompletionStatus(), otherwise it is the "IO Status Block"
127
+ * registered with the "AFD Poll Request" which needs to be dereferenced
128
+ * to the "socket container".
129
+ * 3. If it is a "socket container", disassociate it from the afd list node
130
+ * it was previously submitted to.
131
+ * 4. If it is a "socket container" check to see if we are cleaning up, if so,
132
+ * clean it up.
133
+ * 5. If it is a "socket container" that is still valid, Submit an
134
+ * AFD POLL Request (see "AFD POLL Request"). We must re-enable the request
135
+ * each time we receive a response, it is not persistent.
136
+ * 6. Notify of any events received as indicated in the AFD_POLL_INFO
137
+ * Handles[0].Events (NOTE: check NumberOfHandles > 0, and the status in
138
+ * the IO_STATUS_BLOCK. If we received an AFD_POLL_LOCAL_CLOSE, clean up
139
+ * the connection like the integrator requested it to be cleaned up.
140
+ *
141
+ * AFD Poll Request:
142
+ * 1. Find an afd poll handle in the list that has fewer pending requests than
143
+ * the limit.
144
+ * 2. If an afd poll handle was not associated (e.g. due to all being over
145
+ * limit), create a new afd poll handle by calling NtCreateFile()
146
+ * with path \Device\Afd , then add the AFD handle to the IO Completion
147
+ * Port. We can leave the completion key as blank since events for
148
+ * multiple sockets will be delivered through this and we need to
149
+ * differentiate via the OVERLAPPED member returned. Add the new AFD
150
+ * handle to the list of handles.
151
+ * 3. Initialize the AFD_POLL_INFO structure:
152
+ * Exclusive = FALSE; // allow multiple requests
153
+ * NumberOfHandles = 1;
154
+ * Timeout.QuadPart = LLONG_MAX;
155
+ * Handles[0].Handle = (HANDLE)base_socket;
156
+ * Handles[0].Status = 0;
157
+ * Handles[0].Events = AFD_POLL_LOCAL_CLOSE + additional events to wait for
158
+ * such as AFD_POLL_RECEIVE, etc;
159
+ * 4. Zero out the IO_STATUS_BLOCK structures
160
+ * 5. Set the "Status" member of IO_STATUS_BLOCK to STATUS_PENDING
161
+ * 6. Call
162
+ * NtDeviceIoControlFile(afd, NULL, NULL, &iosb,
163
+ * &iosb, IOCTL_AFD_POLL
164
+ * &afd_poll_info, sizeof(afd_poll_info),
165
+ * &afd_poll_info, sizeof(afd_poll_info));
166
+ *
167
+ *
168
+ * References:
169
+ * - https://github.com/piscisaureus/wepoll/
170
+ * - https://github.com/libuv/libuv/
171
+ */
172
+
173
+ /* Cap the number of outstanding AFD poll requests per AFD handle due to known
174
+ * slowdowns with large lists and NtCancelIoFileEx() */
175
+ # define AFD_POLL_PER_HANDLE 128
176
+
177
+ # include <stdarg.h>
178
+
179
+ /* # define CARES_DEBUG 1 */
180
+
181
+ # ifdef __GNUC__
182
+ # define CARES_PRINTF_LIKE(fmt, args) \
183
+ __attribute__((format(printf, fmt, args)))
184
+ # else
185
+ # define CARES_PRINTF_LIKE(fmt, args)
186
+ # endif
187
+
188
+ static void CARES_DEBUG_LOG(const char *fmt, ...) CARES_PRINTF_LIKE(1, 2);
189
+
190
+ static void CARES_DEBUG_LOG(const char *fmt, ...)
191
+ {
192
+ va_list ap;
193
+
194
+ va_start(ap, fmt);
195
+ # ifdef CARES_DEBUG
196
+ vfprintf(stderr, fmt, ap);
197
+ fflush(stderr);
198
+ # endif
199
+ va_end(ap);
200
+ }
201
+
202
+ typedef struct {
203
+ /* Dynamically loaded symbols */
204
+ NtCreateFile_t NtCreateFile;
205
+ NtDeviceIoControlFile_t NtDeviceIoControlFile;
206
+ NtCancelIoFileEx_t NtCancelIoFileEx;
207
+
208
+ /* Implementation details */
209
+ ares_slist_t *afd_handles;
210
+ HANDLE iocp_handle;
211
+
212
+ /* IO_STATUS_BLOCK * -> ares_evsys_win32_eventdata_t * mapping. There is
213
+ * no completion key passed to IOCP with this method so we have to look
214
+ * up based on the lpOverlapped returned (which is mapped to IO_STATUS_BLOCK)
215
+ */
216
+ ares_htable_vpvp_t *sockets;
217
+
218
+ /* Flag about whether or not we are shutting down */
219
+ ares_bool_t is_shutdown;
220
+ } ares_evsys_win32_t;
221
+
222
+ typedef enum {
223
+ POLL_STATUS_NONE = 0,
224
+ POLL_STATUS_PENDING = 1,
225
+ POLL_STATUS_CANCEL = 2,
226
+ POLL_STATUS_DESTROY = 3
227
+ } poll_status_t;
228
+
229
+ typedef struct {
230
+ /*! Pointer to parent event container */
231
+ ares_event_t *event;
232
+ /*! Socket passed in to monitor */
233
+ SOCKET socket;
234
+ /*! Base socket derived from provided socket */
235
+ SOCKET base_socket;
236
+ /*! Structure for submitting AFD POLL requests (Internals!) */
237
+ AFD_POLL_INFO afd_poll_info;
238
+ /*! Status of current polling operation */
239
+ poll_status_t poll_status;
240
+ /*! IO Status Block structure submitted with AFD POLL requests and returned
241
+ * with IOCP results as lpOverlapped (even though its a different structure)
242
+ */
243
+ IO_STATUS_BLOCK iosb;
244
+ /*! AFD handle node an outstanding poll request is associated with */
245
+ ares_slist_node_t *afd_handle_node;
246
+ /* Lock is only for PostQueuedCompletionStatus() to prevent multiple
247
+ * signals. Tracking via POLL_STATUS_PENDING/POLL_STATUS_NONE */
248
+ ares_thread_mutex_t *lock;
249
+ } ares_evsys_win32_eventdata_t;
250
+
251
+ static size_t ares_evsys_win32_wait(ares_event_thread_t *e,
252
+ unsigned long timeout_ms);
253
+
254
+ static void ares_iocpevent_signal(const ares_event_t *event)
255
+ {
256
+ ares_event_thread_t *e = event->e;
257
+ ares_evsys_win32_t *ew = e->ev_sys_data;
258
+ ares_evsys_win32_eventdata_t *ed = event->data;
259
+ ares_bool_t queue_event = ARES_FALSE;
260
+
261
+ ares_thread_mutex_lock(ed->lock);
262
+ if (ed->poll_status != POLL_STATUS_PENDING) {
263
+ ed->poll_status = POLL_STATUS_PENDING;
264
+ queue_event = ARES_TRUE;
265
+ }
266
+ ares_thread_mutex_unlock(ed->lock);
267
+
268
+ if (!queue_event) {
269
+ return;
270
+ }
271
+
272
+ PostQueuedCompletionStatus(ew->iocp_handle, 0, (ULONG_PTR)event->data, NULL);
273
+ }
274
+
275
+ static void ares_iocpevent_cb(ares_event_thread_t *e, ares_socket_t fd,
276
+ void *data, ares_event_flags_t flags)
277
+ {
278
+ ares_evsys_win32_eventdata_t *ed = data;
279
+ (void)e;
280
+ (void)fd;
281
+ (void)flags;
282
+ ares_thread_mutex_lock(ed->lock);
283
+ ed->poll_status = POLL_STATUS_NONE;
284
+ ares_thread_mutex_unlock(ed->lock);
285
+ }
286
+
287
+ static ares_event_t *ares_iocpevent_create(ares_event_thread_t *e)
288
+ {
289
+ ares_event_t *event = NULL;
290
+ ares_status_t status;
291
+
292
+ status =
293
+ ares_event_update(&event, e, ARES_EVENT_FLAG_OTHER, ares_iocpevent_cb,
294
+ ARES_SOCKET_BAD, NULL, NULL, ares_iocpevent_signal);
295
+ if (status != ARES_SUCCESS) {
296
+ return NULL;
297
+ }
298
+
299
+ return event;
300
+ }
301
+
302
+ static void ares_evsys_win32_destroy(ares_event_thread_t *e)
303
+ {
304
+ ares_evsys_win32_t *ew = NULL;
305
+
306
+ if (e == NULL) {
307
+ return;
308
+ }
309
+
310
+ CARES_DEBUG_LOG("** Win32 Event Destroy\n");
311
+
312
+ ew = e->ev_sys_data;
313
+ if (ew == NULL) {
314
+ return;
315
+ }
316
+
317
+ ew->is_shutdown = ARES_TRUE;
318
+ CARES_DEBUG_LOG(" ** waiting on %lu remaining sockets to be destroyed\n",
319
+ (unsigned long)ares_htable_vpvp_num_keys(ew->sockets));
320
+ while (ares_htable_vpvp_num_keys(ew->sockets)) {
321
+ ares_evsys_win32_wait(e, 0);
322
+ }
323
+ CARES_DEBUG_LOG(" ** all sockets cleaned up\n");
324
+
325
+
326
+ if (ew->iocp_handle != NULL) {
327
+ CloseHandle(ew->iocp_handle);
328
+ }
329
+
330
+ ares_slist_destroy(ew->afd_handles);
331
+
332
+ ares_htable_vpvp_destroy(ew->sockets);
333
+
334
+ ares_free(ew);
335
+ e->ev_sys_data = NULL;
336
+ }
337
+
338
+ typedef struct {
339
+ size_t poll_cnt;
340
+ HANDLE afd_handle;
341
+ } ares_afd_handle_t;
342
+
343
+ static void ares_afd_handle_destroy(void *arg)
344
+ {
345
+ ares_afd_handle_t *hnd = arg;
346
+ if (hnd != NULL && hnd->afd_handle != NULL) {
347
+ CloseHandle(hnd->afd_handle);
348
+ }
349
+ ares_free(hnd);
350
+ }
351
+
352
+ static int ares_afd_handle_cmp(const void *data1, const void *data2)
353
+ {
354
+ const ares_afd_handle_t *hnd1 = data1;
355
+ const ares_afd_handle_t *hnd2 = data2;
356
+
357
+ if (hnd1->poll_cnt > hnd2->poll_cnt) {
358
+ return 1;
359
+ }
360
+ if (hnd1->poll_cnt < hnd2->poll_cnt) {
361
+ return -1;
362
+ }
363
+ return 0;
364
+ }
365
+
366
+ static void fill_object_attributes(OBJECT_ATTRIBUTES *attr,
367
+ UNICODE_STRING *name, ULONG attributes)
368
+ {
369
+ memset(attr, 0, sizeof(*attr));
370
+ attr->Length = sizeof(*attr);
371
+ attr->ObjectName = name;
372
+ attr->Attributes = attributes;
373
+ }
374
+
375
+ # define UNICODE_STRING_CONSTANT(s) \
376
+ { (sizeof(s) - 1) * sizeof(wchar_t), sizeof(s) * sizeof(wchar_t), L##s }
377
+
378
+ static ares_slist_node_t *ares_afd_handle_create(ares_evsys_win32_t *ew)
379
+ {
380
+ UNICODE_STRING afd_device_name = UNICODE_STRING_CONSTANT("\\Device\\Afd");
381
+ OBJECT_ATTRIBUTES afd_attributes;
382
+ NTSTATUS status;
383
+ IO_STATUS_BLOCK iosb;
384
+ ares_afd_handle_t *afd = ares_malloc_zero(sizeof(*afd));
385
+ ares_slist_node_t *node = NULL;
386
+ if (afd == NULL) {
387
+ goto fail;
388
+ }
389
+
390
+ /* Open a handle to the AFD subsystem */
391
+ fill_object_attributes(&afd_attributes, &afd_device_name, 0);
392
+ memset(&iosb, 0, sizeof(iosb));
393
+ iosb.Status = STATUS_PENDING;
394
+ status = ew->NtCreateFile(&afd->afd_handle, SYNCHRONIZE, &afd_attributes,
395
+ &iosb, NULL, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
396
+ FILE_OPEN, 0, NULL, 0);
397
+ if (status != STATUS_SUCCESS) {
398
+ CARES_DEBUG_LOG("** Failed to create AFD endpoint\n");
399
+ goto fail;
400
+ }
401
+
402
+ if (CreateIoCompletionPort(afd->afd_handle, ew->iocp_handle,
403
+ 0 /* CompletionKey */, 0) == NULL) {
404
+ goto fail;
405
+ }
406
+
407
+ if (!SetFileCompletionNotificationModes(afd->afd_handle,
408
+ FILE_SKIP_SET_EVENT_ON_HANDLE)) {
409
+ goto fail;
410
+ }
411
+
412
+ node = ares_slist_insert(ew->afd_handles, afd);
413
+ if (node == NULL) {
414
+ goto fail;
415
+ }
416
+
417
+ return node;
418
+
419
+ fail:
420
+
421
+ ares_afd_handle_destroy(afd);
422
+ return NULL;
423
+ }
424
+
425
+ /* Fetch the lowest poll count entry, but if it exceeds the limit, create a
426
+ * new one and return that */
427
+ static ares_slist_node_t *ares_afd_handle_fetch(ares_evsys_win32_t *ew)
428
+ {
429
+ ares_slist_node_t *node = ares_slist_node_first(ew->afd_handles);
430
+ ares_afd_handle_t *afd = ares_slist_node_val(node);
431
+
432
+ if (afd != NULL && afd->poll_cnt < AFD_POLL_PER_HANDLE) {
433
+ return node;
434
+ }
435
+
436
+ return ares_afd_handle_create(ew);
437
+ }
438
+
439
+ static ares_bool_t ares_evsys_win32_init(ares_event_thread_t *e)
440
+ {
441
+ ares_evsys_win32_t *ew = NULL;
442
+ HMODULE ntdll;
443
+
444
+ CARES_DEBUG_LOG("** Win32 Event Init\n");
445
+
446
+ ew = ares_malloc_zero(sizeof(*ew));
447
+ if (ew == NULL) {
448
+ return ARES_FALSE;
449
+ }
450
+
451
+ e->ev_sys_data = ew;
452
+
453
+ /* All apps should have ntdll.dll already loaded, so just get a handle to
454
+ * this */
455
+ ntdll = GetModuleHandleA("ntdll.dll");
456
+ if (ntdll == NULL) {
457
+ goto fail;
458
+ }
459
+
460
+ # ifdef __GNUC__
461
+ # pragma GCC diagnostic push
462
+ # pragma GCC diagnostic ignored "-Wpedantic"
463
+ /* Without the (void *) cast we get:
464
+ * warning: cast between incompatible function types from 'FARPROC' {aka 'long
465
+ * long int (*)()'} to 'NTSTATUS (*)(...)'} [-Wcast-function-type] but with it
466
+ * we get: warning: ISO C forbids conversion of function pointer to object
467
+ * pointer type [-Wpedantic] look unsolvable short of killing the warning.
468
+ */
469
+ # endif
470
+
471
+ /* Load Internal symbols not typically accessible */
472
+ ew->NtCreateFile =
473
+ (NtCreateFile_t)(void *)GetProcAddress(ntdll, "NtCreateFile");
474
+ ew->NtDeviceIoControlFile = (NtDeviceIoControlFile_t)(void *)GetProcAddress(
475
+ ntdll, "NtDeviceIoControlFile");
476
+ ew->NtCancelIoFileEx =
477
+ (NtCancelIoFileEx_t)(void *)GetProcAddress(ntdll, "NtCancelIoFileEx");
478
+
479
+ # ifdef __GNUC__
480
+ # pragma GCC diagnostic pop
481
+ # endif
482
+
483
+ if (ew->NtCreateFile == NULL || ew->NtCancelIoFileEx == NULL ||
484
+ ew->NtDeviceIoControlFile == NULL) {
485
+ goto fail;
486
+ }
487
+
488
+ ew->iocp_handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
489
+ if (ew->iocp_handle == NULL) {
490
+ goto fail;
491
+ }
492
+
493
+ ew->afd_handles = ares_slist_create(
494
+ e->channel->rand_state, ares_afd_handle_cmp, ares_afd_handle_destroy);
495
+ if (ew->afd_handles == NULL) {
496
+ goto fail;
497
+ }
498
+
499
+ /* Create at least the first afd handle, so we know of any critical system
500
+ * issues during startup */
501
+ if (ares_afd_handle_create(ew) == NULL) {
502
+ goto fail;
503
+ }
504
+
505
+ e->ev_signal = ares_iocpevent_create(e);
506
+ if (e->ev_signal == NULL) {
507
+ goto fail;
508
+ }
509
+
510
+ ew->sockets = ares_htable_vpvp_create(NULL, NULL);
511
+ if (ew->sockets == NULL) {
512
+ goto fail;
513
+ }
514
+
515
+ return ARES_TRUE;
516
+
517
+ fail:
518
+ ares_evsys_win32_destroy(e);
519
+ return ARES_FALSE;
520
+ }
521
+
522
+ static ares_socket_t ares_evsys_win32_basesocket(ares_socket_t socket)
523
+ {
524
+ while (1) {
525
+ DWORD bytes; /* Not used */
526
+ ares_socket_t base_socket = ARES_SOCKET_BAD;
527
+ int rv;
528
+
529
+ rv = WSAIoctl(socket, SIO_BASE_HANDLE, NULL, 0, &base_socket,
530
+ sizeof(base_socket), &bytes, NULL, NULL);
531
+ if (rv != SOCKET_ERROR && base_socket != ARES_SOCKET_BAD) {
532
+ socket = base_socket;
533
+ break;
534
+ }
535
+
536
+ /* If we're here, an error occurred */
537
+ if (GetLastError() == WSAENOTSOCK) {
538
+ /* This is critical, exit */
539
+ return ARES_SOCKET_BAD;
540
+ }
541
+
542
+ /* Work around known bug in Komodia based LSPs, use ARES_BSP_HANDLE_POLL
543
+ * to retrieve the underlying socket to then loop and get the base socket:
544
+ * https://docs.microsoft.com/en-us/windows/win32/winsock/winsock-ioctls
545
+ * https://www.komodia.com/newwiki/index.php?title=Komodia%27s_Redirector_bug_fixes#Version_2.2.2.6
546
+ */
547
+ base_socket = ARES_SOCKET_BAD;
548
+ rv = WSAIoctl(socket, SIO_BSP_HANDLE_POLL, NULL, 0, &base_socket,
549
+ sizeof(base_socket), &bytes, NULL, NULL);
550
+
551
+ if (rv != SOCKET_ERROR && base_socket != ARES_SOCKET_BAD &&
552
+ base_socket != socket) {
553
+ socket = base_socket;
554
+ continue; /* loop! */
555
+ }
556
+
557
+ return ARES_SOCKET_BAD;
558
+ }
559
+
560
+ return socket;
561
+ }
562
+
563
+ static ares_bool_t ares_evsys_win32_afd_enqueue(ares_event_t *event,
564
+ ares_event_flags_t flags)
565
+ {
566
+ ares_event_thread_t *e = event->e;
567
+ ares_evsys_win32_t *ew = e->ev_sys_data;
568
+ ares_evsys_win32_eventdata_t *ed = event->data;
569
+ ares_afd_handle_t *afd;
570
+ NTSTATUS status;
571
+
572
+ if (e == NULL || ed == NULL || ew == NULL) {
573
+ return ARES_FALSE;
574
+ }
575
+
576
+ /* Misuse */
577
+ if (ed->poll_status != POLL_STATUS_NONE) {
578
+ return ARES_FALSE;
579
+ }
580
+
581
+ ed->afd_handle_node = ares_afd_handle_fetch(ew);
582
+ /* System resource issue? */
583
+ if (ed->afd_handle_node == NULL) {
584
+ return ARES_FALSE;
585
+ }
586
+
587
+ afd = ares_slist_node_val(ed->afd_handle_node);
588
+
589
+ /* Enqueue AFD Poll */
590
+ ed->afd_poll_info.Exclusive = FALSE;
591
+ ed->afd_poll_info.NumberOfHandles = 1;
592
+ ed->afd_poll_info.Timeout.QuadPart = LLONG_MAX;
593
+ ed->afd_poll_info.Handles[0].Handle = (HANDLE)ed->base_socket;
594
+ ed->afd_poll_info.Handles[0].Status = 0;
595
+ ed->afd_poll_info.Handles[0].Events = AFD_POLL_LOCAL_CLOSE;
596
+
597
+ if (flags & ARES_EVENT_FLAG_READ) {
598
+ ed->afd_poll_info.Handles[0].Events |=
599
+ (AFD_POLL_RECEIVE | AFD_POLL_DISCONNECT | AFD_POLL_ACCEPT |
600
+ AFD_POLL_ABORT);
601
+ }
602
+ if (flags & ARES_EVENT_FLAG_WRITE) {
603
+ ed->afd_poll_info.Handles[0].Events |=
604
+ (AFD_POLL_SEND | AFD_POLL_CONNECT_FAIL);
605
+ }
606
+ if (flags == 0) {
607
+ ed->afd_poll_info.Handles[0].Events |= AFD_POLL_DISCONNECT;
608
+ }
609
+
610
+ memset(&ed->iosb, 0, sizeof(ed->iosb));
611
+ ed->iosb.Status = STATUS_PENDING;
612
+
613
+ status = ew->NtDeviceIoControlFile(
614
+ afd->afd_handle, NULL, NULL, &ed->iosb, &ed->iosb, IOCTL_AFD_POLL,
615
+ &ed->afd_poll_info, sizeof(ed->afd_poll_info), &ed->afd_poll_info,
616
+ sizeof(ed->afd_poll_info));
617
+ if (status != STATUS_SUCCESS && status != STATUS_PENDING) {
618
+ CARES_DEBUG_LOG("** afd_enqueue ed=%p FAILED\n", (void *)ed);
619
+ ed->afd_handle_node = NULL;
620
+ return ARES_FALSE;
621
+ }
622
+
623
+ /* Record that we submitted a poll request to this handle and tell it to
624
+ * re-sort the node since we changed its sort value */
625
+ afd->poll_cnt++;
626
+ ares_slist_node_reinsert(ed->afd_handle_node);
627
+
628
+ ed->poll_status = POLL_STATUS_PENDING;
629
+ CARES_DEBUG_LOG("++ afd_enqueue ed=%p flags=%X\n", (void *)ed,
630
+ (unsigned int)flags);
631
+ return ARES_TRUE;
632
+ }
633
+
634
+ static ares_bool_t ares_evsys_win32_afd_cancel(ares_evsys_win32_eventdata_t *ed)
635
+ {
636
+ IO_STATUS_BLOCK cancel_iosb;
637
+ ares_evsys_win32_t *ew;
638
+ NTSTATUS status;
639
+ ares_afd_handle_t *afd;
640
+
641
+ ew = ed->event->e->ev_sys_data;
642
+
643
+ /* Misuse */
644
+ if (ed->poll_status != POLL_STATUS_PENDING) {
645
+ return ARES_FALSE;
646
+ }
647
+
648
+ afd = ares_slist_node_val(ed->afd_handle_node);
649
+
650
+ /* Misuse */
651
+ if (afd == NULL) {
652
+ return ARES_FALSE;
653
+ }
654
+
655
+ ed->poll_status = POLL_STATUS_CANCEL;
656
+
657
+ /* Not pending, nothing to do. Most likely that means there is a pending
658
+ * event that hasn't yet been delivered otherwise it would be re-armed
659
+ * already */
660
+ if (ed->iosb.Status != STATUS_PENDING) {
661
+ CARES_DEBUG_LOG("** cancel not needed for ed=%p\n", (void *)ed);
662
+ return ARES_FALSE;
663
+ }
664
+
665
+ status = ew->NtCancelIoFileEx(afd->afd_handle, &ed->iosb, &cancel_iosb);
666
+
667
+ CARES_DEBUG_LOG("** Enqueued cancel for ed=%p, status = %lX\n", (void *)ed,
668
+ status);
669
+
670
+ /* NtCancelIoFileEx() may return STATUS_NOT_FOUND if the operation completed
671
+ * just before calling NtCancelIoFileEx(), but we have not yet received the
672
+ * notification (but it should be queued for the next IOCP event). */
673
+ if (status == STATUS_SUCCESS || status == STATUS_NOT_FOUND) {
674
+ return ARES_TRUE;
675
+ }
676
+
677
+ return ARES_FALSE;
678
+ }
679
+
680
+ static void ares_evsys_win32_eventdata_destroy(ares_evsys_win32_t *ew,
681
+ ares_evsys_win32_eventdata_t *ed)
682
+ {
683
+ if (ew == NULL || ed == NULL) {
684
+ return;
685
+ }
686
+ CARES_DEBUG_LOG("-- deleting ed=%p (%s)\n", (void *)ed,
687
+ (ed->socket == ARES_SOCKET_BAD) ? "data" : "socket");
688
+ /* These type of handles are deferred destroy. Update tracking. */
689
+ if (ed->socket != ARES_SOCKET_BAD) {
690
+ ares_htable_vpvp_remove(ew->sockets, &ed->iosb);
691
+ }
692
+
693
+ ares_thread_mutex_destroy(ed->lock);
694
+
695
+ if (ed->event != NULL) {
696
+ ed->event->data = NULL;
697
+ }
698
+
699
+ ares_free(ed);
700
+ }
701
+
702
+ static ares_bool_t ares_evsys_win32_event_add(ares_event_t *event)
703
+ {
704
+ ares_event_thread_t *e = event->e;
705
+ ares_evsys_win32_t *ew = e->ev_sys_data;
706
+ ares_evsys_win32_eventdata_t *ed;
707
+ ares_bool_t rc = ARES_FALSE;
708
+
709
+ ed = ares_malloc_zero(sizeof(*ed));
710
+ ed->event = event;
711
+ ed->socket = event->fd;
712
+ ed->base_socket = ARES_SOCKET_BAD;
713
+ event->data = ed;
714
+
715
+ CARES_DEBUG_LOG("++ add ed=%p (%s) flags=%X\n", (void *)ed,
716
+ (ed->socket == ARES_SOCKET_BAD) ? "data" : "socket",
717
+ (unsigned int)event->flags);
718
+
719
+ /* Likely a signal event, not something we will directly handle. We create
720
+ * the ares_evsys_win32_eventdata_t as the placeholder to use as the
721
+ * IOCP Completion Key */
722
+ if (ed->socket == ARES_SOCKET_BAD) {
723
+ ed->lock = ares_thread_mutex_create();
724
+ if (ed->lock == NULL) {
725
+ goto done;
726
+ }
727
+ rc = ARES_TRUE;
728
+ goto done;
729
+ }
730
+
731
+ ed->base_socket = ares_evsys_win32_basesocket(ed->socket);
732
+ if (ed->base_socket == ARES_SOCKET_BAD) {
733
+ goto done;
734
+ }
735
+
736
+ if (!ares_htable_vpvp_insert(ew->sockets, &ed->iosb, ed)) {
737
+ goto done;
738
+ }
739
+
740
+ if (!ares_evsys_win32_afd_enqueue(event, event->flags)) {
741
+ goto done;
742
+ }
743
+
744
+ rc = ARES_TRUE;
745
+
746
+ done:
747
+ if (!rc) {
748
+ ares_evsys_win32_eventdata_destroy(ew, ed);
749
+ event->data = NULL;
750
+ }
751
+ return rc;
752
+ }
753
+
754
+ static void ares_evsys_win32_event_del(ares_event_t *event)
755
+ {
756
+ ares_evsys_win32_eventdata_t *ed = event->data;
757
+
758
+ /* Already cleaned up, likely a LOCAL_CLOSE */
759
+ if (ed == NULL) {
760
+ return;
761
+ }
762
+
763
+ CARES_DEBUG_LOG("-- DELETE requested for ed=%p (%s)\n", (void *)ed,
764
+ (ed->socket != ARES_SOCKET_BAD) ? "socket" : "data");
765
+
766
+ /*
767
+ * Cancel pending AFD Poll operation.
768
+ */
769
+ if (ed->socket != ARES_SOCKET_BAD) {
770
+ ares_evsys_win32_afd_cancel(ed);
771
+ ed->poll_status = POLL_STATUS_DESTROY;
772
+ ed->event = NULL;
773
+ } else {
774
+ ares_evsys_win32_eventdata_destroy(event->e->ev_sys_data, ed);
775
+ }
776
+
777
+ event->data = NULL;
778
+ }
779
+
780
+ static void ares_evsys_win32_event_mod(ares_event_t *event,
781
+ ares_event_flags_t new_flags)
782
+ {
783
+ ares_evsys_win32_eventdata_t *ed = event->data;
784
+
785
+ /* Not for us */
786
+ if (event->fd == ARES_SOCKET_BAD || ed == NULL) {
787
+ return;
788
+ }
789
+
790
+ CARES_DEBUG_LOG("** mod ed=%p new_flags=%X\n", (void *)ed,
791
+ (unsigned int)new_flags);
792
+
793
+ /* All we need to do is cancel the pending operation. When the event gets
794
+ * delivered for the cancellation, it will automatically re-enqueue a new
795
+ * event */
796
+ ares_evsys_win32_afd_cancel(ed);
797
+ }
798
+
799
+ static ares_bool_t ares_evsys_win32_process_other_event(
800
+ ares_evsys_win32_t *ew, ares_evsys_win32_eventdata_t *ed, size_t i)
801
+ {
802
+ ares_event_t *event;
803
+
804
+ /* NOTE: do NOT dereference 'ed' if during shutdown as this could be an
805
+ * invalid pointer if the signal handle was cleaned up, but there was still a
806
+ * pending event! */
807
+
808
+ if (ew->is_shutdown) {
809
+ CARES_DEBUG_LOG("\t\t** i=%lu, skip non-socket handle during shutdown\n",
810
+ (unsigned long)i);
811
+ return ARES_FALSE;
812
+ }
813
+
814
+ event = ed->event;
815
+ CARES_DEBUG_LOG("\t\t** i=%lu, ed=%p (data)\n", (unsigned long)i, (void *)ed);
816
+
817
+ event->cb(event->e, event->fd, event->data, ARES_EVENT_FLAG_OTHER);
818
+ return ARES_TRUE;
819
+ }
820
+
821
+ static ares_bool_t ares_evsys_win32_process_socket_event(
822
+ ares_evsys_win32_t *ew, ares_evsys_win32_eventdata_t *ed, size_t i)
823
+ {
824
+ ares_event_flags_t flags = 0;
825
+ ares_event_t *event = NULL;
826
+ ares_afd_handle_t *afd = NULL;
827
+
828
+ /* Shouldn't be possible */
829
+ if (ed == NULL) {
830
+ CARES_DEBUG_LOG("\t\t** i=%lu, Invalid handle.\n", (unsigned long)i);
831
+ return ARES_FALSE;
832
+ }
833
+
834
+ event = ed->event;
835
+
836
+ CARES_DEBUG_LOG("\t\t** i=%lu, ed=%p (socket)\n", (unsigned long)i,
837
+ (void *)ed);
838
+
839
+ /* Process events */
840
+ if (ed->poll_status == POLL_STATUS_PENDING &&
841
+ ed->iosb.Status == STATUS_SUCCESS &&
842
+ ed->afd_poll_info.NumberOfHandles > 0) {
843
+ if (ed->afd_poll_info.Handles[0].Events &
844
+ (AFD_POLL_RECEIVE | AFD_POLL_DISCONNECT | AFD_POLL_ACCEPT |
845
+ AFD_POLL_ABORT)) {
846
+ flags |= ARES_EVENT_FLAG_READ;
847
+ }
848
+ if (ed->afd_poll_info.Handles[0].Events &
849
+ (AFD_POLL_SEND | AFD_POLL_CONNECT_FAIL)) {
850
+ flags |= ARES_EVENT_FLAG_WRITE;
851
+ }
852
+ if (ed->afd_poll_info.Handles[0].Events & AFD_POLL_LOCAL_CLOSE) {
853
+ CARES_DEBUG_LOG("\t\t** ed=%p LOCAL CLOSE\n", (void *)ed);
854
+ ed->poll_status = POLL_STATUS_DESTROY;
855
+ }
856
+ }
857
+
858
+ CARES_DEBUG_LOG("\t\t** ed=%p, iosb status=%lX, poll_status=%d, flags=%X\n",
859
+ (void *)ed, (unsigned long)ed->iosb.Status,
860
+ (int)ed->poll_status, (unsigned int)flags);
861
+
862
+ /* Decrement poll count for AFD handle then resort, also disassociate
863
+ * with socket */
864
+ afd = ares_slist_node_val(ed->afd_handle_node);
865
+ afd->poll_cnt--;
866
+ ares_slist_node_reinsert(ed->afd_handle_node);
867
+ ed->afd_handle_node = NULL;
868
+
869
+ /* Pending destroy, go ahead and kill it */
870
+ if (ed->poll_status == POLL_STATUS_DESTROY) {
871
+ ares_evsys_win32_eventdata_destroy(ew, ed);
872
+ return ARES_FALSE;
873
+ }
874
+
875
+ ed->poll_status = POLL_STATUS_NONE;
876
+
877
+ /* Mask flags against current desired flags. We could have an event
878
+ * queued that is outdated. */
879
+ flags &= event->flags;
880
+
881
+ /* Don't actually do anything with the event that was delivered as we are
882
+ * in a shutdown/cleanup process. Mostly just handling the delayed
883
+ * destruction of sockets */
884
+ if (ew->is_shutdown) {
885
+ return ARES_FALSE;
886
+ }
887
+
888
+ /* Re-enqueue so we can get more events on the socket, we either
889
+ * received a real event, or a cancellation notice. Both cases we
890
+ * re-queue using the current configured event flags.
891
+ *
892
+ * If we can't re-enqueue, that likely means the socket has been
893
+ * closed, so we want to kill our reference to it
894
+ */
895
+ if (!ares_evsys_win32_afd_enqueue(event, event->flags)) {
896
+ ares_evsys_win32_eventdata_destroy(ew, ed);
897
+ return ARES_FALSE;
898
+ }
899
+
900
+ /* No events we recognize to deliver */
901
+ if (flags == 0) {
902
+ return ARES_FALSE;
903
+ }
904
+
905
+ event->cb(event->e, event->fd, event->data, flags);
906
+ return ARES_TRUE;
907
+ }
908
+
909
+ static size_t ares_evsys_win32_wait(ares_event_thread_t *e,
910
+ unsigned long timeout_ms)
911
+ {
912
+ ares_evsys_win32_t *ew = e->ev_sys_data;
913
+ OVERLAPPED_ENTRY entries[16];
914
+ ULONG maxentries = sizeof(entries) / sizeof(*entries);
915
+ ULONG nentries;
916
+ BOOL status;
917
+ size_t i;
918
+ size_t cnt = 0;
919
+ DWORD tout = (timeout_ms == 0) ? INFINITE : (DWORD)timeout_ms;
920
+
921
+ CARES_DEBUG_LOG("** Wait Enter\n");
922
+ /* Process in a loop for as long as it fills the entire entries buffer, and
923
+ * on subsequent attempts, ensure the timeout is 0 */
924
+ do {
925
+ nentries = maxentries;
926
+ status = GetQueuedCompletionStatusEx(ew->iocp_handle, entries, nentries,
927
+ &nentries, tout, FALSE);
928
+
929
+ /* Next loop around, we want to return instantly if there are no events to
930
+ * be processed */
931
+ tout = 0;
932
+
933
+ if (!status) {
934
+ break;
935
+ }
936
+
937
+ CARES_DEBUG_LOG("\t** GetQueuedCompletionStatusEx returned %lu entries\n",
938
+ (unsigned long)nentries);
939
+ for (i = 0; i < (size_t)nentries; i++) {
940
+ ares_evsys_win32_eventdata_t *ed = NULL;
941
+ ares_bool_t rc;
942
+
943
+ /* For things triggered via PostQueuedCompletionStatus() we have an
944
+ * lpCompletionKey we can just use. Otherwise we need to dereference the
945
+ * pointer returned in lpOverlapped to determine the referenced
946
+ * socket */
947
+ if (entries[i].lpCompletionKey) {
948
+ ed = (ares_evsys_win32_eventdata_t *)entries[i].lpCompletionKey;
949
+ rc = ares_evsys_win32_process_other_event(ew, ed, i);
950
+ } else {
951
+ ed = ares_htable_vpvp_get_direct(ew->sockets, entries[i].lpOverlapped);
952
+ rc = ares_evsys_win32_process_socket_event(ew, ed, i);
953
+ }
954
+
955
+ /* We processed actual events */
956
+ if (rc) {
957
+ cnt++;
958
+ }
959
+ }
960
+ } while (nentries == maxentries);
961
+
962
+ CARES_DEBUG_LOG("** Wait Exit\n");
963
+
964
+ return cnt;
965
+ }
966
+
967
+ const ares_event_sys_t ares_evsys_win32 = { "win32",
968
+ ares_evsys_win32_init,
969
+ ares_evsys_win32_destroy,
970
+ ares_evsys_win32_event_add,
971
+ ares_evsys_win32_event_del,
972
+ ares_evsys_win32_event_mod,
973
+ ares_evsys_win32_wait };
974
+ #endif
975
+
976
+ #if defined(__clang__) || defined(__GNUC__)
977
+ # pragma GCC diagnostic pop
978
+ #endif