From 79633d3bb8334fc58be49b6d86fcd6a40f569f75 Mon Sep 17 00:00:00 2001 From: aamine Date: Fri, 22 Dec 2000 18:40:55 +0000 Subject: aamine * lib/net/protocol.rb: set @closed false in Socket#reopen. * lib/net/pop.rb: add POP3.foreach, delete_all. * lib/net/pop.rb: add POP3#delete_all. * lib/net/http.rb: add HTTP.version_1_1, version_1_2 * lib/net/http.rb: refactoring. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/net/protocol.rb | 75 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 28 deletions(-) (limited to 'lib/net/protocol.rb') diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb index 34b379361b..161024cfe2 100644 --- a/lib/net/protocol.rb +++ b/lib/net/protocol.rb @@ -1,6 +1,6 @@ =begin -= net/protocol.rb version 1.1.31 += net/protocol.rb version 1.1.32 written by Minero Aoki @@ -65,7 +65,7 @@ module Net class Protocol - Version = '1.1.31' + Version = '1.1.32' class << self @@ -113,15 +113,18 @@ module Net @address = addr || 'localhost' @port = port || type.port - @active = false - @pipe = nil - @command = nil @socket = nil + + @active = false + @pipe = nil end - attr_reader :address, :port, - :command, :socket + attr_reader :address + attr_reader :port + + attr_reader :command + attr_reader :socket def inspect "#<#{type} #{address}:#{port} open=#{active?}>" @@ -131,20 +134,29 @@ module Net def start( *args ) return false if active? - begin - connect - do_start( *args ) - @active = true - yield self if block_given? - ensure - finish if block_given? + if block_given? then + begin + _start args + yield self + ensure + finish + end + else + _start args end end + def _start( args ) + connect + do_start( *args ) + @active = true + end + private :_start + def finish return false unless active? - do_finish + do_finish unless @command.critical? disconnect @active = false true @@ -375,24 +387,35 @@ module Net rep.error! end - def getok( line, ok = SuccessCode ) + def getok( line, expect = SuccessCode ) @socket.writeline line - check_reply ok + check_reply expect end + # + # error handle + # + + public + + def critical? + @critical + end + + def error_ok + @critical = false + end + + private + def critical - return if @critical @critical = true ret = yield @critical = false ret end - def critical? - @critical - end - def begin_critical ret = @critical @critical = true @@ -403,11 +426,6 @@ module Net @critical = false end - def error_ok - @critical = false - end - public :error_ok - end @@ -441,10 +459,11 @@ module Net def reopen unless closed? then - @socket.close + close @buffer = '' end @socket = TCPsocket.new( @addr, @port ) + @closed = false end attr :socket, true -- cgit v1.2.3