1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

o all: use "critical" to avoid duplicated command dispatch

o  http.rb:  change get2, post2 usage (HTTPWriter)
o  http.rb:  entity reading algorithm is better
o  http.rb:  more reply code (4xx, 5xx)
o  protocol.rb:  arguments of "connect" can be omitted
o  protocol.rb:  "quit" is not template method (now do_quit is removed)
o  protocol.rb:  ReplyCode.error_type was not work: using module_eval


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_4@658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
aamine 2000-03-27 15:52:56 +00:00
parent 2149e2e86b
commit d9a1e63c97
4 changed files with 355 additions and 178 deletions

View file

@ -15,7 +15,7 @@ require 'socket'
module Net
Version = '1.1.10'
Version = '1.1.11'
=begin
@ -144,7 +144,7 @@ Object
def initialize( addr = nil, port = nil )
@address = addr || 'localhost'
@port = port || self.type.port
@port = port || type.port
@active = false
@pipe = nil
@ -160,11 +160,11 @@ Object
def start( *args )
return false if active?
@active = true
begin
connect @address, @port
connect
do_start *args
@active = true
yield if iterator?
ensure
finish if iterator?
@ -174,7 +174,7 @@ Object
def finish
ret = active?
do_finish if @command
do_finish
disconnect
@active = false
@ -201,9 +201,9 @@ Object
end
def connect( addr, port )
@socket = self.type.socket_type.open( addr, port, @pipe )
@command = self.type.command_type.new( @socket )
def connect( addr = @address, port = @port )
@socket = type.socket_type.open( addr, port, @pipe )
@command = type.command_type.new( @socket )
end
def disconnect
@ -213,7 +213,7 @@ Object
end
@socket = nil
end
end
Session = Protocol
@ -226,24 +226,17 @@ Object
@socket = sock
@error_occured = false
@last_reply = nil
@critical = false
end
attr_reader :socket, :error_occured, :last_reply
attr_writer :socket
def quit
if @socket and not @socket.closed? then
do_quit
@error_occured = false
end
end
# abstract quit
private
def do_quit
end
# abstract get_reply()
def check_reply( *oks )
@ -266,7 +259,30 @@ Object
@socket.writeline line
check_reply ok
end
def critical
return if @critical
@critical = true
r = yield
@critical = false
r
end
def critical?
@critical
end
def begin_critical
ret = @critical
@critical = true
not ret
end
def end_critical
@critical = false
end
end
@ -284,11 +300,11 @@ Object
class << self
def error_type( err )
@err = err
module_eval "def self.get_error_type() #{err.name} end"
end
def error!( mes )
raise @err, mes
raise get_error_type, mes
end
end