anchor.diff:            end,
       case Msg of
           finished ->
  -            {[], NewBuf};
  +            {[], 0, NewBuf};
           skip ->
               buffer_to_pkts(NewBuf, BytesRemaining, DrainTok);
           {msg, MData} ->
  
positive.code:         empty ->
              {next_state, ready_to_send, State};
          not_empty ->
              {Data, NewBuf} = buffer_to_pkts(Buf, ?TARGET_SEND_SIZE, DrainTok),
              erlang:port_command(Sock, Data, []),
              {next_state, sending, State#state{buf = NewBuf}}
      end.
  
  buffer_to_pkts(Buf, BytesRemaining, DrainTok) when BytesRemaining > 0 ->
      {Item, NewBuf} = logplex_drain_buffer:pop(Buf),
      Msg = case Item of
                empty ->
  
negative.code:             DataSize = iolist_size(Data),
              case BytesRemaining - DataSize of
                  Remaining when Remaining > 0 ->
                      {Rest, Count, FinalBuf} = buffer_to_pkts(NewBuf,
                                                               Remaining,
                                                               DrainTok),
                      {[Data, Rest], Count + 1, FinalBuf};
                  _ when DataSize > ?TARGET_SEND_SIZE ->
                      %% We will exceed bytes remaining, but this
                      %% message is a pig, so send it anyway.
                      {Data, 1, NewBuf};
                  _ ->
                      %% Would have exceeded BytesRemaining, pretend we
                      %% didn't pop it.
                      {[], 0, Buf}
              end
      end.
  