From 594eb2e0fe69956a2945a5cd85b6ee4fcc8117a0 Mon Sep 17 00:00:00 2001 From: shugo Date: Mon, 4 Aug 2003 01:02:16 +0000 Subject: * lib/net/imap.rb (receive_responses): raise exception to client_thread. Thanks to William Webber. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4310 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/net/imap.rb | 50 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 526f45e00e..5e9178cbf8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Aug 4 10:00:47 2003 Shugo Maeda + + * lib/net/imap.rb (receive_responses): raise exception to + client_thread. Thanks to William Webber. + Mon Aug 4 09:22:53 2003 William Webber * lib/net/imap.rb: convert RD to RDoc. diff --git a/lib/net/imap.rb b/lib/net/imap.rb index e3f6902e98..8902378e61 100644 --- a/lib/net/imap.rb +++ b/lib/net/imap.rb @@ -206,6 +206,9 @@ module Net # Returns all response handlers. attr_reader :response_handlers + # The thread to receive exceptions. + attr_accessor :client_thread + # Flag indicating a message has been seen SEEN = :Seen @@ -841,29 +844,42 @@ module Net raise ByeResponseError, resp[0] end + @client_thread = Thread.current @receiver_thread = Thread.start { receive_responses } end def receive_responses - while resp = get_response - synchronize do - case resp - when TaggedResponse - @tagged_responses[resp.tag] = resp - @tag_arrival.broadcast - when UntaggedResponse - record_response(resp.name, resp.data) - if resp.data.instance_of?(ResponseText) && - (code = resp.data.code) - record_response(code.name, code.data) - end - end - @response_handlers.each do |handler| - handler.call(resp) - end - end + while true + begin + resp = get_response + rescue Exception + @sock.close + @client_thread.raise($!) + break + end + break unless resp + begin + synchronize do + case resp + when TaggedResponse + @tagged_responses[resp.tag] = resp + @tag_arrival.broadcast + when UntaggedResponse + record_response(resp.name, resp.data) + if resp.data.instance_of?(ResponseText) && + (code = resp.data.code) + record_response(code.name, code.data) + end + end + @response_handlers.each do |handler| + handler.call(resp) + end + end + rescue Exception + @client_thread.raise($!) + end end end -- cgit v1.2.3