From d7635413410761a6866c6b39b5bbe8642a6f5643 Mon Sep 17 00:00:00 2001 From: bsbevins <145619550+bsbevins@users.noreply.github.com> Date: Wed, 8 Oct 2025 09:57:30 -0500 Subject: [PATCH] Allow CA clients to determine the server protocol version (#711) * Allow CA clients to determine the server protocol version Adds a call to the CA client API that allows a client to determine the server's protocol minor version number. This is needed to allow the ca-nameserver to report a server's protocol version correctly to a client. * ca_host_minor_protocol return for disconnected channels ca_host_minor_protocol now explicitly returns CA_UKN_MINOR_VERSION for a disconnected channel. --- modules/ca/src/client/cac.h | 7 +++++++ modules/ca/src/client/cacChannel.cpp | 7 +++++++ modules/ca/src/client/cacIO.h | 3 ++- modules/ca/src/client/cadef.h | 11 +++++++++++ modules/ca/src/client/nciu.cpp | 7 +++++++ modules/ca/src/client/nciu.h | 2 ++ modules/ca/src/client/netiiu.cpp | 6 ++++++ modules/ca/src/client/netiiu.h | 2 ++ modules/ca/src/client/oldAccess.h | 2 ++ modules/ca/src/client/oldChannelNotify.cpp | 10 ++++++++++ modules/ca/src/client/tcpiiu.cpp | 7 +++++++ modules/ca/src/client/udpiiu.cpp | 6 ++++++ modules/ca/src/client/udpiiu.h | 4 +++- modules/ca/src/client/virtualCircuit.h | 2 ++ 14 files changed, 74 insertions(+), 2 deletions(-) diff --git a/modules/ca/src/client/cac.h b/modules/ca/src/client/cac.h index 79dcbaa9b..8fcb7c563 100644 --- a/modules/ca/src/client/cac.h +++ b/modules/ca/src/client/cac.h @@ -203,6 +203,7 @@ public: void destroyIIU ( tcpiiu & iiu ); const char * pLocalHostName (); + const resTable < tcpiiu, caServerID > & getServerTable(); private: epicsSingleton < localHostName > :: reference _refLocalHostName; @@ -424,4 +425,10 @@ inline double cac :: return this->connTMO; } +inline const resTable < tcpiiu, caServerID > & cac :: + getServerTable() +{ + return this->serverTable; +} + #endif // ifndef INC_cac_H diff --git a/modules/ca/src/client/cacChannel.cpp b/modules/ca/src/client/cacChannel.cpp index 33345967c..a76d6e957 100644 --- a/modules/ca/src/client/cacChannel.cpp +++ b/modules/ca/src/client/cacChannel.cpp @@ -129,6 +129,13 @@ unsigned cacChannel::getHostName ( return 0u; } +unsigned cacChannel::getHostMinorProtocol ( + epicsGuard < epicsMutex > &) const throw () +{ + epicsThreadOnce ( & cacChannelIdOnce, cacChannelSetup, 0); + return 0u; +} + // the default is to assume that it is a locally hosted channel const char * cacChannel::pHostName ( epicsGuard < epicsMutex > & ) const throw () diff --git a/modules/ca/src/client/cacIO.h b/modules/ca/src/client/cacIO.h index 760d8dd72..777155047 100644 --- a/modules/ca/src/client/cacIO.h +++ b/modules/ca/src/client/cacIO.h @@ -246,7 +246,8 @@ public: // !! deprecated, avoid use !! virtual const char * pHostName ( epicsGuard < epicsMutex > & guard ) const throw (); - + virtual unsigned getHostMinorProtocol ( + epicsGuard < epicsMutex > &) const throw () ; // exceptions class badString {}; class badType {}; diff --git a/modules/ca/src/client/cadef.h b/modules/ca/src/client/cadef.h index e7ab45cbe..5c60a06f7 100644 --- a/modules/ca/src/client/cadef.h +++ b/modules/ca/src/client/cadef.h @@ -1460,6 +1460,17 @@ LIBCA_API const char * epicsStdCall ca_host_name (chid channel); LIBCA_API unsigned epicsStdCall ca_get_host_name ( chid pChan, char *pBuf, unsigned bufLength ); +/** \brief Return the minor protocol version number used by the host to + * which a channel is cuurently connected. + * + * \param[in] pChan channel identifier + * \returns The minor protocol version number. + * If the channel is disconnected CA_UKN_MINOR_VERSION is returned. + */ +LIBCA_API unsigned epicsStdCall ca_host_minor_protocol (chid pChan); + +#define HAS_CA_HOST_MINOR_PROTOCOL + /** \brief Call their function with their argument whenever * a new fd is added or removed. * diff --git a/modules/ca/src/client/nciu.cpp b/modules/ca/src/client/nciu.cpp index a862cb228..fc5d3cb4c 100644 --- a/modules/ca/src/client/nciu.cpp +++ b/modules/ca/src/client/nciu.cpp @@ -410,6 +410,13 @@ const char * nciu::pHostName ( return this->piiu->pHostName ( guard ); } +unsigned nciu::getHostMinorProtocol ( + epicsGuard < epicsMutex > & guard) const throw () +{ + return this->piiu->getHostMinorProtocol ( + guard ); +} + bool nciu::ca_v42_ok ( epicsGuard < epicsMutex > & guard ) const { diff --git a/modules/ca/src/client/nciu.h b/modules/ca/src/client/nciu.h index d909aa917..7e94fe1b8 100644 --- a/modules/ca/src/client/nciu.h +++ b/modules/ca/src/client/nciu.h @@ -183,6 +183,8 @@ public: unsigned getHostName ( epicsGuard < epicsMutex > &, char * pBuf, unsigned bufLen ) const throw (); + unsigned getHostMinorProtocol ( + epicsGuard < epicsMutex > &) const throw (); void writeException ( epicsGuard < epicsMutex > &, epicsGuard < epicsMutex > &, int status, const char *pContext, unsigned type, arrayElementCount count ); diff --git a/modules/ca/src/client/netiiu.cpp b/modules/ca/src/client/netiiu.cpp index c73732af6..04a5fb524 100644 --- a/modules/ca/src/client/netiiu.cpp +++ b/modules/ca/src/client/netiiu.cpp @@ -116,6 +116,12 @@ const char * netiiu::pHostName ( return pHostNameNetIIU; } +unsigned netiiu::getHostMinorProtocol ( + epicsGuard < epicsMutex > & ) const throw () +{ + return CA_UKN_MINOR_VERSION; +} + osiSockAddr netiiu::getNetworkAddress ( epicsGuard < epicsMutex > & ) const { diff --git a/modules/ca/src/client/netiiu.h b/modules/ca/src/client/netiiu.h index 298337bd3..d21ed8428 100644 --- a/modules/ca/src/client/netiiu.h +++ b/modules/ca/src/client/netiiu.h @@ -43,6 +43,8 @@ public: unsigned bufLength ) const throw () = 0; virtual const char * pHostName ( epicsGuard < epicsMutex > & ) const throw () = 0; + virtual unsigned getHostMinorProtocol ( + epicsGuard < epicsMutex > & ) const throw (); virtual bool ca_v41_ok ( epicsGuard < epicsMutex > & ) const = 0; virtual bool ca_v42_ok ( diff --git a/modules/ca/src/client/oldAccess.h b/modules/ca/src/client/oldAccess.h index 2c39d2768..3e8edb914 100644 --- a/modules/ca/src/client/oldAccess.h +++ b/modules/ca/src/client/oldAccess.h @@ -64,6 +64,8 @@ public: chid pChan, char * pBuf, unsigned bufLength ); friend const char * epicsStdCall ca_host_name ( chid pChan ); + friend unsigned epicsStdCall ca_host_minor_protocol ( + chid pChan ); friend const char * epicsStdCall ca_name ( chid pChan ); friend void epicsStdCall ca_set_puser ( diff --git a/modules/ca/src/client/oldChannelNotify.cpp b/modules/ca/src/client/oldChannelNotify.cpp index 71688c94c..0a3512827 100644 --- a/modules/ca/src/client/oldChannelNotify.cpp +++ b/modules/ca/src/client/oldChannelNotify.cpp @@ -193,6 +193,16 @@ const char * epicsStdCall ca_host_name ( return pChan->io.pHostName ( guard ); } +/* + * ca_host_minorProtocol () + */ +unsigned epicsStdCall ca_host_minor_protocol ( + chid pChan ) +{ + epicsGuard < epicsMutex > guard ( pChan->cacCtx.mutexRef () ); + return pChan->io.getHostMinorProtocol( guard ); +} + /* * ca_set_puser () */ diff --git a/modules/ca/src/client/tcpiiu.cpp b/modules/ca/src/client/tcpiiu.cpp index 30f6fad17..b8ebaac32 100644 --- a/modules/ca/src/client/tcpiiu.cpp +++ b/modules/ca/src/client/tcpiiu.cpp @@ -1804,6 +1804,13 @@ const char * tcpiiu::pHostName ( return this->hostNameCacheInstance.pointer (); } +unsigned tcpiiu::getHostMinorProtocol ( + epicsGuard < epicsMutex > & guard) const throw () +{ + guard.assertIdenticalMutex ( this->mutex ); + return this->minorProtocolVersion; +} + void tcpiiu::disconnectAllChannels ( epicsGuard < epicsMutex > & cbGuard, epicsGuard < epicsMutex > & guard, diff --git a/modules/ca/src/client/udpiiu.cpp b/modules/ca/src/client/udpiiu.cpp index d36e2c5b4..bfe3d628e 100644 --- a/modules/ca/src/client/udpiiu.cpp +++ b/modules/ca/src/client/udpiiu.cpp @@ -1342,6 +1342,12 @@ const char * udpiiu::pHostName ( return netiiu::pHostName ( cacGuard ); } +unsigned udpiiu::getHostMinorProtocol ( + epicsGuard < epicsMutex > & cacGuard ) const throw () +{ + return netiiu::getHostMinorProtocol ( cacGuard ); +} + bool udpiiu::ca_v42_ok ( epicsGuard < epicsMutex > & cacGuard ) const { diff --git a/modules/ca/src/client/udpiiu.h b/modules/ca/src/client/udpiiu.h index aba79be5d..abc3fa757 100644 --- a/modules/ca/src/client/udpiiu.h +++ b/modules/ca/src/client/udpiiu.h @@ -239,7 +239,9 @@ private: unsigned bufLength ) const throw (); const char * pHostName ( epicsGuard < epicsMutex > & ) const throw (); - bool ca_v41_ok ( + unsigned getHostMinorProtocol ( + epicsGuard < epicsMutex > & ) const throw (); + bool ca_v41_ok ( epicsGuard < epicsMutex > & ) const; bool ca_v42_ok ( epicsGuard < epicsMutex > & ) const; diff --git a/modules/ca/src/client/virtualCircuit.h b/modules/ca/src/client/virtualCircuit.h index 42af12f5f..0f43ea95e 100644 --- a/modules/ca/src/client/virtualCircuit.h +++ b/modules/ca/src/client/virtualCircuit.h @@ -168,6 +168,8 @@ public: unsigned getHostName ( epicsGuard < epicsMutex > &, char *pBuf, unsigned bufLength ) const throw (); + unsigned getHostMinorProtocol ( + epicsGuard < epicsMutex > &) const throw (); bool alive ( epicsGuard < epicsMutex > & ) const; bool connecting (