Accept filters on FreeBSD?

Scott Lystig Fritchie fritchie@REDACTED
Sat May 31 08:37:30 CEST 2003

>>>>> "nd" == Niall Dalton <ndalton@REDACTED> writes:

nd> Hello, Does anyone have experience using accept filters on FreeBSD
nd> in Erlang applications? 

I'd never even heard of them until you mentioned them.  I should spend
more time reading "man" pages.  :-)

There's an undocumented function in the inet module that you could use
to get the OS file descriptor associated with the socket.

    % erl
    Erlang (BEAM) emulator version [source] [threads:0]
    Eshell V5.2.3.3  (abort with ^G)
    1> {ok, Port} = gen_tcp:connect("localhost", 25, []).
    2> inet:getfd(Port).

According to the accf_http(9) man page, you'd need to call
setsockopt() to invoke the proper magic.  However, the inets driver
doesn't know how to do that.  Your options are:

1. Hack your "beam" executable to add the sockopt you need.

2. Create a linked-in driver that would take the file descriptor from
   inet:getfd() and invoke the setsockopt() as required.

#2 would be really easy to do with EDTK.  See for the source code.  Sorry it's
a hassle to set up, but it really does work quite well once you've
compiled the "gslgen" utility.

Though I haven't tested it, this ought to work pretty well.  Writing
int my_setsockopt(int) is easy enough -- put it in my-sockopt.{h,c}.

    <erldriver name="simple0_drv" abbrev="" default_debug_verbose="0">
    <summary>A very simple setsockopt() driver</summary>
    <verbatim place="top_cpp_stuff">
    #include <errno.h>
    #include <my-sockopt.h> /* Just for prototype */
    <func name="my_sockopt">
     <arg name="fd" ctype="int"/>
     <return ctype="int" name="ret_int" expect="== 0" expect_errval="errno"/>

To make your life easier (probably), borrow the Makefile from the
examples/simple0 driver to assist compiling & linking everything.


More information about the erlang-questions mailing list