mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-17 08:46:24 +00:00
Use SO_DONTLINGER to fix bind() address in use error
This will ensure the socket does not linger, which fixes the common and *super* annoying issue of "bind(): address already in use"
This commit is contained in:
parent
376594f00c
commit
d50980b10f
@ -33,6 +33,11 @@ void Server::TCPClientMain() {
|
|||||||
LOG(ERROR) << "Socket failed! Error code: " << WSAGetLastError();
|
LOG(ERROR) << "Socket failed! Error code: " << WSAGetLastError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const char optval = 0;
|
||||||
|
int status = ::setsockopt(TCPSocket, SOL_SOCKET, SO_DONTLINGER, &optval, sizeof(optval));
|
||||||
|
if (status < 0) {
|
||||||
|
LOG(INFO) << "Failed to set DONTLINGER: " << GetSocketApiError();
|
||||||
|
}
|
||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(Port);
|
ServerAddr.sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user