From 80c62b47011548ba49a676172acc7945aa4c0fc6 Mon Sep 17 00:00:00 2001 From: Rickard Green Date: Tue, 28 Feb 2023 15:48:57 +0100 Subject: [erts] Fix reuseaddr/reuseport on Windows --- erts/emulator/drivers/common/inet_drv.c | 46 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'erts/emulator/drivers') diff --git a/erts/emulator/drivers/common/inet_drv.c b/erts/emulator/drivers/common/inet_drv.c index 538f9133a3..5da854e9a7 100644 --- a/erts/emulator/drivers/common/inet_drv.c +++ b/erts/emulator/drivers/common/inet_drv.c @@ -6931,7 +6931,7 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len) case INET_OPT_EXCLUSIVEADDRUSE: DDBG(desc, ("INET-DRV-DBG[%d][" SOCKET_FSTR ",%T] " - "inet_set_opts(reuseaddr) -> %s\r\n", + "inet_set_opts(exclusiveaddruse) -> %s\r\n", __LINE__, desc->s, driver_caller(desc->port), B2S(ival)) ); #ifdef __WIN32__ type = SO_EXCLUSIVEADDRUSE; @@ -6979,25 +6979,25 @@ static int inet_set_opts(inet_descriptor* desc, char* ptr, int len) __LINE__, desc->s, driver_caller(desc->port), B2S(ival)) ); #ifdef __WIN32__ { - int old_ra, new_ra, compat; + int old_ra, new_ra, compat, ra_bits, opt_bit; /* * We only set SO_REUSEADDR on Windows if both 'reuseaddr' and * 'reuseport' has been passed as options, since SO_REUSEADDR * on Windows behaves like SO_REUSEADDR|SO_REUSEPORT does on BSD. */ + ra_bits = (1<bsd_compat; - old_ra = ((compat & (INET_OPT_REUSEADDR | INET_OPT_REUSEPORT)) - == (INET_OPT_REUSEADDR | INET_OPT_REUSEPORT)); + old_ra = (compat & ra_bits) == ra_bits; if (ival) { - bsd_compat_set = opt; - compat |= opt; + bsd_compat_set = opt_bit; + compat |= opt_bit; } else { - bsd_compat_unset = opt; - compat &= ~opt; + bsd_compat_unset = opt_bit; + compat &= ~opt_bit; } - new_ra = ((compat & (INET_OPT_REUSEADDR | INET_OPT_REUSEPORT)) - == (INET_OPT_REUSEADDR | INET_OPT_REUSEPORT)); + new_ra = (compat & ra_bits) == ra_bits; desc->bsd_compat = compat; if (old_ra == new_ra) continue; @@ -8020,25 +8020,25 @@ static int sctp_set_opts(inet_descriptor* desc, char* ptr, int len) __LINE__, desc->s, driver_caller(desc->port)) ); #ifdef __WIN32__ { - int old_ra, new_ra, compat; + int old_ra, new_ra, compat, ra_bits, opt_bit; /* * We only set SO_REUSEADDR on Windows if both 'reuseaddr' and * 'reuseport' has been passed as options, since SO_REUSEADDR * on Windows behaves like SO_REUSEADDR|SO_REUSEPORT does on BSD. */ + ra_bits = (1<bsd_compat; - old_ra = ((compat & (INET_OPT_REUSEADDR | INET_OPT_REUSEPORT)) - == (INET_OPT_REUSEADDR | INET_OPT_REUSEPORT)); + old_ra = (compat & ra_bits) == ra_bits; if (ival) { - bsd_compat_set = opt; - compat |= opt; + bsd_compat_set = opt_bit; + compat |= opt_bit; } else { - bsd_compat_unset = opt; - compat &= ~opt; + bsd_compat_unset = opt_bit; + compat &= ~opt_bit; } - new_ra = ((compat & (INET_OPT_REUSEADDR | INET_OPT_REUSEPORT)) - == (INET_OPT_REUSEADDR | INET_OPT_REUSEPORT)); + new_ra = (compat & ra_bits) == ra_bits; desc->bsd_compat = compat; if (old_ra == new_ra) continue; @@ -8937,7 +8937,7 @@ static ErlDrvSSizeT inet_fill_opts(inet_descriptor* desc, #endif case INET_OPT_REUSEADDR: { #if defined(__WIN32__) - int res = !!(desc->bsd_compat & INET_OPT_REUSEADDR); + int res = !!(desc->bsd_compat & (1<bsd_compat & INET_OPT_REUSEPORT); + int res = !!(desc->bsd_compat & (1<bsd_compat & INET_OPT_REUSEPORT); + res = !!(desc->bsd_compat & (1<bsd_compat & INET_OPT_REUSEADDR); + res = !!(desc->bsd_compat & (1<