anchor.diff:  			end
   	end.
   
  -send_data(State, []) ->
  -	State;
  -send_data(State0, [{StreamID, IsFin, SendData}|Tail]) ->
  -	State = send_data(State0, StreamID, IsFin, SendData),
  -	send_data(State, Tail).
  -
  -send_data(State0, StreamID, IsFin, [Data]) ->
  -	State = send_data_frame(State0, StreamID, IsFin, Data),
  -	maybe_terminate_stream(State, StreamID, IsFin);
  -send_data(State0, StreamID, IsFin, [Data|Tail]) ->
  -	State = send_data_frame(State0, StreamID, nofin, Data),
  -	send_data(State, StreamID, IsFin, Tail).
  -
  -send_data_frame(State=#state{socket=Socket, transport=Transport},
  -		StreamID, IsFin, {data, Data}) ->
  -	Transport:send(Socket, cow_http2:data(StreamID, IsFin, Data)),
  -	State;
  -send_data_frame(State=#state{socket=Socket, transport=Transport, opts=Opts},
  -		StreamID, IsFin, {sendfile, Offset, Bytes, Path}) ->
  -	Transport:send(Socket, cow_http2:data_header(StreamID, IsFin, Bytes)),
  -	%% When sendfile is disabled we explicitly use the fallback.
  -	_ = case maps:get(sendfile, Opts, true) of
  -		true -> Transport:sendfile(Socket, Path, Offset, Bytes);
  -		false -> ranch_transport:sendfile(Transport, Socket, Path, Offset, Bytes, [])
  -	end,
  -	State;
  +send_data(State0=#state{socket=Socket, transport=Transport, opts=Opts}, SendData, Prefix) ->
  +	{Acc, State} = prepare_data(State0, SendData, [], Prefix),
  +	_ = [case Data of
  +		{sendfile, Offset, Bytes, Path} ->
  +			%% When sendfile is disabled we explicitly use the fallback.
  +			_ = case maps:get(sendfile, Opts, true) of
  +				true -> Transport:sendfile(Socket, Path, Offset, Bytes);
  +				false -> ranch_transport:sendfile(Transport, Socket, Path, Offset, Bytes, [])
  +			end;
  +		_ ->
  +			Transport:send(Socket, Data)
  +	end || Data <- Acc],
  +	State.
  +
  +prepare_data(State, [], Acc, []) ->
  +	{lists:reverse(Acc), State};
  +prepare_data(State, [], Acc, Buffer) ->
  +	{lists:reverse([lists:reverse(Buffer)|Acc]), State};
  +prepare_data(State0, [{StreamID, IsFin, SendData}|Tail], Acc0, Buffer0) ->
  +	{Acc, Buffer, State} = prepare_data(State0, StreamID, IsFin, SendData, Acc0, Buffer0),
  +	prepare_data(State, Tail, Acc, Buffer).
  +
  +prepare_data(State0, StreamID, IsFin, [], Acc, Buffer) ->
  +	State = maybe_terminate_stream(State0, StreamID, IsFin),
  +	{Acc, Buffer, State};
  +prepare_data(State0, StreamID, IsFin, [FrameData|Tail], Acc, Buffer) ->
  +	FrameIsFin = case Tail of
  +		[] -> IsFin;
  +		_ -> nofin
  +	end,
  +	case prepare_data_frame(State0, StreamID, FrameIsFin, FrameData) of
  +		{{MoreData, Sendfile}, State} when is_tuple(Sendfile) ->
  +			case Buffer of
  +				[] ->
  +					prepare_data(State, StreamID, IsFin, Tail,
  +						[Sendfile, MoreData|Acc], []);
  +				_ ->
  +					prepare_data(State, StreamID, IsFin, Tail,
  +						[Sendfile, lists:reverse([MoreData|Buffer])|Acc], [])
  +			end;
  +		{MoreData, State} ->
  +			prepare_data(State, StreamID, IsFin, Tail,
  +				Acc, [MoreData|Buffer])
  +	end.
  +
  +prepare_data_frame(State, StreamID, IsFin, {data, Data}) ->
  +	{cow_http2:data(StreamID, IsFin, Data),
  +		State};
  +prepare_data_frame(State, StreamID, IsFin, Sendfile={sendfile, _, Bytes, _}) ->
  +	{{cow_http2:data_header(StreamID, IsFin, Bytes), Sendfile},
  +		State};
   %% The stream is terminated in cow_http2_machine:prepare_trailers.
  -send_data_frame(State=#state{socket=Socket, transport=Transport,
  -		http2_machine=HTTP2Machine0}, StreamID, nofin, {trailers, Trailers}) ->
  +prepare_data_frame(State=#state{http2_machine=HTTP2Machine0},
  +		StreamID, nofin, {trailers, Trailers}) ->
   	{ok, HeaderBlock, HTTP2Machine}
   		= cow_http2_machine:prepare_trailers(StreamID, HTTP2Machine0, Trailers),
  -	Transport:send(Socket, cow_http2:headers(StreamID, fin, HeaderBlock)),
  -	State#state{http2_machine=HTTP2Machine}.
  +	{cow_http2:headers(StreamID, fin, HeaderBlock),
  +		State#state{http2_machine=HTTP2Machine}}.
   
   %% After we have sent or queued data we may need to set or clear an alarm.
   %% We do this by comparing the HTTP2Machine buffer state before/after for
  
positive.code: 			%% We may need to send an alarm for each of the streams sending data.
  			lists:foldl(
  				fun({StreamID, _, _}, S) -> maybe_send_data_alarm(S, HTTP2Machine0, StreamID) end,
  				send_data(maybe_ack(State#state{http2_machine=HTTP2Machine}, Frame), SendData),
  				SendData);
  		{error, {stream_error, StreamID, Reason, Human}, HTTP2Machine} ->
  			reset_stream(State#state{http2_machine=HTTP2Machine},
  
negative.code: 
  %% Send the response, trailers or data.
  
  send_response(State0=#state{http2_machine=HTTP2Machine0}, StreamID, StatusCode, Headers, Body) ->
  	Size = case Body of
  		{sendfile, _, Bytes, _} -> Bytes;
  		_ -> iolist_size(Body)
  