Skip to content

Commit

Permalink
Merge pull request #1972 from vibe-d/osx_reuseport
Browse files Browse the repository at this point in the history
Set SO_REUSEPORT for the libevent driver on BSD/macOS, too.
merged-on-behalf-of: Sönke Ludwig <[email protected]>
  • Loading branch information
dlang-bot authored Nov 6, 2017
2 parents b43ccb1 + edc228a commit 8972ceb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core/vibe/core/drivers/libevent2.d
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ final class Libevent2Driver : EventDriver {
int tmp_reuse = 1;
socketEnforce(() @trusted { return setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &tmp_reuse, tmp_reuse.sizeof); } () == 0,
"Error enabling socket address reuse on listening socket");
version (linux) {
static if (is(typeof(SO_REUSEPORT))) {
if (options & TCPListenOptions.reusePort) {
if (() @trusted { return setsockopt(listenfd, SOL_SOCKET, SO_REUSEPORT, &tmp_reuse, tmp_reuse.sizeof); } ()) {
if (errno != EINVAL && errno != ENOPROTOOPT) {
Expand Down
9 changes: 4 additions & 5 deletions core/vibe/core/drivers/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ version (Windows) {
alias SystemSocketException = WSAErrorException;
} else alias SystemSocketException = ErrnoException;

version (linux) {
import core.sys.posix.sys.socket;
static if (!is(typeof(SO_REUSEPORT))) {
enum { SO_REUSEPORT = 15 }
}
import core.sys.posix.sys.socket;
static if (!is(typeof(SO_REUSEPORT))) {
version (linux) enum SO_REUSEPORT = 15;
else enum SO_REUSEPORT = 0x200;
}

T socketEnforce(T)(T value, lazy string msg = null, string file = __FILE__, size_t line = __LINE__)
Expand Down

0 comments on commit 8972ceb

Please sign in to comment.