summaryrefslogtreecommitdiff
path: root/lib/net/protocol.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-16 14:03:20 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-16 14:03:20 +0000
commit0d11c322d107ccb3e53d5a429c89fc954c561a93 (patch)
tree1b8f4bac570726c7c66c1d0785da8041176bee83 /lib/net/protocol.rb
parent074203d270bba2046f6d272f9d01385257be9fee (diff)
aamine
* lib/net/http.rb: can call {old,new}_implementation any times. * lib/net/http.rb: HTTP#connecting, receive -> common_oper, connecting. * lib/net/http.rb: output warning if u_header includes duplicated header. * lib/net/http.rb: not check Connection:/Proxy-Connection; always read until eof. * lib/net/protocol: detects and catches "break" from block. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/net/protocol.rb')
-rw-r--r--lib/net/protocol.rb48
1 files changed, 38 insertions, 10 deletions
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 82cc82f..eb90cd4 100644
--- a/lib/net/protocol.rb
+++ b/lib/net/protocol.rb
@@ -314,12 +314,31 @@ module Net
end
def <<( str )
- @block.call str
+ callblock( str, &@block ) if @block
+ end
+
+ private
+
+ def callblock( str )
+ begin
+ user_break = true
+ yield str
+ user_break = false
+ rescue Exception
+ user_break = false
+ raise
+ ensure
+ if user_break then
+ @block = nil
+ return # stop break
+ end
+ end
end
end
+
class Command
def initialize( sock )
@@ -442,6 +461,7 @@ module Net
def address
@addr.dup
end
+
alias addr address
attr_reader :port
@@ -449,12 +469,17 @@ module Net
def ip_address
@ipaddr.dup
end
+
alias ipaddr ip_address
attr_reader :sending
- CRLF = "\r\n"
+ ###
+ ### read
+ ###
+
+ CRLF = "\r\n"
def read( len, dest = '' )
@pipe << "reading #{len} bytes...\n" if @pipe; pipeoff
@@ -514,7 +539,7 @@ module Net
rsize = 0
- while (str = readuntil( "\r\n" )) != ".\r\n" do
+ while (str = readuntil("\r\n")) != ".\r\n" do
rsize += str.size
str.gsub!( /\A\./, '' )
dest << str
@@ -525,20 +550,19 @@ module Net
end
+ # private use only (can not handle 'break')
def read_pendlist
@pipe << "reading list...\n" if @pipe; pipeoff
- arr = []
str = nil
-
- while (str = readuntil( "\r\n" )) != ".\r\n" do
+ i = 0
+ while (str = readuntil("\r\n")) != ".\r\n" do
str.chop!
- arr.push str
- yield str if block_given?
+ yield str
+ i += 1
end
- @pipe << "read #{arr.size} lines\n" if pipeon
- arr
+ @pipe << "read #{i} items\n" if pipeon
end
@@ -561,6 +585,10 @@ module Net
end
+ ###
+ ### write
+ ###
+
public