One thing I've thought about proposing was adding "rack.socket" to env
to get the client socket IO object[1]. Then you could run IO.select
with nil timeout on the socket and check for an exception if the client
closes on you.
But currently there's no standard way to do that other than hacking it
into the handler yourself or walking ObjectSpace (yuck).
[1] - My original reason for wanting "rack.socket" was based around something
more evil, but that reason went away and I stopped caring.
--
Eric Wong
> One thing I've thought about proposing was adding "rack.socket" to env
> to get the client socket IO object[1].
Not generally possible (e.g. on CGI?), but it could be a useful
addition for certain servers...
--
Christian Neukirchen <chneuk...@gmail.com> http://chneukirchen.org
CGI could probably just use stdout for that and IO.select for that in
the exceptfds set (not writefds, since it should already be writable).
Maybe "rack.output" would be a better name than "rack.input"...
If we standardize this, we could have could have standard middleware
that does something like this:
def call(env)
watcher = Thread.new(Thread.current, env) do |parent,env|
begin
IO.select(nil, nil, [ env['rack.output'] ])
rescue Errno::EBADF => err # probably other exceptions depending on OS
parent.raise(err)
end
end
@app.call(env)
ensure
watcher.kill if watcher && watcher.alive?
end
(Completely untested)
--
Eric Wong