anchor.diff:  -behaviour(escalus_connection).
   
   -include_lib("exml/include/exml_stream.hrl").
  +-include_lib("exml/include/exml.hrl").
   -include("escalus.hrl").
   
   %% API exports
  
positive.code:     {ok, Pid} = gen_server:start_link(?MODULE, [Opts1, self()], []),
      Pid.
  
  -spec send(pid(), exml:element()) -> ok.
  send(Pid, Elem) ->
      gen_server:cast(Pid, {send, Elem}).
  
  -spec is_connected(pid()) -> boolean().
  is_connected(Pid) ->
  
negative.code: reply_to_ack_requests({true,H,inactive}, _, _) -> {true, H, inactive};
  reply_to_ack_requests({true, H0, active}, Acks, State) ->
      {true,
       % TODO: Maybe compress here?
       lists:foldl(fun({Ack,H}, _) -> raw_send(exml:to_iolist(Ack), State), H end,
                   H0, Acks),
       active}.
  
  maybe_compress_and_send(Data, #state{ compress = {zlib, {_, Zout}} } = State) ->
      raw_send(zlib:deflate(Zout, Data, sync), State);
  maybe_compress_and_send(Data, State) ->
      raw_send(Data, State).
  
  raw_send(Data, #state{socket = Socket, ssl = true}) ->
      ssl:send(Socket, Data);
  raw_send(Data, #state{socket = Socket}) ->
      gen_tcp:send(Socket, Data).
  
  common_terminate(_Reason, #state{parser = Parser}) ->
      exml_stream:free_parser(Parser).
  