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