From 91b5cc707dc86560d8d8fd6b0ca10f1572feb953 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Wed, 16 Dec 2015 13:52:56 +0100 Subject: [PATCH] fixed testChannelAccess --- src/remoteClient/clientContextImpl.cpp | 10 ++++-- src/utils/inetAddressUtil.cpp | 4 +++ testApp/remote/testServer.cpp | 45 +++++++++++--------------- testApp/utils/testInetAddressUtils.cpp | 3 +- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index 74f625e..15e8e31 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -4439,9 +4439,13 @@ namespace epics { } } - for (size_t i = 0; broadcastAddresses.get() && i < broadcastAddresses->size(); i++) - LOG(logLevelDebug, - "Broadcast address #%d: %s.", i, inetAddressToString((*broadcastAddresses)[i]).c_str()); + if (!broadcastAddresses.get() || !broadcastAddresses->size()) + LOG(logLevelWarn, + "No broadcast addresses found or specified!"); + else + for (size_t i = 0; i < broadcastAddresses->size(); i++) + LOG(logLevelDebug, + "Broadcast address #%d: %s.", i, inetAddressToString((*broadcastAddresses)[i]).c_str()); // where to bind (listen) address osiSockAddr listenLocalAddress; diff --git a/src/utils/inetAddressUtil.cpp b/src/utils/inetAddressUtil.cpp index 768a0d6..24301f6 100644 --- a/src/utils/inetAddressUtil.cpp +++ b/src/utils/inetAddressUtil.cpp @@ -26,6 +26,7 @@ namespace pvAccess { void addDefaultBroadcastAddress(InetAddrVector* v, unsigned short p) { osiSockAddr pNewNode; pNewNode.ia.sin_family = AF_INET; + // TODO this does not work in case of no active interfaces, should return 127.0.0.1 then pNewNode.ia.sin_addr.s_addr = htonl(INADDR_BROADCAST); pNewNode.ia.sin_port = htons(p); v->push_back(pNewNode); @@ -47,6 +48,9 @@ InetAddrVector* getBroadcastAddresses(SOCKET sock, v->push_back(sn->addr); } ellFree(&as); + // add fallback address + if (!v->size()) + addDefaultBroadcastAddress(v, defaultPort); return v; } diff --git a/testApp/remote/testServer.cpp b/testApp/remote/testServer.cpp index 45e1926..18b52b0 100644 --- a/testApp/remote/testServer.cpp +++ b/testApp/remote/testServer.cpp @@ -2649,37 +2649,28 @@ public: short /*priority*/, std::string const & address) { - if (address == "local") + // this is a server instance provider, address holds remote socket IP + if (channelName == "testCounter") { - if (channelName == "testCounter") - { - channelRequester->channelCreated(Status::Ok, m_counterChannel); - return m_counterChannel; - } - else if (channelName == "testADC") - { - channelRequester->channelCreated(Status::Ok, m_adcChannel); - return m_adcChannel; - } - else if (channelName == "testMP") - { - channelRequester->channelCreated(Status::Ok, m_mpChannel); - return m_mpChannel; - } - else - { - ChannelProvider::shared_pointer chProviderPtr = shared_from_this(); - Channel::shared_pointer channel = MockChannel::create(chProviderPtr, channelRequester, channelName, address); - channelRequester->channelCreated(Status::Ok, channel); - return channel; - } + channelRequester->channelCreated(Status::Ok, m_counterChannel); + return m_counterChannel; + } + else if (channelName == "testADC") + { + channelRequester->channelCreated(Status::Ok, m_adcChannel); + return m_adcChannel; + } + else if (channelName == "testMP") + { + channelRequester->channelCreated(Status::Ok, m_mpChannel); + return m_mpChannel; } else { - Channel::shared_pointer nullPtr; - Status errorStatus(Status::STATUSTYPE_ERROR, "only local supported"); - channelRequester->channelCreated(errorStatus, nullPtr); - return nullPtr; + ChannelProvider::shared_pointer chProviderPtr = shared_from_this(); + Channel::shared_pointer channel = MockChannel::create(chProviderPtr, channelRequester, channelName, address); + channelRequester->channelCreated(Status::Ok, channel); + return channel; } } private: diff --git a/testApp/utils/testInetAddressUtils.cpp b/testApp/utils/testInetAddressUtils.cpp index 1ffa24d..38cd696 100644 --- a/testApp/utils/testInetAddressUtils.cpp +++ b/testApp/utils/testInetAddressUtils.cpp @@ -180,8 +180,9 @@ void test_getBroadcastAddresses() SOCKET socket = epicsSocketCreate(AF_INET, SOCK_STREAM, IPPROTO_TCP); auto_ptr broadcasts(getBroadcastAddresses(socket, 6678)); - // at least one is expected + // at least one is expected, in case of no network connection a fallback address is returned testOk1(static_cast(0) < broadcasts->size()); + //testDiag("getBroadcastAddresses() returned %zu entry/-ies.", broadcasts->size()); epicsSocketDestroy(socket); // debug