grpc 1.3.4 → 1.4.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 +581 -450
- data/include/grpc/census.h +49 -49
- data/include/grpc/grpc.h +16 -70
- data/include/grpc/grpc_security.h +59 -59
- data/include/grpc/grpc_security_constants.h +9 -9
- data/include/grpc/impl/codegen/atm.h +1 -1
- data/include/grpc/impl/codegen/atm_windows.h +4 -4
- data/include/grpc/impl/codegen/byte_buffer_reader.h +2 -2
- data/include/grpc/impl/codegen/compression_types.h +4 -5
- data/include/grpc/impl/codegen/gpr_slice.h +5 -5
- data/include/grpc/impl/codegen/gpr_types.h +6 -7
- data/include/grpc/impl/codegen/grpc_types.h +128 -59
- data/include/grpc/impl/codegen/port_platform.h +6 -0
- data/include/grpc/impl/codegen/propagation_bits.h +2 -2
- data/include/grpc/impl/codegen/slice.h +13 -12
- data/include/grpc/impl/codegen/status.h +23 -18
- data/include/grpc/impl/codegen/sync.h +1 -1
- data/include/grpc/load_reporting.h +6 -6
- data/include/grpc/slice.h +47 -25
- data/include/grpc/slice_buffer.h +18 -14
- data/include/grpc/support/alloc.h +7 -7
- data/include/grpc/support/cmdline.h +10 -10
- data/include/grpc/support/cpu.h +3 -3
- data/include/grpc/support/histogram.h +1 -1
- data/include/grpc/support/host_port.h +2 -2
- data/include/grpc/support/log.h +9 -9
- data/include/grpc/support/log_windows.h +1 -1
- data/include/grpc/support/string_util.h +3 -3
- data/include/grpc/support/subprocess.h +3 -3
- data/include/grpc/support/sync.h +31 -31
- data/include/grpc/support/thd.h +11 -11
- data/include/grpc/support/time.h +12 -12
- data/include/grpc/support/tls.h +1 -1
- data/include/grpc/support/tls_gcc.h +2 -2
- data/include/grpc/support/tls_msvc.h +1 -1
- data/include/grpc/support/tls_pthread.h +1 -1
- data/include/grpc/support/useful.h +2 -2
- data/include/grpc/support/workaround_list.h +46 -0
- data/src/core/ext/census/context.c +1 -1
- data/src/core/ext/census/intrusive_hash_map.c +319 -0
- data/src/core/ext/census/intrusive_hash_map.h +167 -0
- data/src/core/ext/census/intrusive_hash_map_internal.h +63 -0
- data/src/core/ext/census/resource.c +3 -1
- data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
- data/src/core/ext/filters/client_channel/client_channel.c +173 -103
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
- data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +8 -7
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +405 -102
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +90 -51
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +7 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +188 -294
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
- data/src/core/ext/filters/client_channel/parse_address.c +90 -59
- data/src/core/ext/filters/client_channel/parse_address.h +17 -8
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +11 -7
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +59 -14
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +6 -0
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
- data/src/core/ext/filters/client_channel/subchannel.c +20 -17
- data/src/core/ext/filters/client_channel/subchannel.h +1 -0
- data/src/core/ext/filters/client_channel/subchannel_index.c +11 -1
- data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
- data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
- data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
- data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
- data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
- data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
- data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
- data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
- data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
- data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
- data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
- data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
- data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
- data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
- data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
- data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +223 -0
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +40 -0
- data/src/core/ext/filters/workarounds/workaround_utils.c +65 -0
- data/src/core/ext/filters/workarounds/workaround_utils.h +52 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +3 -2
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +319 -175
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
- data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
- data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
- data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
- data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
- data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
- data/src/core/lib/channel/channel_args.c +30 -9
- data/src/core/lib/channel/channel_args.h +5 -1
- data/src/core/lib/channel/channel_stack.c +1 -1
- data/src/core/lib/channel/channel_stack.h +2 -2
- data/src/core/lib/channel/channel_stack_builder.c +13 -1
- data/src/core/lib/channel/channel_stack_builder.h +5 -1
- data/src/core/lib/channel/connected_channel.c +3 -1
- data/src/core/lib/channel/context.h +2 -2
- data/src/core/lib/compression/message_compress.c +2 -2
- data/src/core/lib/debug/trace.c +13 -6
- data/src/core/lib/debug/trace.h +27 -1
- data/src/core/lib/http/httpcli.c +1 -1
- data/src/core/lib/http/httpcli_security_connector.c +9 -11
- data/src/core/lib/http/parser.c +2 -2
- data/src/core/lib/http/parser.h +2 -1
- data/src/core/lib/iomgr/combiner.c +6 -6
- data/src/core/lib/iomgr/combiner.h +2 -1
- data/src/core/lib/iomgr/error.c +12 -5
- data/src/core/lib/iomgr/error.h +13 -13
- data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
- data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
- data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
- data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +41 -33
- data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
- data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
- data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
- data/src/core/lib/iomgr/ev_posix.c +22 -8
- data/src/core/lib/iomgr/ev_posix.h +4 -3
- data/src/core/lib/iomgr/ev_windows.c +43 -0
- data/src/core/lib/iomgr/exec_ctx.c +5 -0
- data/src/core/lib/iomgr/exec_ctx.h +2 -0
- data/src/core/lib/iomgr/iomgr.c +4 -0
- data/src/core/lib/iomgr/iomgr.h +3 -0
- data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
- data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
- data/src/core/lib/iomgr/lockfree_event.c +16 -0
- data/src/core/lib/iomgr/pollset.h +2 -5
- data/src/core/lib/iomgr/pollset_uv.c +1 -1
- data/src/core/lib/iomgr/pollset_windows.c +3 -3
- data/src/core/lib/iomgr/resource_quota.c +9 -8
- data/src/core/lib/iomgr/resource_quota.h +2 -1
- data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
- data/src/core/lib/iomgr/socket_mutator.h +2 -0
- data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
- data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
- data/src/core/lib/iomgr/tcp_posix.c +7 -7
- data/src/core/lib/iomgr/tcp_posix.h +2 -1
- data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
- data/src/core/lib/iomgr/tcp_uv.c +6 -6
- data/src/core/lib/iomgr/tcp_uv.h +2 -1
- data/src/core/lib/iomgr/tcp_windows.c +1 -1
- data/src/core/lib/iomgr/timer_generic.c +24 -25
- data/src/core/lib/iomgr/timer_manager.c +276 -0
- data/src/core/lib/iomgr/timer_manager.h +52 -0
- data/src/core/lib/iomgr/timer_uv.c +6 -0
- data/src/core/lib/iomgr/udp_server.c +42 -9
- data/src/core/lib/iomgr/udp_server.h +3 -1
- data/src/core/lib/security/credentials/credentials.c +0 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
- data/src/core/lib/security/transport/client_auth_filter.c +9 -3
- data/src/core/lib/security/transport/secure_endpoint.c +7 -7
- data/src/core/lib/security/transport/secure_endpoint.h +1 -1
- data/src/core/lib/security/transport/security_connector.c +45 -57
- data/src/core/lib/security/transport/security_connector.h +10 -14
- data/src/core/lib/security/transport/security_handshaker.c +123 -97
- data/src/core/lib/slice/b64.c +1 -1
- data/src/core/lib/slice/percent_encoding.c +3 -3
- data/src/core/lib/slice/slice.c +66 -33
- data/src/core/lib/slice/slice_buffer.c +25 -6
- data/src/core/lib/slice/slice_hash_table.c +33 -35
- data/src/core/lib/slice/slice_hash_table.h +7 -12
- data/src/core/lib/support/atomic.h +45 -0
- data/src/core/lib/support/atomic_with_atm.h +70 -0
- data/src/core/lib/support/atomic_with_std.h +48 -0
- data/src/core/lib/support/avl.c +14 -14
- data/src/core/lib/support/cmdline.c +3 -3
- data/src/core/lib/support/histogram.c +2 -2
- data/src/core/lib/support/host_port.c +1 -1
- data/src/core/lib/support/memory.h +74 -0
- data/src/core/lib/support/mpscq.c +36 -2
- data/src/core/lib/support/mpscq.h +28 -1
- data/src/core/lib/support/stack_lockfree.c +3 -36
- data/src/core/lib/support/string.c +12 -12
- data/src/core/lib/support/string_posix.c +1 -1
- data/src/core/lib/support/subprocess_posix.c +2 -2
- data/src/core/lib/support/thd_posix.c +1 -1
- data/src/core/lib/support/time_posix.c +8 -0
- data/src/core/lib/support/tmpfile_posix.c +10 -10
- data/src/core/lib/surface/alarm.c +3 -1
- data/src/core/lib/surface/api_trace.c +2 -1
- data/src/core/lib/surface/api_trace.h +2 -2
- data/src/core/lib/surface/byte_buffer_reader.c +1 -1
- data/src/core/lib/surface/call.c +65 -22
- data/src/core/lib/surface/call.h +4 -2
- data/src/core/lib/surface/channel_init.c +2 -19
- data/src/core/lib/surface/channel_stack_type.c +18 -0
- data/src/core/lib/surface/channel_stack_type.h +2 -0
- data/src/core/lib/surface/completion_queue.c +694 -247
- data/src/core/lib/surface/completion_queue.h +30 -13
- data/src/core/lib/surface/completion_queue_factory.c +24 -9
- data/src/core/lib/surface/init.c +1 -52
- data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
- data/src/core/lib/surface/server.c +79 -110
- data/src/core/lib/surface/server.h +2 -1
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/bdp_estimator.c +25 -9
- data/src/core/lib/transport/bdp_estimator.h +7 -1
- data/src/core/lib/transport/byte_stream.c +23 -9
- data/src/core/lib/transport/byte_stream.h +15 -6
- data/src/core/lib/transport/connectivity_state.c +6 -6
- data/src/core/lib/transport/connectivity_state.h +2 -1
- data/src/core/lib/transport/service_config.c +6 -13
- data/src/core/lib/transport/service_config.h +2 -2
- data/src/core/lib/transport/static_metadata.c +403 -389
- data/src/core/lib/transport/static_metadata.h +127 -114
- data/src/core/plugin_registry/grpc_plugin_registry.c +16 -0
- data/src/core/tsi/fake_transport_security.c +5 -4
- data/src/core/tsi/ssl_transport_security.c +71 -82
- data/src/core/tsi/ssl_transport_security.h +39 -61
- data/src/core/tsi/transport_security.c +83 -2
- data/src/core/tsi/transport_security.h +27 -2
- data/src/core/tsi/transport_security_adapter.c +236 -0
- data/src/core/tsi/transport_security_adapter.h +62 -0
- data/src/core/tsi/transport_security_interface.h +179 -66
- data/src/ruby/ext/grpc/extconf.rb +2 -1
- data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
- data/src/ruby/ext/grpc/rb_call.c +56 -48
- data/src/ruby/ext/grpc/rb_call.h +3 -4
- data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
- data/src/ruby/ext/grpc/rb_channel.c +2 -3
- data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
- data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
- data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
- data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
- data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
- data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
- data/src/ruby/ext/grpc/rb_grpc.c +11 -15
- data/src/ruby/ext/grpc/rb_grpc.h +2 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +16 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +25 -10
- data/src/ruby/ext/grpc/rb_server.c +26 -28
- data/src/ruby/lib/grpc/grpc.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/cares/config_linux/ares_config.h +36 -2
- data/third_party/zlib/adler32.c +14 -7
- data/third_party/zlib/compress.c +24 -18
- data/third_party/zlib/crc32.c +29 -12
- data/third_party/zlib/deflate.c +499 -303
- data/third_party/zlib/deflate.h +19 -16
- data/third_party/zlib/gzguts.h +16 -7
- data/third_party/zlib/gzlib.c +17 -14
- data/third_party/zlib/gzread.c +108 -48
- data/third_party/zlib/gzwrite.c +210 -122
- data/third_party/zlib/infback.c +2 -2
- data/third_party/zlib/inffast.c +34 -51
- data/third_party/zlib/inflate.c +86 -37
- data/third_party/zlib/inflate.h +7 -4
- data/third_party/zlib/inftrees.c +12 -14
- data/third_party/zlib/trees.c +38 -61
- data/third_party/zlib/uncompr.c +66 -32
- data/third_party/zlib/zconf.h +32 -9
- data/third_party/zlib/zlib.h +298 -154
- data/third_party/zlib/zutil.c +25 -24
- data/third_party/zlib/zutil.h +35 -17
- metadata +63 -30
data/third_party/zlib/gzwrite.c
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/* gzwrite.c -- zlib functions for writing gzip files
|
2
|
-
* Copyright (C) 2004
|
2
|
+
* Copyright (C) 2004-2017 Mark Adler
|
3
3
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
4
4
|
*/
|
5
5
|
|
@@ -9,17 +9,19 @@
|
|
9
9
|
local int gz_init OF((gz_statep));
|
10
10
|
local int gz_comp OF((gz_statep, int));
|
11
11
|
local int gz_zero OF((gz_statep, z_off64_t));
|
12
|
+
local z_size_t gz_write OF((gz_statep, voidpc, z_size_t));
|
12
13
|
|
13
14
|
/* Initialize state for writing a gzip file. Mark initialization by setting
|
14
|
-
state->size to non-zero. Return -1 on failure or 0 on
|
15
|
+
state->size to non-zero. Return -1 on a memory allocation failure, or 0 on
|
16
|
+
success. */
|
15
17
|
local int gz_init(state)
|
16
18
|
gz_statep state;
|
17
19
|
{
|
18
20
|
int ret;
|
19
21
|
z_streamp strm = &(state->strm);
|
20
22
|
|
21
|
-
/* allocate input buffer */
|
22
|
-
state->in = (unsigned char *)malloc(state->want);
|
23
|
+
/* allocate input buffer (double size for gzprintf) */
|
24
|
+
state->in = (unsigned char *)malloc(state->want << 1);
|
23
25
|
if (state->in == NULL) {
|
24
26
|
gz_error(state, Z_MEM_ERROR, "out of memory");
|
25
27
|
return -1;
|
@@ -47,6 +49,7 @@ local int gz_init(state)
|
|
47
49
|
gz_error(state, Z_MEM_ERROR, "out of memory");
|
48
50
|
return -1;
|
49
51
|
}
|
52
|
+
strm->next_in = NULL;
|
50
53
|
}
|
51
54
|
|
52
55
|
/* mark state as initialized */
|
@@ -62,17 +65,17 @@ local int gz_init(state)
|
|
62
65
|
}
|
63
66
|
|
64
67
|
/* Compress whatever is at avail_in and next_in and write to the output file.
|
65
|
-
Return -1 if there is an error writing to the output file
|
66
|
-
flush is assumed to be a valid
|
67
|
-
|
68
|
-
|
69
|
-
ignore flush. */
|
68
|
+
Return -1 if there is an error writing to the output file or if gz_init()
|
69
|
+
fails to allocate memory, otherwise 0. flush is assumed to be a valid
|
70
|
+
deflate() flush value. If flush is Z_FINISH, then the deflate() state is
|
71
|
+
reset to start a new gzip stream. If gz->direct is true, then simply write
|
72
|
+
to the output file without compressing, and ignore flush. */
|
70
73
|
local int gz_comp(state, flush)
|
71
74
|
gz_statep state;
|
72
75
|
int flush;
|
73
76
|
{
|
74
|
-
int ret,
|
75
|
-
unsigned have;
|
77
|
+
int ret, writ;
|
78
|
+
unsigned have, put, max = ((unsigned)-1 >> 2) + 1;
|
76
79
|
z_streamp strm = &(state->strm);
|
77
80
|
|
78
81
|
/* allocate memory if this is the first time through */
|
@@ -81,12 +84,16 @@ local int gz_comp(state, flush)
|
|
81
84
|
|
82
85
|
/* write directly if requested */
|
83
86
|
if (state->direct) {
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
87
|
+
while (strm->avail_in) {
|
88
|
+
put = strm->avail_in > max ? max : strm->avail_in;
|
89
|
+
writ = write(state->fd, strm->next_in, put);
|
90
|
+
if (writ < 0) {
|
91
|
+
gz_error(state, Z_ERRNO, zstrerror());
|
92
|
+
return -1;
|
93
|
+
}
|
94
|
+
strm->avail_in -= (unsigned)writ;
|
95
|
+
strm->next_in += writ;
|
88
96
|
}
|
89
|
-
strm->avail_in = 0;
|
90
97
|
return 0;
|
91
98
|
}
|
92
99
|
|
@@ -97,17 +104,21 @@ local int gz_comp(state, flush)
|
|
97
104
|
doing Z_FINISH then don't write until we get to Z_STREAM_END */
|
98
105
|
if (strm->avail_out == 0 || (flush != Z_NO_FLUSH &&
|
99
106
|
(flush != Z_FINISH || ret == Z_STREAM_END))) {
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
107
|
+
while (strm->next_out > state->x.next) {
|
108
|
+
put = strm->next_out - state->x.next > (int)max ? max :
|
109
|
+
(unsigned)(strm->next_out - state->x.next);
|
110
|
+
writ = write(state->fd, state->x.next, put);
|
111
|
+
if (writ < 0) {
|
112
|
+
gz_error(state, Z_ERRNO, zstrerror());
|
113
|
+
return -1;
|
114
|
+
}
|
115
|
+
state->x.next += writ;
|
105
116
|
}
|
106
117
|
if (strm->avail_out == 0) {
|
107
118
|
strm->avail_out = state->size;
|
108
119
|
strm->next_out = state->out;
|
120
|
+
state->x.next = state->out;
|
109
121
|
}
|
110
|
-
state->x.next = strm->next_out;
|
111
122
|
}
|
112
123
|
|
113
124
|
/* compress */
|
@@ -129,7 +140,8 @@ local int gz_comp(state, flush)
|
|
129
140
|
return 0;
|
130
141
|
}
|
131
142
|
|
132
|
-
/* Compress len zeros to output. Return -1 on
|
143
|
+
/* Compress len zeros to output. Return -1 on a write error or memory
|
144
|
+
allocation failure by gz_comp(), or 0 on success. */
|
133
145
|
local int gz_zero(state, len)
|
134
146
|
gz_statep state;
|
135
147
|
z_off64_t len;
|
@@ -161,32 +173,14 @@ local int gz_zero(state, len)
|
|
161
173
|
return 0;
|
162
174
|
}
|
163
175
|
|
164
|
-
/*
|
165
|
-
|
166
|
-
|
176
|
+
/* Write len bytes from buf to file. Return the number of bytes written. If
|
177
|
+
the returned value is less than len, then there was an error. */
|
178
|
+
local z_size_t gz_write(state, buf, len)
|
179
|
+
gz_statep state;
|
167
180
|
voidpc buf;
|
168
|
-
|
181
|
+
z_size_t len;
|
169
182
|
{
|
170
|
-
|
171
|
-
gz_statep state;
|
172
|
-
z_streamp strm;
|
173
|
-
|
174
|
-
/* get internal structure */
|
175
|
-
if (file == NULL)
|
176
|
-
return 0;
|
177
|
-
state = (gz_statep)file;
|
178
|
-
strm = &(state->strm);
|
179
|
-
|
180
|
-
/* check that we're writing and that there's no error */
|
181
|
-
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
182
|
-
return 0;
|
183
|
-
|
184
|
-
/* since an int is returned, make sure len fits in one, otherwise return
|
185
|
-
with an error (this avoids the flaw in the interface) */
|
186
|
-
if ((int)len < 0) {
|
187
|
-
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
188
|
-
return 0;
|
189
|
-
}
|
183
|
+
z_size_t put = len;
|
190
184
|
|
191
185
|
/* if len is zero, avoid unnecessary operations */
|
192
186
|
if (len == 0)
|
@@ -209,14 +203,15 @@ int ZEXPORT gzwrite(file, buf, len)
|
|
209
203
|
do {
|
210
204
|
unsigned have, copy;
|
211
205
|
|
212
|
-
if (strm
|
213
|
-
strm
|
214
|
-
have = (unsigned)((strm
|
206
|
+
if (state->strm.avail_in == 0)
|
207
|
+
state->strm.next_in = state->in;
|
208
|
+
have = (unsigned)((state->strm.next_in + state->strm.avail_in) -
|
209
|
+
state->in);
|
215
210
|
copy = state->size - have;
|
216
211
|
if (copy > len)
|
217
212
|
copy = len;
|
218
213
|
memcpy(state->in + have, buf, copy);
|
219
|
-
strm
|
214
|
+
state->strm.avail_in += copy;
|
220
215
|
state->x.pos += copy;
|
221
216
|
buf = (const char *)buf + copy;
|
222
217
|
len -= copy;
|
@@ -226,19 +221,83 @@ int ZEXPORT gzwrite(file, buf, len)
|
|
226
221
|
}
|
227
222
|
else {
|
228
223
|
/* consume whatever's left in the input buffer */
|
229
|
-
if (strm
|
224
|
+
if (state->strm.avail_in && gz_comp(state, Z_NO_FLUSH) == -1)
|
230
225
|
return 0;
|
231
226
|
|
232
227
|
/* directly compress user buffer to file */
|
233
|
-
strm
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
228
|
+
state->strm.next_in = (z_const Bytef *)buf;
|
229
|
+
do {
|
230
|
+
unsigned n = (unsigned)-1;
|
231
|
+
if (n > len)
|
232
|
+
n = len;
|
233
|
+
state->strm.avail_in = n;
|
234
|
+
state->x.pos += n;
|
235
|
+
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
236
|
+
return 0;
|
237
|
+
len -= n;
|
238
|
+
} while (len);
|
239
|
+
}
|
240
|
+
|
241
|
+
/* input was all buffered or compressed */
|
242
|
+
return put;
|
243
|
+
}
|
244
|
+
|
245
|
+
/* -- see zlib.h -- */
|
246
|
+
int ZEXPORT gzwrite(file, buf, len)
|
247
|
+
gzFile file;
|
248
|
+
voidpc buf;
|
249
|
+
unsigned len;
|
250
|
+
{
|
251
|
+
gz_statep state;
|
252
|
+
|
253
|
+
/* get internal structure */
|
254
|
+
if (file == NULL)
|
255
|
+
return 0;
|
256
|
+
state = (gz_statep)file;
|
257
|
+
|
258
|
+
/* check that we're writing and that there's no error */
|
259
|
+
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
260
|
+
return 0;
|
261
|
+
|
262
|
+
/* since an int is returned, make sure len fits in one, otherwise return
|
263
|
+
with an error (this avoids a flaw in the interface) */
|
264
|
+
if ((int)len < 0) {
|
265
|
+
gz_error(state, Z_DATA_ERROR, "requested length does not fit in int");
|
266
|
+
return 0;
|
267
|
+
}
|
268
|
+
|
269
|
+
/* write len bytes from buf (the return value will fit in an int) */
|
270
|
+
return (int)gz_write(state, buf, len);
|
271
|
+
}
|
272
|
+
|
273
|
+
/* -- see zlib.h -- */
|
274
|
+
z_size_t ZEXPORT gzfwrite(buf, size, nitems, file)
|
275
|
+
voidpc buf;
|
276
|
+
z_size_t size;
|
277
|
+
z_size_t nitems;
|
278
|
+
gzFile file;
|
279
|
+
{
|
280
|
+
z_size_t len;
|
281
|
+
gz_statep state;
|
282
|
+
|
283
|
+
/* get internal structure */
|
284
|
+
if (file == NULL)
|
285
|
+
return 0;
|
286
|
+
state = (gz_statep)file;
|
287
|
+
|
288
|
+
/* check that we're writing and that there's no error */
|
289
|
+
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
290
|
+
return 0;
|
291
|
+
|
292
|
+
/* compute bytes to read -- error on overflow */
|
293
|
+
len = nitems * size;
|
294
|
+
if (size && len / size != nitems) {
|
295
|
+
gz_error(state, Z_STREAM_ERROR, "request does not fit in a size_t");
|
296
|
+
return 0;
|
238
297
|
}
|
239
298
|
|
240
|
-
/*
|
241
|
-
return (
|
299
|
+
/* write len bytes to buf, return the number of full items written */
|
300
|
+
return len ? gz_write(state, buf, len) / size : 0;
|
242
301
|
}
|
243
302
|
|
244
303
|
/* -- see zlib.h -- */
|
@@ -275,7 +334,7 @@ int ZEXPORT gzputc(file, c)
|
|
275
334
|
strm->next_in = state->in;
|
276
335
|
have = (unsigned)((strm->next_in + strm->avail_in) - state->in);
|
277
336
|
if (have < state->size) {
|
278
|
-
state->in[have] = c;
|
337
|
+
state->in[have] = (unsigned char)c;
|
279
338
|
strm->avail_in++;
|
280
339
|
state->x.pos++;
|
281
340
|
return c & 0xff;
|
@@ -283,8 +342,8 @@ int ZEXPORT gzputc(file, c)
|
|
283
342
|
}
|
284
343
|
|
285
344
|
/* no room in buffer or not initialized, use gz_write() */
|
286
|
-
buf[0] = c;
|
287
|
-
if (
|
345
|
+
buf[0] = (unsigned char)c;
|
346
|
+
if (gz_write(state, buf, 1) != 1)
|
288
347
|
return -1;
|
289
348
|
return c & 0xff;
|
290
349
|
}
|
@@ -295,11 +354,21 @@ int ZEXPORT gzputs(file, str)
|
|
295
354
|
const char *str;
|
296
355
|
{
|
297
356
|
int ret;
|
298
|
-
|
357
|
+
z_size_t len;
|
358
|
+
gz_statep state;
|
359
|
+
|
360
|
+
/* get internal structure */
|
361
|
+
if (file == NULL)
|
362
|
+
return -1;
|
363
|
+
state = (gz_statep)file;
|
364
|
+
|
365
|
+
/* check that we're writing and that there's no error */
|
366
|
+
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
367
|
+
return -1;
|
299
368
|
|
300
369
|
/* write string */
|
301
|
-
len =
|
302
|
-
ret =
|
370
|
+
len = strlen(str);
|
371
|
+
ret = gz_write(state, str, len);
|
303
372
|
return ret == 0 && len != 0 ? -1 : ret;
|
304
373
|
}
|
305
374
|
|
@@ -309,63 +378,73 @@ int ZEXPORT gzputs(file, str)
|
|
309
378
|
/* -- see zlib.h -- */
|
310
379
|
int ZEXPORTVA gzvprintf(gzFile file, const char *format, va_list va)
|
311
380
|
{
|
312
|
-
int
|
381
|
+
int len;
|
382
|
+
unsigned left;
|
383
|
+
char *next;
|
313
384
|
gz_statep state;
|
314
385
|
z_streamp strm;
|
315
386
|
|
316
387
|
/* get internal structure */
|
317
388
|
if (file == NULL)
|
318
|
-
return
|
389
|
+
return Z_STREAM_ERROR;
|
319
390
|
state = (gz_statep)file;
|
320
391
|
strm = &(state->strm);
|
321
392
|
|
322
393
|
/* check that we're writing and that there's no error */
|
323
394
|
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
324
|
-
return
|
395
|
+
return Z_STREAM_ERROR;
|
325
396
|
|
326
397
|
/* make sure we have some buffer space */
|
327
398
|
if (state->size == 0 && gz_init(state) == -1)
|
328
|
-
return
|
399
|
+
return state->err;
|
329
400
|
|
330
401
|
/* check for seek request */
|
331
402
|
if (state->seek) {
|
332
403
|
state->seek = 0;
|
333
404
|
if (gz_zero(state, state->skip) == -1)
|
334
|
-
return
|
405
|
+
return state->err;
|
335
406
|
}
|
336
407
|
|
337
|
-
/*
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
state->
|
408
|
+
/* do the printf() into the input buffer, put length in len -- the input
|
409
|
+
buffer is double-sized just for this function, so there is guaranteed to
|
410
|
+
be state->size bytes available after the current contents */
|
411
|
+
if (strm->avail_in == 0)
|
412
|
+
strm->next_in = state->in;
|
413
|
+
next = (char *)(state->in + (strm->next_in - state->in) + strm->avail_in);
|
414
|
+
next[state->size - 1] = 0;
|
344
415
|
#ifdef NO_vsnprintf
|
345
416
|
# ifdef HAS_vsprintf_void
|
346
|
-
(void)vsprintf(
|
347
|
-
for (len = 0; len < size; len++)
|
348
|
-
if (
|
417
|
+
(void)vsprintf(next, format, va);
|
418
|
+
for (len = 0; len < state->size; len++)
|
419
|
+
if (next[len] == 0) break;
|
349
420
|
# else
|
350
|
-
len = vsprintf(
|
421
|
+
len = vsprintf(next, format, va);
|
351
422
|
# endif
|
352
423
|
#else
|
353
424
|
# ifdef HAS_vsnprintf_void
|
354
|
-
(void)vsnprintf(
|
355
|
-
len = strlen(
|
425
|
+
(void)vsnprintf(next, state->size, format, va);
|
426
|
+
len = strlen(next);
|
356
427
|
# else
|
357
|
-
len = vsnprintf(
|
428
|
+
len = vsnprintf(next, state->size, format, va);
|
358
429
|
# endif
|
359
430
|
#endif
|
360
431
|
|
361
432
|
/* check that printf() results fit in buffer */
|
362
|
-
if (len
|
433
|
+
if (len == 0 || (unsigned)len >= state->size || next[state->size - 1] != 0)
|
363
434
|
return 0;
|
364
435
|
|
365
|
-
/* update buffer and position,
|
366
|
-
strm->avail_in
|
367
|
-
strm->next_in = state->in;
|
436
|
+
/* update buffer and position, compress first half if past that */
|
437
|
+
strm->avail_in += (unsigned)len;
|
368
438
|
state->x.pos += len;
|
439
|
+
if (strm->avail_in >= state->size) {
|
440
|
+
left = strm->avail_in - state->size;
|
441
|
+
strm->avail_in = state->size;
|
442
|
+
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
443
|
+
return state->err;
|
444
|
+
memcpy(state->in, state->in + state->size, left);
|
445
|
+
strm->next_in = state->in;
|
446
|
+
strm->avail_in = left;
|
447
|
+
}
|
369
448
|
return len;
|
370
449
|
}
|
371
450
|
|
@@ -390,73 +469,82 @@ int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
|
390
469
|
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
391
470
|
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
|
392
471
|
{
|
393
|
-
|
472
|
+
unsigned len, left;
|
473
|
+
char *next;
|
394
474
|
gz_statep state;
|
395
475
|
z_streamp strm;
|
396
476
|
|
397
477
|
/* get internal structure */
|
398
478
|
if (file == NULL)
|
399
|
-
return
|
479
|
+
return Z_STREAM_ERROR;
|
400
480
|
state = (gz_statep)file;
|
401
481
|
strm = &(state->strm);
|
402
482
|
|
403
483
|
/* check that can really pass pointer in ints */
|
404
484
|
if (sizeof(int) != sizeof(void *))
|
405
|
-
return
|
485
|
+
return Z_STREAM_ERROR;
|
406
486
|
|
407
487
|
/* check that we're writing and that there's no error */
|
408
488
|
if (state->mode != GZ_WRITE || state->err != Z_OK)
|
409
|
-
return
|
489
|
+
return Z_STREAM_ERROR;
|
410
490
|
|
411
491
|
/* make sure we have some buffer space */
|
412
492
|
if (state->size == 0 && gz_init(state) == -1)
|
413
|
-
return
|
493
|
+
return state->error;
|
414
494
|
|
415
495
|
/* check for seek request */
|
416
496
|
if (state->seek) {
|
417
497
|
state->seek = 0;
|
418
498
|
if (gz_zero(state, state->skip) == -1)
|
419
|
-
return
|
499
|
+
return state->error;
|
420
500
|
}
|
421
501
|
|
422
|
-
/*
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
state->
|
502
|
+
/* do the printf() into the input buffer, put length in len -- the input
|
503
|
+
buffer is double-sized just for this function, so there is guaranteed to
|
504
|
+
be state->size bytes available after the current contents */
|
505
|
+
if (strm->avail_in == 0)
|
506
|
+
strm->next_in = state->in;
|
507
|
+
next = (char *)(strm->next_in + strm->avail_in);
|
508
|
+
next[state->size - 1] = 0;
|
429
509
|
#ifdef NO_snprintf
|
430
510
|
# ifdef HAS_sprintf_void
|
431
|
-
sprintf(
|
432
|
-
|
511
|
+
sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
|
512
|
+
a13, a14, a15, a16, a17, a18, a19, a20);
|
433
513
|
for (len = 0; len < size; len++)
|
434
|
-
if (
|
514
|
+
if (next[len] == 0)
|
515
|
+
break;
|
435
516
|
# else
|
436
|
-
len = sprintf(
|
437
|
-
|
517
|
+
len = sprintf(next, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
|
518
|
+
a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
438
519
|
# endif
|
439
520
|
#else
|
440
521
|
# ifdef HAS_snprintf_void
|
441
|
-
snprintf(
|
442
|
-
|
443
|
-
len = strlen(
|
522
|
+
snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8, a9,
|
523
|
+
a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
524
|
+
len = strlen(next);
|
444
525
|
# else
|
445
|
-
len = snprintf(
|
446
|
-
|
447
|
-
a19, a20);
|
526
|
+
len = snprintf(next, state->size, format, a1, a2, a3, a4, a5, a6, a7, a8,
|
527
|
+
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
|
448
528
|
# endif
|
449
529
|
#endif
|
450
530
|
|
451
531
|
/* check that printf() results fit in buffer */
|
452
|
-
if (len
|
532
|
+
if (len == 0 || len >= state->size || next[state->size - 1] != 0)
|
453
533
|
return 0;
|
454
534
|
|
455
|
-
/* update buffer and position,
|
456
|
-
strm->avail_in
|
457
|
-
strm->next_in = state->in;
|
535
|
+
/* update buffer and position, compress first half if past that */
|
536
|
+
strm->avail_in += len;
|
458
537
|
state->x.pos += len;
|
459
|
-
|
538
|
+
if (strm->avail_in >= state->size) {
|
539
|
+
left = strm->avail_in - state->size;
|
540
|
+
strm->avail_in = state->size;
|
541
|
+
if (gz_comp(state, Z_NO_FLUSH) == -1)
|
542
|
+
return state->err;
|
543
|
+
memcpy(state->in, state->in + state->size, left);
|
544
|
+
strm->next_in = state->in;
|
545
|
+
strm->avail_in = left;
|
546
|
+
}
|
547
|
+
return (int)len;
|
460
548
|
}
|
461
549
|
|
462
550
|
#endif
|
@@ -470,7 +558,7 @@ int ZEXPORT gzflush(file, flush)
|
|
470
558
|
|
471
559
|
/* get internal structure */
|
472
560
|
if (file == NULL)
|
473
|
-
return
|
561
|
+
return Z_STREAM_ERROR;
|
474
562
|
state = (gz_statep)file;
|
475
563
|
|
476
564
|
/* check that we're writing and that there's no error */
|
@@ -485,11 +573,11 @@ int ZEXPORT gzflush(file, flush)
|
|
485
573
|
if (state->seek) {
|
486
574
|
state->seek = 0;
|
487
575
|
if (gz_zero(state, state->skip) == -1)
|
488
|
-
return
|
576
|
+
return state->err;
|
489
577
|
}
|
490
578
|
|
491
579
|
/* compress remaining data with requested flush */
|
492
|
-
gz_comp(state, flush);
|
580
|
+
(void)gz_comp(state, flush);
|
493
581
|
return state->err;
|
494
582
|
}
|
495
583
|
|
@@ -520,13 +608,13 @@ int ZEXPORT gzsetparams(file, level, strategy)
|
|
520
608
|
if (state->seek) {
|
521
609
|
state->seek = 0;
|
522
610
|
if (gz_zero(state, state->skip) == -1)
|
523
|
-
return
|
611
|
+
return state->err;
|
524
612
|
}
|
525
613
|
|
526
614
|
/* change compression parameters for subsequent input */
|
527
615
|
if (state->size) {
|
528
616
|
/* flush previous input with previous parameters before changing */
|
529
|
-
if (strm->avail_in && gz_comp(state,
|
617
|
+
if (strm->avail_in && gz_comp(state, Z_BLOCK) == -1)
|
530
618
|
return state->err;
|
531
619
|
deflateParams(strm, level, strategy);
|
532
620
|
}
|