replace int with bool where appropriate; fix to compile with newer g++

This commit is contained in:
ehouse 2008-12-30 05:13:30 +00:00
parent cefd69d8b3
commit ea6fff8f28
15 changed files with 131 additions and 117 deletions

View file

@ -25,6 +25,7 @@
#include <netinet/in.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "cref.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
whether to admit a connection based on its cookie -- whether that cookie
should join an existing cref or get a new one? */
int
bool
CookieRef::NeverFullyConnected()
{
return m_curState != XWS_ALLCONNECTED
&& m_curState != XWS_MISSING;
}
int
bool
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? */
if ( m_curState != XWS_INITED
@ -197,9 +198,9 @@ CookieRef::AcceptingReconnections( HostID hid, int nPlayersH, int nPlayersT )
/* do nothing: reject */
} else {
if ( m_nPlayersTotal == 0 ) {
accept = 1;
accept = true;
} else if ( nPlayersH + m_nPlayersHere <= m_nPlayersTotal ) {
accept = 1;
accept = true;
} else {
logf( XW_LOGINFO, "reject: m_nPlayersTotal=%d, m_nPlayersHere=%d",
m_nPlayersTotal, m_nPlayersHere );
@ -246,15 +247,15 @@ CookieRef::removeSocket( int socket )
}
} /* removeSocket */
int
bool
CookieRef::HasSocket( int socket )
{
int found = 0;
bool found = false;
map<HostID,HostRec>::iterator iter = m_sockets.begin();
while ( iter != m_sockets.end() ) {
if ( iter->second.m_socket == socket ) {
found = 1;
found = true;
break;
}
++iter;
@ -577,7 +578,7 @@ CookieRef::checkCounts( const CRefEvent* evt )
int nPlayersH = evt->u.con.nPlayersH;
/* int nPlayersT = evt->u.con.nPlayersT; */
HostID hid = evt->u.con.srcID;
int success;
bool success;
logf( XW_LOGVERBOSE1, "checkCounts: hid=%d, nPlayers=%d, m_nPlayersTotal = %d, "
"m_nPlayersHere = %d",
@ -617,7 +618,7 @@ CookieRef::cancelAllConnectedTimer()
}
void
CookieRef::sendResponse( const CRefEvent* evt, int initial )
CookieRef::sendResponse( const CRefEvent* evt, bool initial )
{
int socket = evt->u.con.socket;
HostID id = evt->u.con.srcID;
@ -713,7 +714,7 @@ CookieRef::notifyOthers( int socket, XWRelayMsg msg, XWREASON why )
} /* notifyOthers */
void
CookieRef::sendAllHere( int includeName )
CookieRef::sendAllHere( bool includeName )
{
unsigned char buf[1 + 1 + MAX_CONNNAME_LEN];
unsigned char* bufp = buf;

View file

@ -66,17 +66,17 @@ class CookieRef {
If the hostID is HOST_ID_SERVER, it's the server. */
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 HasSocket( int socket );
bool HasSocket( int socket );
const char* Cookie() { return m_cookie.c_str(); }
const char* ConnName() { return m_connName.c_str(); }
short GetHeartbeat() { return m_heatbeat; }
int SocketForHost( HostID dest );
int NeverFullyConnected();
int AcceptingReconnections( HostID hid, int nPlayersH, int nPlayersT );
bool NeverFullyConnected();
bool AcceptingReconnections( HostID hid, int nPlayersH, int nPlayersT );
/* for console */
void _PrintCookieInfo( string& out );
@ -98,7 +98,7 @@ class CookieRef {
void _Remove( int socket );
void _CheckAllConnected();
int ShouldDie() { return m_curState == XWS_DEAD; }
bool ShouldDie() { return m_curState == XWS_DEAD; }
void logf( XW_LogLevel level, const char* format, ... );
@ -161,7 +161,7 @@ class CookieRef {
void handleEvents();
void sendResponse( const CRefEvent* evt, int initial );
void sendResponse( const CRefEvent* evt, bool initial );
void increasePlayerCounts( const CRefEvent* evt );
void reducePlayerCounts( int socket );
void checkCounts( const CRefEvent* evt );
@ -177,7 +177,7 @@ class CookieRef {
void noteHeartbeat(const CRefEvent* evt);
void notifyDisconn(const CRefEvent* evt);
void removeSocket( int socket );
void sendAllHere( int includeName );
void sendAllHere( bool includeName );
HostID nextHostID() { return ++m_nextHostID; }
/* timer callback */

View file

@ -20,6 +20,8 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include "crefmgr.h"
@ -90,7 +92,7 @@ CRefMgr::CloseAll()
} /* CloseAll */
CookieRef*
CRefMgr::FindOpenGameFor( const char* cORn, int isCookie,
CRefMgr::FindOpenGameFor( const char* cORn, bool isCookie,
HostID hid, int nPlayersH, int nPlayersT )
{
logf( XW_LOGINFO, "FindOpenGameFor with %s", cORn );
@ -151,7 +153,7 @@ CRefMgr::cookieIDForConnName( const char* connName )
} /* cookieIDForConnName */
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 )
{
CookieRef* cref;
@ -328,10 +330,10 @@ CRefMgr::getCookieRef_locked( int socket )
return cref;
} /* getCookieRef_locked */
int
bool
CRefMgr::checkCookieRef_locked( CookieRef* cref )
{
int exists = 1;
bool exists = true;
assert( cref != NULL );
#ifdef DEBUG_LOCKS
@ -350,13 +352,13 @@ CRefMgr::checkCookieRef_locked( CookieRef* cref )
logf( XW_LOGINFO, "ULM %p", &m_guard );
#endif
pthread_mutex_unlock( &m_guard );
exists = 0;
exists = false;
}
return exists;
} /* checkCookieRef_locked */
int
bool
CRefMgr::LockCref( CookieRef* cref )
{
/* assertion: m_guard is locked */
@ -379,7 +381,7 @@ CRefMgr::LockCref( CookieRef* cref )
logf( XW_LOGINFO, "ULM %p", &m_guard );
#endif
pthread_mutex_unlock( &m_guard );
return 1;
return true;
} /* LockCref */
void
@ -514,9 +516,9 @@ CRefMgr::checkHeartbeats( time_t now )
}
}
unsigned int i;
for ( i = 0; i < crefs.size(); ++i ) {
SafeCref scr( crefs[i] );
unsigned int ii;
for ( ii = 0; ii < crefs.size(); ++ii ) {
SafeCref scr( crefs[ii] );
scr.CheckHeartbeats( now );
}
} /* checkHeartbeats */
@ -551,7 +553,7 @@ CookieMapIterator::Next()
// SafeCref
//////////////////////////////////////////////////////////////////////////////
SafeCref::SafeCref( const char* cORn, int isCookie, HostID hid,
SafeCref::SafeCref( const char* cORn, bool isCookie, HostID hid,
int nPlayersH, int nPlayersT )
: m_cref( NULL )
, m_mgr( CRefMgr::Get() )

View file

@ -78,15 +78,15 @@ class CRefMgr {
private:
friend class SafeCref;
CookieRef* getMakeCookieRef_locked( const char* cORn, int isCookie,
CookieRef* getMakeCookieRef_locked( const char* cORn, bool isCookie,
HostID hid,
int nPlayersH, int nPlayersT );
CookieRef* getCookieRef_locked( CookieID cookieID );
CookieRef* getCookieRef_locked( int socket );
int checkCookieRef_locked( CookieRef* cref );
bool checkCookieRef_locked( CookieRef* cref );
CookieRef* getCookieRef_impl( CookieID cookieID );
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 );
CookieID cookieIDForConnName( const char* connName );
@ -97,7 +97,7 @@ class CRefMgr {
CookieID m_nextCID;
int LockCref( CookieRef* cref );
bool LockCref( CookieRef* cref );
void UnlockCref( CookieRef* cref );
pthread_mutex_t m_guard;
@ -119,35 +119,35 @@ class SafeCref {
CookieRef instance at a time. */
public:
SafeCref( const char* cookieOrConnName, int cookie, HostID hid,
SafeCref( const char* cookieOrConnName, bool cookie, HostID hid,
int nPlayersH, int nPlayersT );
SafeCref( CookieID cid );
SafeCref( int socket );
SafeCref( CookieRef* cref );
~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() ) {
m_cref->_Forward( src, dest, buf, buflen );
return 1;
return true;
} 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() ) {
m_cref->_Connect( socket, srcID, nPlayersH, nPlayersT );
return 1;
return true;
} 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() ) {
m_cref->_Reconnect( socket, srcID, nPlayersH, nPlayersT );
return 1;
return true;
} else {
return 0;
return false;
}
}
void Disconnect(int socket, HostID hostID ) {
@ -167,12 +167,12 @@ class SafeCref {
}
#ifdef RELAY_HEARTBEAT
int HandleHeartbeat( HostID id, int socket ) {
bool HandleHeartbeat( HostID id, int socket ) {
if ( IsValid() ) {
m_cref->_HandleHeartbeat( id, socket );
return 1;
return true
} else {
return 0;
return false;
}
}
void CheckHeartbeats( time_t now ) {
@ -209,7 +209,7 @@ class SafeCref {
private:
int IsValid() { return m_cref != NULL; }
bool IsValid() { return m_cref != NULL; }
CookieRef* m_cref;
CRefMgr* m_mgr;

View file

@ -82,11 +82,11 @@ match( string* cmd, const char * const* first, int incr, int count )
int nFound = 0;
const char* cmdFound = NULL;
int which = -1;
int i;
for ( i = 0; (i < count) && (nFound <= 1); ++i ) {
int ii;
for ( ii = 0; (ii < count) && (nFound <= 1); ++ii ) {
if ( 0 == strncmp( cmd->c_str(), *first, cmdlen ) ) {
++nFound;
which = i;
which = ii;
cmdFound = *first;
}
first = (char* const*)(((char*)first) + incr);
@ -181,14 +181,14 @@ cmd_stop( int socket, const char** args )
static bool
cmd_kill_eject( int socket, const char** args )
{
int found = 0;
bool found = false;
int isKill = 0 == strcmp( args[0], "kill" );
if ( 0 == strcmp( args[1], "socket" ) ) {
int victim = atoi( args[2] );
if ( victim != 0 ) {
killSocket( victim, "ctrl command" );
found = 1;
found = true;
}
} else if ( 0 == strcmp( args[1], "cref" ) ) {
const char* idhow = args[2];
@ -196,10 +196,10 @@ cmd_kill_eject( int socket, const char** args )
if ( idhow != NULL && id != NULL ) {
if ( 0 == strcmp( idhow, "name" ) ) {
CRefMgr::Get()->Delete( id );
found = 1;
found = true;
} else if ( 0 == strcmp( idhow, "id" ) ) {
CRefMgr::Get()->Delete( atoi( id ) );
found = 1;
found = true;
}
}
} else if ( 0 == strcmp( args[1], "relay" ) ) {
@ -372,9 +372,9 @@ cmd_crash( int socket, const char** args )
args[0] );
} else {
assert(0);
int i = 1;
while ( i > 0 ) --i;
return 6/i > 0;
int ii = 1;
while ( ii > 0 ) --ii;
return 6/ii > 0;
}
return false;
}
@ -435,28 +435,28 @@ static bool
cmd_print( int socket, const char** args )
{
logf( XW_LOGINFO, "cmd_print called" );
int found = 0;
bool found = false;
if ( 0 == strcmp( "cref", args[1] ) ) {
if ( 0 == strcmp( "all", args[2] ) ) {
print_cookies( socket, (CookieID)0 );
found = 1;
found = true;
} else if ( 0 == strcmp( "cookie", args[2] ) ) {
print_cookies( socket, args[3], NULL );
found = 1;
found = true;
} else if ( 0 == strcmp( "connName", args[2] ) ) {
print_cookies( socket, NULL, args[3] );
found = 1;
found = true;
} else if ( 0 == strcmp( "id", args[2] ) ) {
print_cookies( socket, atoi(args[3]) );
found = 1;
found = true;
}
} else if ( 0 == strcmp( "socket", args[1] ) ) {
if ( 0 == strcmp( "all", args[2] ) ) {
print_sockets( socket, 0 );
found = 1;
found = true;
} else if ( 0 == strcmp( "id", args[2] ) ) {
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,
args[0], args[0], args[0], args[0], args[0], args[0] );
}
return 0;
return false;
} /* cmd_print */
static bool
@ -540,7 +540,8 @@ ctrl_thread_main( void* arg )
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]) );
const char* args[] = {
cmd.c_str(),
@ -549,7 +550,8 @@ ctrl_thread_main( void* arg )
arg3.c_str()
};
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 );
} else if ( (*gFuncs[index].func)( sock, args ) ) {
break;

View file

@ -23,6 +23,8 @@
#include <netinet/in.h>
#include <assert.h>
#include <algorithm>
#include "lstnrmgr.h"
#include "mlock.h"

View file

@ -24,6 +24,8 @@
#include <string>
#include <vector>
#include <map>
#include <sys/select.h>
#include "xwrelay_priv.h"
using namespace std;

View file

@ -76,7 +76,7 @@ class SocketWriteLock {
}
}
int socketFound() { return (int)(m_mutex != NULL); }
bool socketFound() { return (m_mutex != NULL); }
private:
int m_socket;

View file

@ -21,6 +21,7 @@
#include "permid.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "mlock.h"

View file

@ -84,18 +84,18 @@ TimerMgr::GetPollTimeout()
return tout;
} /* GetPollTimeout */
int
bool
TimerMgr::getTimer( TimerProc proc, void* closure )
{
list<TimerInfo>::iterator iter;
for ( iter = m_timers.begin(); iter != m_timers.end(); ++iter ) {
if ( (*iter).proc == proc
&& (*iter).closure == closure ) {
return 1;
return true;
}
}
return 0;
return false;
} /* getTimer */
void

View file

@ -59,7 +59,7 @@ class TimerMgr {
/* run once we have the mutex */
void clearTimerImpl( TimerProc proc, void* closure );
int getTimer( TimerProc proc, void* closure );
bool getTimer( TimerProc proc, void* closure );
void figureNextFire();
pthread_mutex_t m_timersMutex;

View file

@ -27,6 +27,8 @@
#include <netinet/in.h>
#include <sys/poll.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include "tpool.h"
#include "xwrelay_priv.h"
@ -80,8 +82,8 @@ XWThreadPool::Setup( int nThreads, packet_func pFunc )
pthread_t thread;
int i;
for ( i = 0; i < nThreads; ++i ) {
int ii;
for ( ii = 0; ii < nThreads; ++ii ) {
int result = pthread_create( &thread, NULL, tpool_main, this );
assert( result == 0 );
pthread_detach( thread );
@ -96,8 +98,8 @@ XWThreadPool::Stop()
{
m_timeToDie = 1;
int i;
for ( i = 0; i < m_nThreads; ++i ) {
int ii;
for ( ii = 0; ii < m_nThreads; ++ii ) {
enqueue( 0 );
}
@ -115,10 +117,10 @@ XWThreadPool::AddSocket( int socket )
interrupt_poll();
}
int
bool
XWThreadPool::RemoveSocket( int socket )
{
int found = 0;
bool found = false;
{
RWWriteLock ml( &m_activeSocketsRWLock );
@ -126,7 +128,7 @@ XWThreadPool::RemoveSocket( int socket )
while ( iter != m_activeSockets.end() ) {
if ( *iter == socket ) {
m_activeSockets.erase( iter );
found = 1;
found = true;
break;
}
++iter;
@ -138,14 +140,14 @@ XWThreadPool::RemoveSocket( int socket )
void
XWThreadPool::CloseSocket( int socket )
{
int do_interrupt = 0;
/* bool do_interrupt = false; */
if ( !RemoveSocket( socket ) ) {
RWWriteLock rwl( &m_activeSocketsRWLock );
deque<int>::iterator iter = m_queue.begin();
while ( iter != m_queue.end() ) {
if ( *iter == socket ) {
m_queue.erase( iter );
do_interrupt = 1;
/* do_interrupt = true; */
break;
}
++iter;
@ -161,7 +163,7 @@ XWThreadPool::CloseSocket( int socket )
/* } */
}
int
bool
XWThreadPool::get_process_packet( int socket )
{
short packetSize;
@ -171,25 +173,25 @@ XWThreadPool::get_process_packet( int socket )
sizeof(packetSize), MSG_WAITALL );
if ( nRead != 2 ) {
killSocket( socket, "nRead != 2" );
return 0;
return false;
}
packetSize = ntohs( packetSize );
if ( packetSize < 0 || packetSize > MAX_MSG_LEN ) {
killSocket( socket, "packetSize wrong" );
return 0;
return false;
}
unsigned char buf[MAX_MSG_LEN];
nRead = recv( socket, buf, packetSize, MSG_WAITALL );
if ( nRead != packetSize ) {
killSocket( socket, "nRead != packetSize" );
return 0;
return false;
}
logf( XW_LOGINFO, "read %d bytes\n", nRead );
logf( XW_LOGINFO, "calling m_pFunc" );
int success = (*m_pFunc)( buf, packetSize, socket );
bool success = (*m_pFunc)( buf, packetSize, socket );
return success;
} /* get_process_packet */
@ -297,8 +299,8 @@ XWThreadPool::real_listener()
--nSockets;
curfd = &fds[1];
int i;
for ( i = 0; i < nSockets && nEvents > 0; ++i ) {
int ii;
for ( ii = 0; ii < nSockets && nEvents > 0; ++ii ) {
if ( curfd->revents != 0 ) {
int socket = curfd->fd;

View file

@ -35,7 +35,7 @@ class XWThreadPool {
public:
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();
@ -52,10 +52,10 @@ class XWThreadPool {
private:
/* Remove from set being listened on */
int RemoveSocket( int socket );
bool RemoveSocket( int socket );
void enqueue( int socket );
int get_process_packet( int socket );
bool get_process_packet( int socket );
void interrupt_poll();
void* real_tpool_main();

View file

@ -114,10 +114,10 @@ logf( XW_LogLevel level, const char* format, ... )
}
} /* logf */
static int
static bool
getNetShort( unsigned char** bufpp, unsigned char* end, unsigned short* out )
{
int ok = *bufpp + 2 <= end;
bool ok = *bufpp + 2 <= end;
if ( ok ) {
unsigned short tmp;
memcpy( &tmp, *bufpp, 2 );
@ -127,10 +127,10 @@ getNetShort( unsigned char** bufpp, unsigned char* end, unsigned short* out )
return ok;
} /* getNetShort */
static int
static bool
getNetByte( unsigned char** bufpp, unsigned char* end, unsigned char* out )
{
int ok = *bufpp < end;
bool ok = *bufpp < end;
if ( ok ) {
*out = **bufpp;
++*bufpp;
@ -139,13 +139,13 @@ getNetByte( unsigned char** bufpp, unsigned char* end, unsigned char* out )
} /* getNetByte */
#ifdef RELAY_HEARTBEAT
static int
static bool
processHeartbeat( unsigned char* buf, int bufLen, int socket )
{
unsigned char* end = buf + bufLen;
CookieID cookieID;
HostID hostID;
int success = 0;
bool success = false;
if ( getNetShort( &buf, end, &cookieID )
&& getNetByte( &buf, end, &hostID ) ) {
@ -162,7 +162,7 @@ processHeartbeat( unsigned char* buf, int bufLen, int socket )
} /* processHeartbeat */
#endif
static int
static bool
readStr( unsigned char** bufp, const unsigned char* end,
char* outBuf, int bufLen )
{
@ -172,9 +172,9 @@ readStr( unsigned char** bufp, const unsigned char* end,
memcpy( outBuf, *bufp, clen );
outBuf[clen] = '\0';
*bufp += clen;
return 1;
return true;
}
return 0;
return false;
} /* readStr */
static XWREASON
@ -197,17 +197,17 @@ denyConnection( int socket, XWREASON err )
/* No mutex here. Caller better be ensuring no other thread can access this
* socket. */
int
bool
send_with_length_unsafe( int socket, unsigned char* buf, int bufLen )
{
int ok = 0;
bool ok = false;
unsigned short len = htons( bufLen );
ssize_t nSent = send( socket, &len, 2, 0 );
if ( nSent == 2 ) {
nSent = send( socket, buf, bufLen, 0 );
if ( nSent == bufLen ) {
logf( XW_LOGINFO, "sent %d bytes on socket %d", nSent, socket );
ok = 1;
ok = true;
}
}
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
* game?
*/
static int
static bool
processConnect( unsigned char* bufp, int bufLen, int socket )
{
char cookie[MAX_COOKIE_LEN+1];
unsigned char* end = bufp + bufLen;
int success = 0;
bool success = false;
logf( XW_LOGINFO, "processConnect" );
@ -260,11 +260,11 @@ processConnect( unsigned char* bufp, int bufLen, int socket )
return success;
} /* processConnect */
static int
static bool
processReconnect( unsigned char* bufp, int bufLen, int socket )
{
unsigned char* end = bufp + bufLen;
int success = 0;
bool success = false;
logf( XW_LOGINFO, "processReconnect" );
@ -295,20 +295,20 @@ processReconnect( unsigned char* bufp, int bufLen, int socket )
return success;
} /* processReconnect */
static int
static bool
processDisconnect( unsigned char* bufp, int bufLen, int socket )
{
unsigned char* end = bufp + bufLen;
CookieID cookieID;
HostID hostID;
int success = 0;
bool success = false;
if ( getNetShort( &bufp, end, &cookieID )
&& getNetByte( &bufp, end, &hostID ) ) {
SafeCref scr( cookieID );
scr.Disconnect( socket, hostID );
success = 1;
success = true;
} else {
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
* socket and it's ready to go. */
static int
static bool
forwardMessage( unsigned char* buf, int buflen, int srcSocket )
{
int success = 0;
bool success = false;
unsigned char* bufp = buf + 1; /* skip cmd */
unsigned char* end = buf + buflen;
CookieID cookieID;
@ -356,10 +356,10 @@ forwardMessage( unsigned char* buf, int buflen, int srcSocket )
return success;
} /* forwardMessage */
static int
static bool
processMessage( unsigned char* buf, int bufLen, int socket )
{
int success = 0; /* default is failure */
bool success = false; /* default is failure */
XWRELAY_Cmd cmd = *buf;
switch( cmd ) {
case XWRELAY_GAME_CONNECT:
@ -512,7 +512,8 @@ parentDied( int sig )
exit(0);
}
int main( int argc, char** argv )
int
main( int argc, char** argv )
{
int port = 0;
int ctrlport = 0;
@ -711,7 +712,8 @@ int main( int argc, char** argv )
if ( FD_ISSET( listener, &rfds ) ) {
struct sockaddr_in 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",
inet_ntoa(newaddr.sin_addr) );

View file

@ -19,7 +19,7 @@ void logf( XW_LogLevel level, const char* format, ... );
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();