evsocket::canIPv6 once

This commit is contained in:
Michael Davidsaver
2022-04-05 07:57:16 -07:00
parent 89fd1bba7a
commit 1be0477ee6
11 changed files with 26 additions and 12 deletions
+1 -2
View File
@@ -468,8 +468,7 @@ Value buildCAMethod()
}
ContextImpl::ContextImpl(const Config& conf, const evbase& tcp_loop)
:canIPv6(evsocket::canIPv6())
,ifmap(IfaceMap::instance())
:ifmap(IfaceMap::instance())
,effective(conf)
,caMethod(buildCAMethod())
,searchTx4(AF_INET, SOCK_DGRAM, 0)
-1
View File
@@ -226,7 +226,6 @@ private:
struct ContextImpl : public std::enable_shared_from_this<ContextImpl>
{
SockAttach attach;
const bool canIPv6;
IfaceMap& ifmap;
// "const" after ctor
+3 -1
View File
@@ -365,6 +365,8 @@ bool evbase::assertInRunningLoop() const
throw std::logic_error("Not in running evbase worker");
}
bool evsocket::canIPv6;
evsocket::evsocket(int af, evutil_socket_t sock)
:sock(sock)
,af(af)
@@ -636,7 +638,7 @@ std::vector<SockAddr> evsocket::broadcasts(const SockAddr* match) const
# define EAFNOSUPPORT WSAESOCKTNOSUPPORT
#endif
bool evsocket::canIPv6()
bool evsocket::init_canIPv6()
{
try {
evsocket sock(AF_INET6, SOCK_DGRAM, 0);
+3 -1
View File
@@ -248,7 +248,9 @@ struct PVXS_API evsocket
std::vector<SockAddr> broadcasts(const SockAddr* match=nullptr) const;
static
bool canIPv6();
bool canIPv6;
static bool init_canIPv6();
};
struct PVXS_API IfaceMap {
+2
View File
@@ -46,6 +46,8 @@ void oseDoOnce(void*)
}
if(!WSARecvMsg)
cantProceed("Unable to get &WSARecvMsg!!");
evsocket::canIPv6 = evsocket::init_canIPv6();
}
void osiSockAttachExt()
+13 -1
View File
@@ -37,7 +37,19 @@ namespace pvxs {
DEFINE_LOGGER(log, "pvxs.util");
DEFINE_LOGGER(logiface, "pvxs.iface");
void osiSockAttachExt() {}
static
epicsThreadOnceId oseOnce = EPICS_THREAD_ONCE_INIT;
static
void oseDoOnce(void*)
{
evsocket::canIPv6 = evsocket::init_canIPv6();
}
void osiSockAttachExt() {
osiSockAttach();
epicsThreadOnce(&oseOnce, &oseDoOnce, nullptr);
}
void evsocket::enable_SO_RXQ_OVFL() const
{
+1 -2
View File
@@ -375,8 +375,7 @@ std::ostream& operator<<(std::ostream& strm, const Server& serv)
}
Server::Pvt::Pvt(const Config &conf)
:canIPv6(evsocket::canIPv6())
,effective(conf)
:effective(conf)
,beaconMsg(128)
,acceptor_loop("PVXTCP", epicsThreadPriorityCAServerLow-2)
,beaconSender4(AF_INET, SOCK_DGRAM, 0)
+1 -1
View File
@@ -387,7 +387,7 @@ ServIface::ServIface(const SockAddr &addr, server::Server::Pvt *server, bool fal
auto orig_port = bind_addr.port();
#ifdef __linux__
if(server->canIPv6 && bind_addr.family()==AF_INET && bind_addr.isAny()) {
if(evsocket::canIPv6 && bind_addr.family()==AF_INET && bind_addr.isAny()) {
// Linux IP stack disallows binding both 0.0.0.0 and [::] for the same port.
// so promote to IPv6 when possible
bind_addr = SockAddr::any(AF_INET6, bind_addr.port());
-1
View File
@@ -200,7 +200,6 @@ using namespace impl;
struct Server::Pvt
{
SockAttach attach;
const bool canIPv6;
std::weak_ptr<Server::Pvt> internal_self;
+1 -1
View File
@@ -502,7 +502,7 @@ MAIN(testget)
testPlan(59);
testSetup();
logger_config_env();
bool canIPv6 = pvxs::impl::evsocket::canIPv6();
const bool canIPv6 = pvxs::impl::evsocket::canIPv6;
Tester().testConnector();
Tester().testWaiter();
Tester(AF_INET).loopback();
+1 -1
View File
@@ -398,7 +398,7 @@ MAIN(testsock)
testSetup();
// check for behavior when binding ipv4 and ipv6 to the same socket
// as a function of socket type and order.
if(evsocket::canIPv6()) {
if(evsocket::canIPv6) {
// IPv4 and v6 loopback addresses are entirely distinct,
// so no problem binding to both w/ or w/o IPV6_V6ONLY
test_bind46("127.0.0.1" , "::1" , SOCK_DGRAM , 0);