ruby-changes:20959
From: shugo <ko1@a...>
Date: Fri, 19 Aug 2011 14:18:31 +0900 (JST)
Subject: [ruby-changes:20959] shugo:r33008 (ruby_1_9_3): * backport r33007 from trunk.
shugo 2011-08-19 14:18:20 +0900 (Fri, 19 Aug 2011) New Revision: 33008 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33008 Log: * backport r33007 from trunk. * lib/net/imap.rb (idle): raises a Net::IMAP::Error when the connection is closed. based on the patch by Hugo Barauna. [Bug #5190] [ruby-core:38930] Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/lib/net/imap.rb branches/ruby_1_9_3/test/net/imap/test_imap.rb Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 33007) +++ ruby_1_9_3/ChangeLog (revision 33008) @@ -1,3 +1,11 @@ +Fri Aug 19 14:12:57 2011 Shugo Maeda <shugo@r...> + + * backport r33007 from trunk. + + * lib/net/imap.rb (idle): raises a Net::IMAP::Error when the + connection is closed. based on the patch by Hugo Barauna. + [Bug #5190] [ruby-core:38930] + Fri Aug 19 11:28:58 2011 Shugo Maeda <shugo@r...> * backport r33001 from trunk. Index: ruby_1_9_3/lib/net/imap.rb =================================================================== --- ruby_1_9_3/lib/net/imap.rb (revision 33007) +++ ruby_1_9_3/lib/net/imap.rb (revision 33008) @@ -905,10 +905,15 @@ @idle_done_cond = new_cond @idle_done_cond.wait @idle_done_cond = nil + if @receiver_thread_terminating + raise Net::IMAP::Error, "connection closed" + end ensure - remove_response_handler(response_handler) - put_string("DONE#{CRLF}") - response = get_tagged_response(tag, "IDLE") + unless @receiver_thread_terminating + remove_response_handler(response_handler) + put_string("DONE#{CRLF}") + response = get_tagged_response(tag, "IDLE") + end end end @@ -1056,6 +1061,7 @@ rescue Exception end } + @receiver_thread_terminating = false end def receive_responses @@ -1115,8 +1121,12 @@ end end synchronize do + @receiver_thread_terminating = true @tagged_response_arrival.broadcast @continuation_request_arrival.broadcast + if @idle_done_cond + @idle_done_cond.signal + end end end Index: ruby_1_9_3/test/net/imap/test_imap.rb =================================================================== --- ruby_1_9_3/test/net/imap/test_imap.rb (revision 33007) +++ ruby_1_9_3/test/net/imap/test_imap.rb (revision 33008) @@ -363,6 +363,61 @@ end end + def test_connection_closed_during_idle + server = create_tcp_server + port = server.addr[1] + requests = [] + sock = nil + Thread.start do + begin + sock = server.accept + sock.print("* OK test server\r\n") + requests.push(sock.gets) + sock.print("+ idling\r\n") + rescue + end + end + begin + imap = Net::IMAP.new(SERVER_ADDR, :port => port) + begin + th = Thread.current + m = Monitor.new + in_idle = false + exception_raised = false + c = m.new_cond + Thread.start do + m.synchronize do + until in_idle + c.wait(0.1) + end + end + sock.close + exception_raised = true + end + assert_raise(Net::IMAP::Error) do + imap.idle do |res| + m.synchronize do + in_idle = true + c.signal + until exception_raised + c.wait(0.1) + end + end + end + end + assert_equal(1, requests.length) + assert_equal("RUBY0001 IDLE\r\n", requests[0]) + ensure + imap.disconnect if imap + end + ensure + server.close + if sock && !sock.closed? + sock.close + end + end + end + private def imaps_test -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/