diff options
author | Eric Wong <normalperson@yhbt.net> | 2012-06-30 19:57:08 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2012-07-01 01:14:46 +0000 |
commit | 36ce10c49ce7aa0df9d47f5a5f870c23c1891258 (patch) | |
tree | e294b2af13568f21172b2286d7e0af5372bcbbcf | |
parent | a5b987619f4b793203f6a50e424fe98c5b0794ba (diff) | |
download | rainbows-36ce10c49ce7aa0df9d47f5a5f870c23c1891258.tar.gz |
Triggering Errno::EBADF is tricky in multithreaded situations due to possible race conditions and yet-to-be discovered bugs. shutdown(2) is also safe against apps the fork() internally but do not execve(2) nor set FD_CLOEXEC. n.b. calling fork() after pthreads are spawned may not be safe on all platforms w.r.t. malloc, but /is/ the case for glibc on GNU/Linux. Follow-up-to: commit a5b987619f4b793203f6a50e424fe98c5b0794ba
-rw-r--r-- | lib/rainbows/coolio/client.rb | 7 | ||||
-rw-r--r-- | lib/rainbows/xepoll_thread_pool/client.rb | 2 | ||||
-rw-r--r-- | lib/rainbows/xepoll_thread_spawn/client.rb | 2 |
3 files changed, 8 insertions, 3 deletions
diff --git a/lib/rainbows/coolio/client.rb b/lib/rainbows/coolio/client.rb index 88fd1d4..8d48bbf 100644 --- a/lib/rainbows/coolio/client.rb +++ b/lib/rainbows/coolio/client.rb @@ -69,7 +69,12 @@ class Rainbows::Coolio::Client < Coolio::IO end def timeout? - nil == @deferred && @_write_buffer.empty? and close.nil? + if nil == @deferred && @_write_buffer.empty? + @_io.shutdown + true + else + false + end end # used for streaming sockets and pipes diff --git a/lib/rainbows/xepoll_thread_pool/client.rb b/lib/rainbows/xepoll_thread_pool/client.rb index 759202b..61b0b68 100644 --- a/lib/rainbows/xepoll_thread_pool/client.rb +++ b/lib/rainbows/xepoll_thread_pool/client.rb @@ -77,7 +77,7 @@ module Rainbows::XEpollThreadPool::Client LOCK.synchronize do KATO.delete_if { |client, time| time < ot and defer << client } end - defer.each { |io| io.closed? or io.close } + defer.each { |io| io.closed? or io.shutdown } end @@last_expire = now end diff --git a/lib/rainbows/xepoll_thread_spawn/client.rb b/lib/rainbows/xepoll_thread_spawn/client.rb index 1d3a280..6c07b92 100644 --- a/lib/rainbows/xepoll_thread_spawn/client.rb +++ b/lib/rainbows/xepoll_thread_spawn/client.rb @@ -33,7 +33,7 @@ module Rainbows::XEpollThreadSpawn::Client Rainbows.at_quit do clients = nil LOCK.synchronize { clients = KATO.keys; KATO.clear } - clients.each { |io| io.closed? or io.close } + clients.each { |io| io.closed? or io.shutdown } end @@last_expire = Time.now |