evsocket::ipstack

This commit is contained in:
Michael Davidsaver
2021-12-12 18:26:51 -08:00
parent 1be0477ee6
commit e809da219d
6 changed files with 33 additions and 21 deletions
+1
View File
@@ -366,6 +366,7 @@ bool evbase::assertInRunningLoop() const
}
bool evsocket::canIPv6;
evsocket::ipstack_t evsocket::ipstack;
evsocket::evsocket(int af, evutil_socket_t sock)
:sock(sock)
+7
View File
@@ -251,6 +251,13 @@ struct PVXS_API evsocket
bool canIPv6;
static bool init_canIPv6();
enum ipstack_t {
Linsock,
Winsock,
GenericBSD,
};
static ipstack_t ipstack;
};
struct PVXS_API IfaceMap {
+11
View File
@@ -19,6 +19,16 @@
#include <epicsThread.h>
#include <cantProceed.h>
# include <windows.h>
# include <psapi.h>
static
bool is_wine()
{
HMODULE nt = GetModuleHandle("ntdll.dll");
return nt && GetProcAddress(nt, "wine_get_version");
}
namespace pvxs {
DEFINE_LOGGER(log, "pvxs.util");
@@ -48,6 +58,7 @@ void oseDoOnce(void*)
cantProceed("Unable to get &WSARecvMsg!!");
evsocket::canIPv6 = evsocket::init_canIPv6();
evsocket::ipstack = is_wine() ? evsocket::Linsock : evsocket::Winsock;
}
void osiSockAttachExt()
+6
View File
@@ -44,6 +44,12 @@ static
void oseDoOnce(void*)
{
evsocket::canIPv6 = evsocket::init_canIPv6();
#ifdef __linux__
// TODO: detect WSL1 somehow. (Is WSL2 really Linux IP stack?)
evsocket::ipstack = evsocket::Linsock;
#else
evsocket::ipstack = evsocket::GenericBSD;
#endif
}
void osiSockAttachExt() {
+2 -3
View File
@@ -416,8 +416,8 @@ Server::Pvt::Pvt(const Config &conf)
listeners.push_back(manager.onSearch(any6, cb));
}
#ifndef _WIN32
if(addr.addr.family()==AF_INET && !addr.addr.isAny() && !addr.addr.isMCast()) {
if(evsocket::ipstack!=evsocket::Winsock
&& addr.addr.family()==AF_INET && !addr.addr.isAny() && !addr.addr.isMCast()) {
/* An oddness of BSD sockets (not winsock) is that binding to
* INADDR_ANY will receive unicast and broadcast, but binding to
* a specific interface address receives only unicast. The trick
@@ -429,7 +429,6 @@ Server::Pvt::Pvt(const Config &conf)
listeners.push_back(manager.onSearch(bcast, cb));
}
}
#endif
}
if(tcpifaces.empty()) {
+6 -18
View File
@@ -19,18 +19,6 @@
#include <pvxs/unittest.h>
#include <pvxs/log.h>
#ifdef _WIN32
# include <windows.h>
# include <psapi.h>
static
bool is_wine()
{
HMODULE nt = GetModuleHandle("ntdll.dll");
return nt && GetProcAddress(nt, "wine_get_version");
}
#endif
namespace {
using namespace pvxs;
@@ -236,11 +224,11 @@ void test_mcast_scope()
testShow()<<" RX2 bound to "<<any;
RX3.bind(lo);
testShow()<<" RX3 bound to "<<lo;
#ifndef _WIN32
// winsock doesn't allow binding to an mcast address
RX4.bind(mcast_addr.addr);
testShow()<<" RX4 bound to "<<mcast_addr;
#endif
if(evsocket::ipstack!=evsocket::Winsock) {
// winsock doesn't allow binding to an mcast address
RX4.bind(mcast_addr.addr);
testShow()<<" RX4 bound to "<<mcast_addr;
}
testShow()<<" Join RX1 to "<<mcast_addr<<" on "<<lo;
RX1.mcast_join(mcast_addr.resolve());
@@ -272,7 +260,7 @@ void test_mcast_scope()
#ifdef _WIN32
doRX(1, RX1, true);
doRX(2, RX2, is_wine()); // really Linux IP stack, and we couldn't clear IP_MULTICAST_ALL
doRX(2, RX2, evsocket::ipstack==evsocket::Linsock); // WINE: really Linux IP stack, but we couldn't clear IP_MULTICAST_ALL
doRX(3, RX3, false);
testSkip(3, "winsock doesn't allow bind() to an mcast address");