summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-08 07:50:07 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-06-08 07:50:07 +0000
commitbbffb26a9d93aaf252cdf218595bd5000ad3d985 (patch)
tree21767f5887e89eff7c1270d73d89813ef29b26e1 /lib
parentc60ce13a12782ae8a6acfb5d781e5ea1cfb412fa (diff)
merge revision(s) 27688:
* 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_7@28218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/imap.rb35
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 662d152207..97b960a0c2 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -913,6 +913,7 @@ module Net
@continuation_request = nil
@logout_command_tag = nil
@debug_output_bol = true
+ @exception = nil
@greeting = get_response
if @greeting.name == "BYE"
@@ -928,14 +929,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
@@ -953,7 +964,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
@@ -963,14 +976,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)
@@ -1103,6 +1123,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])