nifi: Set SO_REUSEPORT on BSD and macOS to prevent creation of socket failing

This commit is contained in:
Nadia Holmquist Pedersen 2022-01-12 20:40:06 +01:00
parent dff8980a27
commit 2bda2f127b
1 changed files with 10 additions and 0 deletions

View File

@ -413,6 +413,16 @@ bool MP_Init()
return false;
}
#if defined(BSD) || defined(__APPLE__)
res = setsockopt(MPSocket, SOL_SOCKET, SO_REUSEPORT, (const char*)&opt_true, sizeof(int));
if (res < 0)
{
closesocket(MPSocket);
MPSocket = INVALID_SOCKET;
return false;
}
#endif
sockaddr_t saddr;
saddr.sa_family = AF_INET;
*(u32*)&saddr.sa_data[2] = htonl(Config::SocketBindAnyAddr ? INADDR_ANY : INADDR_LOOPBACK);