grpc 0.14.1 → 0.15.0
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 +1398 -817
- data/include/grpc/compression.h +2 -1
- data/include/grpc/grpc.h +10 -1
- data/include/grpc/grpc_cronet.h +51 -0
- data/include/grpc/grpc_posix.h +70 -0
- data/include/grpc/impl/codegen/atm.h +2 -2
- data/include/grpc/impl/codegen/{atm_win32.h → atm_windows.h} +3 -3
- data/include/grpc/impl/codegen/compression_types.h +39 -5
- data/include/grpc/impl/codegen/connectivity_state.h +1 -1
- data/include/grpc/impl/codegen/grpc_types.h +10 -0
- data/include/grpc/impl/codegen/log.h +2 -1
- data/include/grpc/impl/codegen/port_platform.h +30 -12
- data/include/grpc/impl/codegen/slice_buffer.h +2 -3
- data/include/grpc/impl/codegen/sync.h +2 -2
- data/include/grpc/impl/codegen/{sync_win32.h → sync_windows.h} +3 -3
- data/include/grpc/support/{sync_win32.h → atm_windows.h} +4 -4
- data/include/grpc/support/avl.h +5 -0
- data/include/grpc/support/{log_win32.h → log_windows.h} +3 -3
- data/include/grpc/support/string_util.h +2 -1
- data/include/grpc/support/{atm_win32.h → sync_windows.h} +4 -4
- data/src/core/ext/census/gen/census.pb.c +179 -0
- data/src/core/ext/census/gen/census.pb.h +294 -0
- data/src/core/ext/census/grpc_filter.c +11 -7
- data/src/core/ext/client_config/channel_connectivity.c +28 -14
- data/src/core/ext/client_config/client_channel.c +77 -53
- data/src/core/ext/client_config/connector.h +1 -1
- data/src/core/ext/client_config/lb_policy.c +9 -6
- data/src/core/ext/client_config/lb_policy.h +9 -5
- data/src/core/ext/client_config/subchannel.c +58 -39
- data/src/core/ext/client_config/subchannel.h +3 -2
- data/src/core/ext/client_config/subchannel_call_holder.c +34 -19
- data/src/core/ext/client_config/subchannel_call_holder.h +2 -1
- data/src/core/ext/client_config/subchannel_index.c +20 -9
- data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +7 -7
- data/src/core/ext/lb_policy/grpclb/load_balancer_api.h +5 -5
- data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/{v0 → v1}/load_balancer.pb.c +29 -30
- data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +178 -0
- data/src/core/ext/lb_policy/pick_first/pick_first.c +65 -45
- data/src/core/ext/lb_policy/round_robin/round_robin.c +84 -43
- data/src/core/ext/load_reporting/load_reporting.c +133 -0
- data/src/core/ext/load_reporting/load_reporting.h +75 -0
- data/src/core/ext/load_reporting/load_reporting_filter.c +151 -0
- data/src/core/ext/load_reporting/load_reporting_filter.h +41 -0
- data/src/core/ext/resolver/dns/native/dns_resolver.c +22 -8
- data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +2 -2
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +4 -4
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +14 -18
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +49 -24
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +82 -0
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +104 -60
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +232 -0
- data/src/{ruby/ext/grpc/rb_signal.c → core/ext/transport/chttp2/transport/bin_decoder.h} +27 -31
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +481 -260
- data/src/core/ext/transport/chttp2/transport/frame.h +1 -7
- data/src/core/ext/transport/chttp2/transport/frame_data.c +44 -27
- data/src/core/ext/transport/chttp2/transport/frame_data.h +6 -5
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +23 -17
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +12 -7
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -3
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +25 -12
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +23 -21
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +17 -9
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +365 -287
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -6
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +24 -20
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +5 -4
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +1 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +1 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +34 -32
- data/src/core/ext/transport/chttp2/transport/parsing.c +296 -212
- data/src/core/ext/transport/chttp2/transport/writing.c +12 -9
- data/src/core/lib/channel/channel_args.c +26 -12
- data/src/core/lib/channel/channel_args.h +1 -1
- data/src/core/lib/channel/channel_stack.c +12 -8
- data/src/core/lib/channel/channel_stack.h +27 -11
- data/src/core/lib/channel/channel_stack_builder.c +2 -2
- data/src/core/lib/channel/compress_filter.c +26 -31
- data/src/core/lib/channel/compress_filter.h +4 -4
- data/src/core/lib/channel/connected_channel.c +7 -5
- data/src/core/lib/channel/http_client_filter.c +34 -8
- data/src/core/lib/channel/http_client_filter.h +1 -1
- data/src/core/lib/channel/http_server_filter.c +21 -12
- data/src/core/lib/compression/{compression_algorithm.c → compression.c} +22 -21
- data/src/core/lib/http/httpcli.c +81 -59
- data/src/core/lib/http/httpcli.h +11 -15
- data/src/core/lib/http/httpcli_security_connector.c +5 -3
- data/src/core/lib/http/parser.c +127 -118
- data/src/core/lib/http/parser.h +11 -6
- data/src/core/lib/iomgr/closure.c +20 -16
- data/src/core/lib/iomgr/closure.h +19 -15
- data/src/core/lib/iomgr/endpoint.h +1 -1
- data/src/core/lib/iomgr/endpoint_pair_posix.c +2 -2
- data/src/core/lib/iomgr/error.c +535 -0
- data/src/core/lib/iomgr/error.h +192 -0
- data/src/core/lib/iomgr/ev_poll_and_epoll_posix.c +190 -83
- data/src/core/lib/iomgr/ev_poll_posix.c +1267 -0
- data/src/{ruby/ext/grpc/rb_signal.h → core/lib/iomgr/ev_poll_posix.h} +7 -5
- data/src/core/lib/iomgr/ev_posix.c +104 -14
- data/src/core/lib/iomgr/ev_posix.h +17 -7
- data/src/core/lib/iomgr/exec_ctx.c +25 -7
- data/src/core/lib/iomgr/exec_ctx.h +27 -8
- data/src/core/lib/iomgr/executor.c +2 -2
- data/src/core/lib/iomgr/executor.h +1 -1
- data/src/core/lib/iomgr/iocp_windows.c +2 -41
- data/src/core/lib/iomgr/iocp_windows.h +0 -8
- data/src/core/lib/iomgr/iomgr.c +5 -4
- data/src/core/lib/iomgr/iomgr_posix.c +5 -1
- data/src/core/lib/iomgr/iomgr_windows.c +1 -1
- data/src/core/lib/{support → iomgr}/load_file.c +15 -17
- data/src/core/lib/{support → iomgr}/load_file.h +8 -7
- data/src/core/lib/iomgr/polling_entity.c +104 -0
- data/src/core/lib/iomgr/polling_entity.h +81 -0
- data/src/core/lib/iomgr/pollset.h +6 -5
- data/src/core/lib/iomgr/pollset_set_windows.c +4 -1
- data/src/core/lib/iomgr/pollset_windows.c +10 -6
- data/src/core/lib/iomgr/resolve_address.h +5 -9
- data/src/core/lib/iomgr/resolve_address_posix.c +55 -38
- data/src/core/lib/iomgr/resolve_address_windows.c +51 -37
- data/src/core/lib/iomgr/sockaddr.h +2 -2
- data/src/core/lib/iomgr/{sockaddr_win32.h → sockaddr_windows.h} +3 -3
- data/src/core/lib/iomgr/socket_utils_common_posix.c +92 -45
- data/src/core/lib/iomgr/socket_utils_posix.h +19 -12
- data/src/core/lib/iomgr/socket_windows.c +61 -2
- data/src/core/lib/iomgr/socket_windows.h +13 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +54 -39
- data/src/core/lib/iomgr/tcp_client_windows.c +34 -34
- data/src/core/lib/iomgr/tcp_posix.c +43 -39
- data/src/core/lib/iomgr/tcp_server.h +5 -3
- data/src/core/lib/iomgr/tcp_server_posix.c +103 -64
- data/src/core/lib/iomgr/tcp_server_windows.c +114 -101
- data/src/core/lib/iomgr/tcp_windows.c +45 -50
- data/src/core/lib/iomgr/tcp_windows.h +1 -1
- data/src/core/lib/iomgr/timer.c +26 -13
- data/src/core/lib/iomgr/udp_server.c +28 -4
- data/src/core/lib/iomgr/udp_server.h +5 -1
- data/src/core/lib/iomgr/unix_sockets_posix.c +8 -7
- data/src/core/lib/iomgr/unix_sockets_posix.h +2 -1
- data/src/core/lib/iomgr/unix_sockets_posix_noop.c +4 -2
- data/src/core/lib/iomgr/wakeup_fd_eventfd.c +15 -5
- data/src/core/lib/iomgr/wakeup_fd_pipe.c +13 -9
- data/src/core/lib/iomgr/wakeup_fd_posix.c +6 -6
- data/src/core/lib/iomgr/wakeup_fd_posix.h +9 -6
- data/src/core/lib/iomgr/workqueue.h +5 -4
- data/src/core/lib/iomgr/workqueue_posix.c +40 -26
- data/src/core/lib/iomgr/workqueue_windows.c +2 -2
- data/src/core/lib/profiling/basic_timers.c +2 -2
- data/src/core/lib/security/{security_context.c → context/security_context.c} +1 -1
- data/src/core/lib/security/{security_context.h → context/security_context.h} +4 -4
- data/src/core/lib/security/credentials/composite/composite_credentials.c +263 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
- data/src/core/lib/security/credentials/credentials.c +233 -0
- data/src/core/lib/security/{credentials.h → credentials/credentials.h} +19 -157
- data/src/core/lib/security/{credentials_metadata.c → credentials/credentials_metadata.c} +1 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.c +139 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.h +56 -0
- data/src/core/lib/security/{credentials_posix.c → credentials/google_default/credentials_posix.c} +1 -1
- data/src/core/lib/security/{credentials_win32.c → credentials/google_default/credentials_windows.c} +3 -3
- data/src/core/lib/security/{google_default_credentials.c → credentials/google_default/google_default_credentials.c} +93 -35
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +46 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
- data/src/core/lib/security/{json_token.c → credentials/jwt/json_token.c} +10 -101
- data/src/core/lib/security/{json_token.h → credentials/jwt/json_token.h} +3 -33
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +160 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +62 -0
- data/src/core/lib/security/{jwt_verifier.c → credentials/jwt/jwt_verifier.c} +35 -15
- data/src/core/lib/security/{jwt_verifier.h → credentials/jwt/jwt_verifier.h} +3 -3
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +433 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +129 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +240 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
- data/src/core/lib/security/{auth_filters.h → transport/auth_filters.h} +3 -3
- data/src/core/lib/security/{client_auth_filter.c → transport/client_auth_filter.c} +27 -20
- data/src/core/lib/security/{handshake.c → transport/handshake.c} +77 -45
- data/src/core/lib/security/{handshake.h → transport/handshake.h} +9 -11
- data/src/core/lib/security/{secure_endpoint.c → transport/secure_endpoint.c} +19 -12
- data/src/core/lib/security/{secure_endpoint.h → transport/secure_endpoint.h} +3 -3
- data/src/core/lib/security/{security_connector.c → transport/security_connector.c} +26 -17
- data/src/core/lib/security/{security_connector.h → transport/security_connector.h} +8 -8
- data/src/core/lib/security/{server_auth_filter.c → transport/server_auth_filter.c} +24 -16
- data/src/core/lib/security/transport/tsi_error.c +40 -0
- data/src/core/lib/security/transport/tsi_error.h +42 -0
- data/src/core/lib/security/{b64.c → util/b64.c} +1 -1
- data/src/core/lib/security/{b64.h → util/b64.h} +3 -3
- data/src/core/lib/security/util/json_util.c +61 -0
- data/src/core/lib/security/util/json_util.h +55 -0
- data/src/core/lib/support/avl.c +11 -0
- data/src/core/lib/support/cpu_windows.c +2 -2
- data/src/core/lib/support/{env_win32.c → env_windows.c} +3 -3
- data/src/core/lib/support/log.c +3 -1
- data/src/core/lib/support/log_linux.c +2 -2
- data/src/core/lib/support/{log_win32.c → log_windows.c} +4 -4
- data/src/core/lib/support/murmur_hash.c +3 -5
- data/src/core/lib/support/string.c +10 -0
- data/src/core/lib/support/string.h +4 -0
- data/src/core/lib/support/{string_util_win32.c → string_util_windows.c} +3 -3
- data/src/core/lib/support/{string_win32.c → string_windows.c} +2 -2
- data/src/core/lib/support/{string_win32.h → string_windows.h} +5 -5
- data/src/core/lib/support/subprocess_windows.c +1 -1
- data/src/core/lib/support/{sync_win32.c → sync_windows.c} +2 -2
- data/src/core/lib/support/{thd_win32.c → thd_windows.c} +2 -2
- data/src/core/lib/support/{time_win32.c → time_windows.c} +2 -2
- data/src/core/lib/support/tmpfile_msys.c +1 -1
- data/src/core/lib/support/{tmpfile_win32.c → tmpfile_windows.c} +3 -3
- data/src/core/lib/surface/alarm.c +2 -2
- data/src/core/lib/surface/byte_buffer_reader.c +13 -6
- data/src/core/lib/surface/call.c +323 -123
- data/src/core/lib/surface/call.h +2 -0
- data/src/core/lib/surface/call_log_batch.c +1 -1
- data/src/core/lib/surface/channel.c +64 -15
- data/src/core/lib/surface/channel.h +9 -0
- data/src/core/lib/surface/channel_ping.c +3 -3
- data/src/core/lib/surface/completion_queue.c +75 -19
- data/src/core/lib/surface/completion_queue.h +7 -2
- data/src/core/lib/surface/init.c +2 -1
- data/src/core/lib/surface/init_secure.c +4 -4
- data/src/core/lib/surface/lame_client.c +12 -8
- data/src/core/lib/surface/server.c +213 -120
- data/src/core/lib/surface/server.h +1 -0
- data/src/core/lib/surface/version.c +1 -1
- data/src/core/lib/transport/connectivity_state.c +40 -18
- data/src/core/lib/transport/connectivity_state.h +4 -1
- data/src/core/lib/transport/metadata.c +23 -23
- data/src/core/lib/transport/metadata.h +4 -0
- data/src/core/lib/transport/metadata_batch.c +9 -0
- data/src/core/lib/transport/metadata_batch.h +3 -0
- data/src/core/lib/transport/static_metadata.c +6 -5
- data/src/core/lib/transport/static_metadata.h +64 -60
- data/src/core/lib/transport/transport.c +24 -12
- data/src/core/lib/transport/transport.h +6 -5
- data/src/core/lib/transport/transport_impl.h +4 -0
- data/src/core/lib/transport/transport_op_string.c +2 -2
- data/src/core/plugin_registry/grpc_plugin_registry.c +4 -0
- data/src/ruby/bin/math_services.rb +41 -2
- data/src/ruby/ext/grpc/rb_call.c +42 -40
- data/src/ruby/ext/grpc/rb_channel.c +1 -1
- data/src/ruby/ext/grpc/rb_completion_queue.c +59 -6
- data/src/ruby/ext/grpc/rb_completion_queue.h +1 -1
- data/src/ruby/ext/grpc/rb_grpc.c +1 -3
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +21 -5
- data/src/ruby/ext/grpc/rb_loader.c +1 -1
- data/src/ruby/ext/grpc/rb_server.c +5 -3
- data/src/ruby/lib/grpc.rb +0 -3
- data/src/ruby/lib/grpc/errors.rb +3 -2
- data/src/ruby/lib/grpc/generic/active_call.rb +32 -42
- data/src/ruby/lib/grpc/generic/bidi_call.rb +20 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +31 -54
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +4 -4
- data/src/ruby/lib/grpc/generic/rpc_server.rb +12 -23
- data/src/ruby/lib/grpc/generic/service.rb +8 -8
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_services.rb +30 -2
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb +34 -4
- data/src/ruby/pb/grpc/testing/metrics_services.rb +39 -2
- data/src/ruby/pb/src/proto/grpc/testing/empty.rb +15 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages.rb +84 -0
- data/src/ruby/pb/src/proto/grpc/testing/test.rb +14 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services.rb +110 -0
- data/src/ruby/pb/test/client.rb +5 -2
- data/src/ruby/spec/generic/active_call_spec.rb +3 -2
- data/src/ruby/spec/generic/client_stub_spec.rb +27 -24
- data/src/ruby/spec/generic/rpc_desc_spec.rb +11 -11
- data/src/ruby/spec/generic/rpc_server_spec.rb +42 -61
- data/src/ruby/spec/pb/health/checker_spec.rb +3 -5
- metadata +86 -48
- data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0/load_balancer.pb.h +0 -182
- data/src/core/lib/security/credentials.c +0 -1296
- data/src/ruby/lib/grpc/signals.rb +0 -69
@@ -41,7 +41,7 @@
|
|
41
41
|
|
42
42
|
#include <grpc/support/alloc.h>
|
43
43
|
#include <grpc/support/log.h>
|
44
|
-
#include <grpc/support/
|
44
|
+
#include <grpc/support/log_windows.h>
|
45
45
|
#include <grpc/support/string_util.h>
|
46
46
|
#include <grpc/support/sync.h>
|
47
47
|
#include <grpc/support/time.h>
|
@@ -102,7 +102,8 @@ struct grpc_tcp_server {
|
|
102
102
|
|
103
103
|
/* Public function. Allocates the proper data structures to hold a
|
104
104
|
grpc_tcp_server. */
|
105
|
-
|
105
|
+
grpc_error *grpc_tcp_server_create(grpc_closure *shutdown_complete,
|
106
|
+
grpc_tcp_server **server) {
|
106
107
|
grpc_tcp_server *s = gpr_malloc(sizeof(grpc_tcp_server));
|
107
108
|
gpr_ref_init(&s->refs, 1);
|
108
109
|
gpr_mu_init(&s->mu);
|
@@ -114,12 +115,13 @@ grpc_tcp_server *grpc_tcp_server_create(grpc_closure *shutdown_complete) {
|
|
114
115
|
s->shutdown_starting.head = NULL;
|
115
116
|
s->shutdown_starting.tail = NULL;
|
116
117
|
s->shutdown_complete = shutdown_complete;
|
117
|
-
|
118
|
+
*server = s;
|
119
|
+
return GRPC_ERROR_NONE;
|
118
120
|
}
|
119
121
|
|
120
122
|
static void finish_shutdown(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
|
121
123
|
if (s->shutdown_complete != NULL) {
|
122
|
-
|
124
|
+
grpc_exec_ctx_sched(exec_ctx, s->shutdown_complete, GRPC_ERROR_NONE, NULL);
|
123
125
|
}
|
124
126
|
|
125
127
|
/* Now that the accepts have been aborted, we can destroy the sockets.
|
@@ -143,7 +145,8 @@ grpc_tcp_server *grpc_tcp_server_ref(grpc_tcp_server *s) {
|
|
143
145
|
void grpc_tcp_server_shutdown_starting_add(grpc_tcp_server *s,
|
144
146
|
grpc_closure *shutdown_starting) {
|
145
147
|
gpr_mu_lock(&s->mu);
|
146
|
-
|
148
|
+
grpc_closure_list_append(&s->shutdown_starting, shutdown_starting,
|
149
|
+
GRPC_ERROR_NONE);
|
147
150
|
gpr_mu_unlock(&s->mu);
|
148
151
|
}
|
149
152
|
|
@@ -187,51 +190,49 @@ void grpc_tcp_server_unref(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s) {
|
|
187
190
|
}
|
188
191
|
|
189
192
|
/* Prepare (bind) a recently-created socket for listening. */
|
190
|
-
static
|
191
|
-
|
193
|
+
static grpc_error *prepare_socket(SOCKET sock, const struct sockaddr *addr,
|
194
|
+
size_t addr_len, int *port) {
|
192
195
|
struct sockaddr_storage sockname_temp;
|
193
196
|
socklen_t sockname_len;
|
197
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
194
198
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
char *utf8_message = gpr_format_message(WSAGetLastError());
|
199
|
-
gpr_log(GPR_ERROR, "Unable to prepare socket: %s", utf8_message);
|
200
|
-
gpr_free(utf8_message);
|
201
|
-
goto error;
|
199
|
+
error = grpc_tcp_prepare_socket(sock);
|
200
|
+
if (error != GRPC_ERROR_NONE) {
|
201
|
+
goto failure;
|
202
202
|
}
|
203
203
|
|
204
204
|
if (bind(sock, addr, (int)addr_len) == SOCKET_ERROR) {
|
205
|
-
|
206
|
-
|
207
|
-
grpc_sockaddr_to_string(&addr_str, addr, 0);
|
208
|
-
gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str, utf8_message);
|
209
|
-
gpr_free(utf8_message);
|
210
|
-
gpr_free(addr_str);
|
211
|
-
goto error;
|
205
|
+
error = GRPC_WSA_ERROR(WSAGetLastError(), "bind");
|
206
|
+
goto failure;
|
212
207
|
}
|
213
208
|
|
214
209
|
if (listen(sock, SOMAXCONN) == SOCKET_ERROR) {
|
215
|
-
|
216
|
-
|
217
|
-
gpr_free(utf8_message);
|
218
|
-
goto error;
|
210
|
+
error = GRPC_WSA_ERROR(WSAGetLastError(), "listen");
|
211
|
+
goto failure;
|
219
212
|
}
|
220
213
|
|
221
214
|
sockname_len = sizeof(sockname_temp);
|
222
215
|
if (getsockname(sock, (struct sockaddr *)&sockname_temp, &sockname_len) ==
|
223
216
|
SOCKET_ERROR) {
|
224
|
-
|
225
|
-
|
226
|
-
gpr_free(utf8_message);
|
227
|
-
goto error;
|
217
|
+
error = GRPC_WSA_ERROR(WSAGetLastError(), "getsockname");
|
218
|
+
goto failure;
|
228
219
|
}
|
229
220
|
|
230
|
-
|
221
|
+
*port = grpc_sockaddr_get_port((struct sockaddr *)&sockname_temp);
|
222
|
+
return GRPC_ERROR_NONE;
|
231
223
|
|
232
|
-
|
224
|
+
failure:
|
225
|
+
GPR_ASSERT(error != GRPC_ERROR_NONE);
|
226
|
+
char *tgtaddr = grpc_sockaddr_to_uri(addr);
|
227
|
+
grpc_error *final_error = grpc_error_set_int(
|
228
|
+
grpc_error_set_str(GRPC_ERROR_CREATE_REFERENCING(
|
229
|
+
"Failed to prepare server socket", &error, 1),
|
230
|
+
GRPC_ERROR_STR_TARGET_ADDRESS, tgtaddr),
|
231
|
+
GRPC_ERROR_INT_FD, (intptr_t)sock);
|
232
|
+
gpr_free(tgtaddr);
|
233
|
+
GRPC_ERROR_UNREF(error);
|
233
234
|
if (sock != INVALID_SOCKET) closesocket(sock);
|
234
|
-
return
|
235
|
+
return error;
|
235
236
|
}
|
236
237
|
|
237
238
|
static void decrement_active_ports_and_notify(grpc_exec_ctx *exec_ctx,
|
@@ -251,26 +252,23 @@ static void decrement_active_ports_and_notify(grpc_exec_ctx *exec_ctx,
|
|
251
252
|
|
252
253
|
/* In order to do an async accept, we need to create a socket first which
|
253
254
|
will be the one assigned to the new incoming connection. */
|
254
|
-
static
|
255
|
+
static grpc_error *start_accept(grpc_exec_ctx *exec_ctx,
|
256
|
+
grpc_tcp_listener *port) {
|
255
257
|
SOCKET sock = INVALID_SOCKET;
|
256
|
-
char *message;
|
257
|
-
char *utf8_message;
|
258
258
|
BOOL success;
|
259
259
|
DWORD addrlen = sizeof(struct sockaddr_in6) + 16;
|
260
260
|
DWORD bytes_received = 0;
|
261
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
261
262
|
|
262
263
|
sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0,
|
263
264
|
WSA_FLAG_OVERLAPPED);
|
264
|
-
|
265
265
|
if (sock == INVALID_SOCKET) {
|
266
|
-
|
266
|
+
error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket");
|
267
267
|
goto failure;
|
268
268
|
}
|
269
269
|
|
270
|
-
|
271
|
-
|
272
|
-
goto failure;
|
273
|
-
}
|
270
|
+
error = grpc_tcp_prepare_socket(sock);
|
271
|
+
if (error != GRPC_ERROR_NONE) goto failure;
|
274
272
|
|
275
273
|
/* Start the "accept" asynchronously. */
|
276
274
|
success = port->AcceptEx(port->socket->socket, sock, port->addresses, 0,
|
@@ -280,9 +278,9 @@ static void start_accept(grpc_exec_ctx *exec_ctx, grpc_tcp_listener *port) {
|
|
280
278
|
/* It is possible to get an accept immediately without delay. However, we
|
281
279
|
will still get an IOCP notification for it. So let's just ignore it. */
|
282
280
|
if (!success) {
|
283
|
-
int
|
284
|
-
if (
|
285
|
-
|
281
|
+
int last_error = WSAGetLastError();
|
282
|
+
if (last_error != ERROR_IO_PENDING) {
|
283
|
+
error = GRPC_WSA_ERROR(last_error, "AcceptEx");
|
286
284
|
goto failure;
|
287
285
|
}
|
288
286
|
}
|
@@ -291,9 +289,10 @@ static void start_accept(grpc_exec_ctx *exec_ctx, grpc_tcp_listener *port) {
|
|
291
289
|
immediately process an accept that happened in the meantime. */
|
292
290
|
port->new_socket = sock;
|
293
291
|
grpc_socket_notify_on_read(exec_ctx, port->socket, &port->on_accept);
|
294
|
-
return;
|
292
|
+
return error;
|
295
293
|
|
296
294
|
failure:
|
295
|
+
GPR_ASSERT(error != GRPC_ERROR_NONE);
|
297
296
|
if (port->shutting_down) {
|
298
297
|
/* We are abandoning the listener port, take that into account to prevent
|
299
298
|
occasional hangs on shutdown. The hang happens when sp->shutting_down
|
@@ -301,16 +300,15 @@ failure:
|
|
301
300
|
but we fail there because the listening port has been closed in the
|
302
301
|
meantime. */
|
303
302
|
decrement_active_ports_and_notify(exec_ctx, port);
|
304
|
-
|
303
|
+
GRPC_ERROR_UNREF(error);
|
304
|
+
return GRPC_ERROR_NONE;
|
305
305
|
}
|
306
|
-
utf8_message = gpr_format_message(WSAGetLastError());
|
307
|
-
gpr_log(GPR_ERROR, message, utf8_message);
|
308
|
-
gpr_free(utf8_message);
|
309
306
|
if (sock != INVALID_SOCKET) closesocket(sock);
|
307
|
+
return error;
|
310
308
|
}
|
311
309
|
|
312
310
|
/* Event manager callback when reads are ready. */
|
313
|
-
static void on_accept(grpc_exec_ctx *exec_ctx, void *arg,
|
311
|
+
static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
|
314
312
|
grpc_tcp_listener *sp = arg;
|
315
313
|
grpc_tcp_server_acceptor acceptor = {sp->server, sp->port_index, 0};
|
316
314
|
SOCKET sock = sp->new_socket;
|
@@ -328,7 +326,10 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, bool from_iocp) {
|
|
328
326
|
/* The general mechanism for shutting down is to queue abortion calls. While
|
329
327
|
this is necessary in the read/write case, it's useless for the accept
|
330
328
|
case. We only need to adjust the pending callback count */
|
331
|
-
if (
|
329
|
+
if (error != GRPC_ERROR_NONE) {
|
330
|
+
const char *msg = grpc_error_string(error);
|
331
|
+
gpr_log(GPR_INFO, "Skipping on_accept due to error: %s", msg);
|
332
|
+
grpc_error_free_string(msg);
|
332
333
|
return;
|
333
334
|
}
|
334
335
|
|
@@ -379,28 +380,28 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, bool from_iocp) {
|
|
379
380
|
|
380
381
|
/* The only time we should call our callback, is where we successfully
|
381
382
|
managed to accept a connection, and created an endpoint. */
|
382
|
-
if (ep)
|
383
|
-
sp->server->on_accept_cb(exec_ctx, sp->server->on_accept_cb_arg, ep,
|
383
|
+
if (ep) {
|
384
|
+
sp->server->on_accept_cb(exec_ctx, sp->server->on_accept_cb_arg, ep, NULL,
|
384
385
|
&acceptor);
|
386
|
+
}
|
385
387
|
/* As we were notified from the IOCP of one and exactly one accept,
|
386
388
|
the former socked we created has now either been destroy or assigned
|
387
389
|
to the new connection. We need to create a new one for the next
|
388
390
|
connection. */
|
389
|
-
start_accept(exec_ctx, sp);
|
391
|
+
GPR_ASSERT(GRPC_LOG_IF_ERROR("start_accept", start_accept(exec_ctx, sp)));
|
390
392
|
}
|
391
393
|
|
392
|
-
static
|
393
|
-
|
394
|
-
|
395
|
-
|
394
|
+
static grpc_error *add_socket_to_server(grpc_tcp_server *s, SOCKET sock,
|
395
|
+
const struct sockaddr *addr,
|
396
|
+
size_t addr_len, unsigned port_index,
|
397
|
+
grpc_tcp_listener **listener) {
|
396
398
|
grpc_tcp_listener *sp = NULL;
|
397
|
-
int port;
|
399
|
+
int port = -1;
|
398
400
|
int status;
|
399
401
|
GUID guid = WSAID_ACCEPTEX;
|
400
402
|
DWORD ioctl_num_bytes;
|
401
403
|
LPFN_ACCEPTEX AcceptEx;
|
402
|
-
|
403
|
-
if (sock == INVALID_SOCKET) return NULL;
|
404
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
404
405
|
|
405
406
|
/* We need to grab the AcceptEx pointer for that port, as it may be
|
406
407
|
interface-dependent. We'll cache it to avoid doing that again. */
|
@@ -416,44 +417,49 @@ static grpc_tcp_listener *add_socket_to_server(grpc_tcp_server *s, SOCKET sock,
|
|
416
417
|
return NULL;
|
417
418
|
}
|
418
419
|
|
419
|
-
|
420
|
-
if (
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
s->
|
431
|
-
|
432
|
-
|
433
|
-
sp->shutting_down = 0;
|
434
|
-
sp->AcceptEx = AcceptEx;
|
435
|
-
sp->new_socket = INVALID_SOCKET;
|
436
|
-
sp->port = port;
|
437
|
-
sp->port_index = port_index;
|
438
|
-
grpc_closure_init(&sp->on_accept, on_accept, sp);
|
439
|
-
GPR_ASSERT(sp->socket);
|
440
|
-
gpr_mu_unlock(&s->mu);
|
420
|
+
error = prepare_socket(sock, addr, addr_len, &port);
|
421
|
+
if (error != GRPC_ERROR_NONE) {
|
422
|
+
return error;
|
423
|
+
}
|
424
|
+
|
425
|
+
GPR_ASSERT(port >= 0);
|
426
|
+
gpr_mu_lock(&s->mu);
|
427
|
+
GPR_ASSERT(!s->on_accept_cb && "must add ports before starting server");
|
428
|
+
sp = gpr_malloc(sizeof(grpc_tcp_listener));
|
429
|
+
sp->next = NULL;
|
430
|
+
if (s->head == NULL) {
|
431
|
+
s->head = sp;
|
432
|
+
} else {
|
433
|
+
s->tail->next = sp;
|
441
434
|
}
|
435
|
+
s->tail = sp;
|
436
|
+
sp->server = s;
|
437
|
+
sp->socket = grpc_winsocket_create(sock, "listener");
|
438
|
+
sp->shutting_down = 0;
|
439
|
+
sp->AcceptEx = AcceptEx;
|
440
|
+
sp->new_socket = INVALID_SOCKET;
|
441
|
+
sp->port = port;
|
442
|
+
sp->port_index = port_index;
|
443
|
+
grpc_closure_init(&sp->on_accept, on_accept, sp);
|
444
|
+
GPR_ASSERT(sp->socket);
|
445
|
+
gpr_mu_unlock(&s->mu);
|
446
|
+
*listener = sp;
|
442
447
|
|
443
|
-
return
|
448
|
+
return GRPC_ERROR_NONE;
|
444
449
|
}
|
445
450
|
|
446
|
-
|
447
|
-
|
448
|
-
grpc_tcp_listener *sp;
|
451
|
+
grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
|
452
|
+
size_t addr_len, int *port) {
|
453
|
+
grpc_tcp_listener *sp = NULL;
|
449
454
|
SOCKET sock;
|
450
455
|
struct sockaddr_in6 addr6_v4mapped;
|
451
456
|
struct sockaddr_in6 wildcard;
|
452
457
|
struct sockaddr *allocated_addr = NULL;
|
453
458
|
struct sockaddr_storage sockname_temp;
|
454
459
|
socklen_t sockname_len;
|
455
|
-
int port;
|
456
460
|
unsigned port_index = 0;
|
461
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
462
|
+
|
457
463
|
if (s->tail != NULL) {
|
458
464
|
port_index = s->tail->port_index + 1;
|
459
465
|
}
|
@@ -465,11 +471,11 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
|
|
465
471
|
sockname_len = sizeof(sockname_temp);
|
466
472
|
if (0 == getsockname(sp->socket->socket,
|
467
473
|
(struct sockaddr *)&sockname_temp, &sockname_len)) {
|
468
|
-
port = grpc_sockaddr_get_port((struct sockaddr *)&sockname_temp);
|
469
|
-
if (port > 0) {
|
474
|
+
*port = grpc_sockaddr_get_port((struct sockaddr *)&sockname_temp);
|
475
|
+
if (*port > 0) {
|
470
476
|
allocated_addr = gpr_malloc(addr_len);
|
471
477
|
memcpy(allocated_addr, addr, addr_len);
|
472
|
-
grpc_sockaddr_set_port(allocated_addr, port);
|
478
|
+
grpc_sockaddr_set_port(allocated_addr, *port);
|
473
479
|
addr = allocated_addr;
|
474
480
|
break;
|
475
481
|
}
|
@@ -483,8 +489,8 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
|
|
483
489
|
}
|
484
490
|
|
485
491
|
/* Treat :: or 0.0.0.0 as a family-agnostic wildcard. */
|
486
|
-
if (grpc_sockaddr_is_wildcard(addr,
|
487
|
-
grpc_sockaddr_make_wildcard6(port, &wildcard);
|
492
|
+
if (grpc_sockaddr_is_wildcard(addr, port)) {
|
493
|
+
grpc_sockaddr_make_wildcard6(*port, &wildcard);
|
488
494
|
|
489
495
|
addr = (struct sockaddr *)&wildcard;
|
490
496
|
addr_len = sizeof(wildcard);
|
@@ -493,19 +499,26 @@ int grpc_tcp_server_add_port(grpc_tcp_server *s, const void *addr,
|
|
493
499
|
sock = WSASocket(AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0,
|
494
500
|
WSA_FLAG_OVERLAPPED);
|
495
501
|
if (sock == INVALID_SOCKET) {
|
496
|
-
|
497
|
-
|
498
|
-
gpr_free(utf8_message);
|
502
|
+
error = GRPC_WSA_ERROR(WSAGetLastError(), "WSASocket");
|
503
|
+
goto done;
|
499
504
|
}
|
500
505
|
|
501
|
-
|
506
|
+
error = add_socket_to_server(s, sock, addr, addr_len, port_index, &sp);
|
507
|
+
|
508
|
+
done:
|
502
509
|
gpr_free(allocated_addr);
|
503
510
|
|
504
|
-
if (
|
505
|
-
|
511
|
+
if (error != GRPC_ERROR_NONE) {
|
512
|
+
grpc_error *error_out = GRPC_ERROR_CREATE_REFERENCING(
|
513
|
+
"Failed to add port to server", &error, 1);
|
514
|
+
GRPC_ERROR_UNREF(error);
|
515
|
+
error = error_out;
|
516
|
+
*port = -1;
|
506
517
|
} else {
|
507
|
-
|
518
|
+
GPR_ASSERT(sp != NULL);
|
519
|
+
*port = sp->port;
|
508
520
|
}
|
521
|
+
return error;
|
509
522
|
}
|
510
523
|
|
511
524
|
void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s,
|
@@ -520,7 +533,7 @@ void grpc_tcp_server_start(grpc_exec_ctx *exec_ctx, grpc_tcp_server *s,
|
|
520
533
|
s->on_accept_cb = on_accept_cb;
|
521
534
|
s->on_accept_cb_arg = on_accept_cb_arg;
|
522
535
|
for (sp = s->head; sp; sp = sp->next) {
|
523
|
-
start_accept(exec_ctx, sp);
|
536
|
+
GPR_ASSERT(GRPC_LOG_IF_ERROR("start_accept", start_accept(exec_ctx, sp)));
|
524
537
|
s->active_ports++;
|
525
538
|
}
|
526
539
|
gpr_mu_unlock(&s->mu);
|
@@ -37,11 +37,11 @@
|
|
37
37
|
|
38
38
|
#include <limits.h>
|
39
39
|
|
40
|
-
#include "src/core/lib/iomgr/
|
40
|
+
#include "src/core/lib/iomgr/sockaddr_windows.h"
|
41
41
|
|
42
42
|
#include <grpc/support/alloc.h>
|
43
43
|
#include <grpc/support/log.h>
|
44
|
-
#include <grpc/support/
|
44
|
+
#include <grpc/support/log_windows.h>
|
45
45
|
#include <grpc/support/slice_buffer.h>
|
46
46
|
#include <grpc/support/string_util.h>
|
47
47
|
#include <grpc/support/useful.h>
|
@@ -61,27 +61,34 @@
|
|
61
61
|
#define GRPC_FIONBIO FIONBIO
|
62
62
|
#endif
|
63
63
|
|
64
|
-
static
|
64
|
+
static grpc_error *set_non_block(SOCKET sock) {
|
65
65
|
int status;
|
66
66
|
uint32_t param = 1;
|
67
67
|
DWORD ret;
|
68
68
|
status = WSAIoctl(sock, GRPC_FIONBIO, ¶m, sizeof(param), NULL, 0, &ret,
|
69
69
|
NULL, NULL);
|
70
|
-
return status == 0
|
70
|
+
return status == 0
|
71
|
+
? GRPC_ERROR_NONE
|
72
|
+
: GRPC_WSA_ERROR(WSAGetLastError(), "WSAIoctl(GRPC_FIONBIO)");
|
71
73
|
}
|
72
74
|
|
73
|
-
static
|
75
|
+
static grpc_error *set_dualstack(SOCKET sock) {
|
74
76
|
int status;
|
75
77
|
unsigned long param = 0;
|
76
78
|
status = setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char *)¶m,
|
77
79
|
sizeof(param));
|
78
|
-
return status == 0
|
80
|
+
return status == 0
|
81
|
+
? GRPC_ERROR_NONE
|
82
|
+
: GRPC_WSA_ERROR(WSAGetLastError(), "setsockopt(IPV6_V6ONLY)");
|
79
83
|
}
|
80
84
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
return
|
85
|
+
grpc_error *grpc_tcp_prepare_socket(SOCKET sock) {
|
86
|
+
grpc_error *err;
|
87
|
+
err = set_non_block(sock);
|
88
|
+
if (err != GRPC_ERROR_NONE) return err;
|
89
|
+
err = set_dualstack(sock);
|
90
|
+
if (err != GRPC_ERROR_NONE) return err;
|
91
|
+
return GRPC_ERROR_NONE;
|
85
92
|
}
|
86
93
|
|
87
94
|
typedef struct grpc_tcp {
|
@@ -148,39 +155,35 @@ static void tcp_ref(grpc_tcp *tcp) { gpr_ref(&tcp->refcount); }
|
|
148
155
|
#endif
|
149
156
|
|
150
157
|
/* Asynchronous callback from the IOCP, or the background thread. */
|
151
|
-
static void on_read(grpc_exec_ctx *exec_ctx, void *tcpp,
|
158
|
+
static void on_read(grpc_exec_ctx *exec_ctx, void *tcpp, grpc_error *error) {
|
152
159
|
grpc_tcp *tcp = tcpp;
|
153
160
|
grpc_closure *cb = tcp->read_cb;
|
154
161
|
grpc_winsocket *socket = tcp->socket;
|
155
162
|
gpr_slice sub;
|
156
163
|
grpc_winsocket_callback_info *info = &socket->read_info;
|
157
164
|
|
158
|
-
|
165
|
+
GRPC_ERROR_REF(error);
|
166
|
+
|
167
|
+
if (error == GRPC_ERROR_NONE) {
|
159
168
|
if (info->wsa_error != 0 && !tcp->shutting_down) {
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
gpr_free(utf8_message);
|
164
|
-
}
|
165
|
-
success = 0;
|
169
|
+
char *utf8_message = gpr_format_message(info->wsa_error);
|
170
|
+
error = GRPC_ERROR_CREATE(utf8_message);
|
171
|
+
gpr_free(utf8_message);
|
166
172
|
gpr_slice_unref(tcp->read_slice);
|
167
173
|
} else {
|
168
174
|
if (info->bytes_transfered != 0 && !tcp->shutting_down) {
|
169
175
|
sub = gpr_slice_sub_no_ref(tcp->read_slice, 0, info->bytes_transfered);
|
170
176
|
gpr_slice_buffer_add(tcp->read_slices, sub);
|
171
|
-
success = 1;
|
172
177
|
} else {
|
173
178
|
gpr_slice_unref(tcp->read_slice);
|
174
|
-
|
179
|
+
error = GRPC_ERROR_CREATE("End of TCP stream");
|
175
180
|
}
|
176
181
|
}
|
177
182
|
}
|
178
183
|
|
179
184
|
tcp->read_cb = NULL;
|
180
185
|
TCP_UNREF(tcp, "read");
|
181
|
-
|
182
|
-
cb->cb(exec_ctx, cb->cb_arg, success);
|
183
|
-
}
|
186
|
+
grpc_exec_ctx_sched(exec_ctx, cb, error, NULL);
|
184
187
|
}
|
185
188
|
|
186
189
|
static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
|
@@ -194,7 +197,8 @@ static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
|
|
194
197
|
WSABUF buffer;
|
195
198
|
|
196
199
|
if (tcp->shutting_down) {
|
197
|
-
|
200
|
+
grpc_exec_ctx_sched(exec_ctx, cb,
|
201
|
+
GRPC_ERROR_CREATE("TCP socket is shutting down"), NULL);
|
198
202
|
return;
|
199
203
|
}
|
200
204
|
|
@@ -218,7 +222,7 @@ static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
|
|
218
222
|
/* Did we get data immediately ? Yay. */
|
219
223
|
if (info->wsa_error != WSAEWOULDBLOCK) {
|
220
224
|
info->bytes_transfered = bytes_read;
|
221
|
-
|
225
|
+
grpc_exec_ctx_sched(exec_ctx, &tcp->on_read, GRPC_ERROR_NONE, NULL);
|
222
226
|
return;
|
223
227
|
}
|
224
228
|
|
@@ -231,7 +235,8 @@ static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
|
|
231
235
|
int wsa_error = WSAGetLastError();
|
232
236
|
if (wsa_error != WSA_IO_PENDING) {
|
233
237
|
info->wsa_error = wsa_error;
|
234
|
-
|
238
|
+
grpc_exec_ctx_sched(exec_ctx, &tcp->on_read,
|
239
|
+
GRPC_WSA_ERROR(info->wsa_error, "WSARecv"), NULL);
|
235
240
|
return;
|
236
241
|
}
|
237
242
|
}
|
@@ -240,32 +245,29 @@ static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
|
|
240
245
|
}
|
241
246
|
|
242
247
|
/* Asynchronous callback from the IOCP, or the background thread. */
|
243
|
-
static void on_write(grpc_exec_ctx *exec_ctx, void *tcpp,
|
248
|
+
static void on_write(grpc_exec_ctx *exec_ctx, void *tcpp, grpc_error *error) {
|
244
249
|
grpc_tcp *tcp = (grpc_tcp *)tcpp;
|
245
250
|
grpc_winsocket *handle = tcp->socket;
|
246
251
|
grpc_winsocket_callback_info *info = &handle->write_info;
|
247
252
|
grpc_closure *cb;
|
248
253
|
|
254
|
+
GRPC_ERROR_REF(error);
|
255
|
+
|
249
256
|
gpr_mu_lock(&tcp->mu);
|
250
257
|
cb = tcp->write_cb;
|
251
258
|
tcp->write_cb = NULL;
|
252
259
|
gpr_mu_unlock(&tcp->mu);
|
253
260
|
|
254
|
-
if (
|
261
|
+
if (error == GRPC_ERROR_NONE) {
|
255
262
|
if (info->wsa_error != 0) {
|
256
|
-
|
257
|
-
char *utf8_message = gpr_format_message(info->wsa_error);
|
258
|
-
gpr_log(GPR_ERROR, "WSASend overlapped error: %s", utf8_message);
|
259
|
-
gpr_free(utf8_message);
|
260
|
-
}
|
261
|
-
success = 0;
|
263
|
+
error = GRPC_WSA_ERROR(info->wsa_error, "WSASend");
|
262
264
|
} else {
|
263
265
|
GPR_ASSERT(info->bytes_transfered == tcp->write_slices->length);
|
264
266
|
}
|
265
267
|
}
|
266
268
|
|
267
269
|
TCP_UNREF(tcp, "write");
|
268
|
-
|
270
|
+
grpc_exec_ctx_sched(exec_ctx, cb, error, NULL);
|
269
271
|
}
|
270
272
|
|
271
273
|
/* Initiates a write. */
|
@@ -283,7 +285,8 @@ static void win_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
|
|
283
285
|
size_t len;
|
284
286
|
|
285
287
|
if (tcp->shutting_down) {
|
286
|
-
|
288
|
+
grpc_exec_ctx_sched(exec_ctx, cb,
|
289
|
+
GRPC_ERROR_CREATE("TCP socket is shutting down"), NULL);
|
287
290
|
return;
|
288
291
|
}
|
289
292
|
|
@@ -311,19 +314,10 @@ static void win_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
|
|
311
314
|
connection that has its send queue filled up. But if we don't, then we can
|
312
315
|
avoid doing an async write operation at all. */
|
313
316
|
if (info->wsa_error != WSAEWOULDBLOCK) {
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
} else {
|
319
|
-
if (info->wsa_error != WSAECONNRESET) {
|
320
|
-
char *utf8_message = gpr_format_message(info->wsa_error);
|
321
|
-
gpr_log(GPR_ERROR, "WSASend error: %s", utf8_message);
|
322
|
-
gpr_free(utf8_message);
|
323
|
-
}
|
324
|
-
}
|
325
|
-
if (allocated) gpr_free(allocated);
|
326
|
-
grpc_exec_ctx_enqueue(exec_ctx, cb, ok, NULL);
|
317
|
+
grpc_error *error = status == 0
|
318
|
+
? GRPC_ERROR_NONE
|
319
|
+
: GRPC_WSA_ERROR(info->wsa_error, "WSASend");
|
320
|
+
grpc_exec_ctx_sched(exec_ctx, cb, error, NULL);
|
327
321
|
return;
|
328
322
|
}
|
329
323
|
|
@@ -340,7 +334,8 @@ static void win_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
|
|
340
334
|
int wsa_error = WSAGetLastError();
|
341
335
|
if (wsa_error != WSA_IO_PENDING) {
|
342
336
|
TCP_UNREF(tcp, "write");
|
343
|
-
|
337
|
+
grpc_exec_ctx_sched(exec_ctx, cb, GRPC_WSA_ERROR(wsa_error, "WSASend"),
|
338
|
+
NULL);
|
344
339
|
return;
|
345
340
|
}
|
346
341
|
}
|