Add a better comment and rename consume_first to remove_first.

pull/18926/head
Soheil Hassas Yeganeh 6 years ago
parent f5f030e675
commit 1f0476267b
  1. 30
      src/core/ext/transport/chttp2/transport/frame_data.cc
  2. 4
      src/core/lib/compression/stream_compression_gzip.cc
  3. 2
      src/core/lib/iomgr/tcp_posix.cc
  4. 2
      src/core/lib/security/transport/security_handshaker.cc
  5. 2
      src/core/lib/slice/slice_buffer.cc
  6. 7
      src/core/lib/slice/slice_internal.h
  7. 6
      test/core/slice/slice_buffer_test.cc

@ -112,14 +112,14 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
char* msg;
if (cur == end) {
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
continue;
}
switch (p->state) {
case GRPC_CHTTP2_DATA_ERROR:
p->state = GRPC_CHTTP2_DATA_ERROR;
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
return GRPC_ERROR_REF(p->error);
case GRPC_CHTTP2_DATA_FH_0:
s->stats.incoming.framing_bytes++;
@ -144,12 +144,12 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
p->error =
grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg);
p->state = GRPC_CHTTP2_DATA_ERROR;
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
return GRPC_ERROR_REF(p->error);
}
if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_1;
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
continue;
}
/* fallthrough */
@ -158,7 +158,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
p->frame_size = (static_cast<uint32_t>(*cur)) << 24;
if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_2;
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
continue;
}
/* fallthrough */
@ -167,7 +167,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
p->frame_size |= (static_cast<uint32_t>(*cur)) << 16;
if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_3;
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
continue;
}
/* fallthrough */
@ -176,7 +176,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
p->frame_size |= (static_cast<uint32_t>(*cur)) << 8;
if (++cur == end) {
p->state = GRPC_CHTTP2_DATA_FH_4;
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
continue;
}
/* fallthrough */
@ -207,14 +207,14 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
grpc_slice_buffer_sub_first(slices, static_cast<size_t>(cur - beg),
static_cast<size_t>(end - beg));
} else {
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
}
return GRPC_ERROR_NONE;
case GRPC_CHTTP2_DATA_FRAME: {
GPR_ASSERT(p->parsing_frame != nullptr);
GPR_ASSERT(slice_out != nullptr);
if (cur == end) {
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
continue;
}
uint32_t remaining = static_cast<uint32_t>(end - cur);
@ -225,17 +225,17 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
grpc_slice_sub(*slice, static_cast<size_t>(cur - beg),
static_cast<size_t>(end - beg)),
slice_out))) {
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
return error;
}
if (GRPC_ERROR_NONE !=
(error = p->parsing_frame->Finished(GRPC_ERROR_NONE, true))) {
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
return error;
}
p->parsing_frame = nullptr;
p->state = GRPC_CHTTP2_DATA_FH_0;
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
return GRPC_ERROR_NONE;
} else if (remaining < p->frame_size) {
s->stats.incoming.data_bytes += remaining;
@ -247,7 +247,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
return error;
}
p->frame_size -= remaining;
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
return GRPC_ERROR_NONE;
} else {
GPR_ASSERT(remaining > p->frame_size);
@ -258,12 +258,12 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
*slice, static_cast<size_t>(cur - beg),
static_cast<size_t>(cur + p->frame_size - beg)),
slice_out)) {
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
return error;
}
if (GRPC_ERROR_NONE !=
(error = p->parsing_frame->Finished(GRPC_ERROR_NONE, true))) {
grpc_slice_buffer_consume_first(slices);
grpc_slice_buffer_remove_first(slices);
return error;
}
p->parsing_frame = nullptr;

@ -60,7 +60,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx,
if (r < 0 && r != Z_BUF_ERROR) {
gpr_log(GPR_ERROR, "zlib error (%d)", r);
grpc_slice_unref_internal(slice_out);
grpc_slice_buffer_consume_first(in);
grpc_slice_buffer_remove_first(in);
return false;
} else if (r == Z_STREAM_END && ctx->flate == inflate) {
eoc = true;
@ -70,7 +70,7 @@ static bool gzip_flate(grpc_stream_compression_context_gzip* ctx,
in, GRPC_SLICE_LENGTH(*slice) - ctx->zs.avail_in,
GRPC_SLICE_LENGTH(*slice));
} else {
grpc_slice_buffer_consume_first(in);
grpc_slice_buffer_remove_first(in);
}
}
if (flush != 0 && ctx->zs.avail_out > 0 && !eoc) {

@ -980,7 +980,7 @@ static bool tcp_flush(grpc_tcp* tcp, grpc_error** error) {
// unref all and forget about all slices that have been written to this
// point
for (size_t idx = 0; idx < unwind_slice_idx; ++idx) {
grpc_slice_buffer_consume_first(tcp->outgoing_buffer);
grpc_slice_buffer_remove_first(tcp->outgoing_buffer);
}
return false;
} else if (errno == EPIPE) {

@ -148,7 +148,7 @@ size_t SecurityHandshaker::MoveReadBufferIntoHandshakeBuffer() {
memcpy(handshake_buffer_ + offset, GRPC_SLICE_START_PTR(*next_slice),
GRPC_SLICE_LENGTH(*next_slice));
offset += GRPC_SLICE_LENGTH(*next_slice);
grpc_slice_buffer_consume_first(args_->read_buffer);
grpc_slice_buffer_remove_first(args_->read_buffer);
}
return bytes_in_read_buffer;
}

@ -370,7 +370,7 @@ grpc_slice grpc_slice_buffer_take_first(grpc_slice_buffer* sb) {
return slice;
}
void grpc_slice_buffer_consume_first(grpc_slice_buffer* sb) {
void grpc_slice_buffer_remove_first(grpc_slice_buffer* sb) {
GPR_DEBUG_ASSERT(sb->count > 0);
sb->length -= GRPC_SLICE_LENGTH(sb->slices[0]);
grpc_slice_unref_internal(sb->slices[0]);

@ -242,14 +242,15 @@ void grpc_slice_buffer_partial_unref_internal(grpc_slice_buffer* sb,
size_t idx);
void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb);
// Returns the first slice in the slice buffer.
// Returns a pointer to the first slice in the slice buffer without giving
// ownership to or a reference count on that slice.
inline grpc_slice* grpc_slice_buffer_peek_first(grpc_slice_buffer* sb) {
GPR_DEBUG_ASSERT(sb->count > 0);
return &sb->slices[0];
}
// Consumes the first slice in the slice buffer.
void grpc_slice_buffer_consume_first(grpc_slice_buffer* sb);
// Removes the first slice from the slice buffer.
void grpc_slice_buffer_remove_first(grpc_slice_buffer* sb);
// Calls grpc_slice_sub with the given parameters on the first slice.
void grpc_slice_buffer_sub_first(grpc_slice_buffer* sb, size_t begin,

@ -130,19 +130,19 @@ void test_slice_buffer_first() {
GPR_ASSERT(buf.count == 3);
GPR_ASSERT(buf.length == 10);
grpc_slice_buffer_consume_first(&buf);
grpc_slice_buffer_remove_first(&buf);
first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == GPR_SLICE_LENGTH(slices[1]));
GPR_ASSERT(buf.count == 2);
GPR_ASSERT(buf.length == 9);
grpc_slice_buffer_consume_first(&buf);
grpc_slice_buffer_remove_first(&buf);
first = grpc_slice_buffer_peek_first(&buf);
GPR_ASSERT(GPR_SLICE_LENGTH(*first) == GPR_SLICE_LENGTH(slices[2]));
GPR_ASSERT(buf.count == 1);
GPR_ASSERT(buf.length == 5);
grpc_slice_buffer_consume_first(&buf);
grpc_slice_buffer_remove_first(&buf);
GPR_ASSERT(buf.count == 0);
GPR_ASSERT(buf.length == 0);
}

Loading…
Cancel
Save