From 5451f0c20d2382ac126e923179c096357d20cf0a Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 19 Jul 2010 10:09:58 +0000 Subject: event_machine: split out uncommonly used modules Some applications may not use Response*Pipe and TryDefer at all, so there's no reason to pollute the runtime with extra nodes to mark during GC. --- lib/rainbows/event_machine/response_pipe.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/rainbows/event_machine/response_pipe.rb (limited to 'lib/rainbows/event_machine/response_pipe.rb') diff --git a/lib/rainbows/event_machine/response_pipe.rb b/lib/rainbows/event_machine/response_pipe.rb new file mode 100644 index 0000000..88d6e5a --- /dev/null +++ b/lib/rainbows/event_machine/response_pipe.rb @@ -0,0 +1,28 @@ +# -*- encoding: binary -*- +# :enddoc: +module Rainbows::EventMachine::ResponsePipe + # garbage avoidance, EM always uses this in a single thread, + # so a single buffer for all clients will work safely + BUF = '' + + def initialize(client, alive) + @client, @alive = client, alive + end + + def notify_readable + begin + @client.write(@io.read_nonblock(16384, BUF)) + rescue Errno::EINTR + rescue Errno::EAGAIN + return + rescue EOFError + detach + return + end while true + end + + def unbind + @client.quit unless @alive + @io.close + end +end -- cgit v1.2.3-24-ge0c7