diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-08 23:09:10 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-08 23:09:10 +0000 |
commit | f78d45b36522f3c40f2af961bd904a5ffab63ea8 (patch) | |
tree | e4b486b61d41e9fc591e3c0902497cb4c76aed91 | |
parent | cccc8cbd45078028a1bae2d28c934172723bebf3 (diff) |
* lib/net/imap.rb: backported exception handling from trunk.
[ruby-core:29745]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27688 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/net/imap.rb | 35 |
2 files changed, 33 insertions, 7 deletions
@@ -1,3 +1,8 @@ +Sun May 9 08:07:55 2010 Shugo Maeda <[email protected]> + + * lib/net/imap.rb: backported exception handling from trunk. + [ruby-core:29745] + Sat May 8 11:07:41 2010 Nobuyoshi Nakada <[email protected]> * ext/bigdecimal/bigdecimal.c (VpAlloc): ensure buf does not get diff --git a/lib/net/imap.rb b/lib/net/imap.rb index 9c4ecd96d8..c80142717d 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -924,6 +924,7 @@ module Net @continuation_request = nil @logout_command_tag = nil @debug_output_bol = true + @exception = nil @greeting = get_response if @greeting.name == "BYE" @@ -939,14 +940,24 @@ module Net 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 + unless resp + synchronize do + @exception = EOFError.new("end of file reached") + end break end - break unless resp begin synchronize do case resp @@ -964,7 +975,9 @@ module Net 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 @@ module Net 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 @@ module Net 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]) |