REUSEADDR and SO_REUSEPORT do not work under FreeBSD
Original Reporter info from Mantis: ilyalyu
-
Reporter name: Ilya Lyubinskiy
Original Reporter info from Mantis: ilyalyu
- Reporter name: Ilya Lyubinskiy
Description:
I used the following code to check these options (I have shortened it for readability):
sock1 := Socket(AF_INET, SOCK_STREAM, 0);
SetSocketOptions(sock1, SOL_Socket, SO_REUSEADDR, 1, Sizeof(1));
SetSocketOptions(sock1, SOL_Socket, SO_REUSEPORT, 1, Sizeof(1));
if not Bind(sock1, Addr, Sizeof(Addr)) then writeln(1, 'Couldn''t bind sock1');
Listen(sock1, 1);
sock2 := Socket(AF_INET, SOCK_STREAM, 0);
SetSocketOptions(sock2, SOL_Socket, SO_REUSEADDR, 1, Sizeof(1));
SetSocketOptions(sock2, SOL_Socket, SO_REUSEPORT, 1, Sizeof(1));
if not Bind(sock2, Addr, Sizeof(Addr)) then writeln(1, 'Couldn''t bind sock2');
Listen(sock2, 1);
The first socket connected and listened, while the second could not bind.
Also, it is impossible to reuse the port for some time after application is closed even though I shut down and close listening socket:
ShutDown(sock, 2);
CloseSocket(sock);
Mantis conversion info:
- Mantis ID: 9015
- Version: 2.2.1
- Fixed in version: 2.4.0
- Fixed in revision: 10426 (#761344e9)
- Target version: 2.3.1