fix adjust_tail_space

pull/19792/head
Jan Tattermusch 6 years ago
parent aaddd42c00
commit 74dcdbb3c3
  1. 26
      src/csharp/ext/grpc_csharp_ext.c

@ -1223,32 +1223,30 @@ GPR_EXPORT void* GPR_CALLTYPE
grpcsharp_slice_buffer_adjust_tail_space(grpc_slice_buffer* buffer, size_t available_tail_space, grpcsharp_slice_buffer_adjust_tail_space(grpc_slice_buffer* buffer, size_t available_tail_space,
size_t requested_tail_space) { size_t requested_tail_space) {
if (available_tail_space == 0 && requested_tail_space == 0) if (available_tail_space == requested_tail_space) {
{ // nothing to do
return NULL;
} }
// TODO: what if available_tail_space == requested_tail_space == 0 else if (available_tail_space >= requested_tail_space)
if (available_tail_space >= requested_tail_space)
{ {
// TODO: should this be allowed at all? grpc_slice_buffer_trim_end(buffer, available_tail_space - requested_tail_space, NULL);
grpc_slice_buffer garbage;
grpc_slice_buffer_trim_end(buffer, available_tail_space - requested_tail_space, &garbage);
grpc_slice_buffer_reset_and_unref(&garbage);
} }
else else
{ {
if (available_tail_space > 0) if (available_tail_space > 0)
{ {
grpc_slice_buffer garbage; grpc_slice_buffer_trim_end(buffer, available_tail_space, NULL);
grpc_slice_buffer_trim_end(buffer, available_tail_space, &garbage);
grpc_slice_buffer_reset_and_unref(&garbage);
} }
grpc_slice new_slice = grpc_slice_malloc(requested_tail_space); grpc_slice new_slice = grpc_slice_malloc(requested_tail_space);
grpc_slice_buffer_add(buffer, new_slice); // TODO: this always adds as a new slice entry into the sb, but it doesn't have the problem of
// sometimes splitting the continguous new_slice across two different slices (like grpc_slice_buffer_add would)
grpc_slice_buffer_add_indexed(buffer, new_slice);
} }
if (buffer->count == 0)
{
return NULL;
}
grpc_slice* last_slice = &(buffer->slices[buffer->count - 1]); grpc_slice* last_slice = &(buffer->slices[buffer->count - 1]);
return GRPC_SLICE_END_PTR(*last_slice) - requested_tail_space; return GRPC_SLICE_END_PTR(*last_slice) - requested_tail_space;
} }

Loading…
Cancel
Save