mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
cleanup ctrl printing; repeat most recent command; cleanup internal names.
This commit is contained in:
parent
57fb57a1e5
commit
be6769a937
6 changed files with 61 additions and 38 deletions
|
@ -70,7 +70,7 @@ SocketsIterator::Next()
|
|||
|
||||
CookieRef::CookieRef( const char* cookie, const char* connName, CookieID id )
|
||||
: m_heatbeat(RelayConfigs::GetConfigs()->GetHeartbeatInterval())
|
||||
, m_name(cookie==NULL?"":cookie)
|
||||
, m_cookie(cookie==NULL?"":cookie)
|
||||
, m_connName(connName)
|
||||
, m_cookieID(id)
|
||||
, m_totalSent(0)
|
||||
|
@ -780,19 +780,24 @@ CookieRef::_CheckAllConnected()
|
|||
void
|
||||
CookieRef::_PrintCookieInfo( string& out )
|
||||
{
|
||||
out += "Name: ";
|
||||
out += Name();
|
||||
out += "Cookie=";
|
||||
out += Cookie();
|
||||
out += "\n";
|
||||
out += "ID: ";
|
||||
out += "connName=";
|
||||
char buf[MAX_CONNNAME_LEN+MAX_COOKIE_LEN];
|
||||
|
||||
snprintf( buf, sizeof(buf), "%s\n", Name() );
|
||||
out += buf;
|
||||
|
||||
snprintf( buf, sizeof(buf), "%s\n", ConnName() );
|
||||
out += buf;
|
||||
|
||||
snprintf( buf, sizeof(buf), "Bytes sent: %d\n", m_totalSent );
|
||||
snprintf( buf, sizeof(buf), "id=%d\n", GetCookieID() );
|
||||
out += buf;
|
||||
|
||||
snprintf( buf, sizeof(buf), "Bytes sent=%d\n", m_totalSent );
|
||||
out += buf;
|
||||
|
||||
snprintf( buf, sizeof(buf), "Total players=%d\n", m_nPlayersTotal );
|
||||
out += buf;
|
||||
snprintf( buf, sizeof(buf), "Players here=%d\n", m_nPlayersHere );
|
||||
out += buf;
|
||||
|
||||
/* n messages */
|
||||
|
|
|
@ -69,7 +69,7 @@ class CookieRef {
|
|||
int HostKnown( HostID host ) { return -1 != SocketForHost( host ); }
|
||||
int CountSockets() { return m_sockets.size(); }
|
||||
int HasSocket( int socket );
|
||||
const char* Name() { return m_name.c_str(); }
|
||||
const char* Cookie() { return m_cookie.c_str(); }
|
||||
const char* ConnName() { return m_connName.c_str(); }
|
||||
|
||||
short GetHeartbeat() { return m_heatbeat; }
|
||||
|
@ -185,7 +185,7 @@ class CookieRef {
|
|||
/* pthread_rwlock_t m_sockets_rwlock; */
|
||||
|
||||
short m_heatbeat; /* might change per carrier or something. */
|
||||
string m_name; /* cookie used for initial connections */
|
||||
string m_cookie; /* cookie used for initial connections */
|
||||
string m_connName; /* globally unique name */
|
||||
CookieID m_cookieID; /* Unique among current games on this server */
|
||||
int m_totalSent;
|
||||
|
|
|
@ -74,7 +74,7 @@ CRefMgr::FindOpenGameFor( const char* cORn, int isCookie,
|
|||
while ( iter != m_cookieMap.end() ) {
|
||||
cref = iter->second;
|
||||
if ( isCookie ) {
|
||||
if ( 0 == strcmp( cref->Name(), cORn ) ) {
|
||||
if ( 0 == strcmp( cref->Cookie(), cORn ) ) {
|
||||
if ( cref->NeverFullyConnected() ) {
|
||||
break;
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ void
|
|||
CRefMgr::PrintSocketInfo( int socket, string& out )
|
||||
{
|
||||
SafeCref scr( socket );
|
||||
const char* name = scr.Name();
|
||||
const char* name = scr.Cookie();
|
||||
if ( name != NULL && name[0] != '\0' ) {
|
||||
char buf[64];
|
||||
|
||||
|
|
|
@ -181,9 +181,16 @@ class SafeCref {
|
|||
m_cref->_CheckAllConnected();
|
||||
}
|
||||
}
|
||||
const char* Name() {
|
||||
const char* Cookie() {
|
||||
if ( IsValid() ) {
|
||||
return m_cref->Name();
|
||||
return m_cref->Cookie();
|
||||
} else {
|
||||
return ""; /* so don't crash.... */
|
||||
}
|
||||
}
|
||||
const char* ConnName() {
|
||||
if ( IsValid() ) {
|
||||
return m_cref->ConnName();
|
||||
} else {
|
||||
return ""; /* so don't crash.... */
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ cmd_kill_eject( int socket, const char** args )
|
|||
killSocket( victim, "ctrl command" );
|
||||
found = 1;
|
||||
}
|
||||
} else if ( 0 == strcmp( args[1], "cookie" ) ) {
|
||||
} else if ( 0 == strcmp( args[1], "cref" ) ) {
|
||||
const char* idhow = args[2];
|
||||
const char* id = args[3];
|
||||
if ( idhow != NULL && id != NULL ) {
|
||||
|
@ -170,8 +170,8 @@ cmd_kill_eject( int socket, const char** args )
|
|||
if ( !found ) {
|
||||
char* msg =
|
||||
"* %s socket <num> -- %s\n"
|
||||
" %s cookie name <connName>\n"
|
||||
" %s cookie id <id>"
|
||||
" %s cref connName <connName>\n"
|
||||
" %s cref id <id>"
|
||||
;
|
||||
print_to_sock( socket, 1, msg, args[0], expl, args[0], args[0] );
|
||||
}
|
||||
|
@ -205,19 +205,25 @@ cmd_shutdown( int socket, const char** args )
|
|||
}
|
||||
|
||||
static void
|
||||
print_cookies( int socket, const char* name )
|
||||
print_cookies( int socket, const char* cookie, const char* connName )
|
||||
{
|
||||
CookieMapIterator iter = CRefMgr::Get()->GetCookieIterator();
|
||||
CookieID id;
|
||||
|
||||
for ( id = iter.Next(); id != 0; id = iter.Next() ) {
|
||||
SafeCref scr( id );
|
||||
if ( scr.Name() == name ) {
|
||||
string s;
|
||||
scr.PrintCookieInfo( s );
|
||||
|
||||
print_to_sock( socket, 1, s.c_str() );
|
||||
if ( cookie != NULL && 0 == strcmp( scr.Cookie(), cookie ) ) {
|
||||
/* print this one */
|
||||
} else if ( connName != NULL &&
|
||||
0 == strcmp( scr.ConnName(), connName ) ) {
|
||||
/* print this one */
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
string s;
|
||||
scr.PrintCookieInfo( s );
|
||||
|
||||
print_to_sock( socket, 1, s.c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,12 +252,15 @@ cmd_print( int socket, const char** args )
|
|||
{
|
||||
logf( XW_LOGINFO, "cmd_print called" );
|
||||
int found = 0;
|
||||
if ( 0 == strcmp( "cookie", args[1] ) ) {
|
||||
if ( 0 == strcmp( "cref", args[1] ) ) {
|
||||
if ( 0 == strcmp( "all", args[2] ) ) {
|
||||
print_cookies( socket, (CookieID)0 );
|
||||
found = 1;
|
||||
} else if ( 0 == strcmp( "name", args[2] ) ) {
|
||||
print_cookies( socket, args[3] );
|
||||
} else if ( 0 == strcmp( "cookie", args[2] ) ) {
|
||||
print_cookies( socket, args[3], NULL );
|
||||
found = 1;
|
||||
} else if ( 0 == strcmp( "connName", args[2] ) ) {
|
||||
print_cookies( socket, NULL, args[3] );
|
||||
found = 1;
|
||||
} else if ( 0 == strcmp( "id", args[2] ) ) {
|
||||
print_cookies( socket, atoi(args[3]) );
|
||||
|
@ -269,11 +278,12 @@ cmd_print( int socket, const char** args )
|
|||
|
||||
if ( !found ) {
|
||||
char* str =
|
||||
"* %s cookie all\n"
|
||||
" %s cookie name <name>\n"
|
||||
" %s cookie id <id>\n"
|
||||
"* %s cref all\n"
|
||||
" %s cref name <name>\n"
|
||||
" %s cref connName <name>\n"
|
||||
" %s cref id <id>\n"
|
||||
" %s socket all\n"
|
||||
" %s socket <num> -- print info about cookies and sockets";
|
||||
" %s socket <num> -- print info about crefs and sockets";
|
||||
print_to_sock( socket, 1, str,
|
||||
args[0], args[0], args[0], args[0], args[0] );
|
||||
}
|
||||
|
@ -346,22 +356,23 @@ static void*
|
|||
ctrl_thread_main( void* arg )
|
||||
{
|
||||
int socket = (int)arg;
|
||||
string arg0, arg1, arg2, arg3;
|
||||
|
||||
for ( ; ; ) {
|
||||
print_prompt( socket );
|
||||
|
||||
char buf[512];
|
||||
ssize_t nGot = recv( socket, buf, sizeof(buf)-1, 0 );
|
||||
logf( XW_LOGINFO, "nGot=%d", nGot );
|
||||
if ( nGot <= 1 ) { /* break when just \n comes in */
|
||||
break;
|
||||
} else if ( nGot > 2 ) {
|
||||
/* if nGot is 2, reuse prev string */
|
||||
buf[nGot] = '\0';
|
||||
istringstream cmd( buf );
|
||||
cmd >> arg0 >> arg1 >> arg2 >> arg3;
|
||||
}
|
||||
|
||||
buf[nGot] = '\0';
|
||||
|
||||
string arg0, arg1, arg2, arg3;
|
||||
istringstream cmd( buf );
|
||||
cmd >> arg0 >> arg1 >> arg2 >> arg3;
|
||||
|
||||
const char* args[] = {
|
||||
arg0.c_str(),
|
||||
arg1.c_str(),
|
||||
|
|
|
@ -244,8 +244,8 @@ XWThreadPool::real_listener()
|
|||
|
||||
int nMillis = tmgr->GetPollTimeout();
|
||||
|
||||
logf( XW_LOGINFO, "polling %s", log );
|
||||
int nEvents = poll( fds, nSockets, nMillis ); /* -1: infinite timeout */
|
||||
logf( XW_LOGINFO, "polling %s nmillis=%d", log, nMillis );
|
||||
int nEvents = poll( fds, nSockets, nMillis );
|
||||
logf( XW_LOGINFO, "back from poll: %d", nEvents );
|
||||
if ( nEvents == 0 ) {
|
||||
tmgr->FireElapsedTimers();
|
||||
|
|
Loading…
Reference in a new issue