grpc 1.6.7 → 1.7.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (277) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +579 -77
  3. data/include/grpc/byte_buffer.h +1 -63
  4. data/include/grpc/compression.h +27 -5
  5. data/include/grpc/fork.h +24 -0
  6. data/include/grpc/grpc.h +12 -6
  7. data/include/grpc/grpc_security.h +28 -7
  8. data/include/grpc/impl/codegen/atm.h +1 -0
  9. data/include/grpc/impl/codegen/byte_buffer.h +86 -0
  10. data/include/grpc/impl/codegen/compression_types.h +63 -5
  11. data/include/grpc/impl/codegen/fork.h +48 -0
  12. data/include/grpc/impl/codegen/grpc_types.h +26 -9
  13. data/include/grpc/impl/codegen/port_platform.h +11 -4
  14. data/include/grpc/impl/codegen/slice.h +6 -1
  15. data/include/grpc/impl/codegen/sync.h +3 -1
  16. data/include/grpc/impl/codegen/sync_custom.h +36 -0
  17. data/include/grpc/module.modulemap +75 -3
  18. data/include/grpc/slice.h +1 -5
  19. data/include/grpc/support/sync_custom.h +24 -0
  20. data/src/core/ext/census/base_resources.c +14 -14
  21. data/src/core/ext/census/context.c +7 -5
  22. data/src/core/ext/census/grpc_filter.c +12 -14
  23. data/src/core/ext/census/mlog.c +2 -1
  24. data/src/core/ext/census/resource.c +13 -9
  25. data/src/core/ext/filters/client_channel/channel_connectivity.c +15 -8
  26. data/src/core/ext/filters/client_channel/client_channel.c +418 -439
  27. data/src/core/ext/filters/client_channel/client_channel_factory.c +4 -5
  28. data/src/core/ext/filters/client_channel/client_channel_plugin.c +2 -2
  29. data/src/core/ext/filters/client_channel/http_connect_handshaker.c +7 -5
  30. data/src/core/ext/filters/client_channel/http_proxy.c +17 -21
  31. data/src/core/ext/filters/client_channel/lb_policy.c +1 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +7 -7
  33. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +371 -257
  34. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +7 -5
  35. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +25 -14
  36. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +16 -16
  37. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +33 -28
  38. data/src/core/ext/filters/client_channel/lb_policy_factory.c +10 -8
  39. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  40. data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +1 -1
  41. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +7 -6
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +62 -28
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +29 -23
  44. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.c +25 -14
  45. data/src/core/ext/filters/client_channel/retry_throttle.c +9 -6
  46. data/src/core/ext/filters/client_channel/subchannel.c +30 -30
  47. data/src/core/ext/filters/client_channel/subchannel.h +1 -4
  48. data/src/core/ext/filters/client_channel/subchannel_index.c +31 -15
  49. data/src/core/ext/filters/client_channel/subchannel_index.h +7 -0
  50. data/src/core/ext/filters/client_channel/uri_parser.c +4 -3
  51. data/src/core/ext/filters/deadline/deadline_filter.c +78 -39
  52. data/src/core/ext/filters/deadline/deadline_filter.h +7 -1
  53. data/src/core/ext/filters/http/client/http_client_filter.c +14 -14
  54. data/src/core/ext/filters/http/http_filters_plugin.c +1 -1
  55. data/src/core/ext/filters/http/message_compress/message_compress_filter.c +240 -175
  56. data/src/core/ext/filters/http/server/http_server_filter.c +48 -36
  57. data/src/core/ext/filters/load_reporting/{load_reporting_filter.c → server_load_reporting_filter.c} +11 -12
  58. data/src/core/ext/filters/load_reporting/{load_reporting_filter.h → server_load_reporting_filter.h} +6 -5
  59. data/src/core/ext/filters/load_reporting/{load_reporting.c → server_load_reporting_plugin.c} +19 -13
  60. data/src/core/ext/filters/load_reporting/{load_reporting.h → server_load_reporting_plugin.h} +4 -3
  61. data/src/core/ext/filters/max_age/max_age_filter.c +2 -3
  62. data/src/core/ext/filters/message_size/message_size_filter.c +4 -2
  63. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +0 -1
  64. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +5 -5
  65. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +1 -1
  67. data/src/core/ext/transport/chttp2/server/chttp2_server.c +20 -18
  68. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +1 -0
  69. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +493 -210
  70. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
  71. data/src/core/ext/transport/chttp2/transport/flow_control.c +9 -8
  72. data/src/core/ext/transport/chttp2/transport/frame_data.c +2 -2
  73. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +2 -2
  74. data/src/core/ext/transport/chttp2/transport/frame_ping.c +5 -4
  75. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  76. data/src/core/ext/transport/chttp2/transport/frame_settings.c +10 -9
  77. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +9 -5
  78. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +62 -41
  79. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +52 -8
  80. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  81. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +3 -2
  82. data/src/core/ext/transport/chttp2/transport/internal.h +60 -30
  83. data/src/core/ext/transport/chttp2/transport/parsing.c +16 -5
  84. data/src/core/ext/transport/chttp2/transport/stream_lists.c +36 -16
  85. data/src/core/ext/transport/chttp2/transport/stream_map.c +6 -4
  86. data/src/core/ext/transport/chttp2/transport/writing.c +133 -105
  87. data/src/core/ext/transport/inproc/inproc_transport.c +61 -65
  88. data/src/core/lib/channel/channel_args.c +112 -12
  89. data/src/core/lib/channel/channel_args.h +31 -0
  90. data/src/core/lib/channel/channel_stack.c +1 -15
  91. data/src/core/lib/channel/channel_stack.h +3 -10
  92. data/src/core/lib/channel/channel_stack_builder.c +41 -10
  93. data/src/core/lib/channel/channel_stack_builder.h +10 -0
  94. data/src/core/lib/channel/connected_channel.c +94 -23
  95. data/src/core/lib/channel/handshaker.c +8 -6
  96. data/src/core/lib/channel/handshaker_registry.c +1 -1
  97. data/src/core/lib/compression/algorithm_metadata.h +14 -0
  98. data/src/core/lib/compression/compression.c +101 -1
  99. data/src/core/lib/compression/stream_compression.c +32 -146
  100. data/src/core/lib/compression/stream_compression.h +28 -4
  101. data/src/core/lib/compression/stream_compression_gzip.c +228 -0
  102. data/src/core/lib/{iomgr/ev_epoll_thread_pool_linux.h → compression/stream_compression_gzip.h} +5 -7
  103. data/src/core/lib/compression/stream_compression_identity.c +94 -0
  104. data/src/core/lib/{iomgr/ev_epoll_limited_pollers_linux.h → compression/stream_compression_identity.h} +7 -8
  105. data/src/core/lib/debug/stats.c +174 -0
  106. data/src/core/lib/debug/stats.h +61 -0
  107. data/src/core/lib/debug/stats_data.c +687 -0
  108. data/src/core/lib/debug/stats_data.h +470 -0
  109. data/src/core/lib/debug/trace.c +3 -3
  110. data/src/core/lib/debug/trace.h +1 -1
  111. data/src/core/lib/http/format_request.c +1 -1
  112. data/src/core/lib/http/httpcli.c +8 -7
  113. data/src/core/lib/http/httpcli_security_connector.c +2 -1
  114. data/src/core/lib/http/parser.c +4 -3
  115. data/src/core/lib/iomgr/call_combiner.c +202 -0
  116. data/src/core/lib/iomgr/call_combiner.h +121 -0
  117. data/src/core/lib/iomgr/closure.c +18 -4
  118. data/src/core/lib/iomgr/combiner.c +11 -4
  119. data/src/core/lib/iomgr/error.c +26 -24
  120. data/src/core/lib/iomgr/ev_epoll1_linux.c +395 -212
  121. data/src/core/lib/iomgr/ev_epollex_linux.c +141 -128
  122. data/src/core/lib/iomgr/ev_epollsig_linux.c +44 -41
  123. data/src/core/lib/iomgr/ev_poll_posix.c +99 -75
  124. data/src/core/lib/iomgr/ev_posix.c +5 -9
  125. data/src/core/lib/iomgr/ev_posix.h +1 -1
  126. data/src/core/lib/iomgr/exec_ctx.h +6 -1
  127. data/src/core/lib/iomgr/executor.c +142 -36
  128. data/src/core/lib/iomgr/executor.h +6 -1
  129. data/src/core/lib/iomgr/fork_posix.c +88 -0
  130. data/src/core/lib/iomgr/fork_windows.c +39 -0
  131. data/src/core/lib/iomgr/iocp_windows.c +2 -0
  132. data/src/core/lib/iomgr/iomgr.c +2 -8
  133. data/src/core/lib/iomgr/is_epollexclusive_available.c +6 -6
  134. data/src/core/lib/iomgr/load_file.c +2 -1
  135. data/src/core/lib/iomgr/polling_entity.c +9 -9
  136. data/src/core/lib/iomgr/polling_entity.h +7 -1
  137. data/src/core/lib/iomgr/pollset.h +1 -1
  138. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  139. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  140. data/src/core/lib/iomgr/port.h +4 -0
  141. data/src/core/lib/iomgr/resolve_address_posix.c +8 -7
  142. data/src/core/lib/iomgr/resolve_address_windows.c +1 -1
  143. data/src/core/lib/iomgr/resource_quota.c +24 -19
  144. data/src/core/lib/iomgr/socket_factory_posix.c +4 -4
  145. data/src/core/lib/iomgr/socket_mutator.c +4 -4
  146. data/src/core/lib/iomgr/socket_utils_windows.c +0 -4
  147. data/src/core/lib/iomgr/tcp_client_posix.c +5 -4
  148. data/src/core/lib/iomgr/tcp_posix.c +181 -20
  149. data/src/core/lib/iomgr/tcp_server_posix.c +8 -7
  150. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +1 -1
  151. data/src/core/lib/iomgr/timer.h +4 -0
  152. data/src/core/lib/iomgr/timer_generic.c +138 -3
  153. data/src/core/lib/iomgr/timer_generic.h +3 -0
  154. data/src/core/lib/iomgr/timer_heap.c +4 -4
  155. data/src/core/lib/iomgr/timer_manager.c +2 -2
  156. data/src/core/lib/iomgr/timer_uv.c +2 -0
  157. data/src/core/lib/iomgr/udp_server.c +10 -8
  158. data/src/core/lib/iomgr/unix_sockets_posix.c +4 -2
  159. data/src/core/lib/iomgr/wakeup_fd_cv.c +9 -8
  160. data/src/core/lib/iomgr/wakeup_fd_cv.h +2 -2
  161. data/src/core/lib/json/json.c +1 -1
  162. data/src/core/lib/json/json_string.c +13 -13
  163. data/src/core/lib/profiling/timers.h +18 -8
  164. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -10
  165. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +2 -1
  166. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +11 -6
  167. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +4 -4
  168. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +132 -50
  169. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
  170. data/src/core/lib/security/transport/client_auth_filter.c +68 -135
  171. data/src/core/lib/security/transport/secure_endpoint.c +110 -90
  172. data/src/core/lib/security/transport/secure_endpoint.h +8 -3
  173. data/src/core/lib/security/transport/security_connector.c +10 -12
  174. data/src/core/lib/security/transport/security_handshaker.c +45 -24
  175. data/src/core/lib/security/transport/server_auth_filter.c +71 -20
  176. data/src/core/lib/slice/b64.c +2 -2
  177. data/src/core/lib/slice/slice.c +16 -14
  178. data/src/core/lib/slice/slice_buffer.c +5 -4
  179. data/src/core/lib/slice/slice_hash_table.c +3 -2
  180. data/src/core/lib/slice/slice_intern.c +8 -5
  181. data/src/core/lib/support/block_annotate.h +22 -0
  182. data/src/core/lib/support/fork.c +62 -0
  183. data/src/core/lib/support/fork.h +35 -0
  184. data/src/core/lib/support/log_linux.c +1 -1
  185. data/src/core/lib/support/string.c +15 -1
  186. data/src/core/lib/support/string.h +3 -0
  187. data/src/core/lib/support/thd_internal.h +6 -0
  188. data/src/core/lib/support/thd_posix.c +56 -0
  189. data/src/core/lib/support/thd_windows.c +2 -0
  190. data/src/core/lib/surface/alarm.c +22 -15
  191. data/src/core/lib/surface/byte_buffer.c +4 -2
  192. data/src/core/lib/surface/call.c +442 -141
  193. data/src/core/lib/surface/call.h +6 -6
  194. data/src/core/lib/surface/call_log_batch.c +1 -1
  195. data/src/core/lib/surface/call_test_only.h +12 -0
  196. data/src/core/lib/surface/channel.c +39 -4
  197. data/src/core/lib/surface/channel_init.c +6 -6
  198. data/src/core/lib/surface/channel_ping.c +2 -2
  199. data/src/core/lib/surface/completion_queue.c +56 -57
  200. data/src/core/lib/surface/init.c +17 -3
  201. data/src/core/lib/surface/init_secure.c +5 -1
  202. data/src/core/lib/surface/lame_client.cc +9 -10
  203. data/src/core/lib/surface/server.c +81 -72
  204. data/src/core/lib/surface/version.c +2 -2
  205. data/src/core/lib/transport/byte_stream.c +1 -0
  206. data/src/core/lib/transport/byte_stream.h +3 -1
  207. data/src/core/lib/transport/connectivity_state.c +2 -1
  208. data/src/core/lib/transport/metadata.c +7 -4
  209. data/src/core/lib/transport/metadata_batch.c +18 -16
  210. data/src/core/lib/transport/metadata_batch.h +1 -0
  211. data/src/core/lib/transport/service_config.c +5 -3
  212. data/src/core/lib/transport/static_metadata.c +395 -614
  213. data/src/core/lib/transport/static_metadata.h +165 -133
  214. data/src/core/lib/transport/status_conversion.c +1 -1
  215. data/src/core/lib/transport/transport.c +20 -20
  216. data/src/core/lib/transport/transport.h +8 -5
  217. data/src/core/lib/transport/transport_impl.h +0 -3
  218. data/src/core/lib/transport/transport_op_string.c +8 -1
  219. data/src/core/plugin_registry/grpc_plugin_registry.c +4 -4
  220. data/src/core/tsi/fake_transport_security.c +133 -2
  221. data/src/core/tsi/fake_transport_security.h +5 -0
  222. data/src/core/tsi/ssl_transport_security.c +105 -8
  223. data/src/core/tsi/ssl_transport_security.h +30 -7
  224. data/src/core/tsi/transport_security.h +8 -2
  225. data/src/core/tsi/transport_security_grpc.c +20 -13
  226. data/src/core/tsi/transport_security_grpc.h +13 -9
  227. data/src/ruby/ext/grpc/rb_call_credentials.c +6 -2
  228. data/src/ruby/ext/grpc/rb_grpc.c +1 -1
  229. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +30 -20
  230. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +50 -35
  231. data/src/ruby/lib/grpc.rb +1 -0
  232. data/src/ruby/lib/grpc/generic/active_call.rb +34 -9
  233. data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -10
  234. data/src/ruby/lib/grpc/generic/client_stub.rb +95 -38
  235. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  236. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  237. data/src/ruby/lib/grpc/generic/rpc_desc.rb +66 -20
  238. data/src/ruby/lib/grpc/generic/rpc_server.rb +15 -3
  239. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +1 -2
  240. data/src/ruby/lib/grpc/version.rb +1 -1
  241. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +1 -0
  242. data/src/ruby/spec/channel_connection_spec.rb +1 -34
  243. data/src/ruby/spec/client_server_spec.rb +188 -82
  244. data/src/ruby/spec/generic/active_call_spec.rb +65 -11
  245. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  246. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  247. data/src/ruby/spec/generic/rpc_desc_spec.rb +38 -0
  248. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -34
  249. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  250. data/src/ruby/spec/spec_helper.rb +4 -0
  251. data/src/ruby/spec/support/helpers.rb +73 -0
  252. data/src/ruby/spec/support/services.rb +147 -0
  253. data/third_party/cares/ares_build.h +21 -62
  254. data/third_party/cares/cares/ares.h +23 -1
  255. data/third_party/cares/cares/ares__close_sockets.c +2 -2
  256. data/third_party/cares/cares/ares_create_query.c +3 -3
  257. data/third_party/cares/cares/ares_expand_name.c +6 -2
  258. data/third_party/cares/cares/ares_expand_string.c +1 -1
  259. data/third_party/cares/cares/ares_getnameinfo.c +27 -7
  260. data/third_party/cares/cares/ares_init.c +407 -39
  261. data/third_party/cares/cares/ares_library_init.c +10 -0
  262. data/third_party/cares/cares/ares_library_init.h +2 -1
  263. data/third_party/cares/cares/ares_nowarn.c +6 -6
  264. data/third_party/cares/cares/ares_nowarn.h +2 -2
  265. data/third_party/cares/cares/ares_parse_naptr_reply.c +6 -1
  266. data/third_party/cares/cares/ares_private.h +11 -0
  267. data/third_party/cares/cares/ares_process.c +126 -37
  268. data/third_party/cares/cares/ares_version.h +2 -2
  269. data/third_party/cares/cares/ares_writev.c +2 -2
  270. data/third_party/cares/cares/config-win32.h +8 -34
  271. data/third_party/cares/cares/inet_net_pton.c +2 -2
  272. data/third_party/cares/cares/setup_once.h +5 -5
  273. data/third_party/cares/config_darwin/ares_config.h +98 -196
  274. data/third_party/cares/config_linux/ares_config.h +103 -203
  275. metadata +47 -20
  276. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +0 -1957
  277. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +0 -1182
@@ -27,6 +27,7 @@
27
27
  fpGetNetworkParams_t ares_fpGetNetworkParams = ZERO_NULL;
28
28
  fpSystemFunction036_t ares_fpSystemFunction036 = ZERO_NULL;
29
29
  fpGetAdaptersAddresses_t ares_fpGetAdaptersAddresses = ZERO_NULL;
30
+ fpGetBestRoute2_t ares_fpGetBestRoute2 = ZERO_NULL;
30
31
  #endif
31
32
 
32
33
  /* library-private global vars with source visibility restricted to this file */
@@ -71,6 +72,15 @@ static int ares_win32_init(void)
71
72
  support Windows 2000 anymore */
72
73
  }
73
74
 
75
+ ares_fpGetBestRoute2 = (fpGetBestRoute2_t)
76
+ GetProcAddress(hnd_iphlpapi, "GetBestRoute2");
77
+ if (!ares_fpGetBestRoute2)
78
+ {
79
+ /* This can happen on clients before Vista, I don't
80
+ think it should be an error, unless we don't want to
81
+ support Windows XP anymore */
82
+ }
83
+
74
84
  /*
75
85
  * When advapi32.dll is unavailable or advapi32.dll has no SystemFunction036,
76
86
  * also known as RtlGenRandom, which is the case for Windows versions prior
@@ -28,13 +28,14 @@
28
28
  typedef DWORD (WINAPI *fpGetNetworkParams_t) (FIXED_INFO*, DWORD*);
29
29
  typedef BOOLEAN (APIENTRY *fpSystemFunction036_t) (void*, ULONG);
30
30
  typedef ULONG (WINAPI *fpGetAdaptersAddresses_t) ( ULONG, ULONG, void*, IP_ADAPTER_ADDRESSES*, ULONG* );
31
-
31
+ typedef NETIO_STATUS (WINAPI *fpGetBestRoute2_t) ( NET_LUID *, NET_IFINDEX, const SOCKADDR_INET *, const SOCKADDR_INET *, ULONG, PMIB_IPFORWARD_ROW2, SOCKADDR_INET * );
32
32
  /* Forward-declaration of variables defined in ares_library_init.c */
33
33
  /* that are global and unique instances for whole c-ares library. */
34
34
 
35
35
  extern fpGetNetworkParams_t ares_fpGetNetworkParams;
36
36
  extern fpSystemFunction036_t ares_fpSystemFunction036;
37
37
  extern fpGetAdaptersAddresses_t ares_fpGetAdaptersAddresses;
38
+ extern fpGetBestRoute2_t ares_fpGetBestRoute2;
38
39
 
39
40
  #endif /* USE_WINSOCK */
40
41
 
@@ -151,10 +151,10 @@ int aresx_sltosi(long slnum)
151
151
  }
152
152
 
153
153
  /*
154
- ** signed ssize_t to signed int
154
+ ** signed ares_ssize_t to signed int
155
155
  */
156
156
 
157
- int aresx_sztosi(ssize_t sznum)
157
+ int aresx_sztosi(ares_ssize_t sznum)
158
158
  {
159
159
  #ifdef __INTEL_COMPILER
160
160
  # pragma warning(push)
@@ -162,7 +162,7 @@ int aresx_sztosi(ssize_t sznum)
162
162
  #endif
163
163
 
164
164
  DEBUGASSERT(sznum >= 0);
165
- return (int)(sznum & (ssize_t) CARES_MASK_SINT);
165
+ return (int)(sznum & (ares_ssize_t) CARES_MASK_SINT);
166
166
 
167
167
  #ifdef __INTEL_COMPILER
168
168
  # pragma warning(pop)
@@ -170,10 +170,10 @@ int aresx_sztosi(ssize_t sznum)
170
170
  }
171
171
 
172
172
  /*
173
- ** signed ssize_t to unsigned int
173
+ ** signed ares_ssize_t to unsigned int
174
174
  */
175
175
 
176
- unsigned int aresx_sztoui(ssize_t sznum)
176
+ unsigned int aresx_sztoui(ares_ssize_t sznum)
177
177
  {
178
178
  #ifdef __INTEL_COMPILER
179
179
  # pragma warning(push)
@@ -181,7 +181,7 @@ unsigned int aresx_sztoui(ssize_t sznum)
181
181
  #endif
182
182
 
183
183
  DEBUGASSERT(sznum >= 0);
184
- return (unsigned int)(sznum & (ssize_t) CARES_MASK_UINT);
184
+ return (unsigned int)(sznum & (ares_ssize_t) CARES_MASK_UINT);
185
185
 
186
186
  #ifdef __INTEL_COMPILER
187
187
  # pragma warning(pop)
@@ -25,9 +25,9 @@ short aresx_sitoss(int sinum);
25
25
 
26
26
  int aresx_sltosi(long slnum);
27
27
 
28
- int aresx_sztosi(ssize_t sznum);
28
+ int aresx_sztosi(ares_ssize_t sznum);
29
29
 
30
- unsigned int aresx_sztoui(ssize_t sznum);
30
+ unsigned int aresx_sztoui(ares_ssize_t sznum);
31
31
 
32
32
  unsigned short aresx_sitous(int sinum);
33
33
 
@@ -110,6 +110,12 @@ ares_parse_naptr_reply (const unsigned char *abuf, int alen,
110
110
  status = ARES_EBADRESP;
111
111
  break;
112
112
  }
113
+ /* RR must contain at least 7 bytes = 2 x int16 + 3 x name */
114
+ if (rr_len < 7)
115
+ {
116
+ status = ARES_EBADRESP;
117
+ break;
118
+ }
113
119
 
114
120
  /* Check if we are really looking at a NAPTR record */
115
121
  if (rr_class == C_IN && rr_type == T_NAPTR)
@@ -185,4 +191,3 @@ ares_parse_naptr_reply (const unsigned char *abuf, int alen,
185
191
 
186
192
  return ARES_SUCCESS;
187
193
  }
188
-
@@ -54,10 +54,16 @@
54
54
 
55
55
  #define WIN_NS_9X "System\\CurrentControlSet\\Services\\VxD\\MSTCP"
56
56
  #define WIN_NS_NT_KEY "System\\CurrentControlSet\\Services\\Tcpip\\Parameters"
57
+ #define WIN_DNSCLIENT "Software\\Policies\\Microsoft\\System\\DNSClient"
57
58
  #define NAMESERVER "NameServer"
58
59
  #define DHCPNAMESERVER "DhcpNameServer"
59
60
  #define DATABASEPATH "DatabasePath"
60
61
  #define WIN_PATH_HOSTS "\\hosts"
62
+ #define SEARCHLIST_KEY "SearchList"
63
+ #define PRIMARYDNSSUFFIX_KEY "PrimaryDNSSuffix"
64
+ #define INTERFACES_KEY "Interfaces"
65
+ #define DOMAIN_KEY "Domain"
66
+ #define DHCPDOMAIN_KEY "DhcpDomain"
61
67
 
62
68
  #elif defined(WATT32)
63
69
 
@@ -314,6 +320,9 @@ struct ares_channeldata {
314
320
 
315
321
  ares_sock_config_callback sock_config_cb;
316
322
  void *sock_config_cb_data;
323
+
324
+ const struct ares_socket_functions * sock_funcs;
325
+ void *sock_func_cb_data;
317
326
  };
318
327
 
319
328
  /* Memory management functions */
@@ -342,6 +351,8 @@ void ares__destroy_servers_state(ares_channel channel);
342
351
  long ares__tvdiff(struct timeval t1, struct timeval t2);
343
352
  #endif
344
353
 
354
+ void ares__socket_close(ares_channel, ares_socket_t);
355
+
345
356
  #define ARES_SWAP_BYTE(a,b) \
346
357
  { unsigned char swapByte = *(a); *(a) = *(b); *(b) = swapByte; }
347
358
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  /* Copyright 1998 by the Massachusetts Institute of Technology.
3
- * Copyright (C) 2004-2016 by Daniel Stenberg
3
+ * Copyright (C) 2004-2017 by Daniel Stenberg
4
4
  *
5
5
  * Permission to use, copy, modify, and distribute this
6
6
  * software and its documentation for any purpose and without
@@ -29,6 +29,9 @@
29
29
  #ifdef HAVE_NETDB_H
30
30
  # include <netdb.h>
31
31
  #endif
32
+ #ifdef HAVE_ARPA_INET_H
33
+ # include <arpa/inet.h>
34
+ #endif
32
35
  #ifdef HAVE_ARPA_NAMESER_H
33
36
  # include <arpa/nameser.h>
34
37
  #else
@@ -65,7 +68,7 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds,
65
68
  static void read_udp_packets(ares_channel channel, fd_set *read_fds,
66
69
  ares_socket_t read_fd, struct timeval *now);
67
70
  static void advance_tcp_send_queue(ares_channel channel, int whichserver,
68
- ssize_t num_bytes);
71
+ ares_ssize_t num_bytes);
69
72
  static void process_timeouts(ares_channel channel, struct timeval *now);
70
73
  static void process_broken_connections(ares_channel channel,
71
74
  struct timeval *now);
@@ -175,6 +178,26 @@ static int try_again(int errnum)
175
178
  return 0;
176
179
  }
177
180
 
181
+ static ares_ssize_t socket_writev(ares_channel channel, ares_socket_t s, const struct iovec * vec, int len)
182
+ {
183
+ if (channel->sock_funcs)
184
+ return channel->sock_funcs->asendv(s, vec, len, channel->sock_func_cb_data);
185
+
186
+ return writev(s, vec, len);
187
+ }
188
+
189
+ static ares_ssize_t socket_write(ares_channel channel, ares_socket_t s, const void * data, size_t len)
190
+ {
191
+ if (channel->sock_funcs)
192
+ {
193
+ struct iovec vec;
194
+ vec.iov_base = (void*)data;
195
+ vec.iov_len = len;
196
+ return channel->sock_funcs->asendv(s, &vec, 1, channel->sock_func_cb_data);
197
+ }
198
+ return swrite(s, data, len);
199
+ }
200
+
178
201
  /* If any TCP sockets select true for writing, write out queued data
179
202
  * we have for them.
180
203
  */
@@ -187,8 +210,8 @@ static void write_tcp_data(ares_channel channel,
187
210
  struct send_request *sendreq;
188
211
  struct iovec *vec;
189
212
  int i;
190
- ssize_t scount;
191
- ssize_t wcount;
213
+ ares_ssize_t scount;
214
+ ares_ssize_t wcount;
192
215
  size_t n;
193
216
 
194
217
  if(!write_fds && (write_fd == ARES_SOCKET_BAD))
@@ -238,7 +261,7 @@ static void write_tcp_data(ares_channel channel,
238
261
  vec[n].iov_len = sendreq->len;
239
262
  n++;
240
263
  }
241
- wcount = (ssize_t)writev(server->tcp_socket, vec, (int)n);
264
+ wcount = socket_writev(channel, server->tcp_socket, vec, (int)n);
242
265
  ares_free(vec);
243
266
  if (wcount < 0)
244
267
  {
@@ -255,7 +278,7 @@ static void write_tcp_data(ares_channel channel,
255
278
  /* Can't allocate iovecs; just send the first request. */
256
279
  sendreq = server->qhead;
257
280
 
258
- scount = swrite(server->tcp_socket, sendreq->data, sendreq->len);
281
+ scount = socket_write(channel, server->tcp_socket, sendreq->data, sendreq->len);
259
282
  if (scount < 0)
260
283
  {
261
284
  if (!try_again(SOCKERRNO))
@@ -271,7 +294,7 @@ static void write_tcp_data(ares_channel channel,
271
294
 
272
295
  /* Consume the given number of bytes from the head of the TCP send queue. */
273
296
  static void advance_tcp_send_queue(ares_channel channel, int whichserver,
274
- ssize_t num_bytes)
297
+ ares_ssize_t num_bytes)
275
298
  {
276
299
  struct send_request *sendreq;
277
300
  struct server_state *server = &channel->servers[whichserver];
@@ -299,6 +322,38 @@ static void advance_tcp_send_queue(ares_channel channel, int whichserver,
299
322
  }
300
323
  }
301
324
 
325
+ static ares_ssize_t socket_recvfrom(ares_channel channel,
326
+ ares_socket_t s,
327
+ void * data,
328
+ size_t data_len,
329
+ int flags,
330
+ struct sockaddr *from,
331
+ ares_socklen_t *from_len)
332
+ {
333
+ if (channel->sock_funcs)
334
+ return channel->sock_funcs->arecvfrom(s, data, data_len,
335
+ flags, from, from_len,
336
+ channel->sock_func_cb_data);
337
+
338
+ #ifdef HAVE_RECVFROM
339
+ return recvfrom(s, data, data_len, flags, from, from_len);
340
+ #else
341
+ return sread(s, data, data_len);
342
+ #endif
343
+ }
344
+
345
+ static ares_ssize_t socket_recv(ares_channel channel,
346
+ ares_socket_t s,
347
+ void * data,
348
+ size_t data_len)
349
+ {
350
+ if (channel->sock_funcs)
351
+ return channel->sock_funcs->arecvfrom(s, data, data_len, 0, 0, 0,
352
+ channel->sock_func_cb_data);
353
+
354
+ return sread(s, data, data_len);
355
+ }
356
+
302
357
  /* If any TCP socket selects true for reading, read some data,
303
358
  * allocate a buffer if we finish reading the length word, and process
304
359
  * a packet if we finish reading one.
@@ -308,7 +363,7 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds,
308
363
  {
309
364
  struct server_state *server;
310
365
  int i;
311
- ssize_t count;
366
+ ares_ssize_t count;
312
367
 
313
368
  if(!read_fds && (read_fd == ARES_SOCKET_BAD))
314
369
  /* no possible action */
@@ -343,9 +398,9 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds,
343
398
  /* We haven't yet read a length word, so read that (or
344
399
  * what's left to read of it).
345
400
  */
346
- count = sread(server->tcp_socket,
347
- server->tcp_lenbuf + server->tcp_lenbuf_pos,
348
- 2 - server->tcp_lenbuf_pos);
401
+ count = socket_recv(channel, server->tcp_socket,
402
+ server->tcp_lenbuf + server->tcp_lenbuf_pos,
403
+ 2 - server->tcp_lenbuf_pos);
349
404
  if (count <= 0)
350
405
  {
351
406
  if (!(count == -1 && try_again(SOCKERRNO)))
@@ -373,9 +428,9 @@ static void read_tcp_data(ares_channel channel, fd_set *read_fds,
373
428
  else
374
429
  {
375
430
  /* Read data into the allocated buffer. */
376
- count = sread(server->tcp_socket,
377
- server->tcp_buffer + server->tcp_buffer_pos,
378
- server->tcp_length - server->tcp_buffer_pos);
431
+ count = socket_recv(channel, server->tcp_socket,
432
+ server->tcp_buffer + server->tcp_buffer_pos,
433
+ server->tcp_length - server->tcp_buffer_pos);
379
434
  if (count <= 0)
380
435
  {
381
436
  if (!(count == -1 && try_again(SOCKERRNO)))
@@ -406,7 +461,7 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
406
461
  {
407
462
  struct server_state *server;
408
463
  int i;
409
- ssize_t count;
464
+ ares_ssize_t count;
410
465
  unsigned char buf[MAXENDSSZ + 1];
411
466
  #ifdef HAVE_RECVFROM
412
467
  ares_socklen_t fromlen;
@@ -453,16 +508,12 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
453
508
  count = 0;
454
509
 
455
510
  else {
456
- #ifdef HAVE_RECVFROM
457
511
  if (server->addr.family == AF_INET)
458
512
  fromlen = sizeof(from.sa4);
459
513
  else
460
514
  fromlen = sizeof(from.sa6);
461
- count = (ssize_t)recvfrom(server->udp_socket, (void *)buf,
462
- sizeof(buf), 0, &from.sa, &fromlen);
463
- #else
464
- count = sread(server->udp_socket, buf, sizeof(buf));
465
- #endif
515
+ count = socket_recvfrom(channel, server->udp_socket, (void *)buf,
516
+ sizeof(buf), 0, &from.sa, &fromlen);
466
517
  }
467
518
 
468
519
  if (count == -1 && try_again(SOCKERRNO))
@@ -812,7 +863,7 @@ void ares__send_query(ares_channel channel, struct query *query,
812
863
  return;
813
864
  }
814
865
  }
815
- if (swrite(server->udp_socket, query->qbuf, query->qlen) == -1)
866
+ if (socket_write(channel, server->udp_socket, query->qbuf, query->qlen) == -1)
816
867
  {
817
868
  /* FIXME: Handle EAGAIN here since it likely can happen. */
818
869
  skip_server(channel, query, query->server);
@@ -904,6 +955,10 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
904
955
  struct sockaddr_in6 sa6;
905
956
  } local;
906
957
 
958
+ /* do not set options for user-managed sockets */
959
+ if (channel->sock_funcs)
960
+ return 0;
961
+
907
962
  (void)setsocknonblock(s, TRUE);
908
963
 
909
964
  #if defined(FD_CLOEXEC) && !defined(MSDOS)
@@ -959,6 +1014,30 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
959
1014
  return 0;
960
1015
  }
961
1016
 
1017
+ static ares_socket_t open_socket(ares_channel channel, int af, int type, int protocol)
1018
+ {
1019
+ if (channel->sock_funcs != 0)
1020
+ return channel->sock_funcs->asocket(af,
1021
+ type,
1022
+ protocol,
1023
+ channel->sock_func_cb_data);
1024
+
1025
+ return socket(af, type, protocol);
1026
+ }
1027
+
1028
+ static int connect_socket(ares_channel channel, ares_socket_t sockfd,
1029
+ const struct sockaddr * addr,
1030
+ ares_socklen_t addrlen)
1031
+ {
1032
+ if (channel->sock_funcs != 0)
1033
+ return channel->sock_funcs->aconnect(sockfd,
1034
+ addr,
1035
+ addrlen,
1036
+ channel->sock_func_cb_data);
1037
+
1038
+ return connect(sockfd, addr, addrlen);
1039
+ }
1040
+
962
1041
  static int open_tcp_socket(ares_channel channel, struct server_state *server)
963
1042
  {
964
1043
  ares_socket_t s;
@@ -1003,14 +1082,14 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
1003
1082
  }
1004
1083
 
1005
1084
  /* Acquire a socket. */
1006
- s = socket(server->addr.family, SOCK_STREAM, 0);
1085
+ s = open_socket(channel, server->addr.family, SOCK_STREAM, 0);
1007
1086
  if (s == ARES_SOCKET_BAD)
1008
1087
  return -1;
1009
1088
 
1010
1089
  /* Configure it. */
1011
1090
  if (configure_socket(s, server->addr.family, channel) < 0)
1012
1091
  {
1013
- sclose(s);
1092
+ ares__socket_close(channel, s);
1014
1093
  return -1;
1015
1094
  }
1016
1095
 
@@ -1022,10 +1101,12 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
1022
1101
  * so batching isn't very interesting.
1023
1102
  */
1024
1103
  opt = 1;
1025
- if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
1026
- (void *)&opt, sizeof(opt)) == -1)
1104
+ if (channel->sock_funcs == 0
1105
+ &&
1106
+ setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
1107
+ (void *)&opt, sizeof(opt)) == -1)
1027
1108
  {
1028
- sclose(s);
1109
+ ares__socket_close(channel, s);
1029
1110
  return -1;
1030
1111
  }
1031
1112
  #endif
@@ -1036,19 +1117,19 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
1036
1117
  channel->sock_config_cb_data);
1037
1118
  if (err < 0)
1038
1119
  {
1039
- sclose(s);
1120
+ ares__socket_close(channel, s);
1040
1121
  return err;
1041
1122
  }
1042
1123
  }
1043
1124
 
1044
1125
  /* Connect to the server. */
1045
- if (connect(s, sa, salen) == -1)
1126
+ if (connect_socket(channel, s, sa, salen) == -1)
1046
1127
  {
1047
1128
  int err = SOCKERRNO;
1048
1129
 
1049
1130
  if (err != EINPROGRESS && err != EWOULDBLOCK)
1050
1131
  {
1051
- sclose(s);
1132
+ ares__socket_close(channel, s);
1052
1133
  return -1;
1053
1134
  }
1054
1135
  }
@@ -1059,7 +1140,7 @@ static int open_tcp_socket(ares_channel channel, struct server_state *server)
1059
1140
  channel->sock_create_cb_data);
1060
1141
  if (err < 0)
1061
1142
  {
1062
- sclose(s);
1143
+ ares__socket_close(channel, s);
1063
1144
  return err;
1064
1145
  }
1065
1146
  }
@@ -1114,14 +1195,14 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
1114
1195
  }
1115
1196
 
1116
1197
  /* Acquire a socket. */
1117
- s = socket(server->addr.family, SOCK_DGRAM, 0);
1198
+ s = open_socket(channel, server->addr.family, SOCK_DGRAM, 0);
1118
1199
  if (s == ARES_SOCKET_BAD)
1119
1200
  return -1;
1120
1201
 
1121
1202
  /* Set the socket non-blocking. */
1122
1203
  if (configure_socket(s, server->addr.family, channel) < 0)
1123
1204
  {
1124
- sclose(s);
1205
+ ares__socket_close(channel, s);
1125
1206
  return -1;
1126
1207
  }
1127
1208
 
@@ -1131,19 +1212,19 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
1131
1212
  channel->sock_config_cb_data);
1132
1213
  if (err < 0)
1133
1214
  {
1134
- sclose(s);
1215
+ ares__socket_close(channel, s);
1135
1216
  return err;
1136
1217
  }
1137
1218
  }
1138
1219
 
1139
1220
  /* Connect to the server. */
1140
- if (connect(s, sa, salen) == -1)
1221
+ if (connect_socket(channel, s, sa, salen) == -1)
1141
1222
  {
1142
1223
  int err = SOCKERRNO;
1143
1224
 
1144
1225
  if (err != EINPROGRESS && err != EWOULDBLOCK)
1145
1226
  {
1146
- sclose(s);
1227
+ ares__socket_close(channel, s);
1147
1228
  return -1;
1148
1229
  }
1149
1230
  }
@@ -1154,7 +1235,7 @@ static int open_udp_socket(ares_channel channel, struct server_state *server)
1154
1235
  channel->sock_create_cb_data);
1155
1236
  if (err < 0)
1156
1237
  {
1157
- sclose(s);
1238
+ ares__socket_close(channel, s);
1158
1239
  return err;
1159
1240
  }
1160
1241
  }
@@ -1357,3 +1438,11 @@ void ares__free_query(struct query *query)
1357
1438
  ares_free(query->server_info);
1358
1439
  ares_free(query);
1359
1440
  }
1441
+
1442
+ void ares__socket_close(ares_channel channel, ares_socket_t s)
1443
+ {
1444
+ if (channel->sock_funcs)
1445
+ channel->sock_funcs->aclose(s, channel->sock_func_cb_data);
1446
+ else
1447
+ sclose(s);
1448
+ }