From c672259ec657483627add5dd55998385142249b1 Mon Sep 17 00:00:00 2001 From: Matej Sekoranja Date: Mon, 17 Nov 2014 13:28:42 +0100 Subject: [PATCH] explicit address channel connect --- src/pva/pvaVersion.h | 4 +-- src/remoteClient/clientContextImpl.cpp | 42 +++++++++++++++++++++----- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/pva/pvaVersion.h b/src/pva/pvaVersion.h index 62d3d9e..606a62b 100644 --- a/src/pva/pvaVersion.h +++ b/src/pva/pvaVersion.h @@ -26,8 +26,8 @@ // TODO to be generated, etc. #define EPICS_PVA_MAJOR_VERSION 4 #define EPICS_PVA_MINOR_VERSION 0 -#define EPICS_PVA_MAINTENANCE_VERSION 1 -#define EPICS_PVA_DEVELOPMENT_FLAG 0 +#define EPICS_PVA_MAINTENANCE_VERSION 2 +#define EPICS_PVA_DEVELOPMENT_FLAG 1 namespace epics { namespace pvAccess { diff --git a/src/remoteClient/clientContextImpl.cpp b/src/remoteClient/clientContextImpl.cpp index 7e8b18a..ad80025 100644 --- a/src/remoteClient/clientContextImpl.cpp +++ b/src/remoteClient/clientContextImpl.cpp @@ -3326,7 +3326,8 @@ namespace epics { */ class InternalChannelImpl : public ChannelImpl, - public std::tr1::enable_shared_from_this + public std::tr1::enable_shared_from_this, + public TimerCallback { private: @@ -3359,7 +3360,12 @@ namespace epics { * List of fixed addresses, if name resolution will be used. */ auto_ptr m_addresses; - + + /** + * @brief m_addressIndex Index of currently used address (rollover pointer in a list). + */ + int m_addressIndex; + /** * Connection status. */ @@ -3429,6 +3435,7 @@ namespace epics { m_requester(requester), m_priority(priority), m_addresses(addresses), + m_addressIndex(0), m_connectionState(NEVER_CONNECTED), m_needSubscriptionUpdate(false), m_allowCreation(true), @@ -3670,6 +3677,8 @@ namespace epics { m_serverChannelID = sid; //setAccessRights(rights); + m_addressIndex = 0; // reset + // user might create monitors in listeners, so this has to be done before this can happen // however, it would not be nice if events would come before connection event is fired // but this cannot happen since transport (TCP) is serving in this thread @@ -3786,6 +3795,9 @@ namespace epics { } + #define STATIC_SEARCH_BASE_DELAY_SEC 5 + #define STATIC_SEARCH_MAX_MULTIPLIER 10 + /** * Initiate search (connect) procedure. */ @@ -3801,13 +3813,29 @@ namespace epics { } else if (!m_addresses->empty()) { - // TODO not only first !!! - // TODO minor version !!! - // TODO what to do if there is no channel, do not search in a loop!!! do this in other thread...! - searchResponse(PVA_PROTOCOL_REVISION, &((*m_addresses)[0])); + TimerCallback::shared_pointer tc = std::tr1::dynamic_pointer_cast(shared_from_this()); + m_context->getTimer()->scheduleAfterDelay(tc, + (m_addressIndex / m_addresses->size())*STATIC_SEARCH_BASE_DELAY_SEC); } } - + + virtual void callback() { + // TODO cancellaction?! + // TODO not in this timer thread !!! + // TODO boost when a server (from address list) is started!!! IP vs address !!! + int ix = m_addressIndex % m_addresses->size(); + m_addressIndex++; + if (m_addressIndex >= (m_addresses->size()*(STATIC_SEARCH_MAX_MULTIPLIER+1))) + m_addressIndex = m_addresses->size()*STATIC_SEARCH_MAX_MULTIPLIER; + + // NOTE: calls channelConnectFailed() on failure + searchResponse(PVA_PROTOCOL_REVISION, &((*m_addresses)[ix])); + } + + virtual void timerStopped() { + // noop + } + virtual void searchResponse(int8 minorRevision, osiSockAddr* serverAddress) { Lock guard(m_channelMutex); Transport::shared_pointer transport = m_transport;