diff --git a/src/ca/hostNameCache.cpp b/src/ca/hostNameCache.cpp index f4e6dfac6..0399efeea 100644 --- a/src/ca/hostNameCache.cpp +++ b/src/ca/hostNameCache.cpp @@ -27,14 +27,16 @@ #include +#if 0 #include "iocinf.h" +#endif #include "hostNameCache.h" +#include "epicsGuard.h" -hostNameCache::hostNameCache ( const osiSockAddr &addr, ipAddrToAsciiEngine &engine ) : - ipAddrToAsciiAsynchronous ( addr ), - ioComplete ( false ) +hostNameCache::hostNameCache ( const osiSockAddr & addr, ipAddrToAsciiEngine & engine ) : + dnsTransaction ( engine.createTransaction() ), ioComplete ( false ) { - this->ioInitiate ( engine ); + this->dnsTransaction.ipAddrToAscii ( addr, *this ); } void hostNameCache::destroy () @@ -44,11 +46,14 @@ void hostNameCache::destroy () hostNameCache::~hostNameCache () { + this->dnsTransaction.release (); } -void hostNameCache::ioCompletionNotify ( const char *pHostNameIn ) +void hostNameCache::transactionComplete ( const char *pHostNameIn ) { + epicsGuard < epicsMutex > guard ( this->mutex ); if ( ! this->ioComplete ) { + this->ioComplete = true; strncpy ( this->hostNameBuf, pHostNameIn, sizeof ( this->hostNameBuf ) ); this->hostNameBuf[ sizeof ( this->hostNameBuf ) - 1 ] = '\0'; } @@ -56,12 +61,13 @@ void hostNameCache::ioCompletionNotify ( const char *pHostNameIn ) void hostNameCache::hostName ( char *pBuf, unsigned bufSize ) const { + epicsGuard < epicsMutex > guard ( this->mutex ); if ( this->ioComplete ) { strncpy ( pBuf, this->hostNameBuf, bufSize); pBuf [ bufSize - 1u ] = '\0'; } else { - osiSockAddr tmpAddr = this->address (); + osiSockAddr tmpAddr = this->dnsTransaction.address (); sockAddrToDottedIP ( &tmpAddr.sa, pBuf, bufSize ); } } diff --git a/src/ca/hostNameCache.h b/src/ca/hostNameCache.h index 9fbb6a0fc..735f99fe6 100644 --- a/src/ca/hostNameCache.h +++ b/src/ca/hostNameCache.h @@ -33,7 +33,7 @@ #endif #include "ipAddrToAsciiAsynchronous.h" -#include "tsFreeList.h" +#include "epicsMutex.h" #ifdef hostNameCache_epicsExportSharedSymbols # define epicsExportSharedSymbols @@ -47,9 +47,10 @@ public: void transactionComplete ( const char * pHostName ); void hostName ( char *pBuf, unsigned bufLength ) const; private: + char hostNameBuf [128]; + mutable epicsMutex mutex; ipAddrToAsciiTransaction & dnsTransaction; bool ioComplete; - char hostNameBuf [128]; }; #endif // #ifndef hostNameCacheh