Socket: Use SO_REUSEADDR, disable SO_LINGER
Use these to avoid "socket in use" errors when restarting a DAP that uses the same port.
This commit is contained in:
parent
9a9d46f6b6
commit
de7dffaf66
@ -74,6 +74,21 @@ class dap::Socket::Shared : public dap::ReaderWriter {
|
||||
if (info) {
|
||||
auto socket =
|
||||
::socket(info->ai_family, info->ai_socktype, info->ai_protocol);
|
||||
|
||||
#if !defined(_WIN32)
|
||||
// Prevent sockets lingering after process termination, causing
|
||||
// reconnection issues on the same port.
|
||||
|
||||
int enable = 1;
|
||||
setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int));
|
||||
|
||||
struct {
|
||||
int l_onoff; /* linger active */
|
||||
int l_linger; /* how many seconds to linger for */
|
||||
} linger = {false, 0};
|
||||
setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger));
|
||||
#endif // !defined(_WIN32)
|
||||
|
||||
return std::make_shared<Shared>(info, socket);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user