diff --git a/xwords4/relay/cref.cpp b/xwords4/relay/cref.cpp index 39778ca86..65ec65932 100644 --- a/xwords4/relay/cref.cpp +++ b/xwords4/relay/cref.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #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::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; diff --git a/xwords4/relay/cref.h b/xwords4/relay/cref.h index e3890b639..b12a3d9bc 100644 --- a/xwords4/relay/cref.h +++ b/xwords4/relay/cref.h @@ -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 */ diff --git a/xwords4/relay/crefmgr.cpp b/xwords4/relay/crefmgr.cpp index 55b3e808f..3e9a791db 100644 --- a/xwords4/relay/crefmgr.cpp +++ b/xwords4/relay/crefmgr.cpp @@ -20,6 +20,8 @@ #include #include +#include +#include #include #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() ) diff --git a/xwords4/relay/crefmgr.h b/xwords4/relay/crefmgr.h index 5f5b1b33f..9d347f255 100644 --- a/xwords4/relay/crefmgr.h +++ b/xwords4/relay/crefmgr.h @@ -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; diff --git a/xwords4/relay/ctrl.cpp b/xwords4/relay/ctrl.cpp index 319bef00f..f57db0d5d 100644 --- a/xwords4/relay/ctrl.cpp +++ b/xwords4/relay/ctrl.cpp @@ -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; diff --git a/xwords4/relay/lstnrmgr.cpp b/xwords4/relay/lstnrmgr.cpp index dc7b6efe8..bbfa9623c 100644 --- a/xwords4/relay/lstnrmgr.cpp +++ b/xwords4/relay/lstnrmgr.cpp @@ -23,6 +23,8 @@ #include #include +#include + #include "lstnrmgr.h" #include "mlock.h" diff --git a/xwords4/relay/lstnrmgr.h b/xwords4/relay/lstnrmgr.h index 9416e2383..8960a28e3 100644 --- a/xwords4/relay/lstnrmgr.h +++ b/xwords4/relay/lstnrmgr.h @@ -24,6 +24,8 @@ #include #include #include +#include + #include "xwrelay_priv.h" using namespace std; diff --git a/xwords4/relay/mlock.h b/xwords4/relay/mlock.h index 9e9af3224..6813a4522 100644 --- a/xwords4/relay/mlock.h +++ b/xwords4/relay/mlock.h @@ -76,7 +76,7 @@ class SocketWriteLock { } } - int socketFound() { return (int)(m_mutex != NULL); } + bool socketFound() { return (m_mutex != NULL); } private: int m_socket; diff --git a/xwords4/relay/permid.cpp b/xwords4/relay/permid.cpp index 7bb23bc85..5bf9647d2 100644 --- a/xwords4/relay/permid.cpp +++ b/xwords4/relay/permid.cpp @@ -21,6 +21,7 @@ #include "permid.h" #include +#include #include #include "mlock.h" diff --git a/xwords4/relay/timermgr.cpp b/xwords4/relay/timermgr.cpp index e6720189f..69e55f88d 100644 --- a/xwords4/relay/timermgr.cpp +++ b/xwords4/relay/timermgr.cpp @@ -84,18 +84,18 @@ TimerMgr::GetPollTimeout() return tout; } /* GetPollTimeout */ -int +bool TimerMgr::getTimer( TimerProc proc, void* closure ) { list::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 diff --git a/xwords4/relay/timermgr.h b/xwords4/relay/timermgr.h index 52137d47b..745242046 100644 --- a/xwords4/relay/timermgr.h +++ b/xwords4/relay/timermgr.h @@ -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; diff --git a/xwords4/relay/tpool.cpp b/xwords4/relay/tpool.cpp index ce2d0d486..b3e17a5c8 100644 --- a/xwords4/relay/tpool.cpp +++ b/xwords4/relay/tpool.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include #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::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; diff --git a/xwords4/relay/tpool.h b/xwords4/relay/tpool.h index 62e331a8e..cdc9cbf2e 100644 --- a/xwords4/relay/tpool.h +++ b/xwords4/relay/tpool.h @@ -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(); diff --git a/xwords4/relay/xwrelay.cpp b/xwords4/relay/xwrelay.cpp index 16dab5223..eddeb87a8 100644 --- a/xwords4/relay/xwrelay.cpp +++ b/xwords4/relay/xwrelay.cpp @@ -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) ); diff --git a/xwords4/relay/xwrelay_priv.h b/xwords4/relay/xwrelay_priv.h index 4d44d4326..60ed6a2ca 100644 --- a/xwords4/relay/xwrelay_priv.h +++ b/xwords4/relay/xwrelay_priv.h @@ -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();