grpc 1.2.5 → 1.3.4

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 (327) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1434 -399
  3. data/etc/roots.pem +34 -150
  4. data/include/grpc/grpc.h +71 -0
  5. data/include/grpc/impl/codegen/atm.h +5 -0
  6. data/include/grpc/impl/codegen/atm_gcc_atomic.h +6 -0
  7. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  8. data/include/grpc/impl/codegen/atm_windows.h +11 -0
  9. data/include/grpc/impl/codegen/grpc_types.h +54 -13
  10. data/include/grpc/impl/codegen/port_platform.h +15 -1
  11. data/include/grpc/support/alloc.h +2 -1
  12. data/include/grpc/support/sync.h +4 -0
  13. data/include/grpc/support/tls.h +1 -1
  14. data/src/core/ext/census/gen/trace_context.pb.h +1 -1
  15. data/src/core/ext/census/grpc_filter.c +14 -10
  16. data/src/core/ext/census/grpc_plugin.c +3 -1
  17. data/src/core/ext/census/trace_label.h +1 -1
  18. data/src/core/ext/census/trace_propagation.h +1 -1
  19. data/src/core/ext/census/trace_status.h +1 -1
  20. data/src/core/ext/census/trace_string.h +1 -1
  21. data/src/core/ext/census/tracing.h +1 -1
  22. data/src/core/ext/{client_channel → filters/client_channel}/channel_connectivity.c +56 -27
  23. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.c +407 -202
  24. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.h +10 -6
  25. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.c +1 -1
  26. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.h +4 -4
  27. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_plugin.c +12 -7
  28. data/src/core/ext/{client_channel → filters/client_channel}/connector.c +1 -1
  29. data/src/core/ext/{client_channel → filters/client_channel}/connector.h +3 -5
  30. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.c +6 -6
  31. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.h +3 -3
  32. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.c +4 -4
  33. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.h +3 -3
  34. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.c +1 -1
  35. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.h +4 -4
  36. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.c +22 -20
  37. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.h +4 -4
  38. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel.h +5 -4
  39. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel_secure.c +2 -2
  40. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.c +1 -1
  41. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.h +6 -5
  42. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +1 -1
  43. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -0
  44. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/pick_first/pick_first.c +20 -15
  45. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/round_robin/round_robin.c +21 -16
  46. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.c +1 -1
  47. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.h +5 -5
  48. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.c +1 -1
  49. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.h +4 -4
  50. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.c +1 -1
  51. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.h +4 -4
  52. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.c +1 -1
  53. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.h +3 -3
  54. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.c +10 -4
  55. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.h +4 -4
  56. data/src/core/ext/{client_channel → filters/client_channel}/resolver.c +1 -1
  57. data/src/core/ext/{client_channel → filters/client_channel}/resolver.h +4 -4
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
  63. data/src/core/ext/{resolver → filters/client_channel/resolver}/dns/native/dns_resolver.c +21 -5
  64. data/src/core/ext/{resolver → filters/client_channel/resolver}/sockaddr/sockaddr_resolver.c +3 -3
  65. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.c +1 -1
  66. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.h +6 -6
  67. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.c +1 -2
  68. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.h +4 -4
  69. data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
  70. data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
  71. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.c +49 -43
  72. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.h +21 -7
  73. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.c +1 -1
  74. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.h +5 -5
  75. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.c +1 -1
  76. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.h +3 -3
  77. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.c +4 -2
  78. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.h +3 -3
  79. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.c +17 -14
  80. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.h +4 -4
  81. data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
  82. data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
  83. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +6 -41
  84. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  85. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +2 -2
  86. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +3 -3
  87. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  88. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +2 -5
  89. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +2 -2
  90. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +449 -204
  91. data/src/core/ext/transport/chttp2/transport/frame_data.c +10 -7
  92. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +3 -2
  93. data/src/core/ext/transport/chttp2/transport/frame_ping.c +37 -7
  94. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -0
  95. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +4 -3
  96. data/src/core/ext/transport/chttp2/transport/frame_settings.c +18 -38
  97. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -29
  98. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +2 -2
  99. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +64 -37
  100. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +11 -4
  101. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +60 -39
  102. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  103. data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
  104. data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
  105. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +22 -43
  106. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +8 -10
  107. data/src/core/ext/transport/chttp2/transport/internal.h +24 -2
  108. data/src/core/ext/transport/chttp2/transport/parsing.c +33 -15
  109. data/src/core/ext/transport/chttp2/transport/writing.c +56 -10
  110. data/src/core/lib/channel/channel_args.c +7 -0
  111. data/src/core/lib/channel/channel_args.h +2 -0
  112. data/src/core/lib/channel/channel_stack.c +20 -27
  113. data/src/core/lib/channel/channel_stack.h +18 -16
  114. data/src/core/lib/channel/compress_filter.c +20 -18
  115. data/src/core/lib/channel/connected_channel.c +9 -8
  116. data/src/core/lib/channel/deadline_filter.c +28 -24
  117. data/src/core/lib/channel/deadline_filter.h +3 -3
  118. data/src/core/lib/channel/handshaker.c +3 -2
  119. data/src/core/lib/channel/http_client_filter.c +119 -61
  120. data/src/core/lib/channel/http_server_filter.c +124 -69
  121. data/src/core/lib/channel/message_size_filter.c +23 -19
  122. data/src/core/lib/http/httpcli.c +8 -6
  123. data/src/core/lib/http/httpcli_security_connector.c +5 -5
  124. data/src/core/lib/http/parser.c +57 -31
  125. data/src/core/lib/iomgr/closure.c +15 -0
  126. data/src/core/lib/iomgr/closure.h +4 -0
  127. data/src/core/lib/iomgr/combiner.c +8 -0
  128. data/src/core/lib/iomgr/endpoint_pair.h +2 -3
  129. data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -7
  130. data/src/core/lib/iomgr/endpoint_pair_uv.c +2 -3
  131. data/src/core/lib/iomgr/endpoint_pair_windows.c +9 -6
  132. data/src/core/lib/iomgr/error.c +360 -177
  133. data/src/core/lib/iomgr/error.h +31 -33
  134. data/src/core/lib/iomgr/error_internal.h +30 -9
  135. data/src/core/lib/iomgr/ev_epoll_linux.c +25 -239
  136. data/src/core/lib/iomgr/ev_poll_posix.c +11 -7
  137. data/src/core/lib/iomgr/ev_posix.c +6 -0
  138. data/src/core/lib/iomgr/ev_posix.h +3 -0
  139. data/src/core/lib/iomgr/exec_ctx.c +6 -0
  140. data/src/core/lib/iomgr/executor.c +8 -2
  141. data/src/core/lib/iomgr/load_file.c +6 -3
  142. data/src/core/lib/iomgr/lockfree_event.c +238 -0
  143. data/src/core/{ext/client_channel/initial_connect_string.h → lib/iomgr/lockfree_event.h} +17 -13
  144. data/src/core/lib/iomgr/pollset.h +4 -0
  145. data/src/core/lib/iomgr/pollset_windows.c +2 -2
  146. data/src/core/lib/iomgr/port.h +9 -0
  147. data/src/core/lib/iomgr/resolve_address_posix.c +15 -9
  148. data/src/core/lib/iomgr/resolve_address_uv.c +8 -6
  149. data/src/core/lib/iomgr/resolve_address_windows.c +2 -2
  150. data/src/core/lib/iomgr/resource_quota.c +19 -4
  151. data/src/core/lib/iomgr/resource_quota.h +2 -0
  152. data/src/core/lib/iomgr/sockaddr_utils.c +3 -1
  153. data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
  154. data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
  155. data/src/core/lib/iomgr/socket_utils_common_posix.c +25 -9
  156. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  157. data/src/core/lib/iomgr/tcp_client.h +0 -4
  158. data/src/core/lib/iomgr/tcp_client_posix.c +15 -31
  159. data/src/core/lib/iomgr/tcp_client_uv.c +10 -6
  160. data/src/core/lib/iomgr/tcp_client_windows.c +9 -19
  161. data/src/core/lib/iomgr/tcp_posix.c +111 -22
  162. data/src/core/lib/iomgr/tcp_posix.h +3 -4
  163. data/src/core/lib/iomgr/tcp_server_posix.c +39 -417
  164. data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
  165. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
  166. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
  167. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
  168. data/src/core/lib/iomgr/tcp_server_uv.c +43 -16
  169. data/src/core/lib/iomgr/tcp_server_windows.c +10 -22
  170. data/src/core/lib/iomgr/tcp_uv.c +16 -13
  171. data/src/core/lib/iomgr/tcp_windows.c +24 -12
  172. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  173. data/src/core/lib/iomgr/timer.h +3 -0
  174. data/src/core/lib/iomgr/timer_generic.c +257 -72
  175. data/src/core/lib/iomgr/timer_generic.h +1 -1
  176. data/src/core/lib/iomgr/timer_heap.c +8 -8
  177. data/src/core/lib/iomgr/udp_server.c +54 -24
  178. data/src/core/lib/iomgr/udp_server.h +7 -7
  179. data/src/core/lib/iomgr/unix_sockets_posix.c +1 -1
  180. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +2 -1
  181. data/src/core/lib/iomgr/wakeup_fd_posix.h +1 -1
  182. data/src/core/lib/profiling/basic_timers.c +1 -1
  183. data/src/core/lib/security/credentials/credentials.h +1 -1
  184. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +10 -9
  185. data/src/core/lib/security/credentials/jwt/json_token.c +1 -1
  186. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +2 -2
  187. data/src/core/lib/security/transport/client_auth_filter.c +33 -26
  188. data/src/core/lib/security/transport/secure_endpoint.c +8 -5
  189. data/src/core/lib/security/transport/security_connector.c +37 -37
  190. data/src/core/lib/security/transport/security_connector.h +1 -1
  191. data/src/core/lib/security/transport/security_handshaker.c +15 -12
  192. data/src/core/lib/security/transport/server_auth_filter.c +20 -18
  193. data/src/core/lib/security/transport/tsi_error.c +5 -3
  194. data/src/core/lib/security/transport/tsi_error.h +1 -1
  195. data/src/core/lib/{security/util → slice}/b64.c +21 -6
  196. data/src/core/lib/{security/util → slice}/b64.h +16 -4
  197. data/src/core/lib/slice/slice.c +4 -2
  198. data/src/core/lib/slice/slice_buffer.c +16 -14
  199. data/src/core/lib/support/arena.c +98 -0
  200. data/src/core/{ext/client_channel/initial_connect_string.c → lib/support/arena.h} +17 -15
  201. data/src/core/{ext/client_channel/default_initial_connect_string.c → lib/support/atm.c} +14 -5
  202. data/src/core/lib/support/cpu_linux.c +5 -0
  203. data/src/core/lib/support/sync.c +4 -0
  204. data/src/core/lib/support/time.c +4 -10
  205. data/src/core/lib/support/wrap_memcpy.c +3 -1
  206. data/src/core/lib/surface/call.c +252 -221
  207. data/src/core/lib/surface/channel.c +72 -21
  208. data/src/core/lib/surface/channel.h +8 -0
  209. data/src/core/lib/surface/completion_queue.c +2 -3
  210. data/src/core/lib/surface/completion_queue_factory.c +77 -0
  211. data/src/core/lib/surface/completion_queue_factory.h +51 -0
  212. data/src/core/lib/surface/init_secure.c +3 -1
  213. data/src/core/lib/surface/lame_client.c +18 -14
  214. data/src/core/lib/surface/server.c +43 -41
  215. data/src/core/lib/surface/validate_metadata.c +8 -4
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.h +1 -1
  218. data/src/core/lib/transport/connectivity_state.c +2 -1
  219. data/src/core/lib/transport/error_utils.c +17 -17
  220. data/src/core/lib/transport/error_utils.h +1 -1
  221. data/src/core/lib/transport/metadata_batch.c +6 -7
  222. data/src/core/lib/transport/pid_controller.c +1 -0
  223. data/src/core/lib/transport/service_config.c +12 -0
  224. data/src/core/lib/transport/service_config.h +6 -0
  225. data/src/core/lib/transport/transport.c +29 -17
  226. data/src/core/lib/transport/transport.h +85 -42
  227. data/src/core/lib/transport/transport_impl.h +5 -3
  228. data/src/core/lib/transport/transport_op_string.c +20 -14
  229. data/src/core/plugin_registry/grpc_plugin_registry.c +8 -0
  230. data/src/core/{lib/tsi → tsi}/fake_transport_security.c +2 -2
  231. data/src/core/{lib/tsi → tsi}/fake_transport_security.h +4 -4
  232. data/src/core/{lib/tsi → tsi}/ssl_transport_security.c +40 -79
  233. data/src/core/{lib/tsi → tsi}/ssl_transport_security.h +44 -21
  234. data/src/core/{lib/tsi → tsi}/ssl_types.h +3 -3
  235. data/src/core/{lib/tsi → tsi}/transport_security.c +2 -2
  236. data/src/core/{lib/tsi → tsi}/transport_security.h +4 -4
  237. data/src/core/{lib/tsi → tsi}/transport_security_interface.h +3 -3
  238. data/src/ruby/ext/grpc/extconf.rb +1 -0
  239. data/src/ruby/ext/grpc/rb_call_credentials.c +2 -2
  240. data/src/ruby/ext/grpc/rb_channel.c +520 -93
  241. data/src/ruby/ext/grpc/rb_channel.h +2 -0
  242. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -0
  243. data/src/ruby/ext/grpc/rb_compression_options.c +5 -2
  244. data/src/ruby/ext/grpc/rb_event_thread.c +6 -6
  245. data/src/ruby/ext/grpc/rb_grpc.c +29 -7
  246. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  247. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
  249. data/src/ruby/ext/grpc/rb_server.c +5 -3
  250. data/src/ruby/lib/grpc/version.rb +1 -1
  251. data/src/ruby/spec/channel_connection_spec.rb +173 -0
  252. data/src/ruby/spec/channel_spec.rb +29 -0
  253. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +27 -17
  254. data/third_party/cares/ares_build.h +264 -0
  255. data/third_party/cares/cares/ares.h +636 -0
  256. data/third_party/cares/cares/ares__close_sockets.c +61 -0
  257. data/third_party/cares/cares/ares__get_hostent.c +261 -0
  258. data/third_party/cares/cares/ares__read_line.c +73 -0
  259. data/third_party/cares/cares/ares__timeval.c +111 -0
  260. data/third_party/cares/cares/ares_cancel.c +63 -0
  261. data/third_party/cares/cares/ares_create_query.c +202 -0
  262. data/third_party/cares/cares/ares_data.c +221 -0
  263. data/third_party/cares/cares/ares_data.h +72 -0
  264. data/third_party/cares/cares/ares_destroy.c +108 -0
  265. data/third_party/cares/cares/ares_dns.h +103 -0
  266. data/third_party/cares/cares/ares_expand_name.c +205 -0
  267. data/third_party/cares/cares/ares_expand_string.c +70 -0
  268. data/third_party/cares/cares/ares_fds.c +59 -0
  269. data/third_party/cares/cares/ares_free_hostent.c +41 -0
  270. data/third_party/cares/cares/ares_free_string.c +25 -0
  271. data/third_party/cares/cares/ares_getenv.c +30 -0
  272. data/third_party/cares/cares/ares_getenv.h +26 -0
  273. data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
  274. data/third_party/cares/cares/ares_gethostbyname.c +518 -0
  275. data/third_party/cares/cares/ares_getnameinfo.c +422 -0
  276. data/third_party/cares/cares/ares_getopt.c +122 -0
  277. data/third_party/cares/cares/ares_getopt.h +53 -0
  278. data/third_party/cares/cares/ares_getsock.c +66 -0
  279. data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
  280. data/third_party/cares/cares/ares_init.c +2146 -0
  281. data/third_party/cares/cares/ares_iphlpapi.h +221 -0
  282. data/third_party/cares/cares/ares_ipv6.h +78 -0
  283. data/third_party/cares/cares/ares_library_init.c +167 -0
  284. data/third_party/cares/cares/ares_library_init.h +42 -0
  285. data/third_party/cares/cares/ares_llist.c +63 -0
  286. data/third_party/cares/cares/ares_llist.h +39 -0
  287. data/third_party/cares/cares/ares_mkquery.c +24 -0
  288. data/third_party/cares/cares/ares_nowarn.c +260 -0
  289. data/third_party/cares/cares/ares_nowarn.h +61 -0
  290. data/third_party/cares/cares/ares_options.c +402 -0
  291. data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
  292. data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
  293. data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
  294. data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
  295. data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
  296. data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
  297. data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
  298. data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
  299. data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
  300. data/third_party/cares/cares/ares_platform.c +11035 -0
  301. data/third_party/cares/cares/ares_platform.h +43 -0
  302. data/third_party/cares/cares/ares_private.h +363 -0
  303. data/third_party/cares/cares/ares_process.c +1359 -0
  304. data/third_party/cares/cares/ares_query.c +186 -0
  305. data/third_party/cares/cares/ares_rules.h +125 -0
  306. data/third_party/cares/cares/ares_search.c +316 -0
  307. data/third_party/cares/cares/ares_send.c +131 -0
  308. data/third_party/cares/cares/ares_setup.h +217 -0
  309. data/third_party/cares/cares/ares_strcasecmp.c +66 -0
  310. data/third_party/cares/cares/ares_strcasecmp.h +30 -0
  311. data/third_party/cares/cares/ares_strdup.c +49 -0
  312. data/third_party/cares/cares/ares_strdup.h +24 -0
  313. data/third_party/cares/cares/ares_strerror.c +56 -0
  314. data/third_party/cares/cares/ares_timeout.c +88 -0
  315. data/third_party/cares/cares/ares_version.c +11 -0
  316. data/third_party/cares/cares/ares_version.h +24 -0
  317. data/third_party/cares/cares/ares_writev.c +79 -0
  318. data/third_party/cares/cares/bitncmp.c +59 -0
  319. data/third_party/cares/cares/bitncmp.h +26 -0
  320. data/third_party/cares/cares/config-win32.h +377 -0
  321. data/third_party/cares/cares/inet_net_pton.c +450 -0
  322. data/third_party/cares/cares/inet_ntop.c +208 -0
  323. data/third_party/cares/cares/setup_once.h +554 -0
  324. data/third_party/cares/cares/windows_port.c +22 -0
  325. data/third_party/cares/config_darwin/ares_config.h +523 -0
  326. data/third_party/cares/config_linux/ares_config.h +524 -0
  327. metadata +164 -68
@@ -0,0 +1,135 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #ifndef GRPC_CORE_LIB_IOMGR_TCP_SERVER_UTILS_POSIX_H
35
+ #define GRPC_CORE_LIB_IOMGR_TCP_SERVER_UTILS_POSIX_H
36
+
37
+ #include "src/core/lib/iomgr/ev_posix.h"
38
+ #include "src/core/lib/iomgr/resolve_address.h"
39
+ #include "src/core/lib/iomgr/socket_utils_posix.h"
40
+ #include "src/core/lib/iomgr/tcp_server.h"
41
+
42
+ /* one listening port */
43
+ typedef struct grpc_tcp_listener {
44
+ int fd;
45
+ grpc_fd *emfd;
46
+ grpc_tcp_server *server;
47
+ grpc_resolved_address addr;
48
+ int port;
49
+ unsigned port_index;
50
+ unsigned fd_index;
51
+ grpc_closure read_closure;
52
+ grpc_closure destroyed_closure;
53
+ struct grpc_tcp_listener *next;
54
+ /* sibling is a linked list of all listeners for a given port. add_port and
55
+ clone_port place all new listeners in the same sibling list. A member of
56
+ the 'sibling' list is also a member of the 'next' list. The head of each
57
+ sibling list has is_sibling==0, and subsequent members of sibling lists
58
+ have is_sibling==1. is_sibling allows separate sibling lists to be
59
+ identified while iterating through 'next'. */
60
+ struct grpc_tcp_listener *sibling;
61
+ int is_sibling;
62
+ } grpc_tcp_listener;
63
+
64
+ /* the overall server */
65
+ struct grpc_tcp_server {
66
+ gpr_refcount refs;
67
+ /* Called whenever accept() succeeds on a server port. */
68
+ grpc_tcp_server_cb on_accept_cb;
69
+ void *on_accept_cb_arg;
70
+
71
+ gpr_mu mu;
72
+
73
+ /* active port count: how many ports are actually still listening */
74
+ size_t active_ports;
75
+ /* destroyed port count: how many ports are completely destroyed */
76
+ size_t destroyed_ports;
77
+
78
+ /* is this server shutting down? */
79
+ bool shutdown;
80
+ /* have listeners been shutdown? */
81
+ bool shutdown_listeners;
82
+ /* use SO_REUSEPORT */
83
+ bool so_reuseport;
84
+ /* expand wildcard addresses to a list of all local addresses */
85
+ bool expand_wildcard_addrs;
86
+
87
+ /* linked list of server ports */
88
+ grpc_tcp_listener *head;
89
+ grpc_tcp_listener *tail;
90
+ unsigned nports;
91
+
92
+ /* List of closures passed to shutdown_starting_add(). */
93
+ grpc_closure_list shutdown_starting;
94
+
95
+ /* shutdown callback */
96
+ grpc_closure *shutdown_complete;
97
+
98
+ /* all pollsets interested in new connections */
99
+ grpc_pollset **pollsets;
100
+ /* number of pollsets in the pollsets array */
101
+ size_t pollset_count;
102
+
103
+ /* next pollset to assign a channel to */
104
+ gpr_atm next_pollset_to_assign;
105
+
106
+ /* channel args for this server */
107
+ grpc_channel_args *channel_args;
108
+ };
109
+
110
+ /* If successful, add a listener to \a s for \a addr, set \a dsmode for the
111
+ socket, and return the \a listener. */
112
+ grpc_error *grpc_tcp_server_add_addr(grpc_tcp_server *s,
113
+ const grpc_resolved_address *addr,
114
+ unsigned port_index, unsigned fd_index,
115
+ grpc_dualstack_mode *dsmode,
116
+ grpc_tcp_listener **listener);
117
+
118
+ /* Get all addresses assigned to network interfaces on the machine and create a
119
+ listener for each. requested_port is the port to use for every listener, or 0
120
+ to select one random port that will be used for every listener. Set *out_port
121
+ to the port selected. Return GRPC_ERROR_NONE only if all listeners were
122
+ added. */
123
+ grpc_error *grpc_tcp_server_add_all_local_addrs(grpc_tcp_server *s,
124
+ unsigned port_index,
125
+ int requested_port,
126
+ int *out_port);
127
+
128
+ /* Prepare a recently-created socket for listening. */
129
+ grpc_error *grpc_tcp_server_prepare_socket(int fd,
130
+ const grpc_resolved_address *addr,
131
+ bool so_reuseport, int *port);
132
+ /* Ruturn true if the platform supports ifaddrs */
133
+ bool grpc_tcp_server_have_ifaddrs(void);
134
+
135
+ #endif /* GRPC_CORE_LIB_IOMGR_TCP_SERVER_UTILS_POSIX_H */
@@ -0,0 +1,221 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include "src/core/lib/iomgr/port.h"
35
+
36
+ #ifdef GRPC_POSIX_SOCKET
37
+
38
+ #include "src/core/lib/iomgr/tcp_server_utils_posix.h"
39
+
40
+ #include <errno.h>
41
+ #include <limits.h>
42
+ #include <stdio.h>
43
+ #include <string.h>
44
+
45
+ #include <grpc/support/alloc.h>
46
+ #include <grpc/support/log.h>
47
+ #include <grpc/support/string_util.h>
48
+ #include <grpc/support/sync.h>
49
+
50
+ #include "src/core/lib/iomgr/error.h"
51
+ #include "src/core/lib/iomgr/sockaddr.h"
52
+ #include "src/core/lib/iomgr/sockaddr_utils.h"
53
+ #include "src/core/lib/iomgr/unix_sockets_posix.h"
54
+
55
+ #define MIN_SAFE_ACCEPT_QUEUE_SIZE 100
56
+
57
+ static gpr_once s_init_max_accept_queue_size;
58
+ static int s_max_accept_queue_size;
59
+
60
+ /* get max listen queue size on linux */
61
+ static void init_max_accept_queue_size(void) {
62
+ int n = SOMAXCONN;
63
+ char buf[64];
64
+ FILE *fp = fopen("/proc/sys/net/core/somaxconn", "r");
65
+ if (fp == NULL) {
66
+ /* 2.4 kernel. */
67
+ s_max_accept_queue_size = SOMAXCONN;
68
+ return;
69
+ }
70
+ if (fgets(buf, sizeof buf, fp)) {
71
+ char *end;
72
+ long i = strtol(buf, &end, 10);
73
+ if (i > 0 && i <= INT_MAX && end && *end == 0) {
74
+ n = (int)i;
75
+ }
76
+ }
77
+ fclose(fp);
78
+ s_max_accept_queue_size = n;
79
+
80
+ if (s_max_accept_queue_size < MIN_SAFE_ACCEPT_QUEUE_SIZE) {
81
+ gpr_log(GPR_INFO,
82
+ "Suspiciously small accept queue (%d) will probably lead to "
83
+ "connection drops",
84
+ s_max_accept_queue_size);
85
+ }
86
+ }
87
+
88
+ static int get_max_accept_queue_size(void) {
89
+ gpr_once_init(&s_init_max_accept_queue_size, init_max_accept_queue_size);
90
+ return s_max_accept_queue_size;
91
+ }
92
+
93
+ static grpc_error *add_socket_to_server(grpc_tcp_server *s, int fd,
94
+ const grpc_resolved_address *addr,
95
+ unsigned port_index, unsigned fd_index,
96
+ grpc_tcp_listener **listener) {
97
+ grpc_tcp_listener *sp = NULL;
98
+ int port = -1;
99
+ char *addr_str;
100
+ char *name;
101
+
102
+ grpc_error *err =
103
+ grpc_tcp_server_prepare_socket(fd, addr, s->so_reuseport, &port);
104
+ if (err == GRPC_ERROR_NONE) {
105
+ GPR_ASSERT(port > 0);
106
+ grpc_sockaddr_to_string(&addr_str, addr, 1);
107
+ gpr_asprintf(&name, "tcp-server-listener:%s", addr_str);
108
+ gpr_mu_lock(&s->mu);
109
+ s->nports++;
110
+ GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server");
111
+ sp = gpr_malloc(sizeof(grpc_tcp_listener));
112
+ sp->next = NULL;
113
+ if (s->head == NULL) {
114
+ s->head = sp;
115
+ } else {
116
+ s->tail->next = sp;
117
+ }
118
+ s->tail = sp;
119
+ sp->server = s;
120
+ sp->fd = fd;
121
+ sp->emfd = grpc_fd_create(fd, name);
122
+ memcpy(&sp->addr, addr, sizeof(grpc_resolved_address));
123
+ sp->port = port;
124
+ sp->port_index = port_index;
125
+ sp->fd_index = fd_index;
126
+ sp->is_sibling = 0;
127
+ sp->sibling = NULL;
128
+ GPR_ASSERT(sp->emfd);
129
+ gpr_mu_unlock(&s->mu);
130
+ gpr_free(addr_str);
131
+ gpr_free(name);
132
+ }
133
+
134
+ *listener = sp;
135
+ return err;
136
+ }
137
+
138
+ /* If successful, add a listener to s for addr, set *dsmode for the socket, and
139
+ return the *listener. */
140
+ grpc_error *grpc_tcp_server_add_addr(grpc_tcp_server *s,
141
+ const grpc_resolved_address *addr,
142
+ unsigned port_index, unsigned fd_index,
143
+ grpc_dualstack_mode *dsmode,
144
+ grpc_tcp_listener **listener) {
145
+ grpc_resolved_address addr4_copy;
146
+ int fd;
147
+ grpc_error *err =
148
+ grpc_create_dualstack_socket(addr, SOCK_STREAM, 0, dsmode, &fd);
149
+ if (err != GRPC_ERROR_NONE) {
150
+ return err;
151
+ }
152
+ if (*dsmode == GRPC_DSMODE_IPV4 &&
153
+ grpc_sockaddr_is_v4mapped(addr, &addr4_copy)) {
154
+ addr = &addr4_copy;
155
+ }
156
+ return add_socket_to_server(s, fd, addr, port_index, fd_index, listener);
157
+ }
158
+
159
+ /* Prepare a recently-created socket for listening. */
160
+ grpc_error *grpc_tcp_server_prepare_socket(int fd,
161
+ const grpc_resolved_address *addr,
162
+ bool so_reuseport, int *port) {
163
+ grpc_resolved_address sockname_temp;
164
+ grpc_error *err = GRPC_ERROR_NONE;
165
+
166
+ GPR_ASSERT(fd >= 0);
167
+
168
+ if (so_reuseport && !grpc_is_unix_socket(addr)) {
169
+ err = grpc_set_socket_reuse_port(fd, 1);
170
+ if (err != GRPC_ERROR_NONE) goto error;
171
+ }
172
+
173
+ err = grpc_set_socket_nonblocking(fd, 1);
174
+ if (err != GRPC_ERROR_NONE) goto error;
175
+ err = grpc_set_socket_cloexec(fd, 1);
176
+ if (err != GRPC_ERROR_NONE) goto error;
177
+ if (!grpc_is_unix_socket(addr)) {
178
+ err = grpc_set_socket_low_latency(fd, 1);
179
+ if (err != GRPC_ERROR_NONE) goto error;
180
+ err = grpc_set_socket_reuse_addr(fd, 1);
181
+ if (err != GRPC_ERROR_NONE) goto error;
182
+ }
183
+ err = grpc_set_socket_no_sigpipe_if_possible(fd);
184
+ if (err != GRPC_ERROR_NONE) goto error;
185
+
186
+ GPR_ASSERT(addr->len < ~(socklen_t)0);
187
+ if (bind(fd, (struct sockaddr *)addr->addr, (socklen_t)addr->len) < 0) {
188
+ err = GRPC_OS_ERROR(errno, "bind");
189
+ goto error;
190
+ }
191
+
192
+ if (listen(fd, get_max_accept_queue_size()) < 0) {
193
+ err = GRPC_OS_ERROR(errno, "listen");
194
+ goto error;
195
+ }
196
+
197
+ sockname_temp.len = sizeof(struct sockaddr_storage);
198
+
199
+ if (getsockname(fd, (struct sockaddr *)sockname_temp.addr,
200
+ (socklen_t *)&sockname_temp.len) < 0) {
201
+ err = GRPC_OS_ERROR(errno, "getsockname");
202
+ goto error;
203
+ }
204
+
205
+ *port = grpc_sockaddr_get_port(&sockname_temp);
206
+ return GRPC_ERROR_NONE;
207
+
208
+ error:
209
+ GPR_ASSERT(err != GRPC_ERROR_NONE);
210
+ if (fd >= 0) {
211
+ close(fd);
212
+ }
213
+ grpc_error *ret =
214
+ grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
215
+ "Unable to configure socket", &err, 1),
216
+ GRPC_ERROR_INT_FD, fd);
217
+ GRPC_ERROR_UNREF(err);
218
+ return ret;
219
+ }
220
+
221
+ #endif /* GRPC_POSIX_SOCKET */
@@ -0,0 +1,196 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include "src/core/lib/iomgr/port.h"
35
+
36
+ #ifdef GRPC_HAVE_IFADDRS
37
+
38
+ #include "src/core/lib/iomgr/tcp_server_utils_posix.h"
39
+
40
+ #include <errno.h>
41
+ #include <ifaddrs.h>
42
+ #include <stddef.h>
43
+ #include <string.h>
44
+
45
+ #include <grpc/support/alloc.h>
46
+ #include <grpc/support/log.h>
47
+ #include <grpc/support/string_util.h>
48
+
49
+ #include "src/core/lib/iomgr/error.h"
50
+ #include "src/core/lib/iomgr/sockaddr.h"
51
+ #include "src/core/lib/iomgr/sockaddr_utils.h"
52
+
53
+ /* Return the listener in s with address addr or NULL. */
54
+ static grpc_tcp_listener *find_listener_with_addr(grpc_tcp_server *s,
55
+ grpc_resolved_address *addr) {
56
+ grpc_tcp_listener *l;
57
+ gpr_mu_lock(&s->mu);
58
+ for (l = s->head; l != NULL; l = l->next) {
59
+ if (l->addr.len != addr->len) {
60
+ continue;
61
+ }
62
+ if (memcmp(l->addr.addr, addr->addr, addr->len) == 0) {
63
+ break;
64
+ }
65
+ }
66
+ gpr_mu_unlock(&s->mu);
67
+ return l;
68
+ }
69
+
70
+ /* Bind to "::" to get a port number not used by any address. */
71
+ static grpc_error *get_unused_port(int *port) {
72
+ grpc_resolved_address wild;
73
+ grpc_sockaddr_make_wildcard6(0, &wild);
74
+ grpc_dualstack_mode dsmode;
75
+ int fd;
76
+ grpc_error *err =
77
+ grpc_create_dualstack_socket(&wild, SOCK_STREAM, 0, &dsmode, &fd);
78
+ if (err != GRPC_ERROR_NONE) {
79
+ return err;
80
+ }
81
+ if (dsmode == GRPC_DSMODE_IPV4) {
82
+ grpc_sockaddr_make_wildcard4(0, &wild);
83
+ }
84
+ if (bind(fd, (const struct sockaddr *)wild.addr, (socklen_t)wild.len) != 0) {
85
+ err = GRPC_OS_ERROR(errno, "bind");
86
+ close(fd);
87
+ return err;
88
+ }
89
+ if (getsockname(fd, (struct sockaddr *)wild.addr, (socklen_t *)&wild.len) !=
90
+ 0) {
91
+ err = GRPC_OS_ERROR(errno, "getsockname");
92
+ close(fd);
93
+ return err;
94
+ }
95
+ close(fd);
96
+ *port = grpc_sockaddr_get_port(&wild);
97
+ return *port <= 0 ? GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad port")
98
+ : GRPC_ERROR_NONE;
99
+ }
100
+
101
+ grpc_error *grpc_tcp_server_add_all_local_addrs(grpc_tcp_server *s,
102
+ unsigned port_index,
103
+ int requested_port,
104
+ int *out_port) {
105
+ struct ifaddrs *ifa = NULL;
106
+ struct ifaddrs *ifa_it;
107
+ unsigned fd_index = 0;
108
+ grpc_tcp_listener *sp = NULL;
109
+ grpc_error *err = GRPC_ERROR_NONE;
110
+ if (requested_port == 0) {
111
+ /* Note: There could be a race where some local addrs can listen on the
112
+ selected port and some can't. The sane way to handle this would be to
113
+ retry by recreating the whole grpc_tcp_server. Backing out individual
114
+ listeners and orphaning the FDs looks like too much trouble. */
115
+ if ((err = get_unused_port(&requested_port)) != GRPC_ERROR_NONE) {
116
+ return err;
117
+ } else if (requested_port <= 0) {
118
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Bad get_unused_port()");
119
+ }
120
+ gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port);
121
+ }
122
+ if (getifaddrs(&ifa) != 0 || ifa == NULL) {
123
+ return GRPC_OS_ERROR(errno, "getifaddrs");
124
+ }
125
+ for (ifa_it = ifa; ifa_it != NULL; ifa_it = ifa_it->ifa_next) {
126
+ grpc_resolved_address addr;
127
+ char *addr_str = NULL;
128
+ grpc_dualstack_mode dsmode;
129
+ grpc_tcp_listener *new_sp = NULL;
130
+ const char *ifa_name = (ifa_it->ifa_name ? ifa_it->ifa_name : "<unknown>");
131
+ if (ifa_it->ifa_addr == NULL) {
132
+ continue;
133
+ } else if (ifa_it->ifa_addr->sa_family == AF_INET) {
134
+ addr.len = sizeof(struct sockaddr_in);
135
+ } else if (ifa_it->ifa_addr->sa_family == AF_INET6) {
136
+ addr.len = sizeof(struct sockaddr_in6);
137
+ } else {
138
+ continue;
139
+ }
140
+ memcpy(addr.addr, ifa_it->ifa_addr, addr.len);
141
+ if (!grpc_sockaddr_set_port(&addr, requested_port)) {
142
+ /* Should never happen, because we check sa_family above. */
143
+ err = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to set port");
144
+ break;
145
+ }
146
+ if (grpc_sockaddr_to_string(&addr_str, &addr, 0) < 0) {
147
+ addr_str = gpr_strdup("<error>");
148
+ }
149
+ gpr_log(GPR_DEBUG,
150
+ "Adding local addr from interface %s flags 0x%x to server: %s",
151
+ ifa_name, ifa_it->ifa_flags, addr_str);
152
+ /* We could have multiple interfaces with the same address (e.g., bonding),
153
+ so look for duplicates. */
154
+ if (find_listener_with_addr(s, &addr) != NULL) {
155
+ gpr_log(GPR_DEBUG, "Skipping duplicate addr %s on interface %s", addr_str,
156
+ ifa_name);
157
+ gpr_free(addr_str);
158
+ continue;
159
+ }
160
+ if ((err = grpc_tcp_server_add_addr(s, &addr, port_index, fd_index, &dsmode,
161
+ &new_sp)) != GRPC_ERROR_NONE) {
162
+ char *err_str = NULL;
163
+ grpc_error *root_err;
164
+ if (gpr_asprintf(&err_str, "Failed to add listener: %s", addr_str) < 0) {
165
+ err_str = gpr_strdup("Failed to add listener");
166
+ }
167
+ root_err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(err_str);
168
+ gpr_free(err_str);
169
+ gpr_free(addr_str);
170
+ err = grpc_error_add_child(root_err, err);
171
+ break;
172
+ } else {
173
+ GPR_ASSERT(requested_port == new_sp->port);
174
+ ++fd_index;
175
+ if (sp != NULL) {
176
+ new_sp->is_sibling = 1;
177
+ sp->sibling = new_sp;
178
+ }
179
+ sp = new_sp;
180
+ }
181
+ gpr_free(addr_str);
182
+ }
183
+ freeifaddrs(ifa);
184
+ if (err != GRPC_ERROR_NONE) {
185
+ return err;
186
+ } else if (sp == NULL) {
187
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("No local addresses");
188
+ } else {
189
+ *out_port = sp->port;
190
+ return GRPC_ERROR_NONE;
191
+ }
192
+ }
193
+
194
+ bool grpc_tcp_server_have_ifaddrs(void) { return true; }
195
+
196
+ #endif /* GRPC_HAVE_IFADDRS */