This is Unofficial EPICS BASE Doxygen Site
hostNameCache Class Reference

#include "hostNameCache.h"

+ Inheritance diagram for hostNameCache:
+ Collaboration diagram for hostNameCache:

Public Member Functions

 hostNameCache (const osiSockAddr &addr, ipAddrToAsciiEngine &engine)
 
 ~hostNameCache ()
 
void destroy ()
 
void transactionComplete (const char *pHostName)
 
unsigned getName (char *pBuf, unsigned bufLength) const
 
const char * pointer () const
 
- Public Member Functions inherited from ipAddrToAsciiCallBack
virtual void show (unsigned level) const
 
virtual ~ipAddrToAsciiCallBack ()=0
 

Detailed Description

Definition at line 31 of file hostNameCache.h.

Constructor & Destructor Documentation

hostNameCache::hostNameCache ( const osiSockAddr addr,
ipAddrToAsciiEngine engine 
)

Definition at line 31 of file hostNameCache.cpp.

32  :
33  dnsTransaction ( engine.createTransaction() ), nameLength ( 0 )
34 {
35  sockAddrToDottedIP ( &addr.sa, hostNameBuf, sizeof ( hostNameBuf ) );
36  hostNameBuf[ sizeof ( hostNameBuf ) - 1 ] = '\0';
37  nameLength = strlen ( hostNameBuf );
38  this->dnsTransaction.ipAddrToAscii ( addr, *this );
39 }
unsigned epicsStdCall sockAddrToDottedIP(const struct sockaddr *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:118
virtual void ipAddrToAscii(const osiSockAddr &, ipAddrToAsciiCallBack &)=0
struct sockaddr sa
Definition: osiSock.h:158
virtual ipAddrToAsciiTransaction & createTransaction()=0
hostNameCache::~hostNameCache ( )

Definition at line 46 of file hostNameCache.cpp.

47 {
48  this->dnsTransaction.release ();
49 }
virtual void release()=0

Member Function Documentation

void hostNameCache::destroy ( )

Definition at line 41 of file hostNameCache.cpp.

42 {
43  delete this;
44 }
unsigned hostNameCache::getName ( char *  pBuf,
unsigned  bufLength 
) const

Definition at line 67 of file hostNameCache.cpp.

69 {
70  if ( bufSize == 0u ) {
71  return 0u;
72  }
73  epicsGuard < epicsMutex > guard ( this->mutex );
74  if ( this->nameLength > 0u ) {
75  if ( this->nameLength < bufSize ) {
76  strcpy ( pBuf, this->hostNameBuf );
77  return this->nameLength;
78  }
79  else {
80  unsigned reducedSize = bufSize - 1u;
81  strncpy ( pBuf, this->hostNameBuf, reducedSize );
82  pBuf [ reducedSize ] = '\0';
83  return reducedSize;
84  }
85  }
86  else {
87  osiSockAddr tmpAddr = this->dnsTransaction.address ();
88  return sockAddrToDottedIP ( &tmpAddr.sa, pBuf, bufSize );
89  }
90 }
unsigned epicsStdCall sockAddrToDottedIP(const struct sockaddr *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:118
struct sockaddr sa
Definition: osiSock.h:158
virtual osiSockAddr address() const =0
const char * hostNameCache::pointer ( ) const
inline

Definition at line 46 of file hostNameCache.h.

47 {
48  return this->hostNameBuf;
49 }
void hostNameCache::transactionComplete ( const char *  pHostName)
virtual

Implements ipAddrToAsciiCallBack.

Definition at line 51 of file hostNameCache.cpp.

52 {
53  epicsGuard < epicsMutex > guard ( this->mutex );
54  // a few legacy clients have a direct pointer to this buffer so we
55  // set the entrire string to nill terminators before we start copying
56  // in the name (this reduces the chance that another thread will see
57  // garbage characters).
58  size_t newNameLen = strlen ( pHostNameIn );
59  if ( newNameLen > sizeof ( this->hostNameBuf ) - 1u ) {
60  newNameLen = sizeof ( this->hostNameBuf ) - 1u;
61  }
62  strncpy ( this->hostNameBuf, "", sizeof ( this->hostNameBuf ) );
63  strncpy ( this->hostNameBuf, pHostNameIn, sizeof ( this->hostNameBuf ) - 1 );
64  this->nameLength = newNameLen;
65 }

The documentation for this class was generated from the following files: