summaryrefslogtreecommitdiff
path: root/lib/net/protocol.rb
diff options
context:
space:
mode:
authoraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-12-22 18:40:55 +0000
committeraamine <aamine@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-12-22 18:40:55 +0000
commit79633d3bb8334fc58be49b6d86fcd6a40f569f75 (patch)
tree498e27da2e1e1fc08fc04bf6e7f84a40f51feecc /lib/net/protocol.rb
parente6bf7809f399b4602c9b3a2aa4761da0e336fb83 (diff)
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
Diffstat (limited to 'lib/net/protocol.rb')
-rw-r--r--lib/net/protocol.rb75
1 files changed, 47 insertions, 28 deletions
diff --git a/lib/net/protocol.rb b/lib/net/protocol.rb
index 34b3793..161024c 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 <aamine@dp.u-netsurf.ne.jp>
@@ -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