ruby-changes:5019
From: shugo <ko1@a...>
Date: Thu, 22 May 2008 02:47:49 +0900 (JST)
Subject: [ruby-changes:5019] shugo - Ruby:r16512 (trunk): * lib/net/imap.rb: do not use Thread#raise.
shugo 2008-05-22 02:47:33 +0900 (Thu, 22 May 2008) New Revision: 16512 Modified files: trunk/ChangeLog trunk/lib/net/imap.rb trunk/test/net/imap/test_imap.rb Log: * lib/net/imap.rb: do not use Thread#raise. [ruby-dev:34739] http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/net/imap.rb?r1=16512&r2=16511&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=16512&r2=16511&diff_format=u http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/net/imap/test_imap.rb?r1=16512&r2=16511&diff_format=u Index: ChangeLog =================================================================== --- ChangeLog (revision 16511) +++ ChangeLog (revision 16512) @@ -1,3 +1,7 @@ +Thu May 22 02:46:08 2008 Shugo Maeda <shugo@r...> + + * lib/net/imap.rb: do not use Thread#raise. [ruby-dev:34739] + Thu May 22 00:30:06 2008 Yusuke Endoh <mame@t...> * test/ruby/test_require.rb: new tests for library requiring, to Index: lib/net/imap.rb =================================================================== --- lib/net/imap.rb (revision 16511) +++ lib/net/imap.rb (revision 16512) @@ -936,6 +936,7 @@ @continuation_request_arrival = new_cond @logout_command_tag = nil @debug_output_bol = true + @exception = nil @greeting = get_response if @greeting.name == "BYE" @@ -951,14 +952,24 @@ 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 + @exception = e + end break end - break unless resp + unless resp + synchronize do + @exception = EOFError.new("end of file reached") + end + break + end begin synchronize do case resp @@ -976,7 +987,8 @@ end if resp.name == "BYE" && @logout_command_tag.nil? @sock.close - raise ByeResponseError, resp.raw_data + @exception = ByeResponseError.new(resp.raw_data) + break end when ContinuationRequest @continuation_request_arrival.signal @@ -985,14 +997,23 @@ handler.call(resp) end end - rescue Exception - @client_thread.raise($!) + rescue Exception => e + @exception = e + synchronize do + @tagged_response_arrival.broadcast + @continuation_request_arrival.broadcast + end end end + synchronize do + @tagged_response_arrival.broadcast + @continuation_request_arrival.broadcast + end end def get_tagged_response(tag, cmd) until @tagged_responses.key?(tag) + raise @exception if @exception @tagged_response_arrival.wait end resp = @tagged_responses.delete(tag) @@ -1119,6 +1140,7 @@ def send_literal(str) put_string("{" + str.length.to_s + "}" + CRLF) @continuation_request_arrival.wait + raise @exception if @exception put_string(str) end Index: test/net/imap/test_imap.rb =================================================================== --- test/net/imap/test_imap.rb (revision 16511) +++ test/net/imap/test_imap.rb (revision 16512) @@ -81,6 +81,37 @@ end end + def test_unexpected_eof + server = TCPServer.new(0) + port = server.addr[1] + Thread.start do + begin + sock = server.accept + begin + sock.print("* OK test server\r\n") + sock.gets +# sock.print("* BYE terminating connection\r\n") +# sock.print("RUBY0001 OK LOGOUT completed\r\n") + ensure + sock.close + end + rescue + end + end + begin + begin + imap = Net::IMAP.new("localhost", :port => port) + assert_raise(EOFError) do + imap.logout + end + ensure + imap.disconnect if imap + end + ensure + server.close + end + end + private def imaps_test -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/