don't copy arrays, unless you have to
This commit is contained in:
parent
15a4f06afa
commit
b5bed34702
1 changed files with 16 additions and 6 deletions
|
|
@ -92,12 +92,22 @@ class NNTP
|
|||
putline cmd
|
||||
end
|
||||
|
||||
# def getline
|
||||
# line = ''
|
||||
# line.concat @socket.recv 1 until line.length > 2 and line[-1] == "\n" or line[-2..-1] == "\r\n"
|
||||
# puts '*getline* '+line if @debuglevel > 0
|
||||
# line = line[0...-2] if line[-2..-1] == "\r\n"
|
||||
# line = line[0...-1] if "\r\n".include? line[-1].to_s
|
||||
# return line
|
||||
# end
|
||||
|
||||
def getline
|
||||
line = ''
|
||||
line.concat @socket.recv 1 until line.length > 2 and line[-1] == "\n" or line[-2..-1] == "\r\n"
|
||||
puts '*getline* '+line if @debuglevel > 0
|
||||
line = line[0...-2] if line[-2..-1] == "\r\n"
|
||||
line = line[0...-1] if "\r\n".include? line[-1].to_s
|
||||
line = @socket.readline
|
||||
print "*getline* '#{line}'" if @debuglevel > 0
|
||||
line.chomp!("\r\n")
|
||||
# line.sub!(/\r?\n?$/, '')
|
||||
# print "*getline* matches end\n" if line == '.'
|
||||
return line
|
||||
end
|
||||
|
||||
|
|
@ -113,14 +123,14 @@ class NNTP
|
|||
return resp
|
||||
end
|
||||
|
||||
def getlongresp
|
||||
def getlongresp
|
||||
resp = getresp
|
||||
raise NNTPReplyError, resp, caller unless LONGRESP.include? resp[0...3]
|
||||
list = []
|
||||
while true
|
||||
line = getline
|
||||
break if line == '.'
|
||||
line = line[1..-1] if line.to_s[0...2] == '..'
|
||||
line.delete_at(0) if line.to_s[0...2] == '..'
|
||||
list << line
|
||||
end
|
||||
return resp, list
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue