about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-12-26 23:54:49 +0000
committerEric Wong <normalperson@yhbt.net>2010-12-27 00:57:32 +0000
commita5ff497e57bc6e8793c38bdd94ea9f1cfefd17fd (patch)
tree2640cfcc85c83dbd10e17bd79289e46e55a7cd27
parentc4d92b384dd3f926fa12eb704eeef663a9cb7b66 (diff)
downloadrainbows-a5ff497e57bc6e8793c38bdd94ea9f1cfefd17fd.tar.gz
Some applications never need TeeSocket, and we don't have
to worry about thread-safety with Revactor.
-rw-r--r--lib/rainbows/revactor.rb44
-rw-r--r--lib/rainbows/revactor/tee_socket.rb44
2 files changed, 45 insertions, 43 deletions
diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb
index 1e4d3b2..d996243 100644
--- a/lib/rainbows/revactor.rb
+++ b/lib/rainbows/revactor.rb
@@ -24,6 +24,7 @@ module Rainbows::Revactor
   RD_ARGS = {}
 
   autoload :Proxy, 'rainbows/revactor/proxy'
+  autoload :TeeSocket, 'rainbows/revactor/tee_socket'
 
   include Rainbows::Base
   LOCALHOST = Kgio::LOCALHOST
@@ -146,48 +147,5 @@ module Rainbows::Revactor
       end
     end
   end
-
-  # Revactor Sockets do not implement readpartial, so we emulate just
-  # enough to avoid mucking with TeeInput internals.  Fortunately
-  # this code is not heavily used so we can usually avoid the overhead
-  # of adding a userspace buffer.
-  class TeeSocket
-    def initialize(socket)
-      # IO::Buffer is used internally by Rev which Revactor is based on
-      # so we'll always have it available
-      @socket, @rbuf = socket, IO::Buffer.new
-    end
-
-    def leftover
-      @rbuf.read
-    end
-
-    # Revactor socket reads always return an unspecified amount,
-    # sometimes too much
-    def kgio_read(length, dst = "")
-      return dst.replace("") if length == 0
-
-      # always check and return from the userspace buffer first
-      @rbuf.size > 0 and return dst.replace(@rbuf.read(length))
-
-      # read off the socket since there was nothing in rbuf
-      tmp = @socket.read
-
-      # we didn't read too much, good, just return it straight back
-      # to avoid needlessly wasting memory bandwidth
-      tmp.size <= length and return dst.replace(tmp)
-
-      # ugh, read returned too much
-      @rbuf << tmp[length, tmp.size]
-      dst.replace(tmp[0, length])
-      rescue EOFError
-    end
-
-    # just proxy any remaining methods TeeInput may use
-    def close
-      @socket.close
-    end
-  end
-
   # :startdoc:
 end
diff --git a/lib/rainbows/revactor/tee_socket.rb b/lib/rainbows/revactor/tee_socket.rb
new file mode 100644
index 0000000..71aeb88
--- /dev/null
+++ b/lib/rainbows/revactor/tee_socket.rb
@@ -0,0 +1,44 @@
+# -*- encoding: binary -*-
+# :enddoc:
+#
+# Revactor Sockets do not implement readpartial, so we emulate just
+# enough to avoid mucking with TeeInput internals.  Fortunately
+# this code is not heavily used so we can usually avoid the overhead
+# of adding a userspace buffer.
+class Rainbows::Revactor::TeeSocket
+  def initialize(socket)
+    # IO::Buffer is used internally by Rev which Revactor is based on
+    # so we'll always have it available
+    @socket, @rbuf = socket, IO::Buffer.new
+  end
+
+  def leftover
+    @rbuf.read
+  end
+
+  # Revactor socket reads always return an unspecified amount,
+  # sometimes too much
+  def kgio_read(length, dst = "")
+    return dst.replace("") if length == 0
+
+    # always check and return from the userspace buffer first
+    @rbuf.size > 0 and return dst.replace(@rbuf.read(length))
+
+    # read off the socket since there was nothing in rbuf
+    tmp = @socket.read
+
+    # we didn't read too much, good, just return it straight back
+    # to avoid needlessly wasting memory bandwidth
+    tmp.size <= length and return dst.replace(tmp)
+
+    # ugh, read returned too much
+    @rbuf << tmp[length, tmp.size]
+    dst.replace(tmp[0, length])
+    rescue EOFError
+  end
+
+  # just proxy any remaining methods TeeInput may use
+  def close
+    @socket.close
+  end
+end