Store start time as time_t rather than string.

This commit is contained in:
ehouse 2009-09-26 14:05:51 +00:00
parent 827f44ff48
commit 030ae52a4b
2 changed files with 10 additions and 10 deletions

View file

@ -30,7 +30,7 @@ using namespace std;
pthread_mutex_t PermID::s_guard = PTHREAD_MUTEX_INITIALIZER;
string PermID::s_serverName;
int PermID::s_nextId = 0;
string PermID::s_startTime;
time_t PermID::s_startTime;
string
PermID::GetNextUniqueID()
@ -38,8 +38,8 @@ PermID::GetNextUniqueID()
MutexLock ml( &s_guard );
char buf[64];
snprintf( buf, sizeof(buf), "%s:%s:%d", s_serverName.c_str(),
s_startTime.c_str(), ++s_nextId );
snprintf( buf, sizeof(buf), "%s:%x:%d", s_serverName.c_str(),
(unsigned int)s_startTime, ++s_nextId );
string s(buf);
return s;
@ -54,8 +54,6 @@ PermID::SetServerName( const char* name )
/* static */ void
PermID::SetStartTime( time_t startTime )
{
char buf[16];
snprintf( buf, sizeof(buf), "%ld", startTime );
s_startTime = buf;
logf( XW_LOGINFO, "assigned startTime: %s", s_startTime.c_str() );
s_startTime = startTime;
logf( XW_LOGINFO, "assigned startTime: %ld", s_startTime );
}

View file

@ -45,7 +45,9 @@ class PermID {
unique to this relay
instance. */
static int s_nextId; /* numeric part of ID */
static std::string s_startTime; /* allows multiple servers per
host to have uniquie names */
};
static time_t s_startTime; /* allows multiple servers per
host to have uniquie names
and to ensure no duplications
after a crash. */
};
#endif