improved performance

This commit is contained in:
Jeff Hill
2000-11-08 03:52:18 +00:00
parent 2ded135da9
commit 4784b73a9f
39 changed files with 2480 additions and 2589 deletions

View File

@@ -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 );
}