Commit de7dffaf by Ben Clayton

Socket: Use SO_REUSEADDR, disable SO_LINGER

Use these to avoid "socket in use" errors when restarting a DAP that uses the same port.
parent 9a9d46f6
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment