mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
Merge branch 'android_invite' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into android_invite
This commit is contained in:
commit
ba4d898de1
5 changed files with 34 additions and 13 deletions
|
@ -175,7 +175,10 @@ CidLock::Relinquish( CidInfo* claim, bool drop )
|
|||
m_infos.erase( iter );
|
||||
delete claim;
|
||||
} else {
|
||||
claim->SetSockets( claim->GetRef()->GetSockets() ); /* cache these */
|
||||
CookieRef* ref = claim->GetRef();
|
||||
if ( NULL != ref ) {
|
||||
claim->SetSockets( ref->GetSockets() ); /* cache these */
|
||||
}
|
||||
claim->SetOwner( 0 );
|
||||
}
|
||||
PRINT_CLAIMED();
|
||||
|
|
|
@ -402,13 +402,15 @@ CRefMgr::PrintSocketInfo( int socket, string& out )
|
|||
}
|
||||
|
||||
CidInfo*
|
||||
CRefMgr::getCookieRef( CookieID cid )
|
||||
CRefMgr::getCookieRef( CookieID cid, bool failOk )
|
||||
{
|
||||
CidInfo* cinfo = NULL;
|
||||
for ( ; ; ) {
|
||||
cinfo = m_cidlock->Claim( cid );
|
||||
if ( NULL != cinfo->GetRef() ) {
|
||||
break;
|
||||
} else if ( failOk ) {
|
||||
break;
|
||||
}
|
||||
m_cidlock->Relinquish( cinfo, true );
|
||||
}
|
||||
|
@ -655,13 +657,16 @@ SafeCref::SafeCref( CookieID cid, bool failOk )
|
|||
: m_cinfo( NULL )
|
||||
, m_mgr( CRefMgr::Get() )
|
||||
, m_isValid( false )
|
||||
, m_locked( false )
|
||||
{
|
||||
CidInfo* cinfo = m_mgr->getCookieRef( cid );
|
||||
CidInfo* cinfo = m_mgr->getCookieRef( cid, failOk );
|
||||
if ( cinfo != NULL ) { /* known cookie? */
|
||||
CookieRef* cref = cinfo->GetRef();
|
||||
assert( cinfo->GetCid() == cref->GetCid() );
|
||||
m_locked = cref->Lock();
|
||||
m_isValid = m_locked && cid == cref->GetCid();
|
||||
if ( NULL != cref ) {
|
||||
assert( cinfo->GetCid() == cref->GetCid() );
|
||||
m_locked = cref->Lock();
|
||||
m_isValid = m_locked && cid == cref->GetCid();
|
||||
}
|
||||
m_cinfo = cinfo;
|
||||
}
|
||||
}
|
||||
|
@ -684,7 +689,7 @@ SafeCref::SafeCref( int socket )
|
|||
SafeCref::~SafeCref()
|
||||
{
|
||||
if ( m_cinfo != NULL ) {
|
||||
bool recycle = false;
|
||||
bool recycle = true;
|
||||
if ( m_locked ) {
|
||||
CookieRef* cref = m_cinfo->GetRef();
|
||||
assert( m_cinfo->GetCid() == cref->GetCid() );
|
||||
|
|
|
@ -131,7 +131,7 @@ class CRefMgr {
|
|||
|
||||
CidInfo* getMakeCookieRef( const char* const connName, bool* isDead );
|
||||
|
||||
CidInfo* getCookieRef( CookieID cid );
|
||||
CidInfo* getCookieRef( CookieID cid, bool failOk = false );
|
||||
CidInfo* getCookieRef( int socket );
|
||||
bool checkCookieRef_locked( CookieRef* cref );
|
||||
CidInfo* getCookieRef_impl( CookieID cid );
|
||||
|
|
|
@ -289,9 +289,10 @@ DBMgr::RmDeviceByHid( const char* connName, HostID hid )
|
|||
return execSql( query );
|
||||
}
|
||||
|
||||
void
|
||||
DBMgr::RmDeviceBySeed( const char* const connName, unsigned short seed )
|
||||
HostID
|
||||
DBMgr::HIDForSeed( const char* const connName, unsigned short seed )
|
||||
{
|
||||
HostID hid = HOST_ID_NONE;
|
||||
char seeds[128] = {0};
|
||||
const char* fmt = "SELECT seeds FROM " GAMES_TABLE
|
||||
" WHERE connName = '%s'"
|
||||
|
@ -316,7 +317,7 @@ DBMgr::RmDeviceBySeed( const char* const connName, unsigned short seed )
|
|||
} else {
|
||||
int asint = atoi( tok );
|
||||
if ( asint == seed ) {
|
||||
RmDeviceByHid( connName, ii + 1 );
|
||||
hid = ii + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -324,6 +325,17 @@ DBMgr::RmDeviceBySeed( const char* const connName, unsigned short seed )
|
|||
} else {
|
||||
assert(0); /* but don't ship with this!!!! */
|
||||
}
|
||||
|
||||
return hid;
|
||||
}
|
||||
|
||||
void
|
||||
DBMgr::RmDeviceBySeed( const char* const connName, unsigned short seed )
|
||||
{
|
||||
HostID hid = HIDForSeed( connName, seed );
|
||||
if ( hid != HOST_ID_NONE ) {
|
||||
RmDeviceByHid( connName, hid );
|
||||
}
|
||||
} /* RmDeviceSeed */
|
||||
|
||||
bool
|
||||
|
@ -639,8 +651,8 @@ formatParams( char* paramValues[], int nParams, const char* fmt, char* buf,
|
|||
static int
|
||||
here_less_seed( const char* seeds, int sumPerDevice, unsigned short seed )
|
||||
{
|
||||
logf( XW_LOGINFO, "%s: find %x in \"%s\", sub from \"%d\"", __func__,
|
||||
seed, seeds, sumPerDevice );
|
||||
logf( XW_LOGINFO, "%s: find %x(%d) in \"%s\", sub from \"%d\"", __func__,
|
||||
seed, seed, seeds, sumPerDevice );
|
||||
return sumPerDevice - 1; /* FIXME */
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ class DBMgr {
|
|||
HostID AddDevice( const char* const connName, HostID curID,
|
||||
int nToAdd, unsigned short seed, bool unAckd );
|
||||
void NoteAckd( const char* const connName, HostID id );
|
||||
HostID HIDForSeed( const char* const connName, unsigned short seed );
|
||||
bool RmDeviceByHid( const char* const connName, HostID id );
|
||||
void RmDeviceBySeed( const char* const connName, unsigned short seed );
|
||||
bool HaveDevice( const char* const connName, HostID id, int seed );
|
||||
|
|
Loading…
Reference in a new issue