From 0d11c322d107ccb3e53d5a429c89fc954c561a93 Mon Sep 17 00:00:00 2001 From: aamine Date: Thu, 16 Nov 2000 14:03:20 +0000 Subject: 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 --- lib/net/protocol.rb | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'lib/net/protocol.rb') diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 82cc82fa24..eb90cd48b3 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 -- cgit v1.2.3