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.
- checksums.yaml +4 -4
- data/Makefile +1434 -399
- data/etc/roots.pem +34 -150
- data/include/grpc/grpc.h +71 -0
- data/include/grpc/impl/codegen/atm.h +5 -0
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +6 -0
- data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
- data/include/grpc/impl/codegen/atm_windows.h +11 -0
- data/include/grpc/impl/codegen/grpc_types.h +54 -13
- data/include/grpc/impl/codegen/port_platform.h +15 -1
- data/include/grpc/support/alloc.h +2 -1
- data/include/grpc/support/sync.h +4 -0
- data/include/grpc/support/tls.h +1 -1
- data/src/core/ext/census/gen/trace_context.pb.h +1 -1
- data/src/core/ext/census/grpc_filter.c +14 -10
- data/src/core/ext/census/grpc_plugin.c +3 -1
- data/src/core/ext/census/trace_label.h +1 -1
- data/src/core/ext/census/trace_propagation.h +1 -1
- data/src/core/ext/census/trace_status.h +1 -1
- data/src/core/ext/census/trace_string.h +1 -1
- data/src/core/ext/census/tracing.h +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/channel_connectivity.c +56 -27
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel.c +407 -202
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel.h +10 -6
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.h +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel_plugin.c +12 -7
- data/src/core/ext/{client_channel → filters/client_channel}/connector.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/connector.h +3 -5
- data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.c +6 -6
- data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.h +3 -3
- data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.c +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.h +3 -3
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.h +4 -4
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.c +22 -20
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.h +4 -4
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel.h +5 -4
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel_secure.c +2 -2
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.c +1 -1
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.h +6 -5
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +1 -1
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -0
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/pick_first/pick_first.c +20 -15
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/round_robin/round_robin.c +21 -16
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.h +5 -5
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.h +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/parse_address.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/parse_address.h +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.h +3 -3
- data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.c +10 -4
- data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.h +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/resolver.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/resolver.h +4 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
- data/src/core/ext/{resolver → filters/client_channel/resolver}/dns/native/dns_resolver.c +21 -5
- data/src/core/ext/{resolver → filters/client_channel/resolver}/sockaddr/sockaddr_resolver.c +3 -3
- data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.h +6 -6
- data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.c +1 -2
- data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.h +4 -4
- data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
- data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
- data/src/core/ext/{client_channel → filters/client_channel}/subchannel.c +49 -43
- data/src/core/ext/{client_channel → filters/client_channel}/subchannel.h +21 -7
- data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.h +5 -5
- data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.h +3 -3
- data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.c +4 -2
- data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.h +3 -3
- data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.c +17 -14
- data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.h +4 -4
- data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
- data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +6 -41
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +2 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +3 -3
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +2 -5
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +2 -2
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +449 -204
- data/src/core/ext/transport/chttp2/transport/frame_data.c +10 -7
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +3 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +37 -7
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +4 -3
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +18 -38
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -29
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +64 -37
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +11 -4
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +60 -39
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
- data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +22 -43
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +8 -10
- data/src/core/ext/transport/chttp2/transport/internal.h +24 -2
- data/src/core/ext/transport/chttp2/transport/parsing.c +33 -15
- data/src/core/ext/transport/chttp2/transport/writing.c +56 -10
- data/src/core/lib/channel/channel_args.c +7 -0
- data/src/core/lib/channel/channel_args.h +2 -0
- data/src/core/lib/channel/channel_stack.c +20 -27
- data/src/core/lib/channel/channel_stack.h +18 -16
- data/src/core/lib/channel/compress_filter.c +20 -18
- data/src/core/lib/channel/connected_channel.c +9 -8
- data/src/core/lib/channel/deadline_filter.c +28 -24
- data/src/core/lib/channel/deadline_filter.h +3 -3
- data/src/core/lib/channel/handshaker.c +3 -2
- data/src/core/lib/channel/http_client_filter.c +119 -61
- data/src/core/lib/channel/http_server_filter.c +124 -69
- data/src/core/lib/channel/message_size_filter.c +23 -19
- data/src/core/lib/http/httpcli.c +8 -6
- data/src/core/lib/http/httpcli_security_connector.c +5 -5
- data/src/core/lib/http/parser.c +57 -31
- data/src/core/lib/iomgr/closure.c +15 -0
- data/src/core/lib/iomgr/closure.h +4 -0
- data/src/core/lib/iomgr/combiner.c +8 -0
- data/src/core/lib/iomgr/endpoint_pair.h +2 -3
- data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -7
- data/src/core/lib/iomgr/endpoint_pair_uv.c +2 -3
- data/src/core/lib/iomgr/endpoint_pair_windows.c +9 -6
- data/src/core/lib/iomgr/error.c +360 -177
- data/src/core/lib/iomgr/error.h +31 -33
- data/src/core/lib/iomgr/error_internal.h +30 -9
- data/src/core/lib/iomgr/ev_epoll_linux.c +25 -239
- data/src/core/lib/iomgr/ev_poll_posix.c +11 -7
- data/src/core/lib/iomgr/ev_posix.c +6 -0
- data/src/core/lib/iomgr/ev_posix.h +3 -0
- data/src/core/lib/iomgr/exec_ctx.c +6 -0
- data/src/core/lib/iomgr/executor.c +8 -2
- data/src/core/lib/iomgr/load_file.c +6 -3
- data/src/core/lib/iomgr/lockfree_event.c +238 -0
- data/src/core/{ext/client_channel/initial_connect_string.h → lib/iomgr/lockfree_event.h} +17 -13
- data/src/core/lib/iomgr/pollset.h +4 -0
- data/src/core/lib/iomgr/pollset_windows.c +2 -2
- data/src/core/lib/iomgr/port.h +9 -0
- data/src/core/lib/iomgr/resolve_address_posix.c +15 -9
- data/src/core/lib/iomgr/resolve_address_uv.c +8 -6
- data/src/core/lib/iomgr/resolve_address_windows.c +2 -2
- data/src/core/lib/iomgr/resource_quota.c +19 -4
- data/src/core/lib/iomgr/resource_quota.h +2 -0
- data/src/core/lib/iomgr/sockaddr_utils.c +3 -1
- data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
- data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.c +25 -9
- data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
- data/src/core/lib/iomgr/tcp_client.h +0 -4
- data/src/core/lib/iomgr/tcp_client_posix.c +15 -31
- data/src/core/lib/iomgr/tcp_client_uv.c +10 -6
- data/src/core/lib/iomgr/tcp_client_windows.c +9 -19
- data/src/core/lib/iomgr/tcp_posix.c +111 -22
- data/src/core/lib/iomgr/tcp_posix.h +3 -4
- data/src/core/lib/iomgr/tcp_server_posix.c +39 -417
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
- data/src/core/lib/iomgr/tcp_server_uv.c +43 -16
- data/src/core/lib/iomgr/tcp_server_windows.c +10 -22
- data/src/core/lib/iomgr/tcp_uv.c +16 -13
- data/src/core/lib/iomgr/tcp_windows.c +24 -12
- data/src/core/lib/iomgr/tcp_windows.h +2 -2
- data/src/core/lib/iomgr/timer.h +3 -0
- data/src/core/lib/iomgr/timer_generic.c +257 -72
- data/src/core/lib/iomgr/timer_generic.h +1 -1
- data/src/core/lib/iomgr/timer_heap.c +8 -8
- data/src/core/lib/iomgr/udp_server.c +54 -24
- data/src/core/lib/iomgr/udp_server.h +7 -7
- data/src/core/lib/iomgr/unix_sockets_posix.c +1 -1
- data/src/core/lib/iomgr/unix_sockets_posix_noop.c +2 -1
- data/src/core/lib/iomgr/wakeup_fd_posix.h +1 -1
- data/src/core/lib/profiling/basic_timers.c +1 -1
- data/src/core/lib/security/credentials/credentials.h +1 -1
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +10 -9
- data/src/core/lib/security/credentials/jwt/json_token.c +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +2 -2
- data/src/core/lib/security/transport/client_auth_filter.c +33 -26
- data/src/core/lib/security/transport/secure_endpoint.c +8 -5
- data/src/core/lib/security/transport/security_connector.c +37 -37
- data/src/core/lib/security/transport/security_connector.h +1 -1
- data/src/core/lib/security/transport/security_handshaker.c +15 -12
- data/src/core/lib/security/transport/server_auth_filter.c +20 -18
- data/src/core/lib/security/transport/tsi_error.c +5 -3
- data/src/core/lib/security/transport/tsi_error.h +1 -1
- data/src/core/lib/{security/util → slice}/b64.c +21 -6
- data/src/core/lib/{security/util → slice}/b64.h +16 -4
- data/src/core/lib/slice/slice.c +4 -2
- data/src/core/lib/slice/slice_buffer.c +16 -14
- data/src/core/lib/support/arena.c +98 -0
- data/src/core/{ext/client_channel/initial_connect_string.c → lib/support/arena.h} +17 -15
- data/src/core/{ext/client_channel/default_initial_connect_string.c → lib/support/atm.c} +14 -5
- data/src/core/lib/support/cpu_linux.c +5 -0
- data/src/core/lib/support/sync.c +4 -0
- data/src/core/lib/support/time.c +4 -10
- data/src/core/lib/support/wrap_memcpy.c +3 -1
- data/src/core/lib/surface/call.c +252 -221
- data/src/core/lib/surface/channel.c +72 -21
- data/src/core/lib/surface/channel.h +8 -0
- data/src/core/lib/surface/completion_queue.c +2 -3
- data/src/core/lib/surface/completion_queue_factory.c +77 -0
- data/src/core/lib/surface/completion_queue_factory.h +51 -0
- data/src/core/lib/surface/init_secure.c +3 -1
- data/src/core/lib/surface/lame_client.c +18 -14
- data/src/core/lib/surface/server.c +43 -41
- data/src/core/lib/surface/validate_metadata.c +8 -4
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/bdp_estimator.h +1 -1
- data/src/core/lib/transport/connectivity_state.c +2 -1
- data/src/core/lib/transport/error_utils.c +17 -17
- data/src/core/lib/transport/error_utils.h +1 -1
- data/src/core/lib/transport/metadata_batch.c +6 -7
- data/src/core/lib/transport/pid_controller.c +1 -0
- data/src/core/lib/transport/service_config.c +12 -0
- data/src/core/lib/transport/service_config.h +6 -0
- data/src/core/lib/transport/transport.c +29 -17
- data/src/core/lib/transport/transport.h +85 -42
- data/src/core/lib/transport/transport_impl.h +5 -3
- data/src/core/lib/transport/transport_op_string.c +20 -14
- data/src/core/plugin_registry/grpc_plugin_registry.c +8 -0
- data/src/core/{lib/tsi → tsi}/fake_transport_security.c +2 -2
- data/src/core/{lib/tsi → tsi}/fake_transport_security.h +4 -4
- data/src/core/{lib/tsi → tsi}/ssl_transport_security.c +40 -79
- data/src/core/{lib/tsi → tsi}/ssl_transport_security.h +44 -21
- data/src/core/{lib/tsi → tsi}/ssl_types.h +3 -3
- data/src/core/{lib/tsi → tsi}/transport_security.c +2 -2
- data/src/core/{lib/tsi → tsi}/transport_security.h +4 -4
- data/src/core/{lib/tsi → tsi}/transport_security_interface.h +3 -3
- data/src/ruby/ext/grpc/extconf.rb +1 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +2 -2
- data/src/ruby/ext/grpc/rb_channel.c +520 -93
- data/src/ruby/ext/grpc/rb_channel.h +2 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +5 -2
- data/src/ruby/ext/grpc/rb_event_thread.c +6 -6
- data/src/ruby/ext/grpc/rb_grpc.c +29 -7
- data/src/ruby/ext/grpc/rb_grpc.h +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
- data/src/ruby/ext/grpc/rb_server.c +5 -3
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/channel_connection_spec.rb +173 -0
- data/src/ruby/spec/channel_spec.rb +29 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +27 -17
- data/third_party/cares/ares_build.h +264 -0
- data/third_party/cares/cares/ares.h +636 -0
- data/third_party/cares/cares/ares__close_sockets.c +61 -0
- data/third_party/cares/cares/ares__get_hostent.c +261 -0
- data/third_party/cares/cares/ares__read_line.c +73 -0
- data/third_party/cares/cares/ares__timeval.c +111 -0
- data/third_party/cares/cares/ares_cancel.c +63 -0
- data/third_party/cares/cares/ares_create_query.c +202 -0
- data/third_party/cares/cares/ares_data.c +221 -0
- data/third_party/cares/cares/ares_data.h +72 -0
- data/third_party/cares/cares/ares_destroy.c +108 -0
- data/third_party/cares/cares/ares_dns.h +103 -0
- data/third_party/cares/cares/ares_expand_name.c +205 -0
- data/third_party/cares/cares/ares_expand_string.c +70 -0
- data/third_party/cares/cares/ares_fds.c +59 -0
- data/third_party/cares/cares/ares_free_hostent.c +41 -0
- data/third_party/cares/cares/ares_free_string.c +25 -0
- data/third_party/cares/cares/ares_getenv.c +30 -0
- data/third_party/cares/cares/ares_getenv.h +26 -0
- data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
- data/third_party/cares/cares/ares_gethostbyname.c +518 -0
- data/third_party/cares/cares/ares_getnameinfo.c +422 -0
- data/third_party/cares/cares/ares_getopt.c +122 -0
- data/third_party/cares/cares/ares_getopt.h +53 -0
- data/third_party/cares/cares/ares_getsock.c +66 -0
- data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
- data/third_party/cares/cares/ares_init.c +2146 -0
- data/third_party/cares/cares/ares_iphlpapi.h +221 -0
- data/third_party/cares/cares/ares_ipv6.h +78 -0
- data/third_party/cares/cares/ares_library_init.c +167 -0
- data/third_party/cares/cares/ares_library_init.h +42 -0
- data/third_party/cares/cares/ares_llist.c +63 -0
- data/third_party/cares/cares/ares_llist.h +39 -0
- data/third_party/cares/cares/ares_mkquery.c +24 -0
- data/third_party/cares/cares/ares_nowarn.c +260 -0
- data/third_party/cares/cares/ares_nowarn.h +61 -0
- data/third_party/cares/cares/ares_options.c +402 -0
- data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
- data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
- data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
- data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
- data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
- data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
- data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
- data/third_party/cares/cares/ares_platform.c +11035 -0
- data/third_party/cares/cares/ares_platform.h +43 -0
- data/third_party/cares/cares/ares_private.h +363 -0
- data/third_party/cares/cares/ares_process.c +1359 -0
- data/third_party/cares/cares/ares_query.c +186 -0
- data/third_party/cares/cares/ares_rules.h +125 -0
- data/third_party/cares/cares/ares_search.c +316 -0
- data/third_party/cares/cares/ares_send.c +131 -0
- data/third_party/cares/cares/ares_setup.h +217 -0
- data/third_party/cares/cares/ares_strcasecmp.c +66 -0
- data/third_party/cares/cares/ares_strcasecmp.h +30 -0
- data/third_party/cares/cares/ares_strdup.c +49 -0
- data/third_party/cares/cares/ares_strdup.h +24 -0
- data/third_party/cares/cares/ares_strerror.c +56 -0
- data/third_party/cares/cares/ares_timeout.c +88 -0
- data/third_party/cares/cares/ares_version.c +11 -0
- data/third_party/cares/cares/ares_version.h +24 -0
- data/third_party/cares/cares/ares_writev.c +79 -0
- data/third_party/cares/cares/bitncmp.c +59 -0
- data/third_party/cares/cares/bitncmp.h +26 -0
- data/third_party/cares/cares/config-win32.h +377 -0
- data/third_party/cares/cares/inet_net_pton.c +450 -0
- data/third_party/cares/cares/inet_ntop.c +208 -0
- data/third_party/cares/cares/setup_once.h +554 -0
- data/third_party/cares/cares/windows_port.c +22 -0
- data/third_party/cares/config_darwin/ares_config.h +523 -0
- data/third_party/cares/config_linux/ares_config.h +524 -0
- metadata +164 -68
@@ -47,14 +47,13 @@
|
|
47
47
|
#include "src/core/lib/iomgr/endpoint.h"
|
48
48
|
#include "src/core/lib/iomgr/ev_posix.h"
|
49
49
|
|
50
|
-
#define GRPC_TCP_DEFAULT_READ_SLICE_SIZE 8192
|
51
|
-
|
52
50
|
extern int grpc_tcp_trace;
|
53
51
|
|
54
52
|
/* Create a tcp endpoint given a file desciptor and a read slice size.
|
55
53
|
Takes ownership of fd. */
|
56
|
-
grpc_endpoint *grpc_tcp_create(
|
57
|
-
|
54
|
+
grpc_endpoint *grpc_tcp_create(grpc_exec_ctx *exec_ctx, grpc_fd *fd,
|
55
|
+
const grpc_channel_args *args,
|
56
|
+
const char *peer_string);
|
58
57
|
|
59
58
|
/* Return the tcp endpoint's fd, or -1 if this is not available. Does not
|
60
59
|
release the fd.
|
@@ -44,11 +44,8 @@
|
|
44
44
|
|
45
45
|
#include <errno.h>
|
46
46
|
#include <fcntl.h>
|
47
|
-
#include <ifaddrs.h>
|
48
|
-
#include <limits.h>
|
49
47
|
#include <netinet/in.h>
|
50
48
|
#include <netinet/tcp.h>
|
51
|
-
#include <stdio.h>
|
52
49
|
#include <string.h>
|
53
50
|
#include <sys/socket.h>
|
54
51
|
#include <sys/stat.h>
|
@@ -62,87 +59,16 @@
|
|
62
59
|
#include <grpc/support/time.h>
|
63
60
|
#include <grpc/support/useful.h>
|
64
61
|
|
62
|
+
#include "src/core/lib/channel/channel_args.h"
|
65
63
|
#include "src/core/lib/iomgr/resolve_address.h"
|
66
64
|
#include "src/core/lib/iomgr/sockaddr.h"
|
67
65
|
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
68
66
|
#include "src/core/lib/iomgr/socket_utils_posix.h"
|
69
67
|
#include "src/core/lib/iomgr/tcp_posix.h"
|
68
|
+
#include "src/core/lib/iomgr/tcp_server_utils_posix.h"
|
70
69
|
#include "src/core/lib/iomgr/unix_sockets_posix.h"
|
71
70
|
#include "src/core/lib/support/string.h"
|
72
71
|
|
73
|
-
#define MIN_SAFE_ACCEPT_QUEUE_SIZE 100
|
74
|
-
|
75
|
-
static gpr_once s_init_max_accept_queue_size;
|
76
|
-
static int s_max_accept_queue_size;
|
77
|
-
|
78
|
-
/* one listening port */
|
79
|
-
typedef struct grpc_tcp_listener grpc_tcp_listener;
|
80
|
-
struct grpc_tcp_listener {
|
81
|
-
int fd;
|
82
|
-
grpc_fd *emfd;
|
83
|
-
grpc_tcp_server *server;
|
84
|
-
grpc_resolved_address addr;
|
85
|
-
int port;
|
86
|
-
unsigned port_index;
|
87
|
-
unsigned fd_index;
|
88
|
-
grpc_closure read_closure;
|
89
|
-
grpc_closure destroyed_closure;
|
90
|
-
struct grpc_tcp_listener *next;
|
91
|
-
/* sibling is a linked list of all listeners for a given port. add_port and
|
92
|
-
clone_port place all new listeners in the same sibling list. A member of
|
93
|
-
the 'sibling' list is also a member of the 'next' list. The head of each
|
94
|
-
sibling list has is_sibling==0, and subsequent members of sibling lists
|
95
|
-
have is_sibling==1. is_sibling allows separate sibling lists to be
|
96
|
-
identified while iterating through 'next'. */
|
97
|
-
struct grpc_tcp_listener *sibling;
|
98
|
-
int is_sibling;
|
99
|
-
};
|
100
|
-
|
101
|
-
/* the overall server */
|
102
|
-
struct grpc_tcp_server {
|
103
|
-
gpr_refcount refs;
|
104
|
-
/* Called whenever accept() succeeds on a server port. */
|
105
|
-
grpc_tcp_server_cb on_accept_cb;
|
106
|
-
void *on_accept_cb_arg;
|
107
|
-
|
108
|
-
gpr_mu mu;
|
109
|
-
|
110
|
-
/* active port count: how many ports are actually still listening */
|
111
|
-
size_t active_ports;
|
112
|
-
/* destroyed port count: how many ports are completely destroyed */
|
113
|
-
size_t destroyed_ports;
|
114
|
-
|
115
|
-
/* is this server shutting down? */
|
116
|
-
bool shutdown;
|
117
|
-
/* have listeners been shutdown? */
|
118
|
-
bool shutdown_listeners;
|
119
|
-
/* use SO_REUSEPORT */
|
120
|
-
bool so_reuseport;
|
121
|
-
/* expand wildcard addresses to a list of all local addresses */
|
122
|
-
bool expand_wildcard_addrs;
|
123
|
-
|
124
|
-
/* linked list of server ports */
|
125
|
-
grpc_tcp_listener *head;
|
126
|
-
grpc_tcp_listener *tail;
|
127
|
-
unsigned nports;
|
128
|
-
|
129
|
-
/* List of closures passed to shutdown_starting_add(). */
|
130
|
-
grpc_closure_list shutdown_starting;
|
131
|
-
|
132
|
-
/* shutdown callback */
|
133
|
-
grpc_closure *shutdown_complete;
|
134
|
-
|
135
|
-
/* all pollsets interested in new connections */
|
136
|
-
grpc_pollset **pollsets;
|
137
|
-
/* number of pollsets in the pollsets array */
|
138
|
-
size_t pollset_count;
|
139
|
-
|
140
|
-
/* next pollset to assign a channel to */
|
141
|
-
gpr_atm next_pollset_to_assign;
|
142
|
-
|
143
|
-
grpc_resource_quota *resource_quota;
|
144
|
-
};
|
145
|
-
|
146
72
|
static gpr_once check_init = GPR_ONCE_INIT;
|
147
73
|
static bool has_so_reuseport = false;
|
148
74
|
|
@@ -165,7 +91,6 @@ grpc_error *grpc_tcp_server_create(grpc_exec_ctx *exec_ctx,
|
|
165
91
|
|
166
92
|
grpc_tcp_server *s = gpr_zalloc(sizeof(grpc_tcp_server));
|
167
93
|
s->so_reuseport = has_so_reuseport;
|
168
|
-
s->resource_quota = grpc_resource_quota_create(NULL);
|
169
94
|
s->expand_wildcard_addrs = false;
|
170
95
|
for (size_t i = 0; i < (args == NULL ? 0 : args->num_args); i++) {
|
171
96
|
if (0 == strcmp(GRPC_ARG_ALLOW_REUSEPORT, args->args[i].key)) {
|
@@ -173,30 +98,17 @@ grpc_error *grpc_tcp_server_create(grpc_exec_ctx *exec_ctx,
|
|
173
98
|
s->so_reuseport =
|
174
99
|
has_so_reuseport && (args->args[i].value.integer != 0);
|
175
100
|
} else {
|
176
|
-
grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
|
177
|
-
gpr_free(s);
|
178
|
-
return GRPC_ERROR_CREATE(GRPC_ARG_ALLOW_REUSEPORT
|
179
|
-
" must be an integer");
|
180
|
-
}
|
181
|
-
} else if (0 == strcmp(GRPC_ARG_RESOURCE_QUOTA, args->args[i].key)) {
|
182
|
-
if (args->args[i].type == GRPC_ARG_POINTER) {
|
183
|
-
grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
|
184
|
-
s->resource_quota =
|
185
|
-
grpc_resource_quota_ref_internal(args->args[i].value.pointer.p);
|
186
|
-
} else {
|
187
|
-
grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
|
188
101
|
gpr_free(s);
|
189
|
-
return
|
190
|
-
|
102
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(GRPC_ARG_ALLOW_REUSEPORT
|
103
|
+
" must be an integer");
|
191
104
|
}
|
192
105
|
} else if (0 == strcmp(GRPC_ARG_EXPAND_WILDCARD_ADDRS, args->args[i].key)) {
|
193
106
|
if (args->args[i].type == GRPC_ARG_INTEGER) {
|
194
107
|
s->expand_wildcard_addrs = (args->args[i].value.integer != 0);
|
195
108
|
} else {
|
196
|
-
grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
|
197
109
|
gpr_free(s);
|
198
|
-
return
|
199
|
-
|
110
|
+
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
111
|
+
GRPC_ARG_EXPAND_WILDCARD_ADDRS " must be an integer");
|
200
112
|
}
|
201
113
|
}
|
202
114
|
}
|
@@ -213,6 +125,7 @@ grpc_error *grpc_tcp_server_create(grpc_exec_ctx *exec_ctx,
|
|
213
125
|
s->head = NULL;
|
214
126
|
s->tail = NULL;
|
215
127
|
s->nports = 0;
|
128
|
+
s->channel_args = grpc_channel_args_copy(args);
|
216
129
|
gpr_atm_no_barrier_store(&s->next_pollset_to_assign, 0);
|
217
130
|
*server = s;
|
218
131
|
return GRPC_ERROR_NONE;
|
@@ -233,8 +146,7 @@ static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
|
|
233
146
|
s->head = sp->next;
|
234
147
|
gpr_free(sp);
|
235
148
|
}
|
236
|
-
|
237
|
-
grpc_resource_quota_unref_internal(exec_ctx, s->resource_quota);
|
149
|
+
grpc_channel_args_destroy(exec_ctx, s->channel_args);
|
238
150
|
|
239
151
|
gpr_free(s);
|
240
152
|
}
|
@@ -288,8 +200,8 @@ static void tcp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
|
|
288
200
|
if (s->active_ports) {
|
289
201
|
grpc_tcp_listener *sp;
|
290
202
|
for (sp = s->head; sp; sp = sp->next) {
|
291
|
-
grpc_fd_shutdown(exec_ctx, sp->emfd,
|
292
|
-
|
203
|
+
grpc_fd_shutdown(exec_ctx, sp->emfd, GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
204
|
+
"Server destroyed"));
|
293
205
|
}
|
294
206
|
gpr_mu_unlock(&s->mu);
|
295
207
|
} else {
|
@@ -298,99 +210,6 @@ static void tcp_server_destroy(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
|
|
298
210
|
}
|
299
211
|
}
|
300
212
|
|
301
|
-
/* get max listen queue size on linux */
|
302
|
-
static void init_max_accept_queue_size(void) {
|
303
|
-
int n = SOMAXCONN;
|
304
|
-
char buf[64];
|
305
|
-
FILE *fp = fopen("/proc/sys/net/core/somaxconn", "r");
|
306
|
-
if (fp == NULL) {
|
307
|
-
/* 2.4 kernel. */
|
308
|
-
s_max_accept_queue_size = SOMAXCONN;
|
309
|
-
return;
|
310
|
-
}
|
311
|
-
if (fgets(buf, sizeof buf, fp)) {
|
312
|
-
char *end;
|
313
|
-
long i = strtol(buf, &end, 10);
|
314
|
-
if (i > 0 && i <= INT_MAX && end && *end == 0) {
|
315
|
-
n = (int)i;
|
316
|
-
}
|
317
|
-
}
|
318
|
-
fclose(fp);
|
319
|
-
s_max_accept_queue_size = n;
|
320
|
-
|
321
|
-
if (s_max_accept_queue_size < MIN_SAFE_ACCEPT_QUEUE_SIZE) {
|
322
|
-
gpr_log(GPR_INFO,
|
323
|
-
"Suspiciously small accept queue (%d) will probably lead to "
|
324
|
-
"connection drops",
|
325
|
-
s_max_accept_queue_size);
|
326
|
-
}
|
327
|
-
}
|
328
|
-
|
329
|
-
static int get_max_accept_queue_size(void) {
|
330
|
-
gpr_once_init(&s_init_max_accept_queue_size, init_max_accept_queue_size);
|
331
|
-
return s_max_accept_queue_size;
|
332
|
-
}
|
333
|
-
|
334
|
-
/* Prepare a recently-created socket for listening. */
|
335
|
-
static grpc_error *prepare_socket(int fd, const grpc_resolved_address *addr,
|
336
|
-
bool so_reuseport, int *port) {
|
337
|
-
grpc_resolved_address sockname_temp;
|
338
|
-
grpc_error *err = GRPC_ERROR_NONE;
|
339
|
-
|
340
|
-
GPR_ASSERT(fd >= 0);
|
341
|
-
|
342
|
-
if (so_reuseport && !grpc_is_unix_socket(addr)) {
|
343
|
-
err = grpc_set_socket_reuse_port(fd, 1);
|
344
|
-
if (err != GRPC_ERROR_NONE) goto error;
|
345
|
-
}
|
346
|
-
|
347
|
-
err = grpc_set_socket_nonblocking(fd, 1);
|
348
|
-
if (err != GRPC_ERROR_NONE) goto error;
|
349
|
-
err = grpc_set_socket_cloexec(fd, 1);
|
350
|
-
if (err != GRPC_ERROR_NONE) goto error;
|
351
|
-
if (!grpc_is_unix_socket(addr)) {
|
352
|
-
err = grpc_set_socket_low_latency(fd, 1);
|
353
|
-
if (err != GRPC_ERROR_NONE) goto error;
|
354
|
-
err = grpc_set_socket_reuse_addr(fd, 1);
|
355
|
-
if (err != GRPC_ERROR_NONE) goto error;
|
356
|
-
}
|
357
|
-
err = grpc_set_socket_no_sigpipe_if_possible(fd);
|
358
|
-
if (err != GRPC_ERROR_NONE) goto error;
|
359
|
-
|
360
|
-
GPR_ASSERT(addr->len < ~(socklen_t)0);
|
361
|
-
if (bind(fd, (struct sockaddr *)addr->addr, (socklen_t)addr->len) < 0) {
|
362
|
-
err = GRPC_OS_ERROR(errno, "bind");
|
363
|
-
goto error;
|
364
|
-
}
|
365
|
-
|
366
|
-
if (listen(fd, get_max_accept_queue_size()) < 0) {
|
367
|
-
err = GRPC_OS_ERROR(errno, "listen");
|
368
|
-
goto error;
|
369
|
-
}
|
370
|
-
|
371
|
-
sockname_temp.len = sizeof(struct sockaddr_storage);
|
372
|
-
|
373
|
-
if (getsockname(fd, (struct sockaddr *)sockname_temp.addr,
|
374
|
-
(socklen_t *)&sockname_temp.len) < 0) {
|
375
|
-
err = GRPC_OS_ERROR(errno, "getsockname");
|
376
|
-
goto error;
|
377
|
-
}
|
378
|
-
|
379
|
-
*port = grpc_sockaddr_get_port(&sockname_temp);
|
380
|
-
return GRPC_ERROR_NONE;
|
381
|
-
|
382
|
-
error:
|
383
|
-
GPR_ASSERT(err != GRPC_ERROR_NONE);
|
384
|
-
if (fd >= 0) {
|
385
|
-
close(fd);
|
386
|
-
}
|
387
|
-
grpc_error *ret = grpc_error_set_int(
|
388
|
-
GRPC_ERROR_CREATE_REFERENCING("Unable to configure socket", &err, 1),
|
389
|
-
GRPC_ERROR_INT_FD, fd);
|
390
|
-
GRPC_ERROR_UNREF(err);
|
391
|
-
return ret;
|
392
|
-
}
|
393
|
-
|
394
213
|
/* event manager callback when reads are ready */
|
395
214
|
static void on_read(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *err) {
|
396
215
|
grpc_tcp_listener *sp = arg;
|
@@ -454,8 +273,7 @@ static void on_read(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *err) {
|
|
454
273
|
|
455
274
|
sp->server->on_accept_cb(
|
456
275
|
exec_ctx, sp->server->on_accept_cb_arg,
|
457
|
-
grpc_tcp_create(fdobj, sp->server->
|
458
|
-
GRPC_TCP_DEFAULT_READ_SLICE_SIZE, addr_str),
|
276
|
+
grpc_tcp_create(exec_ctx, fdobj, sp->server->channel_args, addr_str),
|
459
277
|
read_notifier_pollset, acceptor);
|
460
278
|
|
461
279
|
gpr_free(name);
|
@@ -474,216 +292,6 @@ error:
|
|
474
292
|
}
|
475
293
|
}
|
476
294
|
|
477
|
-
static grpc_error *add_socket_to_server(grpc_tcp_server *s, int fd,
|
478
|
-
const grpc_resolved_address *addr,
|
479
|
-
unsigned port_index, unsigned fd_index,
|
480
|
-
grpc_tcp_listener **listener) {
|
481
|
-
grpc_tcp_listener *sp = NULL;
|
482
|
-
int port = -1;
|
483
|
-
char *addr_str;
|
484
|
-
char *name;
|
485
|
-
|
486
|
-
grpc_error *err = prepare_socket(fd, addr, s->so_reuseport, &port);
|
487
|
-
if (err == GRPC_ERROR_NONE) {
|
488
|
-
GPR_ASSERT(port > 0);
|
489
|
-
grpc_sockaddr_to_string(&addr_str, addr, 1);
|
490
|
-
gpr_asprintf(&name, "tcp-server-listener:%s", addr_str);
|
491
|
-
gpr_mu_lock(&s->mu);
|
492
|
-
s->nports++;
|
493
|
-
GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server");
|
494
|
-
sp = gpr_malloc(sizeof(grpc_tcp_listener));
|
495
|
-
sp->next = NULL;
|
496
|
-
if (s->head == NULL) {
|
497
|
-
s->head = sp;
|
498
|
-
} else {
|
499
|
-
s->tail->next = sp;
|
500
|
-
}
|
501
|
-
s->tail = sp;
|
502
|
-
sp->server = s;
|
503
|
-
sp->fd = fd;
|
504
|
-
sp->emfd = grpc_fd_create(fd, name);
|
505
|
-
memcpy(&sp->addr, addr, sizeof(grpc_resolved_address));
|
506
|
-
sp->port = port;
|
507
|
-
sp->port_index = port_index;
|
508
|
-
sp->fd_index = fd_index;
|
509
|
-
sp->is_sibling = 0;
|
510
|
-
sp->sibling = NULL;
|
511
|
-
GPR_ASSERT(sp->emfd);
|
512
|
-
gpr_mu_unlock(&s->mu);
|
513
|
-
gpr_free(addr_str);
|
514
|
-
gpr_free(name);
|
515
|
-
}
|
516
|
-
|
517
|
-
*listener = sp;
|
518
|
-
return err;
|
519
|
-
}
|
520
|
-
|
521
|
-
/* If successful, add a listener to s for addr, set *dsmode for the socket, and
|
522
|
-
return the *listener. */
|
523
|
-
static grpc_error *add_addr_to_server(grpc_tcp_server *s,
|
524
|
-
const grpc_resolved_address *addr,
|
525
|
-
unsigned port_index, unsigned fd_index,
|
526
|
-
grpc_dualstack_mode *dsmode,
|
527
|
-
grpc_tcp_listener **listener) {
|
528
|
-
grpc_resolved_address addr4_copy;
|
529
|
-
int fd;
|
530
|
-
grpc_error *err =
|
531
|
-
grpc_create_dualstack_socket(addr, SOCK_STREAM, 0, dsmode, &fd);
|
532
|
-
if (err != GRPC_ERROR_NONE) {
|
533
|
-
return err;
|
534
|
-
}
|
535
|
-
if (*dsmode == GRPC_DSMODE_IPV4 &&
|
536
|
-
grpc_sockaddr_is_v4mapped(addr, &addr4_copy)) {
|
537
|
-
addr = &addr4_copy;
|
538
|
-
}
|
539
|
-
return add_socket_to_server(s, fd, addr, port_index, fd_index, listener);
|
540
|
-
}
|
541
|
-
|
542
|
-
/* Bind to "::" to get a port number not used by any address. */
|
543
|
-
static grpc_error *get_unused_port(int *port) {
|
544
|
-
grpc_resolved_address wild;
|
545
|
-
grpc_sockaddr_make_wildcard6(0, &wild);
|
546
|
-
grpc_dualstack_mode dsmode;
|
547
|
-
int fd;
|
548
|
-
grpc_error *err =
|
549
|
-
grpc_create_dualstack_socket(&wild, SOCK_STREAM, 0, &dsmode, &fd);
|
550
|
-
if (err != GRPC_ERROR_NONE) {
|
551
|
-
return err;
|
552
|
-
}
|
553
|
-
if (dsmode == GRPC_DSMODE_IPV4) {
|
554
|
-
grpc_sockaddr_make_wildcard4(0, &wild);
|
555
|
-
}
|
556
|
-
if (bind(fd, (const struct sockaddr *)wild.addr, (socklen_t)wild.len) != 0) {
|
557
|
-
err = GRPC_OS_ERROR(errno, "bind");
|
558
|
-
close(fd);
|
559
|
-
return err;
|
560
|
-
}
|
561
|
-
if (getsockname(fd, (struct sockaddr *)wild.addr, (socklen_t *)&wild.len) !=
|
562
|
-
0) {
|
563
|
-
err = GRPC_OS_ERROR(errno, "getsockname");
|
564
|
-
close(fd);
|
565
|
-
return err;
|
566
|
-
}
|
567
|
-
close(fd);
|
568
|
-
*port = grpc_sockaddr_get_port(&wild);
|
569
|
-
return *port <= 0 ? GRPC_ERROR_CREATE("Bad port") : GRPC_ERROR_NONE;
|
570
|
-
}
|
571
|
-
|
572
|
-
/* Return the listener in s with address addr or NULL. */
|
573
|
-
static grpc_tcp_listener *find_listener_with_addr(grpc_tcp_server *s,
|
574
|
-
grpc_resolved_address *addr) {
|
575
|
-
grpc_tcp_listener *l;
|
576
|
-
gpr_mu_lock(&s->mu);
|
577
|
-
for (l = s->head; l != NULL; l = l->next) {
|
578
|
-
if (l->addr.len != addr->len) {
|
579
|
-
continue;
|
580
|
-
}
|
581
|
-
if (memcmp(l->addr.addr, addr->addr, addr->len) == 0) {
|
582
|
-
break;
|
583
|
-
}
|
584
|
-
}
|
585
|
-
gpr_mu_unlock(&s->mu);
|
586
|
-
return l;
|
587
|
-
}
|
588
|
-
|
589
|
-
/* Get all addresses assigned to network interfaces on the machine and create a
|
590
|
-
listener for each. requested_port is the port to use for every listener, or 0
|
591
|
-
to select one random port that will be used for every listener. Set *out_port
|
592
|
-
to the port selected. Return GRPC_ERROR_NONE only if all listeners were
|
593
|
-
added. */
|
594
|
-
static grpc_error *add_all_local_addrs_to_server(grpc_tcp_server *s,
|
595
|
-
unsigned port_index,
|
596
|
-
int requested_port,
|
597
|
-
int *out_port) {
|
598
|
-
struct ifaddrs *ifa = NULL;
|
599
|
-
struct ifaddrs *ifa_it;
|
600
|
-
unsigned fd_index = 0;
|
601
|
-
grpc_tcp_listener *sp = NULL;
|
602
|
-
grpc_error *err = GRPC_ERROR_NONE;
|
603
|
-
if (requested_port == 0) {
|
604
|
-
/* Note: There could be a race where some local addrs can listen on the
|
605
|
-
selected port and some can't. The sane way to handle this would be to
|
606
|
-
retry by recreating the whole grpc_tcp_server. Backing out individual
|
607
|
-
listeners and orphaning the FDs looks like too much trouble. */
|
608
|
-
if ((err = get_unused_port(&requested_port)) != GRPC_ERROR_NONE) {
|
609
|
-
return err;
|
610
|
-
} else if (requested_port <= 0) {
|
611
|
-
return GRPC_ERROR_CREATE("Bad get_unused_port()");
|
612
|
-
}
|
613
|
-
gpr_log(GPR_DEBUG, "Picked unused port %d", requested_port);
|
614
|
-
}
|
615
|
-
if (getifaddrs(&ifa) != 0 || ifa == NULL) {
|
616
|
-
return GRPC_OS_ERROR(errno, "getifaddrs");
|
617
|
-
}
|
618
|
-
for (ifa_it = ifa; ifa_it != NULL; ifa_it = ifa_it->ifa_next) {
|
619
|
-
grpc_resolved_address addr;
|
620
|
-
char *addr_str = NULL;
|
621
|
-
grpc_dualstack_mode dsmode;
|
622
|
-
grpc_tcp_listener *new_sp = NULL;
|
623
|
-
const char *ifa_name = (ifa_it->ifa_name ? ifa_it->ifa_name : "<unknown>");
|
624
|
-
if (ifa_it->ifa_addr == NULL) {
|
625
|
-
continue;
|
626
|
-
} else if (ifa_it->ifa_addr->sa_family == AF_INET) {
|
627
|
-
addr.len = sizeof(struct sockaddr_in);
|
628
|
-
} else if (ifa_it->ifa_addr->sa_family == AF_INET6) {
|
629
|
-
addr.len = sizeof(struct sockaddr_in6);
|
630
|
-
} else {
|
631
|
-
continue;
|
632
|
-
}
|
633
|
-
memcpy(addr.addr, ifa_it->ifa_addr, addr.len);
|
634
|
-
if (!grpc_sockaddr_set_port(&addr, requested_port)) {
|
635
|
-
/* Should never happen, because we check sa_family above. */
|
636
|
-
err = GRPC_ERROR_CREATE("Failed to set port");
|
637
|
-
break;
|
638
|
-
}
|
639
|
-
if (grpc_sockaddr_to_string(&addr_str, &addr, 0) < 0) {
|
640
|
-
addr_str = gpr_strdup("<error>");
|
641
|
-
}
|
642
|
-
gpr_log(GPR_DEBUG,
|
643
|
-
"Adding local addr from interface %s flags 0x%x to server: %s",
|
644
|
-
ifa_name, ifa_it->ifa_flags, addr_str);
|
645
|
-
/* We could have multiple interfaces with the same address (e.g., bonding),
|
646
|
-
so look for duplicates. */
|
647
|
-
if (find_listener_with_addr(s, &addr) != NULL) {
|
648
|
-
gpr_log(GPR_DEBUG, "Skipping duplicate addr %s on interface %s", addr_str,
|
649
|
-
ifa_name);
|
650
|
-
gpr_free(addr_str);
|
651
|
-
continue;
|
652
|
-
}
|
653
|
-
if ((err = add_addr_to_server(s, &addr, port_index, fd_index, &dsmode,
|
654
|
-
&new_sp)) != GRPC_ERROR_NONE) {
|
655
|
-
char *err_str = NULL;
|
656
|
-
grpc_error *root_err;
|
657
|
-
if (gpr_asprintf(&err_str, "Failed to add listener: %s", addr_str) < 0) {
|
658
|
-
err_str = gpr_strdup("Failed to add listener");
|
659
|
-
}
|
660
|
-
root_err = GRPC_ERROR_CREATE(err_str);
|
661
|
-
gpr_free(err_str);
|
662
|
-
gpr_free(addr_str);
|
663
|
-
err = grpc_error_add_child(root_err, err);
|
664
|
-
break;
|
665
|
-
} else {
|
666
|
-
GPR_ASSERT(requested_port == new_sp->port);
|
667
|
-
++fd_index;
|
668
|
-
if (sp != NULL) {
|
669
|
-
new_sp->is_sibling = 1;
|
670
|
-
sp->sibling = new_sp;
|
671
|
-
}
|
672
|
-
sp = new_sp;
|
673
|
-
}
|
674
|
-
gpr_free(addr_str);
|
675
|
-
}
|
676
|
-
freeifaddrs(ifa);
|
677
|
-
if (err != GRPC_ERROR_NONE) {
|
678
|
-
return err;
|
679
|
-
} else if (sp == NULL) {
|
680
|
-
return GRPC_ERROR_CREATE("No local addresses");
|
681
|
-
} else {
|
682
|
-
*out_port = sp->port;
|
683
|
-
return GRPC_ERROR_NONE;
|
684
|
-
}
|
685
|
-
}
|
686
|
-
|
687
295
|
/* Treat :: or 0.0.0.0 as a family-agnostic wildcard. */
|
688
296
|
static grpc_error *add_wildcard_addrs_to_server(grpc_tcp_server *s,
|
689
297
|
unsigned port_index,
|
@@ -698,14 +306,16 @@ static grpc_error *add_wildcard_addrs_to_server(grpc_tcp_server *s,
|
|
698
306
|
grpc_error *v6_err = GRPC_ERROR_NONE;
|
699
307
|
grpc_error *v4_err = GRPC_ERROR_NONE;
|
700
308
|
*out_port = -1;
|
701
|
-
|
702
|
-
|
703
|
-
|
309
|
+
|
310
|
+
if (grpc_tcp_server_have_ifaddrs() && s->expand_wildcard_addrs) {
|
311
|
+
return grpc_tcp_server_add_all_local_addrs(s, port_index, requested_port,
|
312
|
+
out_port);
|
704
313
|
}
|
314
|
+
|
705
315
|
grpc_sockaddr_make_wildcards(requested_port, &wild4, &wild6);
|
706
316
|
/* Try listening on IPv6 first. */
|
707
|
-
if ((v6_err =
|
708
|
-
|
317
|
+
if ((v6_err = grpc_tcp_server_add_addr(s, &wild6, port_index, fd_index,
|
318
|
+
&dsmode, &sp)) == GRPC_ERROR_NONE) {
|
709
319
|
++fd_index;
|
710
320
|
requested_port = *out_port = sp->port;
|
711
321
|
if (dsmode == GRPC_DSMODE_DUALSTACK || dsmode == GRPC_DSMODE_IPV4) {
|
@@ -714,8 +324,8 @@ static grpc_error *add_wildcard_addrs_to_server(grpc_tcp_server *s,
|
|
714
324
|
}
|
715
325
|
/* If we got a v6-only socket or nothing, try adding 0.0.0.0. */
|
716
326
|
grpc_sockaddr_set_port(&wild4, requested_port);
|
717
|
-
if ((v4_err =
|
718
|
-
|
327
|
+
if ((v4_err = grpc_tcp_server_add_addr(s, &wild4, port_index, fd_index,
|
328
|
+
&dsmode, &sp2)) == GRPC_ERROR_NONE) {
|
719
329
|
*out_port = sp2->port;
|
720
330
|
if (sp != NULL) {
|
721
331
|
sp2->is_sibling = 1;
|
@@ -723,12 +333,24 @@ static grpc_error *add_wildcard_addrs_to_server(grpc_tcp_server *s,
|
|
723
333
|
}
|
724
334
|
}
|
725
335
|
if (*out_port > 0) {
|
726
|
-
|
727
|
-
|
336
|
+
if (v6_err != GRPC_ERROR_NONE) {
|
337
|
+
gpr_log(GPR_INFO,
|
338
|
+
"Failed to add :: listener, "
|
339
|
+
"the environment may not support IPv6: %s",
|
340
|
+
grpc_error_string(v6_err));
|
341
|
+
GRPC_ERROR_UNREF(v6_err);
|
342
|
+
}
|
343
|
+
if (v4_err != GRPC_ERROR_NONE) {
|
344
|
+
gpr_log(GPR_INFO,
|
345
|
+
"Failed to add 0.0.0.0 listener, "
|
346
|
+
"the environment may not support IPv4: %s",
|
347
|
+
grpc_error_string(v4_err));
|
348
|
+
GRPC_ERROR_UNREF(v4_err);
|
349
|
+
}
|
728
350
|
return GRPC_ERROR_NONE;
|
729
351
|
} else {
|
730
|
-
grpc_error *root_err =
|
731
|
-
|
352
|
+
grpc_error *root_err = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
353
|
+
"Failed to add any wildcard listeners");
|
732
354
|
GPR_ASSERT(v6_err != GRPC_ERROR_NONE && v4_err != GRPC_ERROR_NONE);
|
733
355
|
root_err = grpc_error_add_child(root_err, v6_err);
|
734
356
|
root_err = grpc_error_add_child(root_err, v4_err);
|
@@ -753,7 +375,7 @@ static grpc_error *clone_port(grpc_tcp_listener *listener, unsigned count) {
|
|
753
375
|
err = grpc_create_dualstack_socket(&listener->addr, SOCK_STREAM, 0, &dsmode,
|
754
376
|
&fd);
|
755
377
|
if (err != GRPC_ERROR_NONE) return err;
|
756
|
-
err =
|
378
|
+
err = grpc_tcp_server_prepare_socket(fd, &listener->addr, true, &port);
|
757
379
|
if (err != GRPC_ERROR_NONE) return err;
|
758
380
|
listener->server->nports++;
|
759
381
|
grpc_sockaddr_to_string(&addr_str, &listener->addr, 1);
|
@@ -825,7 +447,7 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s,
|
|
825
447
|
if (grpc_sockaddr_to_v4mapped(addr, &addr6_v4mapped)) {
|
826
448
|
addr = &addr6_v4mapped;
|
827
449
|
}
|
828
|
-
if ((err =
|
450
|
+
if ((err = grpc_tcp_server_add_addr(s, addr, port_index, 0, &dsmode, &sp)) ==
|
829
451
|
GRPC_ERROR_NONE) {
|
830
452
|
*out_port = sp->port;
|
831
453
|
}
|
@@ -948,7 +570,7 @@ void grpc_tcp_server_shutdown_listeners(grpc_exec_ctx *exec_ctx,
|
|
948
570
|
grpc_tcp_listener *sp;
|
949
571
|
for (sp = s->head; sp; sp = sp->next) {
|
950
572
|
grpc_fd_shutdown(exec_ctx, sp->emfd,
|
951
|
-
|
573
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"));
|
952
574
|
}
|
953
575
|
}
|
954
576
|
gpr_mu_unlock(&s->mu);
|