Skip to content

Commit

Permalink
request reader: no use state-full `scan_line' method (#34)
Browse files Browse the repository at this point in the history
Github Issue: #34
  • Loading branch information
y10k committed Mar 17, 2020
1 parent 7aa5ed9 commit 65546d0
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/rims/protocol/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,32 @@ def gets
end
end

def read_literal(size)
@logger.debug("found literal: #{size} octets.") if @logger.debug?
@output.write("+ continue\r\n")
@output.flush
@logger.debug('continue literal.') if @logger.debug?
literal_string = @input.read(size) or raise 'unexpected client close.'
@logger.debug("read literal: #{Protocol.io_data_log(literal_string)}") if @logger.debug?

literal_string
end
private :read_literal

def read_line
line = gets or return
@logger.debug("read line: #{Protocol.io_data_log(line)}") if @logger.debug?
line.chomp!("\n")
line.chomp!("\r")
scan_line(line)
atom_list = self.class.scan(line)

if ((atom_list[-1].is_a? Array) && (atom_list[-1][0] == :literal)) then
atom_list[-1] = read_literal(atom_list[-1][1])
next_atom_list = read_line or raise 'unexpected client close.'
atom_list += next_atom_list
end

atom_list
end

def scan_line(line)
Expand Down

0 comments on commit 65546d0

Please sign in to comment.