class Async::HTTP::Protocol::HTTP2::Stream

def send_chunk

def send_chunk
	maximum_size = self.available_frame_size
	
	if maximum_size == 0
		return false
	end
	
	if @remainder
		chunk = @remainder
		@remainder = nil
	elsif chunk = @body.read
		# There was a new chunk of data to send
	else
		if @body
			@body.close
			@body = nil
		end
		
		# @body.read above might take a while and a stream reset might be received in the mean time.
		unless closed?
			send_data(nil, ::Protocol::HTTP2::END_STREAM)
		end
		
		return false
	end
	
	return false if closed?
	
	if chunk.bytesize <= maximum_size
		send_data(chunk, maximum_size: maximum_size)
	else
		send_data(chunk.byteslice(0, maximum_size), maximum_size: maximum_size)
		
		@remainder = chunk.byteslice(maximum_size, chunk.bytesize - maximum_size)
	end
	
	return true
end