summaryrefslogtreecommitdiff
path: root/vendor/bundle/ruby/3.4.0/gems/eventmachine-1.2.7/lib/em/protocols/line_protocol.rb
blob: dfddae8c040e9e09b31197e14a3e66e2bc4d989e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module EventMachine
  module Protocols
    # LineProtocol will parse out newline terminated strings from a receive_data stream
    #
    #  module Server
    #    include EM::P::LineProtocol
    #
    #    def receive_line(line)
    #      send_data("you said: #{line}")
    #    end
    #  end
    #
    module LineProtocol
      # @private
      def receive_data data
        (@buf ||= '') << data

        while @buf.slice!(/(.*?)\r?\n/)
          receive_line($1)
        end
      end

      # Invoked with lines received over the network
      def receive_line(line)
        # stub
      end
    end
  end
end