Project

General

Profile

Bug #6436 » protocol.patch

nobu (Nobuyoshi Nakada), 05/16/2012 10:05 AM

View differences:

/after/lib/ruby/1.9.1/net/protocol.rb 2012-05-15 13:19:09.000000000 -0700
def read(len, dest = '', ignore_eof = false)
LOG "reading #{len} bytes..."
read_bytes = 0
begin
while read_bytes + @rbuf.size < len
dest << (s = rbuf_consume(@rbuf.size))
read_bytes += s.size
while read_bytes + @rbuf.bytesize < len
dest << (s = rbuf_consume(@rbuf.bytesize))
read_bytes += s.bytesize
rbuf_fill
end
dest << (s = rbuf_consume(len - read_bytes))
read_bytes += s.size
read_bytes += s.bytesize
rescue EOFError
raise unless ignore_eof
end
LOG "read #{read_bytes} bytes"
dest
......
def read_all(dest = '')
LOG 'reading all...'
read_bytes = 0
begin
while true
dest << (s = rbuf_consume(@rbuf.size))
read_bytes += s.size
dest << (s = rbuf_consume(@rbuf.bytesize))
read_bytes += s.bytesize
rbuf_fill
end
rescue EOFError
;
end
......
def readuntil(terminator, ignore_eof = false)
begin
until idx = @rbuf.index(terminator)
rbuf_fill
end
return rbuf_consume(idx + terminator.size)
return rbuf_consume(idx + terminator.bytesize)
rescue EOFError
raise unless ignore_eof
return rbuf_consume(@rbuf.size)
return rbuf_consume(@rbuf.bytesize)
end
end
def readline
readuntil("\n").chop
......
def each_message_chunk
LOG 'reading message...'
LOG_off()
read_bytes = 0
while (line = readuntil("\r\n")) != ".\r\n"
read_bytes += line.size
read_bytes += line.bytesize
yield line.sub(/\A\./, '')
end
LOG_on()
LOG "read message (#{read_bytes} bytes)"
end
......
end
def buffer_filling(buf, src)
case src
when String # for speeding up.
0.step(src.size - 1, 1024) do |i|
0.step(src.bytesize - 1, 1024) do |i|
buf << src[i, 1024]
yield
end
when File # for speeding up.
while s = src.read(1024)
......
yield
end
else # generic reader
src.each do |str|
buf << str
yield if buf.size > 1024
yield if buf.bytesize > 1024
end
yield unless buf.empty?
end
end
end
(2-2/2)