From 9f7f497dc21d904a1af20465318d85811daf0652 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 24 Jan 2011 17:13:14 -0800 Subject: epoll/client: thread-safety for write queuing We're living on the EDGE and mixing epoll with threads :D --- lib/rainbows/epoll/client.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/rainbows/epoll/client.rb b/lib/rainbows/epoll/client.rb index dfa5652..2e45b26 100644 --- a/lib/rainbows/epoll/client.rb +++ b/lib/rainbows/epoll/client.rb @@ -139,7 +139,6 @@ module Rainbows::Epoll::Client handle_error(e) end - # this returns an +Array+ write buffer if blocked def write(buf) unless @wr_queue[0] case rv = kgio_trywrite(buf) @@ -148,11 +147,11 @@ module Rainbows::Epoll::Client when String buf = rv # retry when :wait_writable - EP.set(self, OUT) break # queue end while true end @wr_queue << buf.dup # >3-word 1.9 strings are copy-on-write + EP.set(self, OUT) end def close @@ -209,7 +208,8 @@ module Rainbows::Epoll::Client def stream_pipe(pipe) case buf = pipe.tryread when String - if Array === write(buf) + write(buf) + if @wr_queue[0] # client is blocked on write, client will pull from pipe later EP.delete pipe @wr_queue << pipe -- cgit v1.2.3-24-ge0c7