[erlang-questions] clarify: SO_REUSEADDR under darwin?

Valentin Micic valentin@REDACTED
Thu Nov 8 08:45:22 CET 2007


In your program, you're attempting to use the sampe port while the socket is
still active -- SO_REUSEADDR does not serve that purpose.
Rather, it means that when owner of the socket no longer needs it (i.e.
issue close socket, or terminates), another process may reuse the same port
immediately without waiting for TIME_WAIT period to expire.

V.


----- Original Message ----- 
From: "Paul Mineiro" <paul-trapexit@REDACTED>
To: <erlang-questions@REDACTED>
Sent: Thursday, November 08, 2007 6:25 AM
Subject: [erlang-questions] clarify: SO_REUSEADDR under darwin?


> hi.
>
> i've attached a very short erlang program which tries to open two udp
> ports with reuseaddr option.  it works under linux but fails under darwin.
>
> is this a known problem?
>
> i can see the following in the ktrace:
>
> --------
> % ktrace -id -t c erl -eval 'test:test ()' -noshell -noinput -s init stop
> --------
>
> the kdump.out contains:
>
> --------
> 28042 beam     CALL  socket(0x2,0x2,0x11)
> 28042 beam     RET   socket 9
> 28042 beam     CALL  fcntl(0x9,0x3,0)
> 28042 beam     RET   fcntl 2
> 28042 beam     CALL  fcntl(0x9,0x4,0x6)
> 28042 beam     RET   fcntl 0
> 28042 beam     CALL  setsockopt(0x9,0xffff,0x1002,0xbfffe1fc,0x4)
> 28042 beam     RET   setsockopt 0
> 28042 beam     CALL  setsockopt(0x9,0xffff,0x4,0xbfffe1fc,0x4)
> 28042 beam     RET   setsockopt 0
> 28042 beam     CALL  bind(0x9,0xbfffe0e0,0x10)
> 28042 beam     RET   bind -1 errno 48 Address already in use
> --------
>
> setsockopt(0x9,0xffff,0x4,0xbfffe1fc,0x4) looks right:
>
> --------
> % grep -e SO_REUSEADDR -e SOL_SOCKET /usr/include/sys/socket.h
> #define SO_REUSEADDR    0x0004          /* allow local address reuse */
> #define SOL_SOCKET      0xffff          /* options for socket level */
> --------
>
> the only thing i can't verify is that 0xbfffe1fc is a pointer to one.
>
> thanks,
>
> -- p
>
> % dpkg -s erlang-otp | grep Version
> Version: 11b-5-1
> % erl -version
> Erlang (ASYNC_THREADS) (BEAM) emulator version 5.5.5
>
> Optimism is an essential ingredient of innovation. How else can the
> individual favor change over security?
>
>  -- Robert Noyce


--------------------------------------------------------------------------------


> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions 




More information about the erlang-questions mailing list