Thomas Hurst
2006-Nov-25 10:52 UTC
[Mongrel] [PATCH] HTTP accept filter support for FreeBSD
This small patch extends configure_socket_options to support FreeBSD''s
accf_http(9), which defers accept() until there''s a full HTTP request
to read.
Seems to work fine on 6.1-STABLE. DragonflyBSD should work too provided
the /freebsd/ line is modified to match it.
accf_http(9): http://www.freebsd.org/cgi/man.cgi?query=accf_http&sektion=9
--
Thomas ''Freaky'' Hurst
http://hur.st/
-------------- next part --------------
--- mongrel.rb.orig Sat Nov 25 05:19:12 2006
+++ mongrel.rb Sat Nov 25 08:41:20 2006
@@ -666,10 +666,17 @@
end
def configure_socket_options
- if /linux/ === RUBY_PLATFORM
+ case RUBY_PLATFORM
+ when /linux/
# 9 is currently TCP_DEFER_ACCEPT
- $tcp_defer_accept_opts = [9,1]
- $tcp_cork_opts = [3,1]
+ $tcp_defer_accept_opts = [Socket::SOL_TCP, 9, 1]
+ $tcp_cork_opts = [Socket::SOL_TCP, 3, 1]
+ when /freebsd/
+ # Use the HTTP accept filter if available.
+ # The struct made by pack() is defined in /usr/include/sys/socket.h as
accept_filter_arg
+ unless `/sbin/sysctl -nq net.inet.accf.http`.empty?
+ $tcp_defer_accept_opts = [Socket::SOL_SOCKET,
Socket::SO_ACCEPTFILTER, [''httpready'',
nil].pack(''a16a240'')]
+ end
end
end
@@ -680,13 +687,13 @@
configure_socket_options
- @socket.setsockopt(Socket::SOL_TCP, $tcp_defer_accept_opts[0],
$tcp_defer_accept_opts[1]) if $tcp_defer_accept_opts
+ @socket.setsockopt(*$tcp_defer_accept_opts) if $tcp_defer_accept_opts
@acceptor = Thread.new do
while true
begin
client = @socket.accept
- client.setsockopt(Socket::SOL_TCP, $tcp_cork_opts[0],
$tcp_cork_opts[1]) if $tcp_cork_opts
+ client.setsockopt(*$tcp_cork_opts) if $tcp_cork_opts
worker_list = @workers.list
Zed A. Shaw
2006-Nov-25 19:05 UTC
[Mongrel] [PATCH] HTTP accept filter support for FreeBSD
On Sat, 25 Nov 2006 10:52:33 +0000 Thomas Hurst <tom at hur.st> wrote:> This small patch extends configure_socket_options to support FreeBSD''s > accf_http(9), which defers accept() until there''s a full HTTP request > to read.Very nice. This is in the 0.3.18 which is now on the pre-release site. Try it out for me. gem install mongrel --source=http://mongrel.rubyforge.org/releases/ Thanks. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.
Thomas Hurst
2006-Nov-25 21:37 UTC
[Mongrel] [PATCH] HTTP accept filter support for FreeBSD
* Zed A. Shaw (zedshaw at zedshaw.com) wrote:> On Sat, 25 Nov 2006 10:52:33 +0000 Thomas Hurst <tom at hur.st> wrote: > > > This small patch extends configure_socket_options to support > > FreeBSD''s accf_http(9), which defers accept() until there''s a full > > HTTP request to read. > > Very nice. This is in the 0.3.18 which is now on the pre-release > site. Try it out for me.Thanks :)> gem install mongrel --source=http://mongrel.rubyforge.org/releases/This reinstalls 0.3.17 for me. Had to grab the gem manually. One of my camping apps now throws EINVAL; turns out I was calling HttpServer#run twice, once in Mongrel::Camping.start, and again on the returned HttpServer. Oops. The comments in mongrel/camping.rb say to do something like: Mongrel::Camping::start("0.0.0.0",3001,"/tepee",Tepee).join But there''s no HttpServer#join method; either it needs to return the result from .run, .join needs to be added, or this should be changed to .acceptor.join. -- Thomas ''Freaky'' Hurst http://hur.st/
Zed A. Shaw
2006-Nov-25 23:21 UTC
[Mongrel] [PATCH] HTTP accept filter support for FreeBSD
On Sat, 25 Nov 2006 21:37:22 +0000 Thomas Hurst <tom at hur.st> wrote:> * Zed A. Shaw (zedshaw at zedshaw.com) wrote: > > gem install mongrel --source=http://mongrel.rubyforge.org/releases/ > > This reinstalls 0.3.17 for me. Had to grab the gem manually.Oops, looks like the old version was pushed again. 0.3.18 is up now and verified. Try it again.> One of my camping apps now throws EINVAL; turns out I was calling > HttpServer#run twice, once in Mongrel::Camping.start, and again on the > returned HttpServer. Oops. > > The comments in mongrel/camping.rb say to do something like: > > Mongrel::Camping::start("0.0.0.0",3001,"/tepee",Tepee).joinThe docs might be old, I''ll look at the real code and update for 0.3.19. -- Zed A. Shaw, MUDCRAP-CE Master Black Belt Sifu http://www.zedshaw.com/ http://www.awprofessional.com/title/0321483502 -- The Mongrel Book http://mongrel.rubyforge.org/ http://www.lingr.com/room/3yXhqKbfPy8 -- Come get help.