ruby-changes:15761
From: shugo <ko1@a...>
Date: Sun, 9 May 2010 08:09:27 +0900 (JST)
Subject: [ruby-changes:15761] Ruby:r27688 (ruby_1_8): * lib/net/imap.rb: backported exception handling from trunk.
shugo 2010-05-09 08:09:10 +0900 (Sun, 09 May 2010) New Revision: 27688 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27688 Log: * lib/net/imap.rb: backported exception handling from trunk. [ruby-core:29745] Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/lib/net/imap.rb Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 27687) +++ ruby_1_8/ChangeLog (revision 27688) @@ -1,3 +1,8 @@ +Sun May 9 08:07:55 2010 Shugo Maeda <shugo@r...> + + * lib/net/imap.rb: backported exception handling from trunk. + [ruby-core:29745] + Sat May 8 11:07:41 2010 Nobuyoshi Nakada <nobu@r...> * ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get Index: ruby_1_8/lib/net/imap.rb =================================================================== --- ruby_1_8/lib/net/imap.rb (revision 27687) +++ ruby_1_8/lib/net/imap.rb (revision 27688) @@ -924,6 +924,7 @@ @continuation_request = nil @logout_command_tag = nil @debug_output_bol = true + @exception = nil @greeting = get_response if @greeting.name == "BYE" @@ -939,14 +940,24 @@ def receive_responses while true + synchronize do + @exception = nil + end begin resp = get_response - rescue Exception - @sock.close - @client_thread.raise($!) + rescue Exception => e + synchronize do + @sock.close unless @sock.closed? + @exception = e + end break end - break unless resp + unless resp + synchronize do + @exception = EOFError.new("end of file reached") + end + break + end begin synchronize do case resp @@ -964,7 +975,9 @@ end if resp.name == "BYE" && @logout_command_tag.nil? @sock.close - raise ByeResponseError, resp.raw_data + @exception = ByeResponseError.new(resp.raw_data) + @response_arrival.broadcast + return end when ContinuationRequest @continuation_request = resp @@ -974,14 +987,21 @@ handler.call(resp) end end - rescue Exception - @client_thread.raise($!) + rescue Exception => e + @exception = e + synchronize do + @response_arrival.broadcast + end end end + synchronize do + @response_arrival.broadcast + end end def get_tagged_response(tag) until @tagged_responses.key?(tag) + raise @exception if @exception @response_arrival.wait end return pick_up_tagged_response(tag) @@ -1114,6 +1134,7 @@ while @continuation_request.nil? && !@tagged_responses.key?(Thread.current[:net_imap_tag]) @response_arrival.wait + raise @exception if @exception end if @continuation_request.nil? pick_up_tagged_response(Thread.current[:net_imap_tag]) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/