Merge branch 'master' into handshaker

pull/10925/head
jiangtaoli2016 8 years ago
commit 4cae6d0951
  1. 4
      grpc.def
  2. 22
      include/grpc/slice.h
  3. 4
      include/grpc/slice_buffer.h
  4. 2
      src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c
  5. 2
      src/core/ext/filters/http/client/http_client_filter.c
  6. 4
      src/core/ext/transport/chttp2/transport/bin_decoder.c
  7. 6
      src/core/ext/transport/chttp2/transport/bin_encoder.c
  8. 10
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  9. 4
      src/core/ext/transport/chttp2/transport/frame_data.c
  10. 2
      src/core/ext/transport/chttp2/transport/frame_goaway.c
  11. 2
      src/core/ext/transport/chttp2/transport/frame_ping.c
  12. 2
      src/core/ext/transport/chttp2/transport/frame_rst_stream.c
  13. 4
      src/core/ext/transport/chttp2/transport/frame_settings.c
  14. 2
      src/core/ext/transport/chttp2/transport/frame_window_update.c
  15. 2
      src/core/ext/transport/chttp2/transport/hpack_encoder.c
  16. 2
      src/core/ext/transport/cronet/transport/cronet_transport.c
  17. 4
      src/core/lib/compression/message_compress.c
  18. 2
      src/core/lib/iomgr/tcp_windows.c
  19. 8
      src/core/lib/security/transport/secure_endpoint.c
  20. 2
      src/core/lib/slice/b64.c
  21. 6
      src/core/lib/slice/percent_encoding.c
  22. 99
      src/core/lib/slice/slice.c
  23. 31
      src/core/lib/slice/slice_buffer.c
  24. 2
      src/core/lib/surface/byte_buffer_reader.c
  25. 8
      src/ruby/ext/grpc/rb_grpc_imports.generated.c
  26. 12
      src/ruby/ext/grpc/rb_grpc_imports.generated.h
  27. 5
      test/core/util/passthru_endpoint.c
  28. 8
      test/core/util/trickle_endpoint.c
  29. 30
      test/cpp/util/BUILD
  30. 4
      tools/gce/create_linux_performance_worker.sh
  31. 50
      tools/gce/linux_performance_worker_init.sh
  32. 1
      tools/run_tests/sanity/core_banned_functions.py

@ -141,10 +141,12 @@ EXPORTS
grpc_server_credentials_set_auth_metadata_processor grpc_server_credentials_set_auth_metadata_processor
grpc_slice_ref grpc_slice_ref
grpc_slice_unref grpc_slice_unref
grpc_slice_copy
grpc_slice_new grpc_slice_new
grpc_slice_new_with_user_data grpc_slice_new_with_user_data
grpc_slice_new_with_len grpc_slice_new_with_len
grpc_slice_malloc grpc_slice_malloc
grpc_slice_malloc_large
grpc_slice_intern grpc_slice_intern
grpc_slice_from_copied_string grpc_slice_from_copied_string
grpc_slice_from_copied_buffer grpc_slice_from_copied_buffer
@ -153,6 +155,7 @@ EXPORTS
grpc_slice_sub grpc_slice_sub
grpc_slice_sub_no_ref grpc_slice_sub_no_ref
grpc_slice_split_tail grpc_slice_split_tail
grpc_slice_split_tail_maybe_ref
grpc_slice_split_head grpc_slice_split_head
grpc_empty_slice grpc_empty_slice
grpc_slice_default_hash_impl grpc_slice_default_hash_impl
@ -181,6 +184,7 @@ EXPORTS
grpc_slice_buffer_move_into grpc_slice_buffer_move_into
grpc_slice_buffer_trim_end grpc_slice_buffer_trim_end
grpc_slice_buffer_move_first grpc_slice_buffer_move_first
grpc_slice_buffer_move_first_no_ref
grpc_slice_buffer_move_first_into_buffer grpc_slice_buffer_move_first_into_buffer
grpc_slice_buffer_take_first grpc_slice_buffer_take_first
grpc_slice_buffer_undo_take_first grpc_slice_buffer_undo_take_first

@ -53,6 +53,9 @@ GPRAPI grpc_slice grpc_slice_ref(grpc_slice s);
where dest!=NULL , then (*dest)(start, len). Requires s initialized. */ where dest!=NULL , then (*dest)(start, len). Requires s initialized. */
GPRAPI void grpc_slice_unref(grpc_slice s); GPRAPI void grpc_slice_unref(grpc_slice s);
/* Copy slice - create a new slice that contains the same data as s */
GPRAPI grpc_slice grpc_slice_copy(grpc_slice s);
/* Create a slice pointing at some data. Calls malloc to allocate a refcount /* Create a slice pointing at some data. Calls malloc to allocate a refcount
for the object, and arranges that destroy will be called with the pointer for the object, and arranges that destroy will be called with the pointer
passed in at destruction. */ passed in at destruction. */
@ -75,6 +78,13 @@ GPRAPI grpc_slice grpc_slice_new_with_len(void *p, size_t len,
call. call.
Aborts if malloc() fails. */ Aborts if malloc() fails. */
GPRAPI grpc_slice grpc_slice_malloc(size_t length); GPRAPI grpc_slice grpc_slice_malloc(size_t length);
GPRAPI grpc_slice grpc_slice_malloc_large(size_t length);
#define GRPC_SLICE_MALLOC(len) \
((len) <= GRPC_SLICE_INLINED_SIZE \
? (grpc_slice){.refcount = NULL, \
.data.inlined = {.length = (uint8_t)(len)}} \
: grpc_slice_malloc_large((len)))
/* Intern a slice: /* Intern a slice:
@ -117,6 +127,18 @@ GPRAPI grpc_slice grpc_slice_sub_no_ref(grpc_slice s, size_t begin, size_t end);
Requires s intialized, split <= s.length */ Requires s intialized, split <= s.length */
GPRAPI grpc_slice grpc_slice_split_tail(grpc_slice *s, size_t split); GPRAPI grpc_slice grpc_slice_split_tail(grpc_slice *s, size_t split);
typedef enum {
GRPC_SLICE_REF_TAIL = 1,
GRPC_SLICE_REF_HEAD = 2,
GRPC_SLICE_REF_BOTH = 1 + 2
} grpc_slice_ref_whom;
/* The same as grpc_slice_split_tail, but with an option to skip altering
* refcounts (grpc_slice_split_tail_maybe_ref(..., true) is equivalent to
* grpc_slice_split_tail(...)) */
GPRAPI grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice *s, size_t split,
grpc_slice_ref_whom ref_whom);
/* Splits s into two: modifies s to be s[split:s.length], and returns a new /* Splits s into two: modifies s to be s[split:s.length], and returns a new
slice, sharing a refcount with s, that contains s[0:split]. slice, sharing a refcount with s, that contains s[0:split].
Requires s intialized, split <= s.length */ Requires s intialized, split <= s.length */

@ -77,6 +77,10 @@ GPRAPI void grpc_slice_buffer_trim_end(grpc_slice_buffer *src, size_t n,
/* move the first n bytes of src into dst */ /* move the first n bytes of src into dst */
GPRAPI void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n, GPRAPI void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n,
grpc_slice_buffer *dst); grpc_slice_buffer *dst);
/* move the first n bytes of src into dst without adding references */
GPRAPI void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer *src,
size_t n,
grpc_slice_buffer *dst);
/* move the first n bytes of src into dst (copying them) */ /* move the first n bytes of src into dst (copying them) */
GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx *exec_ctx, GPRAPI void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx *exec_ctx,
grpc_slice_buffer *src, grpc_slice_buffer *src,

@ -98,7 +98,7 @@ grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request *request) {
pb_encode(&sizestream, grpc_lb_v1_LoadBalanceRequest_fields, request); pb_encode(&sizestream, grpc_lb_v1_LoadBalanceRequest_fields, request);
encoded_length = sizestream.bytes_written; encoded_length = sizestream.bytes_written;
slice = grpc_slice_malloc(encoded_length); slice = GRPC_SLICE_MALLOC(encoded_length);
outputstream = outputstream =
pb_ostream_from_buffer(GRPC_SLICE_START_PTR(slice), encoded_length); pb_ostream_from_buffer(GRPC_SLICE_START_PTR(slice), encoded_length);
GPR_ASSERT(pb_encode(&outputstream, grpc_lb_v1_LoadBalanceRequest_fields, GPR_ASSERT(pb_encode(&outputstream, grpc_lb_v1_LoadBalanceRequest_fields,

@ -323,7 +323,7 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx,
estimated_len += grpc_base64_estimate_encoded_size( estimated_len += grpc_base64_estimate_encoded_size(
op->payload->send_message.send_message->length, k_url_safe, op->payload->send_message.send_message->length, k_url_safe,
k_multi_line); k_multi_line);
grpc_slice path_with_query_slice = grpc_slice_malloc(estimated_len); grpc_slice path_with_query_slice = GRPC_SLICE_MALLOC(estimated_len);
/* memcopy individual pieces into this slice */ /* memcopy individual pieces into this slice */
uint8_t *write_ptr = uint8_t *write_ptr =

@ -169,7 +169,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx,
} }
} }
} }
output = grpc_slice_malloc(output_length); output = GRPC_SLICE_MALLOC(output_length);
ctx.input_cur = GRPC_SLICE_START_PTR(input); ctx.input_cur = GRPC_SLICE_START_PTR(input);
ctx.input_end = GRPC_SLICE_END_PTR(input); ctx.input_end = GRPC_SLICE_END_PTR(input);
@ -193,7 +193,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx,
grpc_slice input, grpc_slice input,
size_t output_length) { size_t output_length) {
size_t input_length = GRPC_SLICE_LENGTH(input); size_t input_length = GRPC_SLICE_LENGTH(input);
grpc_slice output = grpc_slice_malloc(output_length); grpc_slice output = GRPC_SLICE_MALLOC(output_length);
struct grpc_base64_decode_context ctx; struct grpc_base64_decode_context ctx;
// The length of a base64 string cannot be 4 * n + 1 // The length of a base64 string cannot be 4 * n + 1

@ -66,7 +66,7 @@ grpc_slice grpc_chttp2_base64_encode(grpc_slice input) {
size_t input_triplets = input_length / 3; size_t input_triplets = input_length / 3;
size_t tail_case = input_length % 3; size_t tail_case = input_length % 3;
size_t output_length = input_triplets * 4 + tail_xtra[tail_case]; size_t output_length = input_triplets * 4 + tail_xtra[tail_case];
grpc_slice output = grpc_slice_malloc(output_length); grpc_slice output = GRPC_SLICE_MALLOC(output_length);
uint8_t *in = GRPC_SLICE_START_PTR(input); uint8_t *in = GRPC_SLICE_START_PTR(input);
char *out = (char *)GRPC_SLICE_START_PTR(output); char *out = (char *)GRPC_SLICE_START_PTR(output);
size_t i; size_t i;
@ -119,7 +119,7 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) {
nbits += grpc_chttp2_huffsyms[*in].length; nbits += grpc_chttp2_huffsyms[*in].length;
} }
output = grpc_slice_malloc(nbits / 8 + (nbits % 8 != 0)); output = GRPC_SLICE_MALLOC(nbits / 8 + (nbits % 8 != 0));
out = GRPC_SLICE_START_PTR(output); out = GRPC_SLICE_START_PTR(output);
for (in = GRPC_SLICE_START_PTR(input); in != GRPC_SLICE_END_PTR(input); for (in = GRPC_SLICE_START_PTR(input); in != GRPC_SLICE_END_PTR(input);
++in) { ++in) {
@ -184,7 +184,7 @@ grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) {
size_t output_syms = input_triplets * 4 + tail_xtra[tail_case]; size_t output_syms = input_triplets * 4 + tail_xtra[tail_case];
size_t max_output_bits = 11 * output_syms; size_t max_output_bits = 11 * output_syms;
size_t max_output_length = max_output_bits / 8 + (max_output_bits % 8 != 0); size_t max_output_length = max_output_bits / 8 + (max_output_bits % 8 != 0);
grpc_slice output = grpc_slice_malloc(max_output_length); grpc_slice output = GRPC_SLICE_MALLOC(max_output_length);
uint8_t *in = GRPC_SLICE_START_PTR(input); uint8_t *in = GRPC_SLICE_START_PTR(input);
uint8_t *start_out = GRPC_SLICE_START_PTR(output); uint8_t *start_out = GRPC_SLICE_START_PTR(output);
huff_out out; huff_out out;

@ -1969,7 +1969,7 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
the time we got around to sending this, so instead we ignore HPACK the time we got around to sending this, so instead we ignore HPACK
compression and just write the uncompressed bytes onto the wire. */ compression and just write the uncompressed bytes onto the wire. */
if (!s->sent_initial_metadata) { if (!s->sent_initial_metadata) {
http_status_hdr = grpc_slice_malloc(13); http_status_hdr = GRPC_SLICE_MALLOC(13);
p = GRPC_SLICE_START_PTR(http_status_hdr); p = GRPC_SLICE_START_PTR(http_status_hdr);
*p++ = 0x00; *p++ = 0x00;
*p++ = 7; *p++ = 7;
@ -1987,7 +1987,7 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
GPR_ASSERT(p == GRPC_SLICE_END_PTR(http_status_hdr)); GPR_ASSERT(p == GRPC_SLICE_END_PTR(http_status_hdr));
len += (uint32_t)GRPC_SLICE_LENGTH(http_status_hdr); len += (uint32_t)GRPC_SLICE_LENGTH(http_status_hdr);
content_type_hdr = grpc_slice_malloc(31); content_type_hdr = GRPC_SLICE_MALLOC(31);
p = GRPC_SLICE_START_PTR(content_type_hdr); p = GRPC_SLICE_START_PTR(content_type_hdr);
*p++ = 0x00; *p++ = 0x00;
*p++ = 12; *p++ = 12;
@ -2024,7 +2024,7 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
len += (uint32_t)GRPC_SLICE_LENGTH(content_type_hdr); len += (uint32_t)GRPC_SLICE_LENGTH(content_type_hdr);
} }
status_hdr = grpc_slice_malloc(15 + (grpc_status >= 10)); status_hdr = GRPC_SLICE_MALLOC(15 + (grpc_status >= 10));
p = GRPC_SLICE_START_PTR(status_hdr); p = GRPC_SLICE_START_PTR(status_hdr);
*p++ = 0x00; /* literal header, not indexed */ *p++ = 0x00; /* literal header, not indexed */
*p++ = 11; /* len(grpc-status) */ *p++ = 11; /* len(grpc-status) */
@ -2053,7 +2053,7 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
size_t msg_len = GRPC_SLICE_LENGTH(slice); size_t msg_len = GRPC_SLICE_LENGTH(slice);
GPR_ASSERT(msg_len <= UINT32_MAX); GPR_ASSERT(msg_len <= UINT32_MAX);
uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 1); uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 1);
message_pfx = grpc_slice_malloc(14 + msg_len_len); message_pfx = GRPC_SLICE_MALLOC(14 + msg_len_len);
p = GRPC_SLICE_START_PTR(message_pfx); p = GRPC_SLICE_START_PTR(message_pfx);
*p++ = 0x00; /* literal header, not indexed */ *p++ = 0x00; /* literal header, not indexed */
*p++ = 12; /* len(grpc-message) */ *p++ = 12; /* len(grpc-message) */
@ -2075,7 +2075,7 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx); len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx);
len += (uint32_t)msg_len; len += (uint32_t)msg_len;
hdr = grpc_slice_malloc(9); hdr = GRPC_SLICE_MALLOC(9);
p = GRPC_SLICE_START_PTR(hdr); p = GRPC_SLICE_START_PTR(hdr);
*p++ = (uint8_t)(len >> 16); *p++ = (uint8_t)(len >> 16);
*p++ = (uint8_t)(len >> 8); *p++ = (uint8_t)(len >> 8);

@ -92,7 +92,7 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf,
uint8_t *p; uint8_t *p;
static const size_t header_size = 9; static const size_t header_size = 9;
hdr = grpc_slice_malloc(header_size); hdr = GRPC_SLICE_MALLOC(header_size);
p = GRPC_SLICE_START_PTR(hdr); p = GRPC_SLICE_START_PTR(hdr);
GPR_ASSERT(write_bytes < (1 << 24)); GPR_ASSERT(write_bytes < (1 << 24));
*p++ = (uint8_t)(write_bytes >> 16); *p++ = (uint8_t)(write_bytes >> 16);
@ -106,7 +106,7 @@ void grpc_chttp2_encode_data(uint32_t id, grpc_slice_buffer *inbuf,
*p++ = (uint8_t)(id); *p++ = (uint8_t)(id);
grpc_slice_buffer_add(outbuf, hdr); grpc_slice_buffer_add(outbuf, hdr);
grpc_slice_buffer_move_first(inbuf, write_bytes, outbuf); grpc_slice_buffer_move_first_no_ref(inbuf, write_bytes, outbuf);
stats->framing_bytes += header_size; stats->framing_bytes += header_size;
stats->data_bytes += write_bytes; stats->data_bytes += write_bytes;

@ -163,7 +163,7 @@ grpc_error *grpc_chttp2_goaway_parser_parse(grpc_exec_ctx *exec_ctx,
void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code, void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code,
grpc_slice debug_data, grpc_slice debug_data,
grpc_slice_buffer *slice_buffer) { grpc_slice_buffer *slice_buffer) {
grpc_slice header = grpc_slice_malloc(9 + 4 + 4); grpc_slice header = GRPC_SLICE_MALLOC(9 + 4 + 4);
uint8_t *p = GRPC_SLICE_START_PTR(header); uint8_t *p = GRPC_SLICE_START_PTR(header);
uint32_t frame_length; uint32_t frame_length;
GPR_ASSERT(GRPC_SLICE_LENGTH(debug_data) < UINT32_MAX - 4 - 4); GPR_ASSERT(GRPC_SLICE_LENGTH(debug_data) < UINT32_MAX - 4 - 4);

@ -43,7 +43,7 @@
static bool g_disable_ping_ack = false; static bool g_disable_ping_ack = false;
grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes) { grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes) {
grpc_slice slice = grpc_slice_malloc(9 + 8); grpc_slice slice = GRPC_SLICE_MALLOC(9 + 8);
uint8_t *p = GRPC_SLICE_START_PTR(slice); uint8_t *p = GRPC_SLICE_START_PTR(slice);
*p++ = 0; *p++ = 0;

@ -44,7 +44,7 @@
grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code, grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code,
grpc_transport_one_way_stats *stats) { grpc_transport_one_way_stats *stats) {
static const size_t frame_size = 13; static const size_t frame_size = 13;
grpc_slice slice = grpc_slice_malloc(frame_size); grpc_slice slice = GRPC_SLICE_MALLOC(frame_size);
stats->framing_bytes += frame_size; stats->framing_bytes += frame_size;
uint8_t *p = GRPC_SLICE_START_PTR(slice); uint8_t *p = GRPC_SLICE_START_PTR(slice);

@ -70,7 +70,7 @@ grpc_slice grpc_chttp2_settings_create(uint32_t *old, const uint32_t *new,
n += (new[i] != old[i] || (force_mask & (1u << i)) != 0); n += (new[i] != old[i] || (force_mask & (1u << i)) != 0);
} }
output = grpc_slice_malloc(9 + 6 * n); output = GRPC_SLICE_MALLOC(9 + 6 * n);
p = fill_header(GRPC_SLICE_START_PTR(output), 6 * n, 0); p = fill_header(GRPC_SLICE_START_PTR(output), 6 * n, 0);
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
@ -91,7 +91,7 @@ grpc_slice grpc_chttp2_settings_create(uint32_t *old, const uint32_t *new,
} }
grpc_slice grpc_chttp2_settings_ack_create(void) { grpc_slice grpc_chttp2_settings_ack_create(void) {
grpc_slice output = grpc_slice_malloc(9); grpc_slice output = GRPC_SLICE_MALLOC(9);
fill_header(GRPC_SLICE_START_PTR(output), 0, GRPC_CHTTP2_FLAG_ACK); fill_header(GRPC_SLICE_START_PTR(output), 0, GRPC_CHTTP2_FLAG_ACK);
return output; return output;
} }

@ -41,7 +41,7 @@
grpc_slice grpc_chttp2_window_update_create( grpc_slice grpc_chttp2_window_update_create(
uint32_t id, uint32_t window_update, grpc_transport_one_way_stats *stats) { uint32_t id, uint32_t window_update, grpc_transport_one_way_stats *stats) {
static const size_t frame_size = 13; static const size_t frame_size = 13;
grpc_slice slice = grpc_slice_malloc(frame_size); grpc_slice slice = GRPC_SLICE_MALLOC(frame_size);
stats->header_bytes += frame_size; stats->header_bytes += frame_size;
uint8_t *p = GRPC_SLICE_START_PTR(slice); uint8_t *p = GRPC_SLICE_START_PTR(slice);

@ -123,7 +123,7 @@ static void finish_frame(framer_state *st, int is_header_boundary,
output before beginning */ output before beginning */
static void begin_frame(framer_state *st) { static void begin_frame(framer_state *st) {
st->header_idx = st->header_idx =
grpc_slice_buffer_add_indexed(st->output, grpc_slice_malloc(9)); grpc_slice_buffer_add_indexed(st->output, GRPC_SLICE_MALLOC(9));
st->output_length_at_start_of_frame = st->output->length; st->output_length_at_start_of_frame = st->output->length;
} }

@ -1177,7 +1177,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx,
} else if (stream_state->rs.remaining_bytes == 0) { } else if (stream_state->rs.remaining_bytes == 0) {
CRONET_LOG(GPR_DEBUG, "read operation complete"); CRONET_LOG(GPR_DEBUG, "read operation complete");
grpc_slice read_data_slice = grpc_slice read_data_slice =
grpc_slice_malloc((uint32_t)stream_state->rs.length_field); GRPC_SLICE_MALLOC((uint32_t)stream_state->rs.length_field);
uint8_t *dst_p = GRPC_SLICE_START_PTR(read_data_slice); uint8_t *dst_p = GRPC_SLICE_START_PTR(read_data_slice);
memcpy(dst_p, stream_state->rs.read_buffer, memcpy(dst_p, stream_state->rs.read_buffer,
(size_t)stream_state->rs.length_field); (size_t)stream_state->rs.length_field);

@ -50,7 +50,7 @@ static int zlib_body(grpc_exec_ctx* exec_ctx, z_stream* zs,
int r; int r;
int flush; int flush;
size_t i; size_t i;
grpc_slice outbuf = grpc_slice_malloc(OUTPUT_BLOCK_SIZE); grpc_slice outbuf = GRPC_SLICE_MALLOC(OUTPUT_BLOCK_SIZE);
const uInt uint_max = ~(uInt)0; const uInt uint_max = ~(uInt)0;
GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max); GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max);
@ -65,7 +65,7 @@ static int zlib_body(grpc_exec_ctx* exec_ctx, z_stream* zs,
do { do {
if (zs->avail_out == 0) { if (zs->avail_out == 0) {
grpc_slice_buffer_add_indexed(output, outbuf); grpc_slice_buffer_add_indexed(output, outbuf);
outbuf = grpc_slice_malloc(OUTPUT_BLOCK_SIZE); outbuf = GRPC_SLICE_MALLOC(OUTPUT_BLOCK_SIZE);
GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max); GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max);
zs->avail_out = (uInt)GRPC_SLICE_LENGTH(outbuf); zs->avail_out = (uInt)GRPC_SLICE_LENGTH(outbuf);
zs->next_out = GRPC_SLICE_START_PTR(outbuf); zs->next_out = GRPC_SLICE_START_PTR(outbuf);

@ -219,7 +219,7 @@ static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
tcp->read_slices = read_slices; tcp->read_slices = read_slices;
grpc_slice_buffer_reset_and_unref_internal(exec_ctx, read_slices); grpc_slice_buffer_reset_and_unref_internal(exec_ctx, read_slices);
tcp->read_slice = grpc_slice_malloc(8192); tcp->read_slice = GRPC_SLICE_MALLOC(8192);
buffer.len = (ULONG)GRPC_SLICE_LENGTH( buffer.len = (ULONG)GRPC_SLICE_LENGTH(
tcp->read_slice); // we know slice size fits in 32bit. tcp->read_slice); // we know slice size fits in 32bit.

@ -130,7 +130,7 @@ static void secure_endpoint_ref(secure_endpoint *ep) { gpr_ref(&ep->ref); }
static void flush_read_staging_buffer(secure_endpoint *ep, uint8_t **cur, static void flush_read_staging_buffer(secure_endpoint *ep, uint8_t **cur,
uint8_t **end) { uint8_t **end) {
grpc_slice_buffer_add(ep->read_buffer, ep->read_staging_buffer); grpc_slice_buffer_add(ep->read_buffer, ep->read_staging_buffer);
ep->read_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE); ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
*cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer); *cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer);
*end = GRPC_SLICE_END_PTR(ep->read_staging_buffer); *end = GRPC_SLICE_END_PTR(ep->read_staging_buffer);
} }
@ -252,7 +252,7 @@ static void endpoint_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *secure_ep,
static void flush_write_staging_buffer(secure_endpoint *ep, uint8_t **cur, static void flush_write_staging_buffer(secure_endpoint *ep, uint8_t **cur,
uint8_t **end) { uint8_t **end) {
grpc_slice_buffer_add(&ep->output_buffer, ep->write_staging_buffer); grpc_slice_buffer_add(&ep->output_buffer, ep->write_staging_buffer);
ep->write_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE); ep->write_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
*cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer); *cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer);
*end = GRPC_SLICE_END_PTR(ep->write_staging_buffer); *end = GRPC_SLICE_END_PTR(ep->write_staging_buffer);
} }
@ -415,8 +415,8 @@ grpc_endpoint *grpc_secure_endpoint_create(
grpc_slice_buffer_add(&ep->leftover_bytes, grpc_slice_buffer_add(&ep->leftover_bytes,
grpc_slice_ref_internal(leftover_slices[i])); grpc_slice_ref_internal(leftover_slices[i]));
} }
ep->write_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE); ep->write_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
ep->read_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE); ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
grpc_slice_buffer_init(&ep->output_buffer); grpc_slice_buffer_init(&ep->output_buffer);
grpc_slice_buffer_init(&ep->source_buffer); grpc_slice_buffer_init(&ep->source_buffer);
ep->read_buffer = NULL; ep->read_buffer = NULL;

@ -202,7 +202,7 @@ static int decode_group(const unsigned char *codes, size_t num_codes,
grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx *exec_ctx, const char *b64, grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx *exec_ctx, const char *b64,
size_t b64_len, int url_safe) { size_t b64_len, int url_safe) {
grpc_slice result = grpc_slice_malloc(b64_len); grpc_slice result = GRPC_SLICE_MALLOC(b64_len);
unsigned char *current = GRPC_SLICE_START_PTR(result); unsigned char *current = GRPC_SLICE_START_PTR(result);
size_t result_size = 0; size_t result_size = 0;
unsigned char codes[4]; unsigned char codes[4];

@ -71,7 +71,7 @@ grpc_slice grpc_percent_encode_slice(grpc_slice slice,
return grpc_slice_ref_internal(slice); return grpc_slice_ref_internal(slice);
} }
// second pass: actually encode // second pass: actually encode
grpc_slice out = grpc_slice_malloc(output_length); grpc_slice out = GRPC_SLICE_MALLOC(output_length);
uint8_t *q = GRPC_SLICE_START_PTR(out); uint8_t *q = GRPC_SLICE_START_PTR(out);
for (p = slice_start; p < slice_end; p++) { for (p = slice_start; p < slice_end; p++) {
if (is_unreserved_character(*p, unreserved_bytes)) { if (is_unreserved_character(*p, unreserved_bytes)) {
@ -125,7 +125,7 @@ bool grpc_strict_percent_decode_slice(grpc_slice slice_in,
return true; return true;
} }
p = GRPC_SLICE_START_PTR(slice_in); p = GRPC_SLICE_START_PTR(slice_in);
*slice_out = grpc_slice_malloc(out_length); *slice_out = GRPC_SLICE_MALLOC(out_length);
uint8_t *q = GRPC_SLICE_START_PTR(*slice_out); uint8_t *q = GRPC_SLICE_START_PTR(*slice_out);
while (p != in_end) { while (p != in_end) {
if (*p == '%') { if (*p == '%') {
@ -163,7 +163,7 @@ grpc_slice grpc_permissive_percent_decode_slice(grpc_slice slice_in) {
return grpc_slice_ref_internal(slice_in); return grpc_slice_ref_internal(slice_in);
} }
p = GRPC_SLICE_START_PTR(slice_in); p = GRPC_SLICE_START_PTR(slice_in);
grpc_slice out = grpc_slice_malloc(out_length); grpc_slice out = GRPC_SLICE_MALLOC(out_length);
uint8_t *q = GRPC_SLICE_START_PTR(out); uint8_t *q = GRPC_SLICE_START_PTR(out);
while (p != in_end) { while (p != in_end) {
if (*p == '%') { if (*p == '%') {

@ -55,6 +55,13 @@ grpc_slice grpc_empty_slice(void) {
return out; return out;
} }
grpc_slice grpc_slice_copy(grpc_slice s) {
grpc_slice out = GRPC_SLICE_MALLOC(GRPC_SLICE_LENGTH(s));
memcpy(GRPC_SLICE_START_PTR(out), GRPC_SLICE_START_PTR(s),
GRPC_SLICE_LENGTH(s));
return out;
}
grpc_slice grpc_slice_ref_internal(grpc_slice slice) { grpc_slice grpc_slice_ref_internal(grpc_slice slice) {
if (slice.refcount) { if (slice.refcount) {
slice.refcount->vtable->ref(slice.refcount); slice.refcount->vtable->ref(slice.refcount);
@ -198,7 +205,7 @@ grpc_slice grpc_slice_new_with_len(void *p, size_t len,
grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t length) { grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t length) {
if (length == 0) return grpc_empty_slice(); if (length == 0) return grpc_empty_slice();
grpc_slice slice = grpc_slice_malloc(length); grpc_slice slice = GRPC_SLICE_MALLOC(length);
memcpy(GRPC_SLICE_START_PTR(slice), source, length); memcpy(GRPC_SLICE_START_PTR(slice), source, length);
return slice; return slice;
} }
@ -228,35 +235,42 @@ static const grpc_slice_refcount_vtable malloc_vtable = {
malloc_ref, malloc_unref, grpc_slice_default_eq_impl, malloc_ref, malloc_unref, grpc_slice_default_eq_impl,
grpc_slice_default_hash_impl}; grpc_slice_default_hash_impl};
grpc_slice grpc_slice_malloc_large(size_t length) {
grpc_slice slice;
/* Memory layout used by the slice created here:
+-----------+----------------------------------------------------------+
| refcount | bytes |
+-----------+----------------------------------------------------------+
refcount is a malloc_refcount
bytes is an array of bytes of the requested length
Both parts are placed in the same allocation returned from gpr_malloc */
malloc_refcount *rc = gpr_malloc(sizeof(malloc_refcount) + length);
/* Initial refcount on rc is 1 - and it's up to the caller to release
this reference. */
gpr_ref_init(&rc->refs, 1);
rc->base.vtable = &malloc_vtable;
rc->base.sub_refcount = &rc->base;
/* Build up the slice to be returned. */
/* The slices refcount points back to the allocated block. */
slice.refcount = &rc->base;
/* The data bytes are placed immediately after the refcount struct */
slice.data.refcounted.bytes = (uint8_t *)(rc + 1);
/* And the length of the block is set to the requested length */
slice.data.refcounted.length = length;
return slice;
}
grpc_slice grpc_slice_malloc(size_t length) { grpc_slice grpc_slice_malloc(size_t length) {
grpc_slice slice; grpc_slice slice;
if (length > sizeof(slice.data.inlined.bytes)) { if (length > sizeof(slice.data.inlined.bytes)) {
/* Memory layout used by the slice created here: return grpc_slice_malloc_large(length);
+-----------+----------------------------------------------------------+
| refcount | bytes |
+-----------+----------------------------------------------------------+
refcount is a malloc_refcount
bytes is an array of bytes of the requested length
Both parts are placed in the same allocation returned from gpr_malloc */
malloc_refcount *rc = gpr_malloc(sizeof(malloc_refcount) + length);
/* Initial refcount on rc is 1 - and it's up to the caller to release
this reference. */
gpr_ref_init(&rc->refs, 1);
rc->base.vtable = &malloc_vtable;
rc->base.sub_refcount = &rc->base;
/* Build up the slice to be returned. */
/* The slices refcount points back to the allocated block. */
slice.refcount = &rc->base;
/* The data bytes are placed immediately after the refcount struct */
slice.data.refcounted.bytes = (uint8_t *)(rc + 1);
/* And the length of the block is set to the requested length */
slice.data.refcounted.length = length;
} else { } else {
/* small slice: just inline the data */ /* small slice: just inline the data */
slice.refcount = NULL; slice.refcount = NULL;
@ -306,7 +320,8 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) {
return subset; return subset;
} }
grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) { grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice *source, size_t split,
grpc_slice_ref_whom ref_whom) {
grpc_slice tail; grpc_slice tail;
if (source->refcount == NULL) { if (source->refcount == NULL) {
@ -320,28 +335,46 @@ grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) {
} else { } else {
size_t tail_length = source->data.refcounted.length - split; size_t tail_length = source->data.refcounted.length - split;
GPR_ASSERT(source->data.refcounted.length >= split); GPR_ASSERT(source->data.refcounted.length >= split);
if (tail_length < sizeof(tail.data.inlined.bytes)) { if (tail_length < sizeof(tail.data.inlined.bytes) &&
ref_whom != GRPC_SLICE_REF_TAIL) {
/* Copy out the bytes - it'll be cheaper than refcounting */ /* Copy out the bytes - it'll be cheaper than refcounting */
tail.refcount = NULL; tail.refcount = NULL;
tail.data.inlined.length = (uint8_t)tail_length; tail.data.inlined.length = (uint8_t)tail_length;
memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split, memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split,
tail_length); tail_length);
source->refcount = source->refcount->sub_refcount;
} else { } else {
/* Build the result */ /* Build the result */
tail.refcount = source->refcount->sub_refcount; switch (ref_whom) {
/* Bump the refcount */ case GRPC_SLICE_REF_TAIL:
tail.refcount->vtable->ref(tail.refcount); tail.refcount = source->refcount->sub_refcount;
source->refcount = &noop_refcount;
break;
case GRPC_SLICE_REF_HEAD:
tail.refcount = &noop_refcount;
source->refcount = source->refcount->sub_refcount;
break;
case GRPC_SLICE_REF_BOTH:
tail.refcount = source->refcount->sub_refcount;
source->refcount = source->refcount->sub_refcount;
/* Bump the refcount */
tail.refcount->vtable->ref(tail.refcount);
break;
}
/* Point into the source array */ /* Point into the source array */
tail.data.refcounted.bytes = source->data.refcounted.bytes + split; tail.data.refcounted.bytes = source->data.refcounted.bytes + split;
tail.data.refcounted.length = tail_length; tail.data.refcounted.length = tail_length;
} }
source->refcount = source->refcount->sub_refcount;
source->data.refcounted.length = split; source->data.refcounted.length = split;
} }
return tail; return tail;
} }
grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) {
return grpc_slice_split_tail_maybe_ref(source, split, GRPC_SLICE_REF_BOTH);
}
grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) {
grpc_slice head; grpc_slice head;
@ -459,7 +492,7 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) {
} }
grpc_slice grpc_slice_dup(grpc_slice a) { grpc_slice grpc_slice_dup(grpc_slice a) {
grpc_slice copy = grpc_slice_malloc(GRPC_SLICE_LENGTH(a)); grpc_slice copy = GRPC_SLICE_MALLOC(GRPC_SLICE_LENGTH(a));
memcpy(GRPC_SLICE_START_PTR(copy), GRPC_SLICE_START_PTR(a), memcpy(GRPC_SLICE_START_PTR(copy), GRPC_SLICE_START_PTR(a),
GRPC_SLICE_LENGTH(a)); GRPC_SLICE_LENGTH(a));
return copy; return copy;

@ -253,16 +253,18 @@ void grpc_slice_buffer_move_into(grpc_slice_buffer *src,
src->length = 0; src->length = 0;
} }
void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n, static void slice_buffer_move_first_maybe_ref(grpc_slice_buffer *src, size_t n,
grpc_slice_buffer *dst) { grpc_slice_buffer *dst,
size_t output_len = dst->length + n; bool incref) {
size_t new_input_len = src->length - n;
GPR_ASSERT(src->length >= n); GPR_ASSERT(src->length >= n);
if (src->length == n) { if (src->length == n) {
grpc_slice_buffer_move_into(src, dst); grpc_slice_buffer_move_into(src, dst);
return; return;
} }
size_t output_len = dst->length + n;
size_t new_input_len = src->length - n;
while (src->count > 0) { while (src->count > 0) {
grpc_slice slice = grpc_slice_buffer_take_first(src); grpc_slice slice = grpc_slice_buffer_take_first(src);
size_t slice_len = GRPC_SLICE_LENGTH(slice); size_t slice_len = GRPC_SLICE_LENGTH(slice);
@ -272,11 +274,18 @@ void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n,
} else if (n == slice_len) { } else if (n == slice_len) {
grpc_slice_buffer_add(dst, slice); grpc_slice_buffer_add(dst, slice);
break; break;
} else { /* n < slice_len */ } else if (incref) { /* n < slice_len */
grpc_slice_buffer_undo_take_first(src, grpc_slice_split_tail(&slice, n)); grpc_slice_buffer_undo_take_first(
src, grpc_slice_split_tail_maybe_ref(&slice, n, GRPC_SLICE_REF_BOTH));
GPR_ASSERT(GRPC_SLICE_LENGTH(slice) == n); GPR_ASSERT(GRPC_SLICE_LENGTH(slice) == n);
grpc_slice_buffer_add(dst, slice); grpc_slice_buffer_add(dst, slice);
break; break;
} else { /* n < slice_len */
grpc_slice_buffer_undo_take_first(
src, grpc_slice_split_tail_maybe_ref(&slice, n, GRPC_SLICE_REF_TAIL));
GPR_ASSERT(GRPC_SLICE_LENGTH(slice) == n);
grpc_slice_buffer_add_indexed(dst, slice);
break;
} }
} }
GPR_ASSERT(dst->length == output_len); GPR_ASSERT(dst->length == output_len);
@ -284,6 +293,16 @@ void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n,
GPR_ASSERT(src->count > 0); GPR_ASSERT(src->count > 0);
} }
void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n,
grpc_slice_buffer *dst) {
slice_buffer_move_first_maybe_ref(src, n, dst, true);
}
void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer *src, size_t n,
grpc_slice_buffer *dst) {
slice_buffer_move_first_maybe_ref(src, n, dst, false);
}
void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx *exec_ctx, void grpc_slice_buffer_move_first_into_buffer(grpc_exec_ctx *exec_ctx,
grpc_slice_buffer *src, size_t n, grpc_slice_buffer *src, size_t n,
void *dst) { void *dst) {

@ -124,7 +124,7 @@ grpc_slice grpc_byte_buffer_reader_readall(grpc_byte_buffer_reader *reader) {
grpc_slice in_slice; grpc_slice in_slice;
size_t bytes_read = 0; size_t bytes_read = 0;
const size_t input_size = grpc_byte_buffer_length(reader->buffer_out); const size_t input_size = grpc_byte_buffer_length(reader->buffer_out);
grpc_slice out_slice = grpc_slice_malloc(input_size); grpc_slice out_slice = GRPC_SLICE_MALLOC(input_size);
uint8_t *const outbuf = GRPC_SLICE_START_PTR(out_slice); /* just an alias */ uint8_t *const outbuf = GRPC_SLICE_START_PTR(out_slice); /* just an alias */
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;

@ -179,10 +179,12 @@ grpc_call_set_credentials_type grpc_call_set_credentials_import;
grpc_server_credentials_set_auth_metadata_processor_type grpc_server_credentials_set_auth_metadata_processor_import; grpc_server_credentials_set_auth_metadata_processor_type grpc_server_credentials_set_auth_metadata_processor_import;
grpc_slice_ref_type grpc_slice_ref_import; grpc_slice_ref_type grpc_slice_ref_import;
grpc_slice_unref_type grpc_slice_unref_import; grpc_slice_unref_type grpc_slice_unref_import;
grpc_slice_copy_type grpc_slice_copy_import;
grpc_slice_new_type grpc_slice_new_import; grpc_slice_new_type grpc_slice_new_import;
grpc_slice_new_with_user_data_type grpc_slice_new_with_user_data_import; grpc_slice_new_with_user_data_type grpc_slice_new_with_user_data_import;
grpc_slice_new_with_len_type grpc_slice_new_with_len_import; grpc_slice_new_with_len_type grpc_slice_new_with_len_import;
grpc_slice_malloc_type grpc_slice_malloc_import; grpc_slice_malloc_type grpc_slice_malloc_import;
grpc_slice_malloc_large_type grpc_slice_malloc_large_import;
grpc_slice_intern_type grpc_slice_intern_import; grpc_slice_intern_type grpc_slice_intern_import;
grpc_slice_from_copied_string_type grpc_slice_from_copied_string_import; grpc_slice_from_copied_string_type grpc_slice_from_copied_string_import;
grpc_slice_from_copied_buffer_type grpc_slice_from_copied_buffer_import; grpc_slice_from_copied_buffer_type grpc_slice_from_copied_buffer_import;
@ -191,6 +193,7 @@ grpc_slice_from_static_buffer_type grpc_slice_from_static_buffer_import;
grpc_slice_sub_type grpc_slice_sub_import; grpc_slice_sub_type grpc_slice_sub_import;
grpc_slice_sub_no_ref_type grpc_slice_sub_no_ref_import; grpc_slice_sub_no_ref_type grpc_slice_sub_no_ref_import;
grpc_slice_split_tail_type grpc_slice_split_tail_import; grpc_slice_split_tail_type grpc_slice_split_tail_import;
grpc_slice_split_tail_maybe_ref_type grpc_slice_split_tail_maybe_ref_import;
grpc_slice_split_head_type grpc_slice_split_head_import; grpc_slice_split_head_type grpc_slice_split_head_import;
grpc_empty_slice_type grpc_empty_slice_import; grpc_empty_slice_type grpc_empty_slice_import;
grpc_slice_default_hash_impl_type grpc_slice_default_hash_impl_import; grpc_slice_default_hash_impl_type grpc_slice_default_hash_impl_import;
@ -219,6 +222,7 @@ grpc_slice_buffer_swap_type grpc_slice_buffer_swap_import;
grpc_slice_buffer_move_into_type grpc_slice_buffer_move_into_import; grpc_slice_buffer_move_into_type grpc_slice_buffer_move_into_import;
grpc_slice_buffer_trim_end_type grpc_slice_buffer_trim_end_import; grpc_slice_buffer_trim_end_type grpc_slice_buffer_trim_end_import;
grpc_slice_buffer_move_first_type grpc_slice_buffer_move_first_import; grpc_slice_buffer_move_first_type grpc_slice_buffer_move_first_import;
grpc_slice_buffer_move_first_no_ref_type grpc_slice_buffer_move_first_no_ref_import;
grpc_slice_buffer_move_first_into_buffer_type grpc_slice_buffer_move_first_into_buffer_import; grpc_slice_buffer_move_first_into_buffer_type grpc_slice_buffer_move_first_into_buffer_import;
grpc_slice_buffer_take_first_type grpc_slice_buffer_take_first_import; grpc_slice_buffer_take_first_type grpc_slice_buffer_take_first_import;
grpc_slice_buffer_undo_take_first_type grpc_slice_buffer_undo_take_first_import; grpc_slice_buffer_undo_take_first_type grpc_slice_buffer_undo_take_first_import;
@ -476,10 +480,12 @@ void grpc_rb_load_imports(HMODULE library) {
grpc_server_credentials_set_auth_metadata_processor_import = (grpc_server_credentials_set_auth_metadata_processor_type) GetProcAddress(library, "grpc_server_credentials_set_auth_metadata_processor"); grpc_server_credentials_set_auth_metadata_processor_import = (grpc_server_credentials_set_auth_metadata_processor_type) GetProcAddress(library, "grpc_server_credentials_set_auth_metadata_processor");
grpc_slice_ref_import = (grpc_slice_ref_type) GetProcAddress(library, "grpc_slice_ref"); grpc_slice_ref_import = (grpc_slice_ref_type) GetProcAddress(library, "grpc_slice_ref");
grpc_slice_unref_import = (grpc_slice_unref_type) GetProcAddress(library, "grpc_slice_unref"); grpc_slice_unref_import = (grpc_slice_unref_type) GetProcAddress(library, "grpc_slice_unref");
grpc_slice_copy_import = (grpc_slice_copy_type) GetProcAddress(library, "grpc_slice_copy");
grpc_slice_new_import = (grpc_slice_new_type) GetProcAddress(library, "grpc_slice_new"); grpc_slice_new_import = (grpc_slice_new_type) GetProcAddress(library, "grpc_slice_new");
grpc_slice_new_with_user_data_import = (grpc_slice_new_with_user_data_type) GetProcAddress(library, "grpc_slice_new_with_user_data"); grpc_slice_new_with_user_data_import = (grpc_slice_new_with_user_data_type) GetProcAddress(library, "grpc_slice_new_with_user_data");
grpc_slice_new_with_len_import = (grpc_slice_new_with_len_type) GetProcAddress(library, "grpc_slice_new_with_len"); grpc_slice_new_with_len_import = (grpc_slice_new_with_len_type) GetProcAddress(library, "grpc_slice_new_with_len");
grpc_slice_malloc_import = (grpc_slice_malloc_type) GetProcAddress(library, "grpc_slice_malloc"); grpc_slice_malloc_import = (grpc_slice_malloc_type) GetProcAddress(library, "grpc_slice_malloc");
grpc_slice_malloc_large_import = (grpc_slice_malloc_large_type) GetProcAddress(library, "grpc_slice_malloc_large");
grpc_slice_intern_import = (grpc_slice_intern_type) GetProcAddress(library, "grpc_slice_intern"); grpc_slice_intern_import = (grpc_slice_intern_type) GetProcAddress(library, "grpc_slice_intern");
grpc_slice_from_copied_string_import = (grpc_slice_from_copied_string_type) GetProcAddress(library, "grpc_slice_from_copied_string"); grpc_slice_from_copied_string_import = (grpc_slice_from_copied_string_type) GetProcAddress(library, "grpc_slice_from_copied_string");
grpc_slice_from_copied_buffer_import = (grpc_slice_from_copied_buffer_type) GetProcAddress(library, "grpc_slice_from_copied_buffer"); grpc_slice_from_copied_buffer_import = (grpc_slice_from_copied_buffer_type) GetProcAddress(library, "grpc_slice_from_copied_buffer");
@ -488,6 +494,7 @@ void grpc_rb_load_imports(HMODULE library) {
grpc_slice_sub_import = (grpc_slice_sub_type) GetProcAddress(library, "grpc_slice_sub"); grpc_slice_sub_import = (grpc_slice_sub_type) GetProcAddress(library, "grpc_slice_sub");
grpc_slice_sub_no_ref_import = (grpc_slice_sub_no_ref_type) GetProcAddress(library, "grpc_slice_sub_no_ref"); grpc_slice_sub_no_ref_import = (grpc_slice_sub_no_ref_type) GetProcAddress(library, "grpc_slice_sub_no_ref");
grpc_slice_split_tail_import = (grpc_slice_split_tail_type) GetProcAddress(library, "grpc_slice_split_tail"); grpc_slice_split_tail_import = (grpc_slice_split_tail_type) GetProcAddress(library, "grpc_slice_split_tail");
grpc_slice_split_tail_maybe_ref_import = (grpc_slice_split_tail_maybe_ref_type) GetProcAddress(library, "grpc_slice_split_tail_maybe_ref");
grpc_slice_split_head_import = (grpc_slice_split_head_type) GetProcAddress(library, "grpc_slice_split_head"); grpc_slice_split_head_import = (grpc_slice_split_head_type) GetProcAddress(library, "grpc_slice_split_head");
grpc_empty_slice_import = (grpc_empty_slice_type) GetProcAddress(library, "grpc_empty_slice"); grpc_empty_slice_import = (grpc_empty_slice_type) GetProcAddress(library, "grpc_empty_slice");
grpc_slice_default_hash_impl_import = (grpc_slice_default_hash_impl_type) GetProcAddress(library, "grpc_slice_default_hash_impl"); grpc_slice_default_hash_impl_import = (grpc_slice_default_hash_impl_type) GetProcAddress(library, "grpc_slice_default_hash_impl");
@ -516,6 +523,7 @@ void grpc_rb_load_imports(HMODULE library) {
grpc_slice_buffer_move_into_import = (grpc_slice_buffer_move_into_type) GetProcAddress(library, "grpc_slice_buffer_move_into"); grpc_slice_buffer_move_into_import = (grpc_slice_buffer_move_into_type) GetProcAddress(library, "grpc_slice_buffer_move_into");
grpc_slice_buffer_trim_end_import = (grpc_slice_buffer_trim_end_type) GetProcAddress(library, "grpc_slice_buffer_trim_end"); grpc_slice_buffer_trim_end_import = (grpc_slice_buffer_trim_end_type) GetProcAddress(library, "grpc_slice_buffer_trim_end");
grpc_slice_buffer_move_first_import = (grpc_slice_buffer_move_first_type) GetProcAddress(library, "grpc_slice_buffer_move_first"); grpc_slice_buffer_move_first_import = (grpc_slice_buffer_move_first_type) GetProcAddress(library, "grpc_slice_buffer_move_first");
grpc_slice_buffer_move_first_no_ref_import = (grpc_slice_buffer_move_first_no_ref_type) GetProcAddress(library, "grpc_slice_buffer_move_first_no_ref");
grpc_slice_buffer_move_first_into_buffer_import = (grpc_slice_buffer_move_first_into_buffer_type) GetProcAddress(library, "grpc_slice_buffer_move_first_into_buffer"); grpc_slice_buffer_move_first_into_buffer_import = (grpc_slice_buffer_move_first_into_buffer_type) GetProcAddress(library, "grpc_slice_buffer_move_first_into_buffer");
grpc_slice_buffer_take_first_import = (grpc_slice_buffer_take_first_type) GetProcAddress(library, "grpc_slice_buffer_take_first"); grpc_slice_buffer_take_first_import = (grpc_slice_buffer_take_first_type) GetProcAddress(library, "grpc_slice_buffer_take_first");
grpc_slice_buffer_undo_take_first_import = (grpc_slice_buffer_undo_take_first_type) GetProcAddress(library, "grpc_slice_buffer_undo_take_first"); grpc_slice_buffer_undo_take_first_import = (grpc_slice_buffer_undo_take_first_type) GetProcAddress(library, "grpc_slice_buffer_undo_take_first");

@ -488,6 +488,9 @@ extern grpc_slice_ref_type grpc_slice_ref_import;
typedef void(*grpc_slice_unref_type)(grpc_slice s); typedef void(*grpc_slice_unref_type)(grpc_slice s);
extern grpc_slice_unref_type grpc_slice_unref_import; extern grpc_slice_unref_type grpc_slice_unref_import;
#define grpc_slice_unref grpc_slice_unref_import #define grpc_slice_unref grpc_slice_unref_import
typedef grpc_slice(*grpc_slice_copy_type)(grpc_slice s);
extern grpc_slice_copy_type grpc_slice_copy_import;
#define grpc_slice_copy grpc_slice_copy_import
typedef grpc_slice(*grpc_slice_new_type)(void *p, size_t len, void (*destroy)(void *)); typedef grpc_slice(*grpc_slice_new_type)(void *p, size_t len, void (*destroy)(void *));
extern grpc_slice_new_type grpc_slice_new_import; extern grpc_slice_new_type grpc_slice_new_import;
#define grpc_slice_new grpc_slice_new_import #define grpc_slice_new grpc_slice_new_import
@ -500,6 +503,9 @@ extern grpc_slice_new_with_len_type grpc_slice_new_with_len_import;
typedef grpc_slice(*grpc_slice_malloc_type)(size_t length); typedef grpc_slice(*grpc_slice_malloc_type)(size_t length);
extern grpc_slice_malloc_type grpc_slice_malloc_import; extern grpc_slice_malloc_type grpc_slice_malloc_import;
#define grpc_slice_malloc grpc_slice_malloc_import #define grpc_slice_malloc grpc_slice_malloc_import
typedef grpc_slice(*grpc_slice_malloc_large_type)(size_t length);
extern grpc_slice_malloc_large_type grpc_slice_malloc_large_import;
#define grpc_slice_malloc_large grpc_slice_malloc_large_import
typedef grpc_slice(*grpc_slice_intern_type)(grpc_slice slice); typedef grpc_slice(*grpc_slice_intern_type)(grpc_slice slice);
extern grpc_slice_intern_type grpc_slice_intern_import; extern grpc_slice_intern_type grpc_slice_intern_import;
#define grpc_slice_intern grpc_slice_intern_import #define grpc_slice_intern grpc_slice_intern_import
@ -524,6 +530,9 @@ extern grpc_slice_sub_no_ref_type grpc_slice_sub_no_ref_import;
typedef grpc_slice(*grpc_slice_split_tail_type)(grpc_slice *s, size_t split); typedef grpc_slice(*grpc_slice_split_tail_type)(grpc_slice *s, size_t split);
extern grpc_slice_split_tail_type grpc_slice_split_tail_import; extern grpc_slice_split_tail_type grpc_slice_split_tail_import;
#define grpc_slice_split_tail grpc_slice_split_tail_import #define grpc_slice_split_tail grpc_slice_split_tail_import
typedef grpc_slice(*grpc_slice_split_tail_maybe_ref_type)(grpc_slice *s, size_t split, grpc_slice_ref_whom ref_whom);
extern grpc_slice_split_tail_maybe_ref_type grpc_slice_split_tail_maybe_ref_import;
#define grpc_slice_split_tail_maybe_ref grpc_slice_split_tail_maybe_ref_import
typedef grpc_slice(*grpc_slice_split_head_type)(grpc_slice *s, size_t split); typedef grpc_slice(*grpc_slice_split_head_type)(grpc_slice *s, size_t split);
extern grpc_slice_split_head_type grpc_slice_split_head_import; extern grpc_slice_split_head_type grpc_slice_split_head_import;
#define grpc_slice_split_head grpc_slice_split_head_import #define grpc_slice_split_head grpc_slice_split_head_import
@ -608,6 +617,9 @@ extern grpc_slice_buffer_trim_end_type grpc_slice_buffer_trim_end_import;
typedef void(*grpc_slice_buffer_move_first_type)(grpc_slice_buffer *src, size_t n, grpc_slice_buffer *dst); typedef void(*grpc_slice_buffer_move_first_type)(grpc_slice_buffer *src, size_t n, grpc_slice_buffer *dst);
extern grpc_slice_buffer_move_first_type grpc_slice_buffer_move_first_import; extern grpc_slice_buffer_move_first_type grpc_slice_buffer_move_first_import;
#define grpc_slice_buffer_move_first grpc_slice_buffer_move_first_import #define grpc_slice_buffer_move_first grpc_slice_buffer_move_first_import
typedef void(*grpc_slice_buffer_move_first_no_ref_type)(grpc_slice_buffer *src, size_t n, grpc_slice_buffer *dst);
extern grpc_slice_buffer_move_first_no_ref_type grpc_slice_buffer_move_first_no_ref_import;
#define grpc_slice_buffer_move_first_no_ref grpc_slice_buffer_move_first_no_ref_import
typedef void(*grpc_slice_buffer_move_first_into_buffer_type)(grpc_exec_ctx *exec_ctx, grpc_slice_buffer *src, size_t n, void *dst); typedef void(*grpc_slice_buffer_move_first_into_buffer_type)(grpc_exec_ctx *exec_ctx, grpc_slice_buffer *src, size_t n, void *dst);
extern grpc_slice_buffer_move_first_into_buffer_type grpc_slice_buffer_move_first_into_buffer_import; extern grpc_slice_buffer_move_first_into_buffer_type grpc_slice_buffer_move_first_into_buffer_import;
#define grpc_slice_buffer_move_first_into_buffer grpc_slice_buffer_move_first_into_buffer_import #define grpc_slice_buffer_move_first_into_buffer grpc_slice_buffer_move_first_into_buffer_import

@ -102,13 +102,14 @@ static void me_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Endpoint already shutdown"); error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Endpoint already shutdown");
} else if (m->on_read != NULL) { } else if (m->on_read != NULL) {
for (size_t i = 0; i < slices->count; i++) { for (size_t i = 0; i < slices->count; i++) {
grpc_slice_buffer_add(m->on_read_out, grpc_slice_ref(slices->slices[i])); grpc_slice_buffer_add(m->on_read_out, grpc_slice_copy(slices->slices[i]));
} }
grpc_closure_sched(exec_ctx, m->on_read, GRPC_ERROR_NONE); grpc_closure_sched(exec_ctx, m->on_read, GRPC_ERROR_NONE);
m->on_read = NULL; m->on_read = NULL;
} else { } else {
for (size_t i = 0; i < slices->count; i++) { for (size_t i = 0; i < slices->count; i++) {
grpc_slice_buffer_add(&m->read_buffer, grpc_slice_ref(slices->slices[i])); grpc_slice_buffer_add(&m->read_buffer,
grpc_slice_copy(slices->slices[i]));
} }
} }
gpr_mu_unlock(&m->parent->mu); gpr_mu_unlock(&m->parent->mu);

@ -66,14 +66,14 @@ static void te_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
static void te_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, static void te_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
grpc_slice_buffer *slices, grpc_closure *cb) { grpc_slice_buffer *slices, grpc_closure *cb) {
trickle_endpoint *te = (trickle_endpoint *)ep; trickle_endpoint *te = (trickle_endpoint *)ep;
for (size_t i = 0; i < slices->count; i++) {
grpc_slice_ref_internal(slices->slices[i]);
}
gpr_mu_lock(&te->mu); gpr_mu_lock(&te->mu);
if (te->write_buffer.length == 0) { if (te->write_buffer.length == 0) {
te->last_write = gpr_now(GPR_CLOCK_MONOTONIC); te->last_write = gpr_now(GPR_CLOCK_MONOTONIC);
} }
grpc_slice_buffer_addn(&te->write_buffer, slices->slices, slices->count); for (size_t i = 0; i < slices->count; i++) {
grpc_slice_buffer_add(&te->write_buffer,
grpc_slice_copy(slices->slices[i]));
}
grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_REF(te->error)); grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_REF(te->error));
gpr_mu_unlock(&te->mu); gpr_mu_unlock(&te->mu);
} }

@ -34,8 +34,8 @@ licenses(["notice"]) # 3-clause BSD
cc_binary( cc_binary(
name = "testso.so", name = "testso.so",
srcs = [], srcs = [],
deps = ["//:grpc++_unsecure"],
linkshared = 1, linkshared = 1,
deps = ["//:grpc++_unsecure"],
) )
cc_library( cc_library(
@ -104,5 +104,29 @@ cc_test(
], ],
) )
cc_binary(
name = "grpc_cli",
srcs = [
"cli_call.cc",
"cli_call.h",
"cli_credentials.cc",
"cli_credentials.h",
"config_grpc_cli.h",
"grpc_cli.cc",
"grpc_tool.cc",
"grpc_tool.h",
"proto_file_parser.cc",
"proto_file_parser.h",
"proto_reflection_descriptor_database.cc",
"proto_reflection_descriptor_database.h",
"service_describer.cc",
"service_describer.h",
"test_config.h",
"test_config_cc.cc",
],
deps = [
"//:grpc++",
"//external:gflags",
"//src/proto/grpc/reflection/v1alpha:reflection_proto",
],
)

@ -42,14 +42,14 @@ CLOUD_PROJECT=grpc-testing
ZONE=us-central1-b # this zone allows 32core machines ZONE=us-central1-b # this zone allows 32core machines
INSTANCE_NAME="${1:-grpc-performance-server1}" INSTANCE_NAME="${1:-grpc-performance-server1}"
MACHINE_TYPE=n1-standard-8 MACHINE_TYPE=n1-standard-32
gcloud compute instances create $INSTANCE_NAME \ gcloud compute instances create $INSTANCE_NAME \
--project="$CLOUD_PROJECT" \ --project="$CLOUD_PROJECT" \
--zone "$ZONE" \ --zone "$ZONE" \
--machine-type $MACHINE_TYPE \ --machine-type $MACHINE_TYPE \
--image-project ubuntu-os-cloud \ --image-project ubuntu-os-cloud \
--image-family ubuntu-1604-lts \ --image-family ubuntu-1610 \
--boot-disk-size 300 \ --boot-disk-size 300 \
--scopes https://www.googleapis.com/auth/bigquery --scopes https://www.googleapis.com/auth/bigquery

@ -55,7 +55,10 @@ sudo apt-get install -y \
libc6 \ libc6 \
libc6-dbg \ libc6-dbg \
libc6-dev \ libc6-dev \
libcurl4-openssl-dev \
libgtest-dev \ libgtest-dev \
libreadline-dev \
libssl-dev \
libtool \ libtool \
make \ make \
strace \ strace \
@ -71,7 +74,8 @@ sudo apt-get install -y \
telnet \ telnet \
unzip \ unzip \
wget \ wget \
zip zip \
zlib1g-dev
# perftools # perftools
sudo apt-get install -y google-perftools libgoogle-perftools-dev sudo apt-get install -y google-perftools libgoogle-perftools-dev
@ -87,14 +91,15 @@ sudo pip install tabulate
sudo pip install google-api-python-client sudo pip install google-api-python-client
sudo pip install virtualenv sudo pip install virtualenv
# TODO(jtattermusch): For some reason, building gRPC Python depends on python3.4 # Building gRPC Python depends on python3.4 being installed, but python3.4
# being installed, but python3.4 is not available on Ubuntu 16.04. # is not available on Ubuntu 16.10, so install from source
# Temporarily fixing this by adding a PPA with python3.4, but we should curl -O https://www.python.org/ftp/python/3.4.6/Python-3.4.6.tgz
# really remove this hack once possible. tar xzvf Python-3.4.6.tgz
sudo add-apt-repository -y ppa:fkrull/deadsnakes cd Python-3.4.6
sudo apt-get update ./configure --enable-shared --prefix=/usr/local LDFLAGS="-Wl,--rpath=/usr/local/lib"
sudo apt-get install -y python3.4 python3.4-dev sudo make altinstall
python3.4 -m pip install virtualenv cd ..
rm Python-3.4.6.tgz
curl -O https://bootstrap.pypa.io/get-pip.py curl -O https://bootstrap.pypa.io/get-pip.py
sudo pypy get-pip.py sudo pypy get-pip.py
@ -117,18 +122,25 @@ sudo apt-get update
sudo apt-get install -y mono-devel nuget sudo apt-get install -y mono-devel nuget
# C# .NET Core dependencies (https://www.microsoft.com/net/core#ubuntu) # C# .NET Core dependencies (https://www.microsoft.com/net/core#ubuntu)
sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ xenial main" > /etc/apt/sources.list.d/dotnetdev.list' sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ yakkety main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893 sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
sudo apt-get update sudo apt-get update
sudo apt-get install -y dotnet-dev-1.0.0-preview2-003131 sudo apt-get install -y dotnet-dev-1.0.0-preview2.1-003155
sudo apt-get install -y dotnet-dev-1.0.1 sudo apt-get install -y dotnet-dev-1.0.1
# Ruby dependencies # Ruby dependencies
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 git clone https://github.com/rbenv/rbenv.git ~/.rbenv
curl -sSL https://get.rvm.io | bash -s stable --ruby export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
rbenv install 2.4.0
rbenv global 2.4.0
ruby -v
# Install bundler (prerequisite for gRPC Ruby) # Install bundler (prerequisite for gRPC Ruby)
source ~/.rvm/scripts/rvm
gem install bundler gem install bundler
# Java dependencies - nothing as we already have Java JDK 8 # Java dependencies - nothing as we already have Java JDK 8
@ -163,15 +175,7 @@ echo 4096 | sudo tee /proc/sys/kernel/perf_event_mlock_kb
git clone -v https://github.com/brendangregg/FlameGraph ~/FlameGraph git clone -v https://github.com/brendangregg/FlameGraph ~/FlameGraph
# Install scipy and numpy for benchmarking scripts # Install scipy and numpy for benchmarking scripts
sudo apt-get install python-scipy python-numpy sudo apt-get install -y python-scipy python-numpy
# Update Linux kernel to 4.9
wget \
kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.20/linux-headers-4.9.20-040920_4.9.20-040920.201703310531_all.deb \
kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.20/linux-headers-4.9.20-040920-generic_4.9.20-040920.201703310531_amd64.deb \
kernel.ubuntu.com/~kernel-ppa/mainline/v4.9.20/linux-image-4.9.20-040920-generic_4.9.20-040920.201703310531_amd64.deb
sudo dpkg -i linux-headers-4.9*.deb linux-image-4.9*.deb
rm linux-*
# Add pubkey of jenkins@grpc-jenkins-master to authorized keys of jenkins@ # Add pubkey of jenkins@grpc-jenkins-master to authorized keys of jenkins@
# This needs to happen as the last step to prevent Jenkins master from connecting # This needs to happen as the last step to prevent Jenkins master from connecting

@ -50,6 +50,7 @@ BANNED_EXCEPT = {
'grpc_os_error(': ['src/core/lib/iomgr/error.c'], 'grpc_os_error(': ['src/core/lib/iomgr/error.c'],
'grpc_wsa_error(': ['src/core/lib/iomgr/error.c'], 'grpc_wsa_error(': ['src/core/lib/iomgr/error.c'],
'grpc_log_if_error(': ['src/core/lib/iomgr/error.c'], 'grpc_log_if_error(': ['src/core/lib/iomgr/error.c'],
'grpc_slice_malloc(': ['src/core/lib/slice/slice.c'],
} }
errors = 0 errors = 0

Loading…
Cancel
Save