evsocket::ipstack
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
@@ -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
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user