mirror of
https://github.com/Mercantec-GHC/h5-projekt-mst.git
synced 2026-08-27 05:37:39 +02:00
reuse address
This commit is contained in:
parent
f8412ec21e
commit
a2b36a37ff
@ -47,6 +47,18 @@ auto TcpListener::bind(const std::string& host, uint16_t port)
|
||||
.sin_zero = { },
|
||||
};
|
||||
|
||||
// enable immediate reuse of socket address
|
||||
// see socket(7) about SO_REUSEADDR
|
||||
// > Argument is an integer boolean flag.
|
||||
int reuse_address = true;
|
||||
if (::setsockopt(socket_fd,
|
||||
SOL_SOCKET,
|
||||
SO_REUSEADDR,
|
||||
&reuse_address,
|
||||
sizeof(reuse_address))) {
|
||||
return std::unexpected(errno_shim("could not configure socket"));
|
||||
}
|
||||
|
||||
if (::bind(socket_fd, (struct sockaddr*)&address, sizeof(address)) < 0) {
|
||||
return std::unexpected(errno_shim("could not bind"));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user