mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
change varible names; remove instance variable than can be on the stack.
This commit is contained in:
parent
82c15f7f09
commit
7a71c4636b
3 changed files with 37 additions and 38 deletions
|
@ -87,7 +87,6 @@ CookieRef::ReInit( const char* cookie, const char* connName, CookieID id )
|
||||||
m_cookieID = id;
|
m_cookieID = id;
|
||||||
m_totalSent = 0;
|
m_totalSent = 0;
|
||||||
m_curState = XWS_INITED;
|
m_curState = XWS_INITED;
|
||||||
m_nextState = XWS_INITED;
|
|
||||||
m_nextHostID = HOST_ID_SERVER;
|
m_nextHostID = HOST_ID_SERVER;
|
||||||
m_nPlayersSought = 0;
|
m_nPlayersSought = 0;
|
||||||
m_nPlayersHere = 0;
|
m_nPlayersHere = 0;
|
||||||
|
@ -169,7 +168,7 @@ CookieRef::Unlock() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::_Connect( int socket, HostID hid, int nPlayersH, int nPlayersT,
|
CookieRef::_Connect( int socket, HostID hid, int nPlayersH, int nPlayersS,
|
||||||
int seed )
|
int seed )
|
||||||
{
|
{
|
||||||
if ( CRefMgr::Get()->Associate( socket, this ) ) {
|
if ( CRefMgr::Get()->Associate( socket, this ) ) {
|
||||||
|
@ -178,7 +177,7 @@ CookieRef::_Connect( int socket, HostID hid, int nPlayersH, int nPlayersT,
|
||||||
} else {
|
} else {
|
||||||
logf( XW_LOGINFO, "NOT assigned host id; why?" );
|
logf( XW_LOGINFO, "NOT assigned host id; why?" );
|
||||||
}
|
}
|
||||||
pushConnectEvent( socket, hid, nPlayersH, nPlayersT, seed );
|
pushConnectEvent( socket, hid, nPlayersH, nPlayersS, seed );
|
||||||
handleEvents();
|
handleEvents();
|
||||||
} else {
|
} else {
|
||||||
logf( XW_LOGINFO, "dropping connect event; already connected" );
|
logf( XW_LOGINFO, "dropping connect event; already connected" );
|
||||||
|
@ -186,11 +185,11 @@ CookieRef::_Connect( int socket, HostID hid, int nPlayersH, int nPlayersT,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::_Reconnect( int socket, HostID hid, int nPlayersH, int nPlayersT,
|
CookieRef::_Reconnect( int socket, HostID hid, int nPlayersH, int nPlayersS,
|
||||||
int seed )
|
int seed )
|
||||||
{
|
{
|
||||||
(void)CRefMgr::Get()->Associate( socket, this );
|
(void)CRefMgr::Get()->Associate( socket, this );
|
||||||
pushReconnectEvent( socket, hid, nPlayersH, nPlayersT, seed );
|
pushReconnectEvent( socket, hid, nPlayersH, nPlayersS, seed );
|
||||||
handleEvents();
|
handleEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +394,7 @@ CookieRef::_Remove( int socket )
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::pushConnectEvent( int socket, HostID srcID,
|
CookieRef::pushConnectEvent( int socket, HostID srcID,
|
||||||
int nPlayersH, int nPlayersT,
|
int nPlayersH, int nPlayersS,
|
||||||
int seed )
|
int seed )
|
||||||
{
|
{
|
||||||
CRefEvent evt;
|
CRefEvent evt;
|
||||||
|
@ -403,21 +402,21 @@ CookieRef::pushConnectEvent( int socket, HostID srcID,
|
||||||
evt.u.con.socket = socket;
|
evt.u.con.socket = socket;
|
||||||
evt.u.con.srcID = srcID;
|
evt.u.con.srcID = srcID;
|
||||||
evt.u.con.nPlayersH = nPlayersH;
|
evt.u.con.nPlayersH = nPlayersH;
|
||||||
evt.u.con.nPlayersT = nPlayersT;
|
evt.u.con.nPlayersS = nPlayersS;
|
||||||
evt.u.con.seed = seed;
|
evt.u.con.seed = seed;
|
||||||
m_eventQueue.push_back( evt );
|
m_eventQueue.push_back( evt );
|
||||||
} /* pushConnectEvent */
|
} /* pushConnectEvent */
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::pushReconnectEvent( int socket, HostID srcID, int nPlayersH,
|
CookieRef::pushReconnectEvent( int socket, HostID srcID, int nPlayersH,
|
||||||
int nPlayersT, int seed )
|
int nPlayersS, int seed )
|
||||||
{
|
{
|
||||||
CRefEvent evt;
|
CRefEvent evt;
|
||||||
evt.type = XWE_RECONNECTMSG;
|
evt.type = XWE_RECONNECTMSG;
|
||||||
evt.u.con.socket = socket;
|
evt.u.con.socket = socket;
|
||||||
evt.u.con.srcID = srcID;
|
evt.u.con.srcID = srcID;
|
||||||
evt.u.con.nPlayersH = nPlayersH;
|
evt.u.con.nPlayersH = nPlayersH;
|
||||||
evt.u.con.nPlayersT = nPlayersT;
|
evt.u.con.nPlayersS = nPlayersS;
|
||||||
evt.u.con.seed = seed;
|
evt.u.con.seed = seed;
|
||||||
m_eventQueue.push_back( evt );
|
m_eventQueue.push_back( evt );
|
||||||
} /* pushReconnectEvent */
|
} /* pushReconnectEvent */
|
||||||
|
@ -490,14 +489,15 @@ CookieRef::handleEvents()
|
||||||
{
|
{
|
||||||
/* Assumption: has mutex!!!! */
|
/* Assumption: has mutex!!!! */
|
||||||
while ( m_eventQueue.size () > 0 ) {
|
while ( m_eventQueue.size () > 0 ) {
|
||||||
|
XW_RELAY_STATE nextState;
|
||||||
CRefEvent evt = m_eventQueue.front();
|
CRefEvent evt = m_eventQueue.front();
|
||||||
m_eventQueue.pop_front();
|
m_eventQueue.pop_front();
|
||||||
|
|
||||||
XW_RELAY_ACTION takeAction;
|
XW_RELAY_ACTION takeAction;
|
||||||
if ( getFromTable( m_curState, evt.type, &takeAction, &m_nextState ) ) {
|
if ( getFromTable( m_curState, evt.type, &takeAction, &nextState ) ) {
|
||||||
|
|
||||||
logf( XW_LOGINFO, "%s: %s -> %s on evt %s, act=%s", __func__,
|
logf( XW_LOGINFO, "%s: %s -> %s on evt %s, act=%s", __func__,
|
||||||
stateString(m_curState), stateString(m_nextState),
|
stateString(m_curState), stateString(nextState),
|
||||||
eventString(evt.type), actString(takeAction) );
|
eventString(evt.type), actString(takeAction) );
|
||||||
|
|
||||||
switch( takeAction ) {
|
switch( takeAction ) {
|
||||||
|
@ -585,7 +585,7 @@ CookieRef::handleEvents()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_curState = m_nextState;
|
m_curState = nextState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* handleEvents */
|
} /* handleEvents */
|
||||||
|
@ -619,18 +619,18 @@ void
|
||||||
CookieRef::increasePlayerCounts( const CRefEvent* evt )
|
CookieRef::increasePlayerCounts( const CRefEvent* evt )
|
||||||
{
|
{
|
||||||
int nPlayersH = evt->u.con.nPlayersH;
|
int nPlayersH = evt->u.con.nPlayersH;
|
||||||
int nPlayersT = evt->u.con.nPlayersT;
|
int nPlayersS = evt->u.con.nPlayersS;
|
||||||
HostID hid = evt->u.con.srcID;
|
HostID hid = evt->u.con.srcID;
|
||||||
assert( hid <= 4 );
|
assert( hid <= 4 );
|
||||||
|
|
||||||
logf( XW_LOGINFO, "%s: hid=%d, nPlayersH=%d, ", __func__,
|
logf( XW_LOGINFO, "%s: hid=%d, nPlayersH=%d, ", __func__,
|
||||||
"nPlayersT=%d", hid, nPlayersH, nPlayersT );
|
"nPlayersS=%d", hid, nPlayersH, nPlayersS );
|
||||||
|
|
||||||
if ( hid == HOST_ID_SERVER ) {
|
if ( hid == HOST_ID_SERVER ) {
|
||||||
assert( m_nPlayersSought == 0 );
|
assert( m_nPlayersSought == 0 );
|
||||||
m_nPlayersSought = nPlayersT;
|
m_nPlayersSought = nPlayersS;
|
||||||
} else {
|
} else {
|
||||||
assert( nPlayersT == 0 ); /* should catch this earlier!!! */
|
assert( nPlayersS == 0 ); /* should catch this earlier!!! */
|
||||||
assert( m_nPlayersSought == 0 || m_nPlayersHere <= m_nPlayersSought );
|
assert( m_nPlayersSought == 0 || m_nPlayersHere <= m_nPlayersSought );
|
||||||
}
|
}
|
||||||
m_nPlayersHere += nPlayersH;
|
m_nPlayersHere += nPlayersH;
|
||||||
|
@ -659,7 +659,7 @@ CookieRef::reducePlayerCounts( int socket )
|
||||||
if ( iter->m_hostID == HOST_ID_SERVER ) {
|
if ( iter->m_hostID == HOST_ID_SERVER ) {
|
||||||
m_nPlayersSought = 0;
|
m_nPlayersSought = 0;
|
||||||
} else {
|
} else {
|
||||||
assert( iter->m_nPlayersT == 0 );
|
assert( iter->m_nPlayersS == 0 );
|
||||||
}
|
}
|
||||||
m_nPlayersHere -= iter->m_nPlayersH;
|
m_nPlayersHere -= iter->m_nPlayersH;
|
||||||
|
|
||||||
|
@ -677,7 +677,6 @@ void
|
||||||
CookieRef::checkCounts( const CRefEvent* evt )
|
CookieRef::checkCounts( const CRefEvent* evt )
|
||||||
{
|
{
|
||||||
int nPlayersH = evt->u.con.nPlayersH;
|
int nPlayersH = evt->u.con.nPlayersH;
|
||||||
/* int nPlayersT = evt->u.con.nPlayersT; */
|
|
||||||
HostID hid = evt->u.con.srcID;
|
HostID hid = evt->u.con.srcID;
|
||||||
bool success;
|
bool success;
|
||||||
|
|
||||||
|
@ -724,14 +723,14 @@ CookieRef::sendResponse( const CRefEvent* evt, bool initial )
|
||||||
int socket = evt->u.con.socket;
|
int socket = evt->u.con.socket;
|
||||||
HostID hid = evt->u.con.srcID;
|
HostID hid = evt->u.con.srcID;
|
||||||
int nPlayersH = evt->u.con.nPlayersH;
|
int nPlayersH = evt->u.con.nPlayersH;
|
||||||
int nPlayersT = evt->u.con.nPlayersT;
|
int nPlayersS = evt->u.con.nPlayersS;
|
||||||
int seed = evt->u.con.seed;
|
int seed = evt->u.con.seed;
|
||||||
|
|
||||||
ASSERT_LOCKED();
|
ASSERT_LOCKED();
|
||||||
|
|
||||||
logf( XW_LOGINFO, "%s: remembering pair: hostid=%x, socket=%d (size=%d)",
|
logf( XW_LOGINFO, "%s: remembering pair: hostid=%x, socket=%d (size=%d)",
|
||||||
__func__, hid, socket, m_sockets.size());
|
__func__, hid, socket, m_sockets.size());
|
||||||
HostRec hr(hid, socket, nPlayersH, nPlayersT, seed );
|
HostRec hr(hid, socket, nPlayersH, nPlayersS, seed );
|
||||||
m_sockets.push_back( hr );
|
m_sockets.push_back( hr );
|
||||||
logf( XW_LOGINFO, "m_sockets.size() now %d", m_sockets.size() );
|
logf( XW_LOGINFO, "m_sockets.size() now %d", m_sockets.size() );
|
||||||
|
|
||||||
|
|
|
@ -37,19 +37,19 @@ class CookieMapIterator; /* forward */
|
||||||
|
|
||||||
struct HostRec {
|
struct HostRec {
|
||||||
public:
|
public:
|
||||||
HostRec(HostID hostID, int socket, int nPlayersH, int nPlayersT,
|
HostRec(HostID hostID, int socket, int nPlayersH, int nPlayersS,
|
||||||
int seed )
|
int seed )
|
||||||
: m_hostID(hostID)
|
: m_hostID(hostID)
|
||||||
, m_socket(socket)
|
, m_socket(socket)
|
||||||
, m_nPlayersH(nPlayersH)
|
, m_nPlayersH(nPlayersH)
|
||||||
, m_nPlayersT(nPlayersT)
|
, m_nPlayersS(nPlayersS)
|
||||||
, m_seed(seed)
|
, m_seed(seed)
|
||||||
, m_lastHeartbeat(uptime())
|
, m_lastHeartbeat(uptime())
|
||||||
{}
|
{}
|
||||||
HostID m_hostID;
|
HostID m_hostID;
|
||||||
int m_socket;
|
int m_socket;
|
||||||
int m_nPlayersH;
|
int m_nPlayersH;
|
||||||
int m_nPlayersT;
|
int m_nPlayersS;
|
||||||
int m_seed;
|
int m_seed;
|
||||||
time_t m_lastHeartbeat;
|
time_t m_lastHeartbeat;
|
||||||
};
|
};
|
||||||
|
@ -103,9 +103,9 @@ class CookieRef {
|
||||||
static void Delete( CookieID id );
|
static void Delete( CookieID id );
|
||||||
static void Delete( const char* name );
|
static void Delete( const char* name );
|
||||||
|
|
||||||
void _Connect( int socket, HostID srcID, int nPlayersH, int nPlayersT,
|
void _Connect( int socket, HostID srcID, int nPlayersH, int nPlayersS,
|
||||||
int seed );
|
int seed );
|
||||||
void _Reconnect( int socket, HostID srcID, int nPlayersH, int nPlayersT,
|
void _Reconnect( int socket, HostID srcID, int nPlayersH, int nPlayersS,
|
||||||
int seed );
|
int seed );
|
||||||
void _Disconnect(int socket, HostID hostID );
|
void _Disconnect(int socket, HostID hostID );
|
||||||
void _Shutdown();
|
void _Shutdown();
|
||||||
|
@ -132,7 +132,7 @@ class CookieRef {
|
||||||
struct {
|
struct {
|
||||||
int socket;
|
int socket;
|
||||||
int nPlayersH;
|
int nPlayersH;
|
||||||
int nPlayersT;
|
int nPlayersS;
|
||||||
int seed;
|
int seed;
|
||||||
HostID srcID;
|
HostID srcID;
|
||||||
} con;
|
} con;
|
||||||
|
@ -167,10 +167,10 @@ class CookieRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushConnectEvent( int socket, HostID srcID,
|
void pushConnectEvent( int socket, HostID srcID,
|
||||||
int nPlayersH, int nPlayersT,
|
int nPlayersH, int nPlayersS,
|
||||||
int seed );
|
int seed );
|
||||||
void pushReconnectEvent( int socket, HostID srcID,
|
void pushReconnectEvent( int socket, HostID srcID,
|
||||||
int nPlayersH, int nPlayersT,
|
int nPlayersH, int nPlayersS,
|
||||||
int seed );
|
int seed );
|
||||||
void pushHeartbeatEvent( HostID id, int socket );
|
void pushHeartbeatEvent( HostID id, int socket );
|
||||||
void pushHeartFailedEvent( int socket );
|
void pushHeartFailedEvent( int socket );
|
||||||
|
@ -231,7 +231,6 @@ class CookieRef {
|
||||||
|
|
||||||
|
|
||||||
XW_RELAY_STATE m_curState;
|
XW_RELAY_STATE m_curState;
|
||||||
XW_RELAY_STATE m_nextState;
|
|
||||||
deque<CRefEvent> m_eventQueue;
|
deque<CRefEvent> m_eventQueue;
|
||||||
|
|
||||||
HostID m_nextHostID;
|
HostID m_nextHostID;
|
||||||
|
|
|
@ -125,9 +125,10 @@ class CRefMgr {
|
||||||
void addToFreeList( CookieRef* cref );
|
void addToFreeList( CookieRef* cref );
|
||||||
CookieRef* getFromFreeList( void );
|
CookieRef* getFromFreeList( void );
|
||||||
|
|
||||||
CookieRef* getMakeCookieRef_locked( const char* cookie, const char* connName,
|
CookieRef* getMakeCookieRef_locked( const char* cookie,
|
||||||
HostID hid, int socket,
|
const char* connName,
|
||||||
int nPlayersH, int nPlayersT, int seed );
|
HostID hid, int socket, int nPlayersH,
|
||||||
|
int nPlayersS, int seed );
|
||||||
CookieRef* getCookieRef( CookieID cookieID );
|
CookieRef* getCookieRef( CookieID cookieID );
|
||||||
CookieRef* getCookieRef( int socket );
|
CookieRef* getCookieRef( int socket );
|
||||||
bool checkCookieRef_locked( CookieRef* cref );
|
bool checkCookieRef_locked( CookieRef* cref );
|
||||||
|
@ -136,7 +137,7 @@ class CRefMgr {
|
||||||
CookieID id );
|
CookieID id );
|
||||||
CookieRef* FindOpenGameFor( const char* cookie, const char* connName,
|
CookieRef* FindOpenGameFor( const char* cookie, const char* connName,
|
||||||
HostID hid, int socket, int nPlayersH,
|
HostID hid, int socket, int nPlayersH,
|
||||||
int nPlayersT, int gameSeed,
|
int nPlayersS, int gameSeed,
|
||||||
bool* alreadyHere );
|
bool* alreadyHere );
|
||||||
|
|
||||||
CookieID cookieIDForConnName( const char* connName );
|
CookieID cookieIDForConnName( const char* connName );
|
||||||
|
@ -167,7 +168,7 @@ class SafeCref {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SafeCref( const char* cookie, const char* connName, HostID hid,
|
SafeCref( const char* cookie, const char* connName, HostID hid,
|
||||||
int socket, int nPlayersH, int nPlayersT,
|
int socket, int nPlayersH, int nPlayersS,
|
||||||
unsigned short gameSeed );
|
unsigned short gameSeed );
|
||||||
SafeCref( CookieID cid, bool failOk = false );
|
SafeCref( CookieID cid, bool failOk = false );
|
||||||
SafeCref( int socket );
|
SafeCref( int socket );
|
||||||
|
@ -182,19 +183,19 @@ class SafeCref {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Connect( int socket, HostID srcID, int nPlayersH, int nPlayersT,
|
bool Connect( int socket, HostID srcID, int nPlayersH, int nPlayersS,
|
||||||
int seed ) {
|
int seed ) {
|
||||||
if ( IsValid() ) {
|
if ( IsValid() ) {
|
||||||
m_cref->_Connect( socket, srcID, nPlayersH, nPlayersT, seed );
|
m_cref->_Connect( socket, srcID, nPlayersH, nPlayersS, seed );
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Reconnect( int socket, HostID srcID, int nPlayersH, int nPlayersT,
|
bool Reconnect( int socket, HostID srcID, int nPlayersH, int nPlayersS,
|
||||||
int seed ) {
|
int seed ) {
|
||||||
if ( IsValid() ) {
|
if ( IsValid() ) {
|
||||||
m_cref->_Reconnect( socket, srcID, nPlayersH, nPlayersT, seed );
|
m_cref->_Reconnect( socket, srcID, nPlayersH, nPlayersS, seed );
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue