1 # -*- encoding: binary -*-
3 # Generic IO wrapper for proxying pipe and socket objects
4 # this behaves more like Rainbows::Fiber::IO than anything,
5 # making it highly suitable for proxying data from pipes/sockets
6 class Rainbows::Revactor::Proxy < Rev::IO
8 @receiver = Actor.current
10 attach(Rev::Loop.default)
21 # when yield-ing, Revactor::TCP#write may raise EOFError
22 # (instead of Errno::EPIPE), so we need to limit the rescue
23 # to just readpartial and let EOFErrors during yield bubble up
25 buf = readpartial(INPUT_SIZE)
28 end while yield(buf) || true
31 # this may return more than the specified length, Rainbows! won't care...
32 def readpartial(length)
33 @receiver = Actor.current
34 enable if attached? && ! enabled?
36 Actor.receive do |filter|
37 filter.when(T[:rainbows_io_input, self]) do |_, _, data|
41 filter.when(T[:rainbows_io_closed, self]) do
42 raise EOFError, "connection closed"
48 @receiver << T[:rainbows_io_closed, self]
52 @receiver << T[:rainbows_io_input, self, data ]