Forum: Ruby socket_accept_filter

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2006-03-24 02:52
(Received via mailing list)
= socket_accept_filter

Rubyforge Project:

http://rubyforge.org/projects/rctools/

Documentation:

http://dev.robotcoop.com/Libraries/socket_accept_filter

== About

Socket#set_accept_filter allows you to enable accept filters on
server sockets.

In FreeBSD accept filters allow you to delay the return from an accept
() call
until enough data arrives on the connection for processing avoiding
extra
context switches while waiting for the missing data.

Consult the accf_data(9), accf_http(9) and accept_filter(9) man pages
for
further details.

== Installing socket_accept_filter

Run FreeBSD (or any BSD, I think).

Then install the gem:

   $ sudo gem install socket_accept_filter

== Using socket_accept_filter

=== Regular sockets

   require 'rubygems'
   require 'socket'
   require 'socket_accept_filter'

   server = TCPServer.new host, port
   server.set_accept_filter 'dataready'

Then use the server socket as you would ordinarily.

=== WEBrick

   require 'rubygems'
   require 'socket'
   require 'socket_accept_filter'
   require 'webrick'

   class MyServer < WEBrick::HTTPServer

     def listen(*args)
       super

       @listeners.each do |server|
         server.set_accept_filter 'httpready'
       end
     end

   end

Then use MyServer where you would ordinarily use WEBrick::HTTPServer.

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant

http://trackmap.robotcoop.com
This topic is locked and can not be replied to.