diff --git a/src/ca/cacChannel.cpp b/src/ca/cacChannel.cpp index 0ff26047e..578962100 100644 --- a/src/ca/cacChannel.cpp +++ b/src/ca/cacChannel.cpp @@ -100,6 +100,16 @@ void cacChannel::hostName ( char *pBuf, unsigned bufLength ) const } } +const char * cacChannel::pHostName () const +{ + if ( this->pChannelIO ) { + return pChannelIO->pHostName (); + } + else { + return ""; + } +} + short cacChannel::nativeType () const { if ( this->pChannelIO ) { diff --git a/src/ca/cacChannelIO.cpp b/src/ca/cacChannelIO.cpp index b8eec0bda..0f6b6fa6a 100644 --- a/src/ca/cacChannelIO.cpp +++ b/src/ca/cacChannelIO.cpp @@ -89,14 +89,16 @@ unsigned cacChannelIO::readSequence () const void cacChannelIO::hostName ( char *pBuf, unsigned bufLength ) const { if ( bufLength ) { - int status = gethostname ( pBuf, bufLength ); - if ( status ) { - strncpy ( pBuf, "", bufLength ); - pBuf[ bufLength - 1u ] = '\0'; - } + localHostNameAtLoadTime.copy (pBuf, bufLength ); } } +// deprecated - please do not use +const char * cacChannelIO::pHostName () const +{ + return localHostNameAtLoadTime.pointer (); +} + void cacChannelIO::incrementOutstandingIO () { } @@ -104,3 +106,5 @@ void cacChannelIO::incrementOutstandingIO () void cacChannelIO::decrementOutstandingIO () { } + + diff --git a/src/ca/cacIO.h b/src/ca/cacIO.h index 26bf65c51..7269f9aa2 100644 --- a/src/ca/cacIO.h +++ b/src/ca/cacIO.h @@ -81,6 +81,8 @@ public: void decrementOutstandingIO (); void decrementOutstandingIO ( unsigned seqNumber ); + const char * pHostName () const; // deprecated - please do not use + protected: class cacChannelIO *pChannelIO; @@ -134,8 +136,10 @@ private: virtual unsigned readSequence () const; // defaults to always zero virtual void incrementOutstandingIO (); virtual void decrementOutstandingIO (); + virtual const char * pHostName () const; // deprecated - please do not use cacChannel &chan; + friend class cacChannel; }; diff --git a/src/ca/iocinf.cpp b/src/ca/iocinf.cpp index a00ec3db6..386a0d9c2 100644 --- a/src/ca/iocinf.cpp +++ b/src/ca/iocinf.cpp @@ -16,45 +16,6 @@ #include "iocinf.h" #include "addrList.h" -/* - * localHostName() - * - * o Indicates failure by setting ptr to nill - * - * o Calls non posix gethostbyname() so that we get DNS style names - * (gethostbyname() should be available with most BSD sock libs) - * - * vxWorks user will need to configure a DNS format name for the - * host name if they wish to be cnsistent with UNIX and VMS hosts. - * - * this needs to attempt to determine if the process is a remote - * login - hard to do under UNIX - */ -char *localHostName () -{ - int size; - int status; - char pName[MAXHOSTNAMELEN]; - char *pTmp; - - status = gethostname ( pName, sizeof (pName) ); - if(status){ - return NULL; - } - - size = strlen (pName)+1; - pTmp = (char *) malloc (size); - if (!pTmp) { - return pTmp; - } - - strncpy ( pTmp, pName, size-1 ); - pTmp[size-1] = '\0'; - - return pTmp; -} - - /* * getToken() */ diff --git a/src/ca/iocinf.h b/src/ca/iocinf.h index 775c749e7..e9ad2772b 100644 --- a/src/ca/iocinf.h +++ b/src/ca/iocinf.h @@ -58,6 +58,7 @@ #include "osiMutex.h" #include "osiEvent.h" #include "resourceLib.h" +#include "localHostName.h" #if defined(epicsExportSharedSymbols) #error suspect that libCom was not imported @@ -179,11 +180,14 @@ private: unsigned f_connected:1; unsigned f_fullyConstructed:1; static tsFreeList < class nciu, 1024 > freeList; + ~nciu (); // force pool allocation int issuePut ( ca_uint16_t cmd, unsigned id, chtype type, unsigned long count, const void *pvalue ); void lock () const; void unlock () const; + + const char * pHostName () const; // deprecated - please do not use }; class baseNMIU : public tsDLNode , @@ -355,7 +359,10 @@ public: virtual void removeFromChanList ( nciu &chan ) = 0; virtual void disconnect ( nciu &chan ) = 0; + virtual const char * pHostName () const = 0; // deprecated - please do not use + tsDLList chidList; +private: }; class udpiiu; @@ -444,6 +451,8 @@ public: private: SOCKET sock; bool compareIfTCP (nciu &chan, const sockaddr_in &) const; + + const char * pHostName () const; // deprecated - please do not use }; class tcpRecvWatchdog : public osiTimer { @@ -562,6 +571,7 @@ private: static tsFreeList < class tcpiiu, 16 > freeList; friend void cacSendThreadTCP ( void *pParam ); + const char * pHostName () const; // deprecated - please do not use }; class inetAddrID { @@ -750,6 +760,7 @@ public: void installDisconnectedChannel ( nciu &chan ); void notifySearchResponse ( unsigned short retrySeqNo ); void repeaterSubscribeConfirmNotify (); + void replaceErrLogHandler ( caPrintfFunc *ca_printf_func ); osiTimerQueue *pTimerQueue; ELLLIST activeCASGOP; @@ -762,7 +773,6 @@ public: void *ca_exception_arg; caPrintfFunc *ca_printf_func; char *ca_pUserName; - char *ca_pHostName; resTable < bhe, inetAddrID > beaconTable; tsDLIterBD endOfBCastList; @@ -814,8 +824,6 @@ int ca_vPrintf (const char *pformat, va_list args); void manage_conn (cac *pcac); epicsShareFunc void epicsShareAPI ca_repeater (void); -char *localHostName (void); - bhe *lookupBeaconInetAddr(cac *pcac, const struct sockaddr_in *pnet_addr); diff --git a/src/ca/tcpiiu.cpp b/src/ca/tcpiiu.cpp index 21396ee20..5e1890e7d 100644 --- a/src/ca/tcpiiu.cpp +++ b/src/ca/tcpiiu.cpp @@ -15,6 +15,10 @@ #include "inetAddrID_IL.h" #include "bhe_IL.h" +const caHdr cacnullmsg = { + 0,0,0,0,0,0 +}; + tsFreeList < class tcpiiu, 16 > tcpiiu::freeList; #ifdef DEBUG @@ -147,7 +151,7 @@ LOCAL void retryPendingClaims (tcpiiu *piiu) piiu->pcas->lock (); tsDLIterBD chan ( piiu->chidList.first () ); - while ( chan != chan.eol () ) { + while ( chan.valid () ) { if ( ! chan->claimPending ) { piiu->claimRequestsPending = false; piiu->flush (); @@ -555,7 +559,7 @@ tcpiiu::~tcpiiu () } tsDLIterBD iter ( this->chidList.first () ); - while ( iter != iter.eol () ) { + while ( iter.valid () ) { tsDLIterBD next = iter.itemAfter (); iter->disconnect (); iter = next; @@ -708,24 +712,17 @@ int tcpiiu::readyRequestMsg () */ void tcpiiu::hostNameSetMsg () { - unsigned size; caHdr hdr; - char *pName; - if ( ! CA_V41(CA_PROTOCOL_VERSION, this->minor_version_number) ) { + if ( ! CA_V41 ( CA_PROTOCOL_VERSION, this->minor_version_number ) ) { return; } - /* - * allocate space in the outgoing buffer - */ - pName = this->pcas->ca_pHostName, - size = strlen (pName) + 1; hdr = cacnullmsg; - hdr.m_cmmd = htons (CA_PROTO_HOST_NAME); - hdr.m_postsize = size; + hdr.m_cmmd = htons ( CA_PROTO_HOST_NAME ); + hdr.m_postsize = localHostNameAtLoadTime.stringLength () + 1u; - this->pushStreamMsg (&hdr, pName, true); + this->pushStreamMsg ( &hdr, localHostNameAtLoadTime.pointer (), true ); return; } @@ -1328,6 +1325,12 @@ void tcpiiu::hostName ( char *pBuf, unsigned bufLength ) const } } +// deprecated - please dont use +const char * tcpiiu::pHostName () const +{ + return this->host_name_str; +} + bool tcpiiu::ca_v42_ok () const { return CA_V42 (CA_PROTOCOL_VERSION, this->minor_version_number);