mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-31 19:57:06 +01:00
replace int with bool where appropriate; fix to compile with newer g++
This commit is contained in:
parent
cefd69d8b3
commit
ea6fff8f28
15 changed files with 131 additions and 117 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "cref.h"
|
#include "cref.h"
|
||||||
#include "xwrelay.h"
|
#include "xwrelay.h"
|
||||||
|
@ -174,17 +175,17 @@ CookieRef::SocketForHost( HostID dest )
|
||||||
recovery back to XW_ST_ALLCONNECTED is possible. This is used to decide
|
recovery back to XW_ST_ALLCONNECTED is possible. This is used to decide
|
||||||
whether to admit a connection based on its cookie -- whether that cookie
|
whether to admit a connection based on its cookie -- whether that cookie
|
||||||
should join an existing cref or get a new one? */
|
should join an existing cref or get a new one? */
|
||||||
int
|
bool
|
||||||
CookieRef::NeverFullyConnected()
|
CookieRef::NeverFullyConnected()
|
||||||
{
|
{
|
||||||
return m_curState != XWS_ALLCONNECTED
|
return m_curState != XWS_ALLCONNECTED
|
||||||
&& m_curState != XWS_MISSING;
|
&& m_curState != XWS_MISSING;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
bool
|
||||||
CookieRef::AcceptingReconnections( HostID hid, int nPlayersH, int nPlayersT )
|
CookieRef::AcceptingReconnections( HostID hid, int nPlayersH, int nPlayersT )
|
||||||
{
|
{
|
||||||
int accept = 0;
|
bool accept = false;
|
||||||
/* First, do we have room. Second, are we missing this guy? */
|
/* First, do we have room. Second, are we missing this guy? */
|
||||||
|
|
||||||
if ( m_curState != XWS_INITED
|
if ( m_curState != XWS_INITED
|
||||||
|
@ -197,9 +198,9 @@ CookieRef::AcceptingReconnections( HostID hid, int nPlayersH, int nPlayersT )
|
||||||
/* do nothing: reject */
|
/* do nothing: reject */
|
||||||
} else {
|
} else {
|
||||||
if ( m_nPlayersTotal == 0 ) {
|
if ( m_nPlayersTotal == 0 ) {
|
||||||
accept = 1;
|
accept = true;
|
||||||
} else if ( nPlayersH + m_nPlayersHere <= m_nPlayersTotal ) {
|
} else if ( nPlayersH + m_nPlayersHere <= m_nPlayersTotal ) {
|
||||||
accept = 1;
|
accept = true;
|
||||||
} else {
|
} else {
|
||||||
logf( XW_LOGINFO, "reject: m_nPlayersTotal=%d, m_nPlayersHere=%d",
|
logf( XW_LOGINFO, "reject: m_nPlayersTotal=%d, m_nPlayersHere=%d",
|
||||||
m_nPlayersTotal, m_nPlayersHere );
|
m_nPlayersTotal, m_nPlayersHere );
|
||||||
|
@ -246,15 +247,15 @@ CookieRef::removeSocket( int socket )
|
||||||
}
|
}
|
||||||
} /* removeSocket */
|
} /* removeSocket */
|
||||||
|
|
||||||
int
|
bool
|
||||||
CookieRef::HasSocket( int socket )
|
CookieRef::HasSocket( int socket )
|
||||||
{
|
{
|
||||||
int found = 0;
|
bool found = false;
|
||||||
|
|
||||||
map<HostID,HostRec>::iterator iter = m_sockets.begin();
|
map<HostID,HostRec>::iterator iter = m_sockets.begin();
|
||||||
while ( iter != m_sockets.end() ) {
|
while ( iter != m_sockets.end() ) {
|
||||||
if ( iter->second.m_socket == socket ) {
|
if ( iter->second.m_socket == socket ) {
|
||||||
found = 1;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -577,7 +578,7 @@ CookieRef::checkCounts( const CRefEvent* evt )
|
||||||
int nPlayersH = evt->u.con.nPlayersH;
|
int nPlayersH = evt->u.con.nPlayersH;
|
||||||
/* int nPlayersT = evt->u.con.nPlayersT; */
|
/* int nPlayersT = evt->u.con.nPlayersT; */
|
||||||
HostID hid = evt->u.con.srcID;
|
HostID hid = evt->u.con.srcID;
|
||||||
int success;
|
bool success;
|
||||||
|
|
||||||
logf( XW_LOGVERBOSE1, "checkCounts: hid=%d, nPlayers=%d, m_nPlayersTotal = %d, "
|
logf( XW_LOGVERBOSE1, "checkCounts: hid=%d, nPlayers=%d, m_nPlayersTotal = %d, "
|
||||||
"m_nPlayersHere = %d",
|
"m_nPlayersHere = %d",
|
||||||
|
@ -617,7 +618,7 @@ CookieRef::cancelAllConnectedTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::sendResponse( const CRefEvent* evt, int initial )
|
CookieRef::sendResponse( const CRefEvent* evt, bool initial )
|
||||||
{
|
{
|
||||||
int socket = evt->u.con.socket;
|
int socket = evt->u.con.socket;
|
||||||
HostID id = evt->u.con.srcID;
|
HostID id = evt->u.con.srcID;
|
||||||
|
@ -713,7 +714,7 @@ CookieRef::notifyOthers( int socket, XWRelayMsg msg, XWREASON why )
|
||||||
} /* notifyOthers */
|
} /* notifyOthers */
|
||||||
|
|
||||||
void
|
void
|
||||||
CookieRef::sendAllHere( int includeName )
|
CookieRef::sendAllHere( bool includeName )
|
||||||
{
|
{
|
||||||
unsigned char buf[1 + 1 + MAX_CONNNAME_LEN];
|
unsigned char buf[1 + 1 + MAX_CONNNAME_LEN];
|
||||||
unsigned char* bufp = buf;
|
unsigned char* bufp = buf;
|
||||||
|
|
|
@ -66,17 +66,17 @@ class CookieRef {
|
||||||
If the hostID is HOST_ID_SERVER, it's the server. */
|
If the hostID is HOST_ID_SERVER, it's the server. */
|
||||||
CookieID GetCookieID() { return m_cookieID; }
|
CookieID GetCookieID() { return m_cookieID; }
|
||||||
|
|
||||||
int HostKnown( HostID host ) { return -1 != SocketForHost( host ); }
|
bool HostKnown( HostID host ) { return -1 != SocketForHost( host ); }
|
||||||
int CountSockets() { return m_sockets.size(); }
|
int CountSockets() { return m_sockets.size(); }
|
||||||
int HasSocket( int socket );
|
bool HasSocket( int socket );
|
||||||
const char* Cookie() { return m_cookie.c_str(); }
|
const char* Cookie() { return m_cookie.c_str(); }
|
||||||
const char* ConnName() { return m_connName.c_str(); }
|
const char* ConnName() { return m_connName.c_str(); }
|
||||||
|
|
||||||
short GetHeartbeat() { return m_heatbeat; }
|
short GetHeartbeat() { return m_heatbeat; }
|
||||||
int SocketForHost( HostID dest );
|
int SocketForHost( HostID dest );
|
||||||
|
|
||||||
int NeverFullyConnected();
|
bool NeverFullyConnected();
|
||||||
int AcceptingReconnections( HostID hid, int nPlayersH, int nPlayersT );
|
bool AcceptingReconnections( HostID hid, int nPlayersH, int nPlayersT );
|
||||||
|
|
||||||
/* for console */
|
/* for console */
|
||||||
void _PrintCookieInfo( string& out );
|
void _PrintCookieInfo( string& out );
|
||||||
|
@ -98,7 +98,7 @@ class CookieRef {
|
||||||
void _Remove( int socket );
|
void _Remove( int socket );
|
||||||
void _CheckAllConnected();
|
void _CheckAllConnected();
|
||||||
|
|
||||||
int ShouldDie() { return m_curState == XWS_DEAD; }
|
bool ShouldDie() { return m_curState == XWS_DEAD; }
|
||||||
|
|
||||||
void logf( XW_LogLevel level, const char* format, ... );
|
void logf( XW_LogLevel level, const char* format, ... );
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ class CookieRef {
|
||||||
|
|
||||||
void handleEvents();
|
void handleEvents();
|
||||||
|
|
||||||
void sendResponse( const CRefEvent* evt, int initial );
|
void sendResponse( const CRefEvent* evt, bool initial );
|
||||||
void increasePlayerCounts( const CRefEvent* evt );
|
void increasePlayerCounts( const CRefEvent* evt );
|
||||||
void reducePlayerCounts( int socket );
|
void reducePlayerCounts( int socket );
|
||||||
void checkCounts( const CRefEvent* evt );
|
void checkCounts( const CRefEvent* evt );
|
||||||
|
@ -177,7 +177,7 @@ class CookieRef {
|
||||||
void noteHeartbeat(const CRefEvent* evt);
|
void noteHeartbeat(const CRefEvent* evt);
|
||||||
void notifyDisconn(const CRefEvent* evt);
|
void notifyDisconn(const CRefEvent* evt);
|
||||||
void removeSocket( int socket );
|
void removeSocket( int socket );
|
||||||
void sendAllHere( int includeName );
|
void sendAllHere( bool includeName );
|
||||||
|
|
||||||
HostID nextHostID() { return ++m_nextHostID; }
|
HostID nextHostID() { return ++m_nextHostID; }
|
||||||
/* timer callback */
|
/* timer callback */
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "crefmgr.h"
|
#include "crefmgr.h"
|
||||||
|
@ -90,7 +92,7 @@ CRefMgr::CloseAll()
|
||||||
} /* CloseAll */
|
} /* CloseAll */
|
||||||
|
|
||||||
CookieRef*
|
CookieRef*
|
||||||
CRefMgr::FindOpenGameFor( const char* cORn, int isCookie,
|
CRefMgr::FindOpenGameFor( const char* cORn, bool isCookie,
|
||||||
HostID hid, int nPlayersH, int nPlayersT )
|
HostID hid, int nPlayersH, int nPlayersT )
|
||||||
{
|
{
|
||||||
logf( XW_LOGINFO, "FindOpenGameFor with %s", cORn );
|
logf( XW_LOGINFO, "FindOpenGameFor with %s", cORn );
|
||||||
|
@ -151,7 +153,7 @@ CRefMgr::cookieIDForConnName( const char* connName )
|
||||||
} /* cookieIDForConnName */
|
} /* cookieIDForConnName */
|
||||||
|
|
||||||
CookieRef*
|
CookieRef*
|
||||||
CRefMgr::getMakeCookieRef_locked( const char* cORn, int isCookie, HostID hid,
|
CRefMgr::getMakeCookieRef_locked( const char* cORn, bool isCookie, HostID hid,
|
||||||
int nPlayersH, int nPlayersT )
|
int nPlayersH, int nPlayersT )
|
||||||
{
|
{
|
||||||
CookieRef* cref;
|
CookieRef* cref;
|
||||||
|
@ -328,10 +330,10 @@ CRefMgr::getCookieRef_locked( int socket )
|
||||||
return cref;
|
return cref;
|
||||||
} /* getCookieRef_locked */
|
} /* getCookieRef_locked */
|
||||||
|
|
||||||
int
|
bool
|
||||||
CRefMgr::checkCookieRef_locked( CookieRef* cref )
|
CRefMgr::checkCookieRef_locked( CookieRef* cref )
|
||||||
{
|
{
|
||||||
int exists = 1;
|
bool exists = true;
|
||||||
assert( cref != NULL );
|
assert( cref != NULL );
|
||||||
|
|
||||||
#ifdef DEBUG_LOCKS
|
#ifdef DEBUG_LOCKS
|
||||||
|
@ -350,13 +352,13 @@ CRefMgr::checkCookieRef_locked( CookieRef* cref )
|
||||||
logf( XW_LOGINFO, "ULM %p", &m_guard );
|
logf( XW_LOGINFO, "ULM %p", &m_guard );
|
||||||
#endif
|
#endif
|
||||||
pthread_mutex_unlock( &m_guard );
|
pthread_mutex_unlock( &m_guard );
|
||||||
exists = 0;
|
exists = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return exists;
|
return exists;
|
||||||
} /* checkCookieRef_locked */
|
} /* checkCookieRef_locked */
|
||||||
|
|
||||||
int
|
bool
|
||||||
CRefMgr::LockCref( CookieRef* cref )
|
CRefMgr::LockCref( CookieRef* cref )
|
||||||
{
|
{
|
||||||
/* assertion: m_guard is locked */
|
/* assertion: m_guard is locked */
|
||||||
|
@ -379,7 +381,7 @@ CRefMgr::LockCref( CookieRef* cref )
|
||||||
logf( XW_LOGINFO, "ULM %p", &m_guard );
|
logf( XW_LOGINFO, "ULM %p", &m_guard );
|
||||||
#endif
|
#endif
|
||||||
pthread_mutex_unlock( &m_guard );
|
pthread_mutex_unlock( &m_guard );
|
||||||
return 1;
|
return true;
|
||||||
} /* LockCref */
|
} /* LockCref */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -514,9 +516,9 @@ CRefMgr::checkHeartbeats( time_t now )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int ii;
|
||||||
for ( i = 0; i < crefs.size(); ++i ) {
|
for ( ii = 0; ii < crefs.size(); ++ii ) {
|
||||||
SafeCref scr( crefs[i] );
|
SafeCref scr( crefs[ii] );
|
||||||
scr.CheckHeartbeats( now );
|
scr.CheckHeartbeats( now );
|
||||||
}
|
}
|
||||||
} /* checkHeartbeats */
|
} /* checkHeartbeats */
|
||||||
|
@ -551,7 +553,7 @@ CookieMapIterator::Next()
|
||||||
// SafeCref
|
// SafeCref
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
SafeCref::SafeCref( const char* cORn, int isCookie, HostID hid,
|
SafeCref::SafeCref( const char* cORn, bool isCookie, HostID hid,
|
||||||
int nPlayersH, int nPlayersT )
|
int nPlayersH, int nPlayersT )
|
||||||
: m_cref( NULL )
|
: m_cref( NULL )
|
||||||
, m_mgr( CRefMgr::Get() )
|
, m_mgr( CRefMgr::Get() )
|
||||||
|
|
|
@ -78,15 +78,15 @@ class CRefMgr {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class SafeCref;
|
friend class SafeCref;
|
||||||
CookieRef* getMakeCookieRef_locked( const char* cORn, int isCookie,
|
CookieRef* getMakeCookieRef_locked( const char* cORn, bool isCookie,
|
||||||
HostID hid,
|
HostID hid,
|
||||||
int nPlayersH, int nPlayersT );
|
int nPlayersH, int nPlayersT );
|
||||||
CookieRef* getCookieRef_locked( CookieID cookieID );
|
CookieRef* getCookieRef_locked( CookieID cookieID );
|
||||||
CookieRef* getCookieRef_locked( int socket );
|
CookieRef* getCookieRef_locked( int socket );
|
||||||
int checkCookieRef_locked( CookieRef* cref );
|
bool checkCookieRef_locked( CookieRef* cref );
|
||||||
CookieRef* getCookieRef_impl( CookieID cookieID );
|
CookieRef* getCookieRef_impl( CookieID cookieID );
|
||||||
CookieRef* AddNew( const char* cookie, const char* connName, CookieID id );
|
CookieRef* AddNew( const char* cookie, const char* connName, CookieID id );
|
||||||
CookieRef* FindOpenGameFor( const char* cORn, int isCookie,
|
CookieRef* FindOpenGameFor( const char* cORn, bool isCookie,
|
||||||
HostID hid, int nPlayersH, int nPlayersT );
|
HostID hid, int nPlayersH, int nPlayersT );
|
||||||
|
|
||||||
CookieID cookieIDForConnName( const char* connName );
|
CookieID cookieIDForConnName( const char* connName );
|
||||||
|
@ -97,7 +97,7 @@ class CRefMgr {
|
||||||
|
|
||||||
CookieID m_nextCID;
|
CookieID m_nextCID;
|
||||||
|
|
||||||
int LockCref( CookieRef* cref );
|
bool LockCref( CookieRef* cref );
|
||||||
void UnlockCref( CookieRef* cref );
|
void UnlockCref( CookieRef* cref );
|
||||||
|
|
||||||
pthread_mutex_t m_guard;
|
pthread_mutex_t m_guard;
|
||||||
|
@ -119,35 +119,35 @@ class SafeCref {
|
||||||
CookieRef instance at a time. */
|
CookieRef instance at a time. */
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SafeCref( const char* cookieOrConnName, int cookie, HostID hid,
|
SafeCref( const char* cookieOrConnName, bool cookie, HostID hid,
|
||||||
int nPlayersH, int nPlayersT );
|
int nPlayersH, int nPlayersT );
|
||||||
SafeCref( CookieID cid );
|
SafeCref( CookieID cid );
|
||||||
SafeCref( int socket );
|
SafeCref( int socket );
|
||||||
SafeCref( CookieRef* cref );
|
SafeCref( CookieRef* cref );
|
||||||
~SafeCref();
|
~SafeCref();
|
||||||
|
|
||||||
int Forward( HostID src, HostID dest, unsigned char* buf, int buflen ) {
|
bool Forward( HostID src, HostID dest, unsigned char* buf, int buflen ) {
|
||||||
if ( IsValid() ) {
|
if ( IsValid() ) {
|
||||||
m_cref->_Forward( src, dest, buf, buflen );
|
m_cref->_Forward( src, dest, buf, buflen );
|
||||||
return 1;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int Connect( int socket, HostID srcID, int nPlayersH, int nPlayersT ) {
|
bool Connect( int socket, HostID srcID, int nPlayersH, int nPlayersT ) {
|
||||||
if ( IsValid() ) {
|
if ( IsValid() ) {
|
||||||
m_cref->_Connect( socket, srcID, nPlayersH, nPlayersT );
|
m_cref->_Connect( socket, srcID, nPlayersH, nPlayersT );
|
||||||
return 1;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int Reconnect( int socket, HostID srcID, int nPlayersH, int nPlayersT ) {
|
bool Reconnect( int socket, HostID srcID, int nPlayersH, int nPlayersT ) {
|
||||||
if ( IsValid() ) {
|
if ( IsValid() ) {
|
||||||
m_cref->_Reconnect( socket, srcID, nPlayersH, nPlayersT );
|
m_cref->_Reconnect( socket, srcID, nPlayersH, nPlayersT );
|
||||||
return 1;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Disconnect(int socket, HostID hostID ) {
|
void Disconnect(int socket, HostID hostID ) {
|
||||||
|
@ -167,12 +167,12 @@ class SafeCref {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RELAY_HEARTBEAT
|
#ifdef RELAY_HEARTBEAT
|
||||||
int HandleHeartbeat( HostID id, int socket ) {
|
bool HandleHeartbeat( HostID id, int socket ) {
|
||||||
if ( IsValid() ) {
|
if ( IsValid() ) {
|
||||||
m_cref->_HandleHeartbeat( id, socket );
|
m_cref->_HandleHeartbeat( id, socket );
|
||||||
return 1;
|
return true
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void CheckHeartbeats( time_t now ) {
|
void CheckHeartbeats( time_t now ) {
|
||||||
|
@ -209,7 +209,7 @@ class SafeCref {
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int IsValid() { return m_cref != NULL; }
|
bool IsValid() { return m_cref != NULL; }
|
||||||
|
|
||||||
CookieRef* m_cref;
|
CookieRef* m_cref;
|
||||||
CRefMgr* m_mgr;
|
CRefMgr* m_mgr;
|
||||||
|
|
|
@ -82,11 +82,11 @@ match( string* cmd, const char * const* first, int incr, int count )
|
||||||
int nFound = 0;
|
int nFound = 0;
|
||||||
const char* cmdFound = NULL;
|
const char* cmdFound = NULL;
|
||||||
int which = -1;
|
int which = -1;
|
||||||
int i;
|
int ii;
|
||||||
for ( i = 0; (i < count) && (nFound <= 1); ++i ) {
|
for ( ii = 0; (ii < count) && (nFound <= 1); ++ii ) {
|
||||||
if ( 0 == strncmp( cmd->c_str(), *first, cmdlen ) ) {
|
if ( 0 == strncmp( cmd->c_str(), *first, cmdlen ) ) {
|
||||||
++nFound;
|
++nFound;
|
||||||
which = i;
|
which = ii;
|
||||||
cmdFound = *first;
|
cmdFound = *first;
|
||||||
}
|
}
|
||||||
first = (char* const*)(((char*)first) + incr);
|
first = (char* const*)(((char*)first) + incr);
|
||||||
|
@ -181,14 +181,14 @@ cmd_stop( int socket, const char** args )
|
||||||
static bool
|
static bool
|
||||||
cmd_kill_eject( int socket, const char** args )
|
cmd_kill_eject( int socket, const char** args )
|
||||||
{
|
{
|
||||||
int found = 0;
|
bool found = false;
|
||||||
int isKill = 0 == strcmp( args[0], "kill" );
|
int isKill = 0 == strcmp( args[0], "kill" );
|
||||||
|
|
||||||
if ( 0 == strcmp( args[1], "socket" ) ) {
|
if ( 0 == strcmp( args[1], "socket" ) ) {
|
||||||
int victim = atoi( args[2] );
|
int victim = atoi( args[2] );
|
||||||
if ( victim != 0 ) {
|
if ( victim != 0 ) {
|
||||||
killSocket( victim, "ctrl command" );
|
killSocket( victim, "ctrl command" );
|
||||||
found = 1;
|
found = true;
|
||||||
}
|
}
|
||||||
} else if ( 0 == strcmp( args[1], "cref" ) ) {
|
} else if ( 0 == strcmp( args[1], "cref" ) ) {
|
||||||
const char* idhow = args[2];
|
const char* idhow = args[2];
|
||||||
|
@ -196,10 +196,10 @@ cmd_kill_eject( int socket, const char** args )
|
||||||
if ( idhow != NULL && id != NULL ) {
|
if ( idhow != NULL && id != NULL ) {
|
||||||
if ( 0 == strcmp( idhow, "name" ) ) {
|
if ( 0 == strcmp( idhow, "name" ) ) {
|
||||||
CRefMgr::Get()->Delete( id );
|
CRefMgr::Get()->Delete( id );
|
||||||
found = 1;
|
found = true;
|
||||||
} else if ( 0 == strcmp( idhow, "id" ) ) {
|
} else if ( 0 == strcmp( idhow, "id" ) ) {
|
||||||
CRefMgr::Get()->Delete( atoi( id ) );
|
CRefMgr::Get()->Delete( atoi( id ) );
|
||||||
found = 1;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( 0 == strcmp( args[1], "relay" ) ) {
|
} else if ( 0 == strcmp( args[1], "relay" ) ) {
|
||||||
|
@ -372,9 +372,9 @@ cmd_crash( int socket, const char** args )
|
||||||
args[0] );
|
args[0] );
|
||||||
} else {
|
} else {
|
||||||
assert(0);
|
assert(0);
|
||||||
int i = 1;
|
int ii = 1;
|
||||||
while ( i > 0 ) --i;
|
while ( ii > 0 ) --ii;
|
||||||
return 6/i > 0;
|
return 6/ii > 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -435,28 +435,28 @@ static bool
|
||||||
cmd_print( int socket, const char** args )
|
cmd_print( int socket, const char** args )
|
||||||
{
|
{
|
||||||
logf( XW_LOGINFO, "cmd_print called" );
|
logf( XW_LOGINFO, "cmd_print called" );
|
||||||
int found = 0;
|
bool found = false;
|
||||||
if ( 0 == strcmp( "cref", args[1] ) ) {
|
if ( 0 == strcmp( "cref", args[1] ) ) {
|
||||||
if ( 0 == strcmp( "all", args[2] ) ) {
|
if ( 0 == strcmp( "all", args[2] ) ) {
|
||||||
print_cookies( socket, (CookieID)0 );
|
print_cookies( socket, (CookieID)0 );
|
||||||
found = 1;
|
found = true;
|
||||||
} else if ( 0 == strcmp( "cookie", args[2] ) ) {
|
} else if ( 0 == strcmp( "cookie", args[2] ) ) {
|
||||||
print_cookies( socket, args[3], NULL );
|
print_cookies( socket, args[3], NULL );
|
||||||
found = 1;
|
found = true;
|
||||||
} else if ( 0 == strcmp( "connName", args[2] ) ) {
|
} else if ( 0 == strcmp( "connName", args[2] ) ) {
|
||||||
print_cookies( socket, NULL, args[3] );
|
print_cookies( socket, NULL, args[3] );
|
||||||
found = 1;
|
found = true;
|
||||||
} else if ( 0 == strcmp( "id", args[2] ) ) {
|
} else if ( 0 == strcmp( "id", args[2] ) ) {
|
||||||
print_cookies( socket, atoi(args[3]) );
|
print_cookies( socket, atoi(args[3]) );
|
||||||
found = 1;
|
found = true;
|
||||||
}
|
}
|
||||||
} else if ( 0 == strcmp( "socket", args[1] ) ) {
|
} else if ( 0 == strcmp( "socket", args[1] ) ) {
|
||||||
if ( 0 == strcmp( "all", args[2] ) ) {
|
if ( 0 == strcmp( "all", args[2] ) ) {
|
||||||
print_sockets( socket, 0 );
|
print_sockets( socket, 0 );
|
||||||
found = 1;
|
found = true;
|
||||||
} else if ( 0 == strcmp( "id", args[2] ) ) {
|
} else if ( 0 == strcmp( "id", args[2] ) ) {
|
||||||
print_sockets( socket, atoi(args[3]) );
|
print_sockets( socket, atoi(args[3]) );
|
||||||
found = 1;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,7 +471,7 @@ cmd_print( int socket, const char** args )
|
||||||
print_to_sock( socket, true, str,
|
print_to_sock( socket, true, str,
|
||||||
args[0], args[0], args[0], args[0], args[0], args[0] );
|
args[0], args[0], args[0], args[0], args[0], args[0] );
|
||||||
}
|
}
|
||||||
return 0;
|
return false;
|
||||||
} /* cmd_print */
|
} /* cmd_print */
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
@ -540,7 +540,8 @@ ctrl_thread_main( void* arg )
|
||||||
s >> cmd >> arg1 >> arg2 >> arg3;
|
s >> cmd >> arg1 >> arg2 >> arg3;
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = match( &cmd, (char*const*)&gFuncs[0].name, sizeof(gFuncs[0]),
|
int index = match( &cmd, (char*const*)&gFuncs[0].name,
|
||||||
|
sizeof(gFuncs[0]),
|
||||||
sizeof(gFuncs)/sizeof(gFuncs[0]) );
|
sizeof(gFuncs)/sizeof(gFuncs[0]) );
|
||||||
const char* args[] = {
|
const char* args[] = {
|
||||||
cmd.c_str(),
|
cmd.c_str(),
|
||||||
|
@ -549,7 +550,8 @@ ctrl_thread_main( void* arg )
|
||||||
arg3.c_str()
|
arg3.c_str()
|
||||||
};
|
};
|
||||||
if ( index == -1 ) {
|
if ( index == -1 ) {
|
||||||
print_to_sock( sock, 1, "unknown or ambiguous command: \"%s\"", cmd.c_str() );
|
print_to_sock( sock, 1, "unknown or ambiguous command: \"%s\"",
|
||||||
|
cmd.c_str() );
|
||||||
(void)cmd_help( sock, args );
|
(void)cmd_help( sock, args );
|
||||||
} else if ( (*gFuncs[index].func)( sock, args ) ) {
|
} else if ( (*gFuncs[index].func)( sock, args ) ) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "lstnrmgr.h"
|
#include "lstnrmgr.h"
|
||||||
#include "mlock.h"
|
#include "mlock.h"
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <sys/select.h>
|
||||||
|
|
||||||
#include "xwrelay_priv.h"
|
#include "xwrelay_priv.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -76,7 +76,7 @@ class SocketWriteLock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int socketFound() { return (int)(m_mutex != NULL); }
|
bool socketFound() { return (m_mutex != NULL); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_socket;
|
int m_socket;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "permid.h"
|
#include "permid.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "mlock.h"
|
#include "mlock.h"
|
||||||
|
|
||||||
|
|
|
@ -84,18 +84,18 @@ TimerMgr::GetPollTimeout()
|
||||||
return tout;
|
return tout;
|
||||||
} /* GetPollTimeout */
|
} /* GetPollTimeout */
|
||||||
|
|
||||||
int
|
bool
|
||||||
TimerMgr::getTimer( TimerProc proc, void* closure )
|
TimerMgr::getTimer( TimerProc proc, void* closure )
|
||||||
{
|
{
|
||||||
list<TimerInfo>::iterator iter;
|
list<TimerInfo>::iterator iter;
|
||||||
for ( iter = m_timers.begin(); iter != m_timers.end(); ++iter ) {
|
for ( iter = m_timers.begin(); iter != m_timers.end(); ++iter ) {
|
||||||
if ( (*iter).proc == proc
|
if ( (*iter).proc == proc
|
||||||
&& (*iter).closure == closure ) {
|
&& (*iter).closure == closure ) {
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return false;
|
||||||
} /* getTimer */
|
} /* getTimer */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -59,7 +59,7 @@ class TimerMgr {
|
||||||
|
|
||||||
/* run once we have the mutex */
|
/* run once we have the mutex */
|
||||||
void clearTimerImpl( TimerProc proc, void* closure );
|
void clearTimerImpl( TimerProc proc, void* closure );
|
||||||
int getTimer( TimerProc proc, void* closure );
|
bool getTimer( TimerProc proc, void* closure );
|
||||||
void figureNextFire();
|
void figureNextFire();
|
||||||
|
|
||||||
pthread_mutex_t m_timersMutex;
|
pthread_mutex_t m_timersMutex;
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/poll.h>
|
#include <sys/poll.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "tpool.h"
|
#include "tpool.h"
|
||||||
#include "xwrelay_priv.h"
|
#include "xwrelay_priv.h"
|
||||||
|
@ -80,8 +82,8 @@ XWThreadPool::Setup( int nThreads, packet_func pFunc )
|
||||||
|
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
int i;
|
int ii;
|
||||||
for ( i = 0; i < nThreads; ++i ) {
|
for ( ii = 0; ii < nThreads; ++ii ) {
|
||||||
int result = pthread_create( &thread, NULL, tpool_main, this );
|
int result = pthread_create( &thread, NULL, tpool_main, this );
|
||||||
assert( result == 0 );
|
assert( result == 0 );
|
||||||
pthread_detach( thread );
|
pthread_detach( thread );
|
||||||
|
@ -96,8 +98,8 @@ XWThreadPool::Stop()
|
||||||
{
|
{
|
||||||
m_timeToDie = 1;
|
m_timeToDie = 1;
|
||||||
|
|
||||||
int i;
|
int ii;
|
||||||
for ( i = 0; i < m_nThreads; ++i ) {
|
for ( ii = 0; ii < m_nThreads; ++ii ) {
|
||||||
enqueue( 0 );
|
enqueue( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,10 +117,10 @@ XWThreadPool::AddSocket( int socket )
|
||||||
interrupt_poll();
|
interrupt_poll();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
bool
|
||||||
XWThreadPool::RemoveSocket( int socket )
|
XWThreadPool::RemoveSocket( int socket )
|
||||||
{
|
{
|
||||||
int found = 0;
|
bool found = false;
|
||||||
{
|
{
|
||||||
RWWriteLock ml( &m_activeSocketsRWLock );
|
RWWriteLock ml( &m_activeSocketsRWLock );
|
||||||
|
|
||||||
|
@ -126,7 +128,7 @@ XWThreadPool::RemoveSocket( int socket )
|
||||||
while ( iter != m_activeSockets.end() ) {
|
while ( iter != m_activeSockets.end() ) {
|
||||||
if ( *iter == socket ) {
|
if ( *iter == socket ) {
|
||||||
m_activeSockets.erase( iter );
|
m_activeSockets.erase( iter );
|
||||||
found = 1;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -138,14 +140,14 @@ XWThreadPool::RemoveSocket( int socket )
|
||||||
void
|
void
|
||||||
XWThreadPool::CloseSocket( int socket )
|
XWThreadPool::CloseSocket( int socket )
|
||||||
{
|
{
|
||||||
int do_interrupt = 0;
|
/* bool do_interrupt = false; */
|
||||||
if ( !RemoveSocket( socket ) ) {
|
if ( !RemoveSocket( socket ) ) {
|
||||||
RWWriteLock rwl( &m_activeSocketsRWLock );
|
RWWriteLock rwl( &m_activeSocketsRWLock );
|
||||||
deque<int>::iterator iter = m_queue.begin();
|
deque<int>::iterator iter = m_queue.begin();
|
||||||
while ( iter != m_queue.end() ) {
|
while ( iter != m_queue.end() ) {
|
||||||
if ( *iter == socket ) {
|
if ( *iter == socket ) {
|
||||||
m_queue.erase( iter );
|
m_queue.erase( iter );
|
||||||
do_interrupt = 1;
|
/* do_interrupt = true; */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -161,7 +163,7 @@ XWThreadPool::CloseSocket( int socket )
|
||||||
/* } */
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
bool
|
||||||
XWThreadPool::get_process_packet( int socket )
|
XWThreadPool::get_process_packet( int socket )
|
||||||
{
|
{
|
||||||
short packetSize;
|
short packetSize;
|
||||||
|
@ -171,25 +173,25 @@ XWThreadPool::get_process_packet( int socket )
|
||||||
sizeof(packetSize), MSG_WAITALL );
|
sizeof(packetSize), MSG_WAITALL );
|
||||||
if ( nRead != 2 ) {
|
if ( nRead != 2 ) {
|
||||||
killSocket( socket, "nRead != 2" );
|
killSocket( socket, "nRead != 2" );
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
packetSize = ntohs( packetSize );
|
packetSize = ntohs( packetSize );
|
||||||
if ( packetSize < 0 || packetSize > MAX_MSG_LEN ) {
|
if ( packetSize < 0 || packetSize > MAX_MSG_LEN ) {
|
||||||
killSocket( socket, "packetSize wrong" );
|
killSocket( socket, "packetSize wrong" );
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char buf[MAX_MSG_LEN];
|
unsigned char buf[MAX_MSG_LEN];
|
||||||
nRead = recv( socket, buf, packetSize, MSG_WAITALL );
|
nRead = recv( socket, buf, packetSize, MSG_WAITALL );
|
||||||
if ( nRead != packetSize ) {
|
if ( nRead != packetSize ) {
|
||||||
killSocket( socket, "nRead != packetSize" );
|
killSocket( socket, "nRead != packetSize" );
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
logf( XW_LOGINFO, "read %d bytes\n", nRead );
|
logf( XW_LOGINFO, "read %d bytes\n", nRead );
|
||||||
|
|
||||||
logf( XW_LOGINFO, "calling m_pFunc" );
|
logf( XW_LOGINFO, "calling m_pFunc" );
|
||||||
int success = (*m_pFunc)( buf, packetSize, socket );
|
bool success = (*m_pFunc)( buf, packetSize, socket );
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
} /* get_process_packet */
|
} /* get_process_packet */
|
||||||
|
@ -297,8 +299,8 @@ XWThreadPool::real_listener()
|
||||||
--nSockets;
|
--nSockets;
|
||||||
curfd = &fds[1];
|
curfd = &fds[1];
|
||||||
|
|
||||||
int i;
|
int ii;
|
||||||
for ( i = 0; i < nSockets && nEvents > 0; ++i ) {
|
for ( ii = 0; ii < nSockets && nEvents > 0; ++ii ) {
|
||||||
|
|
||||||
if ( curfd->revents != 0 ) {
|
if ( curfd->revents != 0 ) {
|
||||||
int socket = curfd->fd;
|
int socket = curfd->fd;
|
||||||
|
|
|
@ -35,7 +35,7 @@ class XWThreadPool {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static XWThreadPool* GetTPool();
|
static XWThreadPool* GetTPool();
|
||||||
typedef int (*packet_func)( unsigned char* buf, int bufLen, int socket );
|
typedef bool (*packet_func)( unsigned char* buf, int bufLen, int socket );
|
||||||
|
|
||||||
XWThreadPool();
|
XWThreadPool();
|
||||||
~XWThreadPool();
|
~XWThreadPool();
|
||||||
|
@ -52,10 +52,10 @@ class XWThreadPool {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Remove from set being listened on */
|
/* Remove from set being listened on */
|
||||||
int RemoveSocket( int socket );
|
bool RemoveSocket( int socket );
|
||||||
|
|
||||||
void enqueue( int socket );
|
void enqueue( int socket );
|
||||||
int get_process_packet( int socket );
|
bool get_process_packet( int socket );
|
||||||
void interrupt_poll();
|
void interrupt_poll();
|
||||||
|
|
||||||
void* real_tpool_main();
|
void* real_tpool_main();
|
||||||
|
|
|
@ -114,10 +114,10 @@ logf( XW_LogLevel level, const char* format, ... )
|
||||||
}
|
}
|
||||||
} /* logf */
|
} /* logf */
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
getNetShort( unsigned char** bufpp, unsigned char* end, unsigned short* out )
|
getNetShort( unsigned char** bufpp, unsigned char* end, unsigned short* out )
|
||||||
{
|
{
|
||||||
int ok = *bufpp + 2 <= end;
|
bool ok = *bufpp + 2 <= end;
|
||||||
if ( ok ) {
|
if ( ok ) {
|
||||||
unsigned short tmp;
|
unsigned short tmp;
|
||||||
memcpy( &tmp, *bufpp, 2 );
|
memcpy( &tmp, *bufpp, 2 );
|
||||||
|
@ -127,10 +127,10 @@ getNetShort( unsigned char** bufpp, unsigned char* end, unsigned short* out )
|
||||||
return ok;
|
return ok;
|
||||||
} /* getNetShort */
|
} /* getNetShort */
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
getNetByte( unsigned char** bufpp, unsigned char* end, unsigned char* out )
|
getNetByte( unsigned char** bufpp, unsigned char* end, unsigned char* out )
|
||||||
{
|
{
|
||||||
int ok = *bufpp < end;
|
bool ok = *bufpp < end;
|
||||||
if ( ok ) {
|
if ( ok ) {
|
||||||
*out = **bufpp;
|
*out = **bufpp;
|
||||||
++*bufpp;
|
++*bufpp;
|
||||||
|
@ -139,13 +139,13 @@ getNetByte( unsigned char** bufpp, unsigned char* end, unsigned char* out )
|
||||||
} /* getNetByte */
|
} /* getNetByte */
|
||||||
|
|
||||||
#ifdef RELAY_HEARTBEAT
|
#ifdef RELAY_HEARTBEAT
|
||||||
static int
|
static bool
|
||||||
processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
||||||
{
|
{
|
||||||
unsigned char* end = buf + bufLen;
|
unsigned char* end = buf + bufLen;
|
||||||
CookieID cookieID;
|
CookieID cookieID;
|
||||||
HostID hostID;
|
HostID hostID;
|
||||||
int success = 0;
|
bool success = false;
|
||||||
|
|
||||||
if ( getNetShort( &buf, end, &cookieID )
|
if ( getNetShort( &buf, end, &cookieID )
|
||||||
&& getNetByte( &buf, end, &hostID ) ) {
|
&& getNetByte( &buf, end, &hostID ) ) {
|
||||||
|
@ -162,7 +162,7 @@ processHeartbeat( unsigned char* buf, int bufLen, int socket )
|
||||||
} /* processHeartbeat */
|
} /* processHeartbeat */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
readStr( unsigned char** bufp, const unsigned char* end,
|
readStr( unsigned char** bufp, const unsigned char* end,
|
||||||
char* outBuf, int bufLen )
|
char* outBuf, int bufLen )
|
||||||
{
|
{
|
||||||
|
@ -172,9 +172,9 @@ readStr( unsigned char** bufp, const unsigned char* end,
|
||||||
memcpy( outBuf, *bufp, clen );
|
memcpy( outBuf, *bufp, clen );
|
||||||
outBuf[clen] = '\0';
|
outBuf[clen] = '\0';
|
||||||
*bufp += clen;
|
*bufp += clen;
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
return 0;
|
return false;
|
||||||
} /* readStr */
|
} /* readStr */
|
||||||
|
|
||||||
static XWREASON
|
static XWREASON
|
||||||
|
@ -197,17 +197,17 @@ denyConnection( int socket, XWREASON err )
|
||||||
|
|
||||||
/* No mutex here. Caller better be ensuring no other thread can access this
|
/* No mutex here. Caller better be ensuring no other thread can access this
|
||||||
* socket. */
|
* socket. */
|
||||||
int
|
bool
|
||||||
send_with_length_unsafe( int socket, unsigned char* buf, int bufLen )
|
send_with_length_unsafe( int socket, unsigned char* buf, int bufLen )
|
||||||
{
|
{
|
||||||
int ok = 0;
|
bool ok = false;
|
||||||
unsigned short len = htons( bufLen );
|
unsigned short len = htons( bufLen );
|
||||||
ssize_t nSent = send( socket, &len, 2, 0 );
|
ssize_t nSent = send( socket, &len, 2, 0 );
|
||||||
if ( nSent == 2 ) {
|
if ( nSent == 2 ) {
|
||||||
nSent = send( socket, buf, bufLen, 0 );
|
nSent = send( socket, buf, bufLen, 0 );
|
||||||
if ( nSent == bufLen ) {
|
if ( nSent == bufLen ) {
|
||||||
logf( XW_LOGINFO, "sent %d bytes on socket %d", nSent, socket );
|
logf( XW_LOGINFO, "sent %d bytes on socket %d", nSent, socket );
|
||||||
ok = 1;
|
ok = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
|
@ -225,12 +225,12 @@ send_with_length_unsafe( int socket, unsigned char* buf, int bufLen )
|
||||||
* outstanding. Otherwise close down the socket. And maybe the others in the
|
* outstanding. Otherwise close down the socket. And maybe the others in the
|
||||||
* game?
|
* game?
|
||||||
*/
|
*/
|
||||||
static int
|
static bool
|
||||||
processConnect( unsigned char* bufp, int bufLen, int socket )
|
processConnect( unsigned char* bufp, int bufLen, int socket )
|
||||||
{
|
{
|
||||||
char cookie[MAX_COOKIE_LEN+1];
|
char cookie[MAX_COOKIE_LEN+1];
|
||||||
unsigned char* end = bufp + bufLen;
|
unsigned char* end = bufp + bufLen;
|
||||||
int success = 0;
|
bool success = false;
|
||||||
|
|
||||||
logf( XW_LOGINFO, "processConnect" );
|
logf( XW_LOGINFO, "processConnect" );
|
||||||
|
|
||||||
|
@ -260,11 +260,11 @@ processConnect( unsigned char* bufp, int bufLen, int socket )
|
||||||
return success;
|
return success;
|
||||||
} /* processConnect */
|
} /* processConnect */
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
processReconnect( unsigned char* bufp, int bufLen, int socket )
|
processReconnect( unsigned char* bufp, int bufLen, int socket )
|
||||||
{
|
{
|
||||||
unsigned char* end = bufp + bufLen;
|
unsigned char* end = bufp + bufLen;
|
||||||
int success = 0;
|
bool success = false;
|
||||||
|
|
||||||
logf( XW_LOGINFO, "processReconnect" );
|
logf( XW_LOGINFO, "processReconnect" );
|
||||||
|
|
||||||
|
@ -295,20 +295,20 @@ processReconnect( unsigned char* bufp, int bufLen, int socket )
|
||||||
return success;
|
return success;
|
||||||
} /* processReconnect */
|
} /* processReconnect */
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
processDisconnect( unsigned char* bufp, int bufLen, int socket )
|
processDisconnect( unsigned char* bufp, int bufLen, int socket )
|
||||||
{
|
{
|
||||||
unsigned char* end = bufp + bufLen;
|
unsigned char* end = bufp + bufLen;
|
||||||
CookieID cookieID;
|
CookieID cookieID;
|
||||||
HostID hostID;
|
HostID hostID;
|
||||||
int success = 0;
|
bool success = false;
|
||||||
|
|
||||||
if ( getNetShort( &bufp, end, &cookieID )
|
if ( getNetShort( &bufp, end, &cookieID )
|
||||||
&& getNetByte( &bufp, end, &hostID ) ) {
|
&& getNetByte( &bufp, end, &hostID ) ) {
|
||||||
|
|
||||||
SafeCref scr( cookieID );
|
SafeCref scr( cookieID );
|
||||||
scr.Disconnect( socket, hostID );
|
scr.Disconnect( socket, hostID );
|
||||||
success = 1;
|
success = true;
|
||||||
} else {
|
} else {
|
||||||
logf( XW_LOGERROR, "dropping XWRELAY_GAME_DISCONNECT; wrong length" );
|
logf( XW_LOGERROR, "dropping XWRELAY_GAME_DISCONNECT; wrong length" );
|
||||||
}
|
}
|
||||||
|
@ -335,10 +335,10 @@ now()
|
||||||
|
|
||||||
/* forward the message. Need only change the command after looking up the
|
/* forward the message. Need only change the command after looking up the
|
||||||
* socket and it's ready to go. */
|
* socket and it's ready to go. */
|
||||||
static int
|
static bool
|
||||||
forwardMessage( unsigned char* buf, int buflen, int srcSocket )
|
forwardMessage( unsigned char* buf, int buflen, int srcSocket )
|
||||||
{
|
{
|
||||||
int success = 0;
|
bool success = false;
|
||||||
unsigned char* bufp = buf + 1; /* skip cmd */
|
unsigned char* bufp = buf + 1; /* skip cmd */
|
||||||
unsigned char* end = buf + buflen;
|
unsigned char* end = buf + buflen;
|
||||||
CookieID cookieID;
|
CookieID cookieID;
|
||||||
|
@ -356,10 +356,10 @@ forwardMessage( unsigned char* buf, int buflen, int srcSocket )
|
||||||
return success;
|
return success;
|
||||||
} /* forwardMessage */
|
} /* forwardMessage */
|
||||||
|
|
||||||
static int
|
static bool
|
||||||
processMessage( unsigned char* buf, int bufLen, int socket )
|
processMessage( unsigned char* buf, int bufLen, int socket )
|
||||||
{
|
{
|
||||||
int success = 0; /* default is failure */
|
bool success = false; /* default is failure */
|
||||||
XWRELAY_Cmd cmd = *buf;
|
XWRELAY_Cmd cmd = *buf;
|
||||||
switch( cmd ) {
|
switch( cmd ) {
|
||||||
case XWRELAY_GAME_CONNECT:
|
case XWRELAY_GAME_CONNECT:
|
||||||
|
@ -512,7 +512,8 @@ parentDied( int sig )
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char** argv )
|
int
|
||||||
|
main( int argc, char** argv )
|
||||||
{
|
{
|
||||||
int port = 0;
|
int port = 0;
|
||||||
int ctrlport = 0;
|
int ctrlport = 0;
|
||||||
|
@ -711,7 +712,8 @@ int main( int argc, char** argv )
|
||||||
if ( FD_ISSET( listener, &rfds ) ) {
|
if ( FD_ISSET( listener, &rfds ) ) {
|
||||||
struct sockaddr_in newaddr;
|
struct sockaddr_in newaddr;
|
||||||
socklen_t siz = sizeof(newaddr);
|
socklen_t siz = sizeof(newaddr);
|
||||||
int newSock = accept( listener, (sockaddr*)&newaddr, &siz );
|
int newSock = accept( listener, (sockaddr*)&newaddr,
|
||||||
|
&siz );
|
||||||
|
|
||||||
logf( XW_LOGINFO, "accepting connection from %s",
|
logf( XW_LOGINFO, "accepting connection from %s",
|
||||||
inet_ntoa(newaddr.sin_addr) );
|
inet_ntoa(newaddr.sin_addr) );
|
||||||
|
|
|
@ -19,7 +19,7 @@ void logf( XW_LogLevel level, const char* format, ... );
|
||||||
|
|
||||||
void killSocket( int socket, const char* why );
|
void killSocket( int socket, const char* why );
|
||||||
|
|
||||||
int send_with_length_unsafe( int socket, unsigned char* buf, int bufLen );
|
bool send_with_length_unsafe( int socket, unsigned char* buf, int bufLen );
|
||||||
|
|
||||||
time_t now();
|
time_t now();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue