        # File lib/em/protocols/linetext2.rb, line 48
    48:       def receive_data data
    49:         return unless (data and data.length > 0)
    50:
    51:         # Do this stuff in lieu of a constructor.
    52:         @lt2_mode ||= :lines
    53:         @lt2_delimiter ||= "\n"
    54:         @lt2_linebuffer ||= []
    55:
    56:         if @lt2_mode == :lines
    57:           if ix = data.index( @lt2_delimiter )
    58:             @lt2_linebuffer << data[0...ix]
    59:             ln = @lt2_linebuffer.join
    60:             @lt2_linebuffer.clear
    61:             if @lt2_delimiter == "\n"
    62:               ln.chomp!
    63:             end
    64:             receive_line ln
    65:             receive_data data[(ix+@lt2_delimiter.length)..-1]
    66:           else
    67:             @lt2_linebuffer << data
    68:           end
    69:         elsif @lt2_mode == :text
    70:           if @lt2_textsize
    71:             needed = @lt2_textsize - @lt2_textpos
    72:             will_take = if data.length > needed
    73:                           needed
    74:                         else
    75:                           data.length
    76:                         end
    77:
    78:             @lt2_textbuffer << data[0...will_take]
    79:             tail = data[will_take..-1]
    80:
    81:             @lt2_textpos += will_take
    82:             if @lt2_textpos >= @lt2_textsize
    83:               # Reset line mode (the default behavior) BEFORE calling the
    84:               # receive_binary_data. This makes it possible for user code
    85:               # to call set_text_mode, enabling chains of text blocks
    86:               # (which can possibly be of different sizes).
    87:               set_line_mode
    88:               receive_binary_data @lt2_textbuffer.join
    89:               receive_end_of_binary_data
    90:             end
    91:
    92:             receive_data tail
    93:           else
    94:             receive_binary_data data
    95:           end
    96:         end
    97:       end