improved performance
This commit is contained in:
@@ -16,42 +16,50 @@
|
||||
|
||||
#include "iocinf.h"
|
||||
|
||||
tsFreeList < hostNameCache, 16 > hostNameCache::freeList;
|
||||
|
||||
hostNameCache::hostNameCache ( const osiSockAddr &addr, ipAddrToAsciiEngine &engine ) :
|
||||
ipAddrToAsciiAsynchronous ( addr ),
|
||||
pHostName ( 0u )
|
||||
ioComplete ( false )
|
||||
{
|
||||
this->ioInitiate ( engine );
|
||||
}
|
||||
|
||||
void hostNameCache::destroy ()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
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;
|
||||
if ( ! this->ioComplete ) {
|
||||
strncpy ( this->hostNameBuf, pHostNameIn, sizeof ( this->hostNameBuf ) );
|
||||
this->hostNameBuf[ sizeof ( this->hostNameBuf ) - 1 ] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
void hostNameCache::hostName ( char *pBuf, unsigned bufSize ) const
|
||||
{
|
||||
if ( this->pHostName ) {
|
||||
strncpy ( pBuf, this->pHostName, bufSize);
|
||||
if ( this->ioComplete ) {
|
||||
strncpy ( pBuf, this->hostNameBuf, bufSize);
|
||||
pBuf [ bufSize - 1u ] = '\0';
|
||||
}
|
||||
else {
|
||||
osiSockAddr tmpAddr = this->address ();
|
||||
sockAddrToDottedIP ( &tmpAddr.sa, pBuf, bufSize );
|
||||
}
|
||||
pBuf [ bufSize - 1u ] = '\0';
|
||||
}
|
||||
|
||||
void * hostNameCache::operator new ( size_t size )
|
||||
{
|
||||
return hostNameCache::freeList.allocate ( size );
|
||||
}
|
||||
|
||||
void hostNameCache::operator delete ( void *pCadaver, size_t size )
|
||||
{
|
||||
hostNameCache::freeList.release ( pCadaver, size );
|
||||
}
|
||||
Reference in New Issue
Block a user