pull/13391/head
ncteisen 7 years ago
parent 50cfbe358e
commit 589c940195
  1. 4
      src/core/lib/iomgr/tcp_posix.cc
  2. 9
      src/core/lib/slice/slice_buffer.cc
  3. 6
      src/core/lib/slice/slice_internal.h
  4. 39
      test/core/slice/slice_buffer_test.cc

@ -576,8 +576,8 @@ static bool tcp_flush(grpc_exec_ctx* exec_ctx, grpc_tcp* tcp,
if (errno == EAGAIN) {
tcp->outgoing_slice_idx = unwind_slice_idx;
tcp->outgoing_byte_idx = unwind_byte_idx;
grpc_slice_buffer_partial_reset_and_unref_internal(
exec_ctx, tcp->outgoing_buffer, unwind_slice_idx);
grpc_slice_buffer_partial_unref_internal(exec_ctx, tcp->outgoing_buffer,
unwind_slice_idx);
return false;
} else if (errno == EPIPE) {
*error = grpc_error_set_int(GRPC_OS_ERROR(errno, "sendmsg"),

@ -176,10 +176,11 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx,
sb->idx_of_first_valid_slice = 0;
}
void grpc_slice_buffer_partial_reset_and_unref_internal(grpc_exec_ctx* exec_ctx,
grpc_slice_buffer* sb,
size_t idx) {
GPR_ASSERT(idx <= sb->count);
void grpc_slice_buffer_partial_unref_internal(grpc_exec_ctx* exec_ctx,
grpc_slice_buffer* sb,
size_t idx) {
GPR_ASSERT(idx < sb->count); // if idx == count, then partial is not needed
GPR_ASSERT(sb->idx_of_first_valid_slice <= idx);
size_t i;
for (i = sb->idx_of_first_valid_slice; i < idx; i++) {

@ -32,9 +32,9 @@ grpc_slice grpc_slice_ref_internal(grpc_slice slice);
void grpc_slice_unref_internal(grpc_exec_ctx* exec_ctx, grpc_slice slice);
void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx* exec_ctx,
grpc_slice_buffer* sb);
void grpc_slice_buffer_partial_reset_and_unref_internal(grpc_exec_ctx* exec_ctx,
grpc_slice_buffer* sb,
size_t idx);
void grpc_slice_buffer_partial_unref_internal(grpc_exec_ctx* exec_ctx,
grpc_slice_buffer* sb,
size_t idx);
void grpc_slice_buffer_destroy_internal(grpc_exec_ctx* exec_ctx,
grpc_slice_buffer* sb);

@ -18,6 +18,7 @@
#include <grpc/slice_buffer.h>
#include <grpc/support/log.h>
#include "src/core/lib/slice/slice_internal.h"
#include "test/core/util/test_config.h"
void test_slice_buffer_add() {
@ -104,11 +105,49 @@ void test_slice_buffer_move_first() {
GPR_ASSERT(dst.length == dst_len);
}
static void populate_slice_buffer(grpc_slice_buffer* sb) {
grpc_slice slices[4];
int idx = 0;
slices[0] = grpc_slice_from_copied_string("aaa");
slices[1] = grpc_slice_from_copied_string("bbbb");
slices[2] = grpc_slice_from_copied_string("ccc");
slices[3] = grpc_slice_from_copied_string("ddddd");
for (idx = 0; idx < 4; idx++) {
grpc_slice_ref(slices[idx]);
grpc_slice_buffer_add_indexed(sb, slices[idx]);
}
}
void test_slice_buffer_unref() {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_slice_buffer sb;
grpc_slice_buffer_init(&sb);
// regular init and unref
populate_slice_buffer(&sb);
grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &sb);
// inits, then unrefs partial, then unrefs the rest
populate_slice_buffer(&sb);
grpc_slice_buffer_partial_unref_internal(&exec_ctx, &sb, 1);
grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &sb);
// two partial unrefs
populate_slice_buffer(&sb);
grpc_slice_buffer_partial_unref_internal(&exec_ctx, &sb, 1);
grpc_slice_buffer_partial_unref_internal(&exec_ctx, &sb, 3);
grpc_slice_buffer_reset_and_unref_internal(&exec_ctx, &sb);
}
int main(int argc, char** argv) {
grpc_test_init(argc, argv);
test_slice_buffer_add();
test_slice_buffer_move_first();
test_slice_buffer_unref();
return 0;
}

Loading…
Cancel
Save