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

* test/openssl: Join threads.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2014-05-25 05:22:49 +00:00
parent bafe3bf3da
commit 504453d929
3 changed files with 21 additions and 5 deletions

View file

@ -1,3 +1,7 @@
Sun May 25 14:22:30 2014 Tanaka Akira <akr@fsij.org>
* test/openssl: Join threads.
Sun May 25 12:46:47 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> Sun May 25 12:46:47 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* error.c (rb_bug_context): new function to report bug with * error.c (rb_bug_context): new function to report bug with

View file

@ -83,16 +83,20 @@ end
module OpenSSL::TestEOF1M module OpenSSL::TestEOF1M
def open_file(content) def open_file(content)
s1, s2 = ssl_pair s1, s2 = ssl_pair
Thread.new { s2 << content; s2.close } th = Thread.new { s2 << content; s2.close }
yield s1 yield s1
ensure
th.join
end end
end end
module OpenSSL::TestEOF2M module OpenSSL::TestEOF2M
def open_file(content) def open_file(content)
s1, s2 = ssl_pair s1, s2 = ssl_pair
Thread.new { s1 << content; s1.close } th = Thread.new { s1 << content; s1.close }
yield s2 yield s2
ensure
th.join
end end
end end
@ -317,6 +321,7 @@ module OpenSSL::TestPairM
s1.print "a\ndef" s1.print "a\ndef"
assert_equal("a\n", s2.gets) assert_equal("a\n", s2.gets)
ensure ensure
th.join
s1.close if s1 && !s1.closed? s1.close if s1 && !s1.closed?
s2.close if s2 && !s2.closed? s2.close if s2 && !s2.closed?
sock1.close if sock1 && !sock1.closed? sock1.close if sock1 && !sock1.closed?

View file

@ -240,7 +240,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
ssl.close rescue nil ssl.close rescue nil
end end
def server_loop(ctx, ssls, server_proc) def server_loop(ctx, ssls, server_proc, threads)
loop do loop do
ssl = nil ssl = nil
begin begin
@ -249,10 +249,11 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
retry retry
end end
Thread.start do th = Thread.start do
Thread.current.abort_on_exception = true Thread.current.abort_on_exception = true
server_proc.call(ctx, ssl) server_proc.call(ctx, ssl)
end end
threads << th
end end
rescue Errno::EBADF, IOError, Errno::EINVAL, Errno::ECONNABORTED, Errno::ENOTSOCK, Errno::ECONNRESET rescue Errno::EBADF, IOError, Errno::EINVAL, Errno::ECONNABORTED, Errno::ENOTSOCK, Errno::ECONNRESET
end end
@ -261,6 +262,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
ctx_proc = args[:ctx_proc] ctx_proc = args[:ctx_proc]
server_proc = args[:server_proc] server_proc = args[:server_proc]
server_proc ||= method(:readwrite_loop) server_proc ||= method(:readwrite_loop)
threads = []
store = OpenSSL::X509::Store.new store = OpenSSL::X509::Store.new
store.add_cert(@ca_cert) store.add_cert(@ca_cert)
@ -290,7 +292,7 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
begin begin
server = Thread.new do server = Thread.new do
Thread.current.abort_on_exception = true Thread.current.abort_on_exception = true
server_loop(ctx, ssls, server_proc) server_loop(ctx, ssls, server_proc, threads)
end end
$stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, $$, port) if $DEBUG $stderr.printf("%s started: pid=%d port=%d\n", SSL_SERVER, $$, port) if $DEBUG
@ -318,6 +320,11 @@ AQjjxMXhwULlmuR/K+WwlaZPiLIBYalLAZQ7ZbOPeVkJ8ePao0eLAgEC
tcps.close if (tcps) tcps.close if (tcps)
end end
end end
ensure
threads.each {|th|
th.kill
th.join
}
end end
def starttls(ssl) def starttls(ssl)