Merge pull request #107 from vibe-d/disable_so_addr
Add `StreamListenOptions.reuseAddress`.
This commit is contained in:
commit
1bbe244196
|
@ -876,8 +876,13 @@ enum ConnectionState {
|
||||||
}
|
}
|
||||||
|
|
||||||
enum StreamListenOptions {
|
enum StreamListenOptions {
|
||||||
defaults = 0,
|
none = 0,
|
||||||
|
/// Applies the `SO_REUSEPORT` flag
|
||||||
reusePort = 1<<0,
|
reusePort = 1<<0,
|
||||||
|
/// Avoids applying the `SO_REUSEADDR` flag
|
||||||
|
reuseAddress = 1<<1,
|
||||||
|
///
|
||||||
|
defaults = reuseAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum StreamSocketOption {
|
enum StreamSocketOption {
|
||||||
|
|
|
@ -221,9 +221,11 @@ final class PosixEventDriverSockets(Loop : PosixEventLoop) : EventDriverSockets
|
||||||
() @trusted {
|
() @trusted {
|
||||||
int tmp_reuse = 1;
|
int tmp_reuse = 1;
|
||||||
// FIXME: error handling!
|
// FIXME: error handling!
|
||||||
if ((options & StreamListenOptions.reusePort) && setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &tmp_reuse, tmp_reuse.sizeof) != 0) {
|
if (options & StreamListenOptions.reuseAddress) {
|
||||||
invalidateSocket();
|
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &tmp_reuse, tmp_reuse.sizeof) != 0) {
|
||||||
return;
|
invalidateSocket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
version (Windows) {} else {
|
version (Windows) {} else {
|
||||||
if ((options & StreamListenOptions.reusePort) && setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &tmp_reuse, tmp_reuse.sizeof) != 0) {
|
if ((options & StreamListenOptions.reusePort) && setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &tmp_reuse, tmp_reuse.sizeof) != 0) {
|
||||||
|
|
|
@ -42,7 +42,7 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
package bool checkForLeakedHandles()
|
package bool checkForLeakedHandles()
|
||||||
{
|
{
|
||||||
if (m_socketCount == 0) return false;
|
if (m_socketCount == 0) return false;
|
||||||
print("Warning: Socket handles leaked at driver shutdown.");
|
print("Warning: %s socket handles leaked at driver shutdown.", m_socketCount);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,10 +155,12 @@ final class WinAPIEventDriverSockets : EventDriverSockets {
|
||||||
void invalidateSocket() @nogc @trusted nothrow { closesocket(fd); fd = INVALID_SOCKET; }
|
void invalidateSocket() @nogc @trusted nothrow { closesocket(fd); fd = INVALID_SOCKET; }
|
||||||
|
|
||||||
() @trusted {
|
() @trusted {
|
||||||
int tmp_reuse = 1;
|
if (options & StreamListenOptions.reuseAddress) {
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp_reuse, tmp_reuse.sizeof) != 0) {
|
int tmp_reuse = 1;
|
||||||
invalidateSocket();
|
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &tmp_reuse, tmp_reuse.sizeof) != 0) {
|
||||||
return;
|
invalidateSocket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: should SO_EXCLUSIVEADDRUSE be used of StreamListenOptions.reuseAddress isn't set?
|
// FIXME: should SO_EXCLUSIVEADDRUSE be used of StreamListenOptions.reuseAddress isn't set?
|
||||||
|
|
Loading…
Reference in a new issue