[erlang-questions] SO_REUSEPORT with UDP

pablo platt pablo.platt@REDACTED
Sat May 23 18:50:29 CEST 2015


>From the stackoverflow link, SO_REUSEADDR let you use the same source
address when a previous socket is closing (TIME_WAIT).
SO_REUSEPORT let you use the same source address and port as long as the
socket tuple is different.
{<protocol>, <src addr>, <src port>, <dest addr>, <dest port>}
On some systems (Linux =< 3.9, Windos) SO_REUSEADDR is the same as the
combination of SO_REUSEADDR and SO_REUSEPORT.

It seems that Linux and BSD use a slightly different raw setting for
SO_REUSEPORT:
https://github.com/aetrion/erl-dns/commit/0c8d768ae69773d2163ea0741125471983b9a57d#diff-06495a7d8430a91558d99be5f1209c32R83
[{raw, 1, 15, <<1:32/native>>}];

How can I build a UDP server that listen on a fixed {Addr, Port} and
creates a new process for a new client connection?
Does this suppose to work?

1. Open a UDP socket and listen on a fixed port with SO_REUSEPORT set.
gen_udp:open(Port, Opts)
2. When we get a UDP packet, connect to the client and create a new process
and pass the existing socket to it.
gen_udp:connect(Socket, Address, Port)
3. goto 1.


On Fri, May 22, 2015 at 8:16 PM, Max Lapshin <max.lapshin@REDACTED> wrote:

> Wow!
>
> Thanks for this thing!
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150523/018eb2c1/attachment.htm>


More information about the erlang-questions mailing list