1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
shugo 2003-08-04 01:02:16 +00:00
parent 79c0605534
commit 594eb2e0fe
2 changed files with 38 additions and 17 deletions

View file

@ -1,3 +1,8 @@
Mon Aug 4 10:00:47 2003 Shugo Maeda <shugo@ruby-lang.org>
* lib/net/imap.rb (receive_responses): raise exception to
client_thread. Thanks to William Webber.
Mon Aug 4 09:22:53 2003 William Webber <wew@williamwebber.com> Mon Aug 4 09:22:53 2003 William Webber <wew@williamwebber.com>
* lib/net/imap.rb: convert RD to RDoc. * lib/net/imap.rb: convert RD to RDoc.

View file

@ -206,6 +206,9 @@ module Net
# Returns all response handlers. # Returns all response handlers.
attr_reader :response_handlers attr_reader :response_handlers
# The thread to receive exceptions.
attr_accessor :client_thread
# Flag indicating a message has been seen # Flag indicating a message has been seen
SEEN = :Seen SEEN = :Seen
@ -841,29 +844,42 @@ module Net
raise ByeResponseError, resp[0] raise ByeResponseError, resp[0]
end end
@client_thread = Thread.current
@receiver_thread = Thread.start { @receiver_thread = Thread.start {
receive_responses receive_responses
} }
end end
def receive_responses def receive_responses
while resp = get_response while true
synchronize do begin
case resp resp = get_response
when TaggedResponse rescue Exception
@tagged_responses[resp.tag] = resp @sock.close
@tag_arrival.broadcast @client_thread.raise($!)
when UntaggedResponse break
record_response(resp.name, resp.data) end
if resp.data.instance_of?(ResponseText) && break unless resp
(code = resp.data.code) begin
record_response(code.name, code.data) synchronize do
end case resp
end when TaggedResponse
@response_handlers.each do |handler| @tagged_responses[resp.tag] = resp
handler.call(resp) @tag_arrival.broadcast
end when UntaggedResponse
end 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
end end