From 030ae52a4b9d8c0db20d12ce1bbfe935f6878765 Mon Sep 17 00:00:00 2001 From: ehouse Date: Sat, 26 Sep 2009 14:05:51 +0000 Subject: [PATCH] Store start time as time_t rather than string. --- xwords4/relay/permid.cpp | 12 +++++------- xwords4/relay/permid.h | 8 +++++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/xwords4/relay/permid.cpp b/xwords4/relay/permid.cpp index 77da4a96a..3c13bbb64 100644 --- a/xwords4/relay/permid.cpp +++ b/xwords4/relay/permid.cpp @@ -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 ); } diff --git a/xwords4/relay/permid.h b/xwords4/relay/permid.h index 43f73a572..8ea4ed2bd 100644 --- a/xwords4/relay/permid.h +++ b/xwords4/relay/permid.h @@ -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