about summary refs log tree commit homepage
path: root/lib/rainbows/fiber/io.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-06-28 06:29:54 +0000
committerEric Wong <normalperson@yhbt.net>2010-06-28 06:30:23 +0000
commit86e9c7013308d77def5fe41b52a35dea60c7361c (patch)
treeed9ca86f78cb455958a47b0acf28ba98fb5613e2 /lib/rainbows/fiber/io.rb
parentb75ad975856a681fe96651592b2bb24cc044fd50 (diff)
downloadrainbows-86e9c7013308d77def5fe41b52a35dea60c7361c.tar.gz
This fleshes out Rainbows::Fiber::IO with a few
more methods for people using it.
Diffstat (limited to 'lib/rainbows/fiber/io.rb')
-rw-r--r--lib/rainbows/fiber/io.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/rainbows/fiber/io.rb b/lib/rainbows/fiber/io.rb
index 5f925ca..d4f2512 100644
--- a/lib/rainbows/fiber/io.rb
+++ b/lib/rainbows/fiber/io.rb
@@ -8,6 +8,20 @@ module Rainbows
     # the underlying IO object cannot read or write
     class IO < Struct.new(:to_io, :f)
 
+      # :stopdoc:
+      LOCALHOST = Unicorn::HttpRequest::LOCALHOST
+
+      # needed to write errors with
+      def write_nonblock(buf)
+        to_io.write_nonblock(buf)
+      end
+
+      # enough for Rainbows.addr
+      def peeraddr
+        to_io.respond_to?(:peeraddr) ? to_io.peeraddr : [ LOCALHOST ]
+      end
+      # :stopdoc:
+
       # for wrapping output response bodies
       def each(&block)
         begin
@@ -24,6 +38,10 @@ module Rainbows
         to_io.close unless to_io.closed?
       end
 
+      def closed?
+        to_io.closed?
+      end
+
       def wait_readable
         fileno = to_io.fileno
         RD[fileno] = self