many, many changes
This commit is contained in:
57
src/ca/hostNameCache.cpp
Normal file
57
src/ca/hostNameCache.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
*
|
||||
* L O S A L A M O S
|
||||
* Los Alamos National Laboratory
|
||||
* Los Alamos, New Mexico 87545
|
||||
*
|
||||
* Copyright, 1986, The Regents of the University of California.
|
||||
*
|
||||
*
|
||||
* Author Jeffrey O. Hill
|
||||
* johill@lanl.gov
|
||||
*/
|
||||
|
||||
#include "iocinf.h"
|
||||
|
||||
hostNameCache::hostNameCache ( const osiSockAddr &addr, ipAddrToAsciiEngine &engine ) :
|
||||
ipAddrToAsciiAsynchronous ( addr ),
|
||||
pHostName ( 0u )
|
||||
{
|
||||
this->ioInitiate ( engine );
|
||||
}
|
||||
|
||||
hostNameCache::~hostNameCache ()
|
||||
{
|
||||
if ( this->pHostName ) {
|
||||
delete [] this->pHostName;
|
||||
}
|
||||
}
|
||||
|
||||
void hostNameCache::ioCompletionNotify ( const char *pHostNameIn )
|
||||
{
|
||||
if ( ! this->pHostName ) {
|
||||
unsigned size = strlen ( pHostNameIn ) + 1u;
|
||||
char *pTmp = new char [size];
|
||||
if ( ! pTmp ) {
|
||||
// we fail over to using the IP address for the name
|
||||
return;
|
||||
}
|
||||
strcpy ( pTmp, pHostNameIn );
|
||||
this->pHostName = pTmp;
|
||||
}
|
||||
}
|
||||
|
||||
void hostNameCache::hostName ( char *pBuf, unsigned bufSize ) const
|
||||
{
|
||||
if ( this->pHostName ) {
|
||||
strncpy ( pBuf, this->pHostName, bufSize);
|
||||
}
|
||||
else {
|
||||
osiSockAddr addr = this->address();
|
||||
sockAddrToDottedA ( &addr.sa, pBuf, bufSize );
|
||||
}
|
||||
pBuf [ bufSize - 1u ] = '\0';
|
||||
}
|
||||
Reference in New Issue
Block a user