Fri Jun 16 22:56:02 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>
* protocol.rb (each_crlf_line): too many CRLF is concat-ed: remove each_crlf_line2(), @wbuf * protocol.rb: CRLF -> "\r\n", D_CRLF -> ".\r\n", strip //o git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
feb82209ab
commit
290f4e0d8d
@ -7,15 +7,6 @@ written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
|
|||||||
This library is distributed under the terms of the Ruby license.
|
This library is distributed under the terms of the Ruby license.
|
||||||
You can freely distribute/modify this library.
|
You can freely distribute/modify this library.
|
||||||
|
|
||||||
=end
|
|
||||||
|
|
||||||
|
|
||||||
require 'socket'
|
|
||||||
|
|
||||||
|
|
||||||
module Net
|
|
||||||
|
|
||||||
=begin
|
|
||||||
|
|
||||||
== Net::Protocol
|
== Net::Protocol
|
||||||
|
|
||||||
@ -66,9 +57,15 @@ Object
|
|||||||
|
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
require 'socket'
|
||||||
|
|
||||||
|
|
||||||
|
module Net
|
||||||
|
|
||||||
class Protocol
|
class Protocol
|
||||||
|
|
||||||
Version = '1.1.22'
|
Version = '1.1.23'
|
||||||
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
@ -480,9 +477,6 @@ Object
|
|||||||
|
|
||||||
|
|
||||||
CRLF = "\r\n"
|
CRLF = "\r\n"
|
||||||
D_CRLF = ".\r\n"
|
|
||||||
TERMEXP = /\n|\r\n|\r/o
|
|
||||||
|
|
||||||
|
|
||||||
def read( len, dest = '' )
|
def read( len, dest = '' )
|
||||||
@pipe << "reading #{len} bytes...\n" if @pipe; pipeoff
|
@pipe << "reading #{len} bytes...\n" if @pipe; pipeoff
|
||||||
@ -531,7 +525,7 @@ Object
|
|||||||
|
|
||||||
|
|
||||||
def readline
|
def readline
|
||||||
ret = readuntil( CRLF )
|
ret = readuntil( "\r\n" )
|
||||||
ret.chop!
|
ret.chop!
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
@ -542,9 +536,9 @@ Object
|
|||||||
|
|
||||||
rsize = 0
|
rsize = 0
|
||||||
|
|
||||||
while (str = readuntil( CRLF )) != D_CRLF do
|
while (str = readuntil( "\r\n" )) != ".\r\n" do
|
||||||
rsize += str.size
|
rsize += str.size
|
||||||
str.gsub!( /\A\./o, '' )
|
str.gsub!( /\A\./, '' )
|
||||||
dest << str
|
dest << str
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -559,7 +553,7 @@ Object
|
|||||||
arr = []
|
arr = []
|
||||||
str = nil
|
str = nil
|
||||||
|
|
||||||
while (str = readuntil( CRLF )) != D_CRLF do
|
while (str = readuntil( "\r\n" )) != ".\r\n" do
|
||||||
str.chop!
|
str.chop!
|
||||||
arr.push str
|
arr.push str
|
||||||
yield str if iterator?
|
yield str if iterator?
|
||||||
@ -602,7 +596,7 @@ Object
|
|||||||
def writeline( str )
|
def writeline( str )
|
||||||
do_write_beg
|
do_write_beg
|
||||||
do_write_do str
|
do_write_do str
|
||||||
do_write_do CRLF
|
do_write_do "\r\n"
|
||||||
do_write_fin
|
do_write_fin
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -629,8 +623,7 @@ Object
|
|||||||
else
|
else
|
||||||
write_pendstr_inner src
|
write_pendstr_inner src
|
||||||
end
|
end
|
||||||
each_crlf_line2( :i_w_pend )
|
do_write_do ".\r\n"
|
||||||
do_write_do D_CRLF
|
|
||||||
wsize = do_write_fin
|
wsize = do_write_fin
|
||||||
|
|
||||||
@pipe << "wrote #{wsize} bytes text\n" if pipeon
|
@pipe << "wrote #{wsize} bytes text\n" if pipeon
|
||||||
@ -657,32 +650,40 @@ Object
|
|||||||
|
|
||||||
|
|
||||||
def each_crlf_line( src, mid )
|
def each_crlf_line( src, mid )
|
||||||
beg = 0
|
buf = ''
|
||||||
buf = pos = s = bin = nil
|
str = m = nil
|
||||||
|
|
||||||
adding( src ) do
|
adding( src, buf ) do
|
||||||
beg = 0
|
|
||||||
buf = @wbuf
|
|
||||||
while true do
|
while true do
|
||||||
pos = buf.index( TERMEXP, beg )
|
m = /[^\r\n]*(\n|\r\n|\r)/.match( buf )
|
||||||
break unless pos
|
break unless m
|
||||||
s = $&.size
|
|
||||||
break if pos + s == buf.size - 1 and buf[-1] == ?\r
|
|
||||||
|
|
||||||
__send__ mid, buf[ beg, pos - beg ] << CRLF
|
str = m[0]
|
||||||
beg = pos + s
|
if str.size == buf.size and buf[-1] == ?\r then
|
||||||
|
# "...\r" : can follow "\n..."
|
||||||
|
break
|
||||||
|
end
|
||||||
|
buf[ 0, str.size ] = ''
|
||||||
|
str.chop!
|
||||||
|
str.concat "\r\n"
|
||||||
|
__send__ mid, str
|
||||||
end
|
end
|
||||||
@wbuf = buf[ beg, buf.size - beg ] if beg != 0
|
end
|
||||||
|
if not buf.empty? then # un-terminated last line
|
||||||
|
buf.concat "\r\n"
|
||||||
|
__send__ mid, buf
|
||||||
|
elsif not str then # empty src
|
||||||
|
__send__ mid, "\r\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def adding( src )
|
def adding( src, buf )
|
||||||
i = nil
|
i = nil
|
||||||
|
|
||||||
case src
|
case src
|
||||||
when String
|
when String
|
||||||
0.step( src.size, 512 ) do |i|
|
0.step( src.size, 512 ) do |i|
|
||||||
@wbuf << src[ i, 512 ]
|
buf << src[ i, 512 ]
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -690,38 +691,22 @@ Object
|
|||||||
while true do
|
while true do
|
||||||
i = src.read( 512 )
|
i = src.read( 512 )
|
||||||
break unless i
|
break unless i
|
||||||
@wbuf << i
|
buf << i
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
src.each do |bin|
|
src.each do |bin|
|
||||||
@wbuf << bin
|
buf << bin
|
||||||
yield if @wbuf.size > 512
|
yield if buf.size > 512
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_crlf_line2( mid )
|
|
||||||
buf = @wbuf
|
|
||||||
beg = pos = nil
|
|
||||||
|
|
||||||
buf << "\n" unless /\n|\r/o === buf[-1,1]
|
|
||||||
|
|
||||||
beg = 0
|
|
||||||
while true do
|
|
||||||
pos = buf.index( TERMEXP, beg )
|
|
||||||
break unless pos
|
|
||||||
__send__ mid, buf[ beg, pos - beg ] << CRLF
|
|
||||||
beg = pos + $&.size
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
def do_write_beg
|
def do_write_beg
|
||||||
@writtensize = 0
|
@writtensize = 0
|
||||||
@sending = ''
|
@sending = ''
|
||||||
@wbuf = ''
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def do_write_do( arg )
|
def do_write_do( arg )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user